mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-16 08:25:09 -04:00
improved error handling
This commit is contained in:
parent
f4393f91d9
commit
6e09ffaa1b
@ -165,7 +165,7 @@ public class Model {
|
|||||||
int counter = 0;
|
int counter = 0;
|
||||||
while (needsUpdate()) {
|
while (needsUpdate()) {
|
||||||
if (counter++ > MAX_COUNTER) {
|
if (counter++ > MAX_COUNTER) {
|
||||||
throw new NodeException(Lang.get("err_seemsToOscillate"), nodesToUpdateNext.get(0));
|
throw new NodeException(Lang.get("err_seemsToOscillate")).addNodes(nodesToUpdateNext);
|
||||||
}
|
}
|
||||||
doMicroStep(noise);
|
doMicroStep(noise);
|
||||||
}
|
}
|
||||||
@ -236,7 +236,7 @@ public class Model {
|
|||||||
}
|
}
|
||||||
lastIn = brIn;
|
lastIn = brIn;
|
||||||
}
|
}
|
||||||
throw new NodeException(Lang.get("err_breakTimeOut", aBreak.getCycles()), null, brVal);
|
throw new NodeException(Lang.get("err_breakTimeOut", aBreak.getCycles()), brVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -7,23 +7,30 @@ import java.util.Collection;
|
|||||||
* @author hneemann
|
* @author hneemann
|
||||||
*/
|
*/
|
||||||
public class NodeException extends Exception {
|
public class NodeException extends Exception {
|
||||||
private final Node node;
|
private final ArrayList<Node> nodes;
|
||||||
private final ObservableValue[] values;
|
private final ObservableValue[] values;
|
||||||
|
|
||||||
|
public NodeException(String message, ObservableValue... values) {
|
||||||
|
this(message, null, values);
|
||||||
|
}
|
||||||
|
|
||||||
public NodeException(String message, Node node, ObservableValue... values) {
|
public NodeException(String message, Node node, ObservableValue... values) {
|
||||||
super(message);
|
super(message);
|
||||||
this.node = node;
|
this.nodes = new ArrayList<>();
|
||||||
|
if (node != null)
|
||||||
|
nodes.add(node);
|
||||||
this.values = values;
|
this.values = values;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public NodeException addNodes(Collection<Node> nodesToAdd) {
|
||||||
|
nodes.addAll(nodesToAdd);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
public ObservableValue[] getValues() {
|
public ObservableValue[] getValues() {
|
||||||
return values;
|
return values;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Node getNode() {
|
|
||||||
return node;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getMessage() {
|
public String getMessage() {
|
||||||
if (values == null || values.length == 0)
|
if (values == null || values.length == 0)
|
||||||
@ -44,11 +51,6 @@ public class NodeException extends Exception {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Collection<Node> getNodes() {
|
public Collection<Node> getNodes() {
|
||||||
if (node == null)
|
return nodes;
|
||||||
return null;
|
|
||||||
|
|
||||||
ArrayList<Node> list = new ArrayList<>();
|
|
||||||
list.add(node);
|
|
||||||
return list;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,7 +45,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
private static final Icon ICON_STEP = IconCreator.create("step.gif");
|
private static final Icon ICON_STEP = IconCreator.create("step.gif");
|
||||||
private static final Icon ICON_ELEMENT = IconCreator.create("element.gif");
|
private static final Icon ICON_ELEMENT = IconCreator.create("element.gif");
|
||||||
private static final Icon ICON_SELECT = IconCreator.create("Select24.gif");
|
private static final Icon ICON_SELECT = IconCreator.create("Select24.gif");
|
||||||
private static final Icon ICON_WIRE = IconCreator.create("wire.gif");
|
// private static final Icon ICON_WIRE = IconCreator.create("wire.gif");
|
||||||
private static final Icon ICON_NEW = IconCreator.create("New24.gif");
|
private static final Icon ICON_NEW = IconCreator.create("New24.gif");
|
||||||
private static final Icon ICON_OPEN = IconCreator.create("Open24.gif");
|
private static final Icon ICON_OPEN = IconCreator.create("Open24.gif");
|
||||||
private static final Icon ICON_OPEN_WIN = IconCreator.create("OpenNew24.gif");
|
private static final Icon ICON_OPEN_WIN = IconCreator.create("OpenNew24.gif");
|
||||||
@ -232,7 +232,6 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
}.setToolTip(Lang.get("menu_orderMeasurements_tt"));
|
}.setToolTip(Lang.get("menu_orderMeasurements_tt"));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
ToolTipAction editAttributes = new ToolTipAction(Lang.get("menu_editAttributes")) {
|
ToolTipAction editAttributes = new ToolTipAction(Lang.get("menu_editAttributes")) {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
@ -362,7 +361,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
super.enter();
|
super.enter();
|
||||||
createAndStartModel(runClock.isSelected(), ModelEvent.Event.STEP);
|
if (createAndStartModel(runClock.isSelected(), ModelEvent.Event.STEP))
|
||||||
circuitComponent.setManualChangeObserver(new FullStepObserver(model));
|
circuitComponent.setManualChangeObserver(new FullStepObserver(model));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -370,7 +369,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
@Override
|
@Override
|
||||||
public void enter() {
|
public void enter() {
|
||||||
super.enter();
|
super.enter();
|
||||||
createAndStartModel(false, ModelEvent.Event.MICROSTEP);
|
if (createAndStartModel(false, ModelEvent.Event.MICROSTEP))
|
||||||
circuitComponent.setManualChangeObserver(new MicroStepObserver(model));
|
circuitComponent.setManualChangeObserver(new MicroStepObserver(model));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -378,6 +377,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts the main app
|
* Starts the main app
|
||||||
|
*
|
||||||
* @param args the arguments
|
* @param args the arguments
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
@ -393,7 +393,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
model = null;
|
model = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setModelDescription(ModelDescription md, boolean runClock) throws NodeException, PinException {
|
private void setModelDescription(ModelDescription md) throws NodeException, PinException {
|
||||||
modelDescription = md;
|
modelDescription = md;
|
||||||
|
|
||||||
if (model != null)
|
if (model != null)
|
||||||
@ -403,12 +403,12 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void createAndStartModel(boolean runClock, ModelEvent.Event updateEvent) {
|
private boolean createAndStartModel(boolean runClock, ModelEvent.Event updateEvent) {
|
||||||
try {
|
try {
|
||||||
circuitComponent.removeHighLighted();
|
circuitComponent.removeHighLighted();
|
||||||
circuitComponent.setModeAndReset(CircuitComponent.Mode.running);
|
circuitComponent.setModeAndReset(CircuitComponent.Mode.running);
|
||||||
|
|
||||||
setModelDescription(new ModelDescription(circuitComponent.getCircuit(), library), runClock);
|
setModelDescription(new ModelDescription(circuitComponent.getCircuit(), library));
|
||||||
if (runClock) {
|
if (runClock) {
|
||||||
// if clock is running, enable automatic update of gui
|
// if clock is running, enable automatic update of gui
|
||||||
GuiModelObserver gmo = new GuiModelObserver(circuitComponent, updateEvent);
|
GuiModelObserver gmo = new GuiModelObserver(circuitComponent, updateEvent);
|
||||||
@ -425,14 +425,12 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
|
|
||||||
runToBreak.setEnabled(!runClock && model.isFastRunModel());
|
runToBreak.setEnabled(!runClock && model.isFastRunModel());
|
||||||
|
|
||||||
|
|
||||||
if (showProbes.isSelected())
|
if (showProbes.isSelected())
|
||||||
new ProbeDialog(this, model, updateEvent).setVisible(true);
|
new ProbeDialog(this, model, updateEvent).setVisible(true);
|
||||||
|
|
||||||
if (showGraph.isSelected())
|
if (showGraph.isSelected())
|
||||||
new DataSetDialog(this, model, updateEvent).setVisible(true);
|
new DataSetDialog(this, model, updateEvent).setVisible(true);
|
||||||
|
|
||||||
|
|
||||||
if (showListing.isSelected())
|
if (showListing.isSelected())
|
||||||
for (ROM rom : model.getRoms())
|
for (ROM rom : model.getRoms())
|
||||||
try {
|
try {
|
||||||
@ -444,17 +442,16 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
|
|
||||||
model.init();
|
model.init();
|
||||||
|
|
||||||
|
return true;
|
||||||
} catch (NodeException e) {
|
} catch (NodeException e) {
|
||||||
if (modelDescription != null) {
|
if (modelDescription != null) {
|
||||||
if (e.getNodes() != null)
|
if (e.getNodes() != null)
|
||||||
modelDescription.addNodeElementsTo(e.getNodes(), circuitComponent.getHighLighted());
|
modelDescription.addNodeElementsTo(e.getNodes(), circuitComponent.getHighLighted());
|
||||||
else
|
else
|
||||||
circuitComponent.addHighLightedWires(e.getValues());
|
circuitComponent.addHighLightedWires(e.getValues());
|
||||||
|
|
||||||
circuitComponent.repaint();
|
circuitComponent.repaint();
|
||||||
}
|
}
|
||||||
SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorCreatingModel")).addCause(e).setComponent(Main.this));
|
showSwingError(Lang.get("msg_errorCreatingModel"), e);
|
||||||
circuitComponent.setModeAndReset(CircuitComponent.Mode.part);
|
|
||||||
} catch (PinException e) {
|
} catch (PinException e) {
|
||||||
if (modelDescription != null) {
|
if (modelDescription != null) {
|
||||||
circuitComponent.addHighLighted(e.getVisualElement());
|
circuitComponent.addHighLighted(e.getVisualElement());
|
||||||
@ -462,9 +459,18 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
circuitComponent.addHighLighted(e.getNet().getWires());
|
circuitComponent.addHighLighted(e.getNet().getWires());
|
||||||
circuitComponent.repaint();
|
circuitComponent.repaint();
|
||||||
}
|
}
|
||||||
SwingUtilities.invokeLater(new ErrorMessage(Lang.get("msg_errorCreatingModel")).addCause(e).setComponent(Main.this));
|
showSwingError(Lang.get("msg_errorCreatingModel"), e);
|
||||||
circuitComponent.setModeAndReset(CircuitComponent.Mode.part);
|
} catch (RuntimeException e) {
|
||||||
|
showSwingError(Lang.get("msg_errorCreatingModel"), e);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showSwingError(String message, Throwable cause) {
|
||||||
|
SwingUtilities.invokeLater(() -> {
|
||||||
|
new ErrorMessage(message).addCause(cause).show(Main.this);
|
||||||
|
elementState.activate();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static JFileChooser getjFileChooser(File filename) {
|
private static JFileChooser getjFileChooser(File filename) {
|
||||||
@ -549,10 +555,14 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
try {
|
try {
|
||||||
model.doStep();
|
model.doStep();
|
||||||
circuitComponent.repaint();
|
circuitComponent.repaint();
|
||||||
} catch (Exception e) {
|
} catch (NodeException e) {
|
||||||
SwingUtilities.invokeLater(
|
if (modelDescription != null) {
|
||||||
new ErrorMessage(Lang.get("msg_errorCalculatingStep")).addCause(e).setComponent(Main.this)
|
modelDescription.addNodeElementsTo(e.getNodes(), circuitComponent.getHighLighted());
|
||||||
);
|
circuitComponent.repaint();
|
||||||
|
}
|
||||||
|
showSwingError(Lang.get("msg_errorCalculatingStep"), e);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
showSwingError(Lang.get("msg_errorCalculatingStep"), e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,10 @@ import de.neemann.gui.ToolTipAction;
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseMotionListener;
|
||||||
import java.awt.geom.AffineTransform;
|
import java.awt.geom.AffineTransform;
|
||||||
import java.awt.geom.NoninvertibleTransformException;
|
import java.awt.geom.NoninvertibleTransformException;
|
||||||
import java.awt.geom.Point2D;
|
import java.awt.geom.Point2D;
|
||||||
@ -61,19 +64,14 @@ public class CircuitComponent extends JComponent {
|
|||||||
|
|
||||||
setFocusable(true);
|
setFocusable(true);
|
||||||
|
|
||||||
addMouseWheelListener(new MouseWheelListener() {
|
addMouseWheelListener(e -> {
|
||||||
@Override
|
|
||||||
public void mouseWheelMoved(MouseWheelEvent e) {
|
|
||||||
Vector pos = getPosVector(e);
|
Vector pos = getPosVector(e);
|
||||||
double f = Math.pow(0.9, e.getWheelRotation());
|
double f = Math.pow(0.9, e.getWheelRotation());
|
||||||
transform.translate(pos.x, pos.y);
|
transform.translate(pos.x, pos.y);
|
||||||
transform.scale(f, f);
|
transform.scale(f, f);
|
||||||
transform.translate(-pos.x, -pos.y);
|
transform.translate(-pos.x, -pos.y);
|
||||||
repaint();
|
repaint();
|
||||||
}
|
});
|
||||||
}
|
|
||||||
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public ToolTipAction getDeleteAction() {
|
public ToolTipAction getDeleteAction() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user