More intuitive tool bar buttons to start and stop the simulation.

This commit is contained in:
hneemann 2017-03-05 14:35:21 +01:00
parent 3f1f0b2fb0
commit 204f80aebd
5 changed files with 51 additions and 40 deletions

View File

@ -88,7 +88,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
private static final Icon ICON_MICRO = IconCreator.create("media-playback-start-2.png");
private static final Icon ICON_TEST = IconCreator.create("media-playback-start-T.png");
private static final Icon ICON_STEP = IconCreator.create("media-seek-forward.png");
private static final Icon ICON_ELEMENT = IconCreator.create("preferences-system.png");
private static final Icon ICON_STOP = IconCreator.create("media-playback-stop.png");
private static final Icon ICON_NEW = IconCreator.create("document-new.png");
private static final Icon ICON_OPEN = IconCreator.create("document-open.png");
private static final Icon ICON_OPEN_WIN = IconCreator.create("document-open-new.png");
@ -123,7 +123,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
private ModelCreator modelCreator;
private boolean realtimeClockRunning;
private State elementState;
private State stoppedState;
private RunModelState runModelState;
private State runModelMicroState;
@ -214,11 +214,8 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
toolBar.addSeparator();
ToolTipAction elementStateAction = elementState.createToolTipAction(Lang.get("menu_element"), ICON_ELEMENT).setToolTip(Lang.get("menu_element_tt"));
createEditMenu(menuBar);
createEditMenu(menuBar, elementStateAction);
toolBar.add(elementState.setIndicator(elementStateAction.createJButtonNoText()));
toolBar.add(circuitComponent.getDeleteAction().createJButtonNoText());
toolBar.addSeparator();
@ -228,7 +225,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
toolBar.addSeparator();
librarySelector = new LibrarySelector(library, shapeFactory, elementState);
librarySelector = new LibrarySelector(library, shapeFactory, stoppedState);
menuBar.add(librarySelector.buildMenu(new InsertHistory(toolBar), circuitComponent));
getContentPane().add(toolBar, BorderLayout.NORTH);
@ -405,9 +402,8 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
* Creates the edit menu
*
* @param menuBar the menu bar
* @param elementStateAction state action to add to menu
*/
private void createEditMenu(JMenuBar menuBar, ToolTipAction elementStateAction) {
private void createEditMenu(JMenuBar menuBar) {
JMenu edit = new JMenu(Lang.get("menu_edit"));
menuBar.add(edit);
@ -462,23 +458,22 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
@Override
public void actionPerformed(ActionEvent e) {
circuitComponent.getCircuit().actualToDefault();
elementState.enter();
stoppedState.enter();
}
}.setToolTip(Lang.get("menu_actualToDefault_tt"));
ToolTipAction unprogramAlFuses = new ToolTipAction(Lang.get("menu_unprogramAllFuses")) {
ToolTipAction unprogramAllFuses = new ToolTipAction(Lang.get("menu_unprogramAllFuses")) {
@Override
public void actionPerformed(ActionEvent e) {
circuitComponent.getCircuit().unprogramAllFuses();
elementState.enter();
stoppedState.enter();
}
}.setToolTip(Lang.get("menu_unprogramAllFuses_tt"));
edit.add(editAttributes.createJMenuItem());
edit.add(actualToDefault.createJMenuItem());
edit.add(unprogramAlFuses.createJMenuItem());
edit.add(unprogramAllFuses.createJMenuItem());
edit.addSeparator();
edit.add(elementStateAction.createJMenuItem());
edit.add(orderInputs.createJMenuItem());
edit.add(orderOutputs.createJMenuItem());
edit.add(orderMeasurements.createJMenuItem());
@ -499,8 +494,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
/**
* Creates the start menu
*
* @param menuBar the menu bar
* @param menuBar the menu bar
* @param toolBar the tool bar
*/
private void createStartMenu(JMenuBar menuBar, JToolBar toolBar) {
@ -533,12 +527,13 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
circuitComponent.hasChanged();
statusLabel.setText(Lang.get("stat_clocks", i));
} catch (NodeException e1) {
elementState.enter();
stoppedState.enter();
new ErrorMessage(Lang.get("msg_fastRunError")).addCause(e1).show(Main.this);
}
}
}.setToolTip(Lang.get("menu_fast_tt")).setActive(false);
ToolTipAction stoppedStateAction = stoppedState.createToolTipAction(Lang.get("menu_element"), ICON_STOP).setToolTip(Lang.get("menu_element_tt"));
ToolTipAction runTests = new ToolTipAction(Lang.get("menu_runTests"), ICON_TEST) {
@Override
@ -578,6 +573,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
run.add(runModelMicroAction.createJMenuItem());
run.add(doStep.createJMenuItem());
run.add(runToBreakAction.createJMenuItem());
run.add(stoppedStateAction.createJMenuItem());
run.add(runTests.createJMenuItem());
run.addSeparator();
run.add(speedTest.createJMenuItem());
@ -589,6 +585,8 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
toolBar.add(runModelMicroState.setIndicator(runModelMicroAction.createJButtonNoText()));
toolBar.add(doStep.createJButtonNoText());
toolBar.addSeparator();
toolBar.add(stoppedStateAction.createJButtonNoText());
toolBar.addSeparator();
toolBar.add(runTests.createJButtonNoText());
}
@ -609,7 +607,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
windowPosManager.register("testresult", new TestResultDialog(Main.this, tsl, circuitComponent.getCircuit(), library)).setVisible(true);
elementState.enter();
stoppedState.enter();
} catch (Exception e1) {
showErrorAndStopModel(Lang.get("msg_runningTestError"), e1);
}
@ -631,7 +629,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
new TableDialog(Main.this, new ModelAnalyser(model).analyse(), shapeFactory, filename)
.setPinMap(new PinMap().addModel(model))
.setVisible(true);
elementState.enter();
stoppedState.enter();
} catch (PinException | PinMapException | NodeException | AnalyseException | ElementNotFoundException e1) {
showErrorAndStopModel(Lang.get("msg_annalyseErr"), e1);
}
@ -645,7 +643,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
public void actionPerformed(ActionEvent e) {
TruthTable tt = new TruthTable(3).addResult();
new TableDialog(Main.this, tt, shapeFactory, null).setVisible(true);
elementState.enter();
stoppedState.enter();
}
}
.setToolTip(Lang.get("menu_synthesise_tt"))
@ -665,7 +663,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
private void orderMeasurements() {
try {
Model m = new ModelCreator(circuitComponent.getCircuit(), library).createModel(false);
elementState.enter();
stoppedState.enter();
ArrayList<String> names = new ArrayList<>();
for (Signal s : m.getSignals())
names.add(s.getName());
@ -682,13 +680,14 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
}
private void setupStates() {
elementState = stateManager.register(new State() {
stoppedState = stateManager.register(new State() {
@Override
public void enter() {
super.enter();
clearModelDescription();
circuitComponent.setModeAndReset(false, NoSync.INST);
doStep.setEnabled(false);
stoppedState.getAction().setEnabled(false);
runToBreakAction.setEnabled(false);
}
@ -698,6 +697,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
@Override
public void enter() {
super.enter();
stoppedState.getAction().setEnabled(true);
if (createAndStartModel(false, ModelEvent.MICROSTEP, null))
circuitComponent.setManualChangeObserver(new MicroStepObserver(model));
}
@ -793,7 +793,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
}
circuitComponent.hasChanged();
new ErrorMessage(message).addCause(cause).show(Main.this);
elementState.enter();
stoppedState.enter();
});
}
@ -830,7 +830,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
librarySelector.setFilePath(filename.getParentFile());
Circuit circ = Circuit.loadCircuit(filename, shapeFactory);
circuitComponent.setCircuit(circ);
elementState.enter();
stoppedState.enter();
windowPosManager.closeAll();
setFilename(filename, toPrefs);
statusLabel.setText(" ");
@ -847,7 +847,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
circuitComponent.getCircuit().save(filename);
if (savedListener != null)
savedListener.saved(filename);
elementState.enter();
stoppedState.enter();
setFilename(filename, toPrefs);
} catch (IOException e) {
new ErrorMessage(Lang.get("msg_errorWritingFile")).addCause(e).show();
@ -974,6 +974,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
void enter(boolean runRealTime, ModelModifier modelModifier) {
super.enter();
stoppedState.getAction().setEnabled(true);
if (createAndStartModel(runRealTime, ModelEvent.STEP, modelModifier))
circuitComponent.setManualChangeObserver(new FullStepObserver(model));
}
@ -1074,7 +1075,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
@Override
public void stop() {
SwingUtilities.invokeLater(() -> {
elementState.enter();
stoppedState.enter();
circuitComponent.hasChanged();
});
}

View File

@ -17,6 +17,7 @@ public class State implements StateInterface {
private static final Border DISABLED_BORDER = BorderFactory.createCompoundBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED), BorderFactory.createEmptyBorder(4, 4, 4, 4));
private JComponent indicator;
private StateManager stateManager;
private ToolTipAction action;
/**
* Creates new state
@ -56,20 +57,29 @@ public class State implements StateInterface {
indicator.setBorder(DISABLED_BORDER);
}
/**
* @return the action associated with this state
*/
public ToolTipAction getAction() {
return action;
}
/**
* Creates a tooltip action which activates the state
*
* @param name the name of the action to create
* @param icon the icon to use
* @return the acttion
* @return the action
*/
public ToolTipAction createToolTipAction(String name, Icon icon) {
return new ToolTipAction(name, icon) {
@Override
public void actionPerformed(ActionEvent e) {
enter();
}
};
if (action == null)
action = new ToolTipAction(name, icon) {
@Override
public void actionPerformed(ActionEvent e) {
enter();
}
};
return action;
}
}

View File

@ -534,8 +534,8 @@ Zur Analyse können Sie die Schaltung im Gatterschrittmodus ausführen.</string>
<string name="menu_editRunAttributes_tt">Einstellungen für den Start der Simulation</string>
<string name="menu_editSettings">Einstellungen</string>
<string name="menu_editSettings_tt">Bearbeitet die globalen Einstellungen</string>
<string name="menu_element">Elemente bearbeiten</string>
<string name="menu_element_tt">Bearbeitet die vorhandenen Elemente oder dessen Eigenschaften</string>
<string name="menu_element">Stoppen der Simulation</string>
<string name="menu_element_tt">Stopt die Simulation und erlaubt das Bearbeiten der Schaltung.</string>
<string name="menu_elements">Bauteile</string>
<string name="menu_export">Export</string>
<string name="menu_exportPNGLarge">Export PNG groß</string>
@ -566,7 +566,7 @@ Zur Analyse können Sie die Schaltung im Gatterschrittmodus ausführen.</string>
<string name="menu_refresh">Alle neu laden</string>
<string name="menu_refresh_tt">Alle importierten Schaltungen werden neu geladen</string>
<string name="menu_rotate">Rotieren</string>
<string name="menu_run">Start</string>
<string name="menu_run">Start der Simulation</string>
<string name="menu_run_tt">Startet die Simulation der Schaltung</string>
<string name="menu_save">Speichern</string>
<string name="menu_saveAs">Speichern unter</string>

View File

@ -520,8 +520,8 @@ To analyse you can run the circuit in single gate step mode.</string>
<string name="menu_editRunAttributes_tt">Settings used to start the simulation</string>
<string name="menu_editSettings">Settings</string>
<string name="menu_editSettings_tt">Edits Digitals Preferences</string>
<string name="menu_element">Edit components</string>
<string name="menu_element_tt">Edits the circuit. Moves a single component or edits its properties.</string>
<string name="menu_element">Stop Simulation</string>
<string name="menu_element_tt">Stops the simulation and allows to edits the circuit.</string>
<string name="menu_elements">Components</string>
<string name="menu_export">Export</string>
<string name="menu_exportPNGLarge">Export PNG large</string>
@ -552,8 +552,8 @@ To analyse you can run the circuit in single gate step mode.</string>
<string name="menu_refresh">Reload</string>
<string name="menu_refresh_tt">Reload all imported circuits</string>
<string name="menu_rotate">Rotate</string>
<string name="menu_run">Run</string>
<string name="menu_run_tt">Runs the circuit</string>
<string name="menu_run">Start Simulation</string>
<string name="menu_run_tt">Starts the simulation of the circuit.</string>
<string name="menu_save">Save</string>
<string name="menu_saveAs">Save As</string>
<string name="menu_saveData">Save Data</string>

Binary file not shown.

After

Width:  |  Height:  |  Size: 728 B