mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-16 08:25:09 -04:00
new and open checks for modification
This commit is contained in:
parent
92f1ec7d3f
commit
87d00a6d17
@ -39,7 +39,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
private static final String MESSAGE = "Digital\n\nA simple simulator for digital circuits.\nWritten bei H.Neemann in 2016";
|
||||
private final CircuitComponent circuitComponent;
|
||||
private final ToolTipAction save;
|
||||
private final PartLibrary library = ShapeFactory.INSTANCE.setLibrary(new PartLibrary());
|
||||
private final PartLibrary library = ShapeFactory.getInstance().setLibrary(new PartLibrary());
|
||||
private final ToolTipAction doStep;
|
||||
private File filename;
|
||||
private Model model;
|
||||
@ -71,17 +71,21 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
ToolTipAction newFile = new ToolTipAction("New") {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
setFilename(null);
|
||||
circuitComponent.setCircuit(new Circuit());
|
||||
if (ClosingWindowListener.checkForSave(Main.this, Main.this)) {
|
||||
setFilename(null);
|
||||
circuitComponent.setCircuit(new Circuit());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
ToolTipAction open = new ToolTipAction("Open") {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser fc = getjFileChooser();
|
||||
if (fc.showOpenDialog(Main.this) == JFileChooser.APPROVE_OPTION) {
|
||||
loadFile(fc.getSelectedFile());
|
||||
if (ClosingWindowListener.checkForSave(Main.this, Main.this)) {
|
||||
JFileChooser fc = getjFileChooser();
|
||||
if (fc.showOpenDialog(Main.this) == JFileChooser.APPROVE_OPTION) {
|
||||
loadFile(fc.getSelectedFile());
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -7,6 +7,7 @@ import java.awt.*;
|
||||
*/
|
||||
public class Style {
|
||||
public static final Style NORMAL = new Style(2, false, Color.BLACK);
|
||||
public static final Style WIRE = new Style(2, true, Color.BLUE.darker());
|
||||
public static final Style WIRE_LOW = new Style(3, true, new Color(0, 112, 0));
|
||||
public static final Style WIRE_HIGH = new Style(3, true, new Color(102, 255, 102));
|
||||
public static final Style FILLED = new Style(2, true, Color.BLACK);
|
||||
|
@ -26,7 +26,7 @@ public class VisualPart implements Drawable, Moveable, AttributeListener {
|
||||
private transient Shape shape;
|
||||
private transient IOState ioState;
|
||||
private transient Interactor interactor;
|
||||
private transient boolean highLight = true;
|
||||
private transient boolean highLight = false;
|
||||
private Vector pos;
|
||||
private int rotate;
|
||||
|
||||
@ -83,7 +83,7 @@ public class VisualPart implements Drawable, Moveable, AttributeListener {
|
||||
|
||||
public Shape getShape() {
|
||||
if (shape == null)
|
||||
shape = ShapeFactory.INSTANCE.getShape(partName, partAttributes);
|
||||
shape = ShapeFactory.getInstance().getShape(partName, partAttributes);
|
||||
return shape;
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ public class Wire implements Drawable, Moveable {
|
||||
|
||||
@Override
|
||||
public void drawTo(Graphic graphic) {
|
||||
Style style = Style.FILLED;
|
||||
Style style = Style.WIRE;
|
||||
|
||||
Vector r = RAD;
|
||||
if (value != null) {
|
||||
|
@ -20,7 +20,7 @@ import java.util.HashMap;
|
||||
* @author hneemann
|
||||
*/
|
||||
public final class ShapeFactory {
|
||||
public static final ShapeFactory INSTANCE = new ShapeFactory();
|
||||
|
||||
public HashMap<String, Creator> map = new HashMap<>();
|
||||
private PartLibrary library;
|
||||
|
||||
@ -47,6 +47,10 @@ public final class ShapeFactory {
|
||||
map.put(Out.PROBEDESCRIPTION.getName(), attr -> new ProbeShape(attr.get(AttributeKey.Label)));
|
||||
}
|
||||
|
||||
public static ShapeFactory getInstance() {
|
||||
return InstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
public PartLibrary setLibrary(PartLibrary library) {
|
||||
this.library = library;
|
||||
return library;
|
||||
@ -85,6 +89,10 @@ public final class ShapeFactory {
|
||||
Shape create(PartAttributes attributes);
|
||||
}
|
||||
|
||||
private static final class InstanceHolder {
|
||||
static final ShapeFactory INSTANCE = new ShapeFactory();
|
||||
}
|
||||
|
||||
public class CreatorSimple implements Creator {
|
||||
|
||||
private final String name;
|
||||
|
Loading…
x
Reference in New Issue
Block a user