package ls.graph.ui;
import java.awt.FlowLayout;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import ls.graph.script.Algorithm;
import ls.graph.script.AlgorithmListener;
public class ControlPanel extends JPanel implements AlgorithmListener
{
private static final long serialVersionUID = 1L;
MainWindow mainWindow = null;
private JButton btnExecute, btnExit, btnSave, btnLoad, btnStop,btnReset;
private StopAlgorithmAction stopAction = null;
// Algorithm currentAlgorithm = null;
ControlPanel(MainWindow mWindow)
{
super();
this.mainWindow = mWindow;
initComponents();
}
private void initComponents()
{
BoxLayout l = new BoxLayout(this,BoxLayout.Y_AXIS);
this.setLayout(l);
JPanel controlPane = new JPanel();
controlPane.setLayout(new FlowLayout());
btnExecute = new JButton(new ExecuteAction(this.mainWindow));
btnExit = new JButton(new ExitAction(this.mainWindow));
btnSave = new JButton(new SaveScriptAction(this.mainWindow, this.mainWindow));
btnLoad = new JButton(new LoadScriptAction(this.mainWindow, this.mainWindow));
stopAction = new StopAlgorithmAction();
btnStop = new JButton(stopAction);
btnStop.setEnabled(false); //starts disabled
btnReset = new JButton(
new ResetAlgorithmAction(this.mainWindow.getScriptEngine()));
btnReset.setEnabled(false);
controlPane.add(btnLoad);
controlPane.add(btnSave);
controlPane.add(btnExecute);
controlPane.add(btnStop);
controlPane.add(btnReset);
controlPane.add(btnExit);
this.add(controlPane);
this.add(this.mainWindow.createStatusPanel());
}
public void executionEnded(Algorithm alg)
{
btnSave.setEnabled(true);
btnLoad.setEnabled(true);
btnExecute.setEnabled(true);
btnExit.setEnabled(true);
btnStop.setEnabled(false);
btnReset.setEnabled(true);
stopAction.setAlgorithm(null);
}
public void executionStarted(Algorithm alg)
{
stopAction.setAlgorithm(alg);
btnSave.setEnabled(false);
btnLoad.setEnabled(false);
btnExecute.setEnabled(false);
btnExit.setEnabled(false);
btnStop.setEnabled(true);
btnReset.setEnabled(false);
}
public void startingStep(int stepIndex)
{}
} //end of ControlPanel class