mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-26 22:41:59 -04:00
more concise handling of model stopping
This commit is contained in:
parent
214f002797
commit
d6e1a3e510
@ -565,7 +565,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
circuitComponent.actualToDefault();
|
circuitComponent.actualToDefault();
|
||||||
stoppedState.enter();
|
ensureModelIsStopped();
|
||||||
}
|
}
|
||||||
}.setToolTip(Lang.get("menu_actualToDefault_tt"));
|
}.setToolTip(Lang.get("menu_actualToDefault_tt"));
|
||||||
|
|
||||||
@ -573,7 +573,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
circuitComponent.restoreAllFuses();
|
circuitComponent.restoreAllFuses();
|
||||||
stoppedState.enter();
|
ensureModelIsStopped();
|
||||||
}
|
}
|
||||||
}.setToolTip(Lang.get("menu_restoreAllFuses_tt"));
|
}.setToolTip(Lang.get("menu_restoreAllFuses_tt"));
|
||||||
|
|
||||||
@ -740,7 +740,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
circuitComponent.repaintNeeded();
|
circuitComponent.repaintNeeded();
|
||||||
statusLabel.setText(Lang.get("stat_clocks", i));
|
statusLabel.setText(Lang.get("stat_clocks", i));
|
||||||
} catch (NodeException e1) {
|
} catch (NodeException e1) {
|
||||||
stoppedState.enter();
|
ensureModelIsStopped();
|
||||||
new ErrorMessage(Lang.get("msg_fastRunError")).addCause(e1).show(Main.this);
|
new ErrorMessage(Lang.get("msg_fastRunError")).addCause(e1).show(Main.this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -832,7 +832,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
|
|
||||||
windowPosManager.register("testResult", new TestResultDialog(Main.this, tsl, circuitComponent.getCircuit(), library)).setVisible(true);
|
windowPosManager.register("testResult", new TestResultDialog(Main.this, tsl, circuitComponent.getCircuit(), library)).setVisible(true);
|
||||||
|
|
||||||
stoppedState.enter();
|
ensureModelIsStopped();
|
||||||
} catch (NodeException | ElementNotFoundException | PinException | TestingDataException | RuntimeException e1) {
|
} catch (NodeException | ElementNotFoundException | PinException | TestingDataException | RuntimeException e1) {
|
||||||
showErrorAndStopModel(Lang.get("msg_runningTestError"), e1);
|
showErrorAndStopModel(Lang.get("msg_runningTestError"), e1);
|
||||||
}
|
}
|
||||||
@ -853,7 +853,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
Model model = new ModelCreator(circuitComponent.getCircuit(), library).createModel(false);
|
Model model = new ModelCreator(circuitComponent.getCircuit(), library).createModel(false);
|
||||||
new TableDialog(Main.this, new ModelAnalyser(model).analyse(), library, shapeFactory, getBaseFileName())
|
new TableDialog(Main.this, new ModelAnalyser(model).analyse(), library, shapeFactory, getBaseFileName())
|
||||||
.setVisible(true);
|
.setVisible(true);
|
||||||
stoppedState.enter();
|
ensureModelIsStopped();
|
||||||
} catch (PinException | NodeException | AnalyseException | ElementNotFoundException | RuntimeException e1) {
|
} catch (PinException | NodeException | AnalyseException | ElementNotFoundException | RuntimeException e1) {
|
||||||
showErrorAndStopModel(Lang.get("msg_analyseErr"), e1);
|
showErrorAndStopModel(Lang.get("msg_analyseErr"), e1);
|
||||||
}
|
}
|
||||||
@ -867,7 +867,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
TruthTable tt = new TruthTable(3).addResult();
|
TruthTable tt = new TruthTable(3).addResult();
|
||||||
new TableDialog(Main.this, tt, library, shapeFactory, getBaseFileName()).setVisible(true);
|
new TableDialog(Main.this, tt, library, shapeFactory, getBaseFileName()).setVisible(true);
|
||||||
stoppedState.enter();
|
ensureModelIsStopped();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.setToolTip(Lang.get("menu_synthesise_tt"))
|
.setToolTip(Lang.get("menu_synthesise_tt"))
|
||||||
@ -887,7 +887,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
private void orderMeasurements() {
|
private void orderMeasurements() {
|
||||||
try {
|
try {
|
||||||
Model m = new ModelCreator(circuitComponent.getCircuit(), library).createModel(false);
|
Model m = new ModelCreator(circuitComponent.getCircuit(), library).createModel(false);
|
||||||
stoppedState.enter();
|
ensureModelIsStopped();
|
||||||
ArrayList<String> names = new ArrayList<>();
|
ArrayList<String> names = new ArrayList<>();
|
||||||
for (Signal s : m.getSignals())
|
for (Signal s : m.getSignals())
|
||||||
names.add(s.getName());
|
names.add(s.getName());
|
||||||
@ -1030,8 +1030,9 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
/**
|
/**
|
||||||
* stops the model
|
* stops the model
|
||||||
*/
|
*/
|
||||||
public void stopModel() {
|
public void ensureModelIsStopped() {
|
||||||
stoppedState.enter();
|
if (!stoppedState.isActive())
|
||||||
|
stoppedState.enter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1068,7 +1069,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
if (setLibraryRoot) library.setRootFilePath(filename.getParentFile());
|
if (setLibraryRoot) library.setRootFilePath(filename.getParentFile());
|
||||||
Circuit circuit = Circuit.loadCircuit(filename, shapeFactory);
|
Circuit circuit = Circuit.loadCircuit(filename, shapeFactory);
|
||||||
circuitComponent.setCircuit(circuit);
|
circuitComponent.setCircuit(circuit);
|
||||||
stoppedState.enter();
|
ensureModelIsStopped();
|
||||||
windowPosManager.closeAll();
|
windowPosManager.closeAll();
|
||||||
statusLabel.setText(" ");
|
statusLabel.setText(" ");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -1081,7 +1082,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
private void saveFile(File filename, boolean toPrefs) {
|
private void saveFile(File filename, boolean toPrefs) {
|
||||||
try {
|
try {
|
||||||
circuitComponent.getCircuit().save(filename);
|
circuitComponent.getCircuit().save(filename);
|
||||||
stoppedState.enter();
|
ensureModelIsStopped();
|
||||||
setFilename(filename, toPrefs);
|
setFilename(filename, toPrefs);
|
||||||
|
|
||||||
library.invalidateElement(filename);
|
library.invalidateElement(filename);
|
||||||
@ -1112,6 +1113,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void circuitHasChanged() {
|
public void circuitHasChanged() {
|
||||||
|
ensureModelIsStopped();
|
||||||
if (!modifiedPrefixVisible)
|
if (!modifiedPrefixVisible)
|
||||||
setFilename(filename, false);
|
setFilename(filename, false);
|
||||||
}
|
}
|
||||||
@ -1339,7 +1341,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
|||||||
@Override
|
@Override
|
||||||
public void stop() {
|
public void stop() {
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
stoppedState.enter();
|
ensureModelIsStopped();
|
||||||
circuitComponent.repaintNeeded();
|
circuitComponent.repaintNeeded();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -595,7 +595,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
|||||||
* @param element the element to insert
|
* @param element the element to insert
|
||||||
*/
|
*/
|
||||||
public void setPartToInsert(VisualElement element) {
|
public void setPartToInsert(VisualElement element) {
|
||||||
parent.stopModel();
|
parent.ensureModelIsStopped();
|
||||||
mouseInsertElement.activate(element);
|
mouseInsertElement.activate(element);
|
||||||
Point point = MouseInfo.getPointerInfo().getLocation();
|
Point point = MouseInfo.getPointerInfo().getLocation();
|
||||||
SwingUtilities.convertPointFromScreen(point, this);
|
SwingUtilities.convertPointFromScreen(point, this);
|
||||||
|
@ -82,4 +82,10 @@ public class State implements StateInterface {
|
|||||||
return action;
|
return action;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if this state is active
|
||||||
|
*/
|
||||||
|
public boolean isActive() {
|
||||||
|
return stateManager.isActive(this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,4 +39,13 @@ public class StateManager {
|
|||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the given state is the active state
|
||||||
|
*
|
||||||
|
* @param state the state
|
||||||
|
* @return true if the given state is active
|
||||||
|
*/
|
||||||
|
public boolean isActive(State state) {
|
||||||
|
return actualState == state;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user