import java.awt.BorderLayout;
import java.awt.Container;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

/**
 * @author David Matuszek
 * @version Apr 6, 2005
 */
public class RobotGui extends JFrame {
    private static final int ROWS = 12;
    private static final int COLUMNS = 15;
    
    Robot robby;
    JPanel controlPanel = new JPanel();
    JTextArea programArea = new JTextArea(20, 20);
    JScrollPane programPane = new JScrollPane(programArea);
    JButton loadButton = new JButton("Load");
    JButton saveButton = new JButton("Save");
    JButton initializeButton = new JButton("Initialize");
    JButton runButton = new JButton("Run");
    JButton pauseButton = new JButton("Pause");
    JButton stopButton = new JButton("Stop");
    private Board board;

    public static void main(String[] args) {
        new RobotGui().run();
        
    }

    /**
     * Creates the GUI and runs the program.
     */
    private void run() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        createGui();
        attachListeners();
        initialize();
        doRandomStuff();
    }

    /**
     * Creates the GUI for the Robot language, but does not
     * attach listeners to the buttons.
     */
    private void createGui() {
        board = new Board(ROWS, COLUMNS);
        Container pane = getContentPane();
        JPanel display = board.getJPanel();
        pane.add(display, BorderLayout.CENTER);
        pane.add(programPane, BorderLayout.EAST);
        pane.add(controlPanel, BorderLayout.SOUTH);
            controlPanel.add(loadButton);
            controlPanel.add(saveButton);
            controlPanel.add(new JLabel("          "));
            controlPanel.add(initializeButton);
            controlPanel.add(runButton);
            controlPanel.add(pauseButton);
            controlPanel.add(stopButton);
        pack();
        setSize(600, 400);
        setLocationRelativeTo(null);
        setVisible(true);
    }

    /**
     * Attaches listeners to each of the buttons.
     */
    private void attachListeners() {
        // TODO Auto-generated method stub
    }
    
    /**
     * Creates a Robot and puts in on the Board.
     */
    private void initialize() {
        robby = new Robot(ROWS, COLUMNS);
        board.place(robby, 0, 0);
    }

    /**
     * TODO Replace this method.
     * Does random things with the robot. This method should
     * be replaced by a method to interpret the Robot program
     * and tell the Robot what to do.
     */
    public void doRandomStuff() {
        for (int i = 0; i < 4; i++) {
            robby.forward(10);
            robby.turnRight();
        }
    }
}
