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