mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-26 22:41:59 -04:00
added a modified indicator to the window title
This commit is contained in:
parent
0c6944320c
commit
192cb531d0
@ -687,6 +687,19 @@ public class Circuit {
|
||||
listeners.add(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* takes the listener attached to the given circuit
|
||||
*
|
||||
* @param circuit the circuit to take the listeners from
|
||||
*/
|
||||
public void getListenersFrom(Circuit circuit) {
|
||||
if (circuit.listeners!=null) {
|
||||
if (listeners==null)
|
||||
listeners=new ArrayList<>();
|
||||
listeners.addAll(circuit.listeners);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a listener for circuit changes from this circuit
|
||||
*
|
||||
|
@ -68,7 +68,7 @@ import static javax.swing.JOptionPane.showInputDialog;
|
||||
*
|
||||
* @author hneemann
|
||||
*/
|
||||
public final class Main extends JFrame implements ClosingWindowListener.ConfirmSave, ErrorStopper, FileHistory.OpenInterface, DigitalRemoteInterface, StatusInterface {
|
||||
public final class Main extends JFrame implements ClosingWindowListener.ConfirmSave, ErrorStopper, FileHistory.OpenInterface, DigitalRemoteInterface, StatusInterface, Circuit.ChangedListener {
|
||||
private static final ArrayList<Key> ATTR_LIST = new ArrayList<>();
|
||||
private static final String KEY_START_STOP_ACTION = "startStop";
|
||||
private static boolean experimental;
|
||||
@ -124,6 +124,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
private File baseFilename;
|
||||
private File filename;
|
||||
private FileHistory fileHistory;
|
||||
private boolean modifiedPrefixVisible = false;
|
||||
|
||||
private Sync modelSync;
|
||||
private Model model;
|
||||
@ -159,6 +160,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
baseFilename = builder.baseFileName;
|
||||
|
||||
circuitComponent = new CircuitComponent(this, library, shapeFactory);
|
||||
circuitComponent.getCircuit().addListener(this);
|
||||
if (builder.circuit != null) {
|
||||
SwingUtilities.invokeLater(() -> circuitComponent.setCircuit(builder.circuit));
|
||||
setFilename(builder.fileToOpen, false);
|
||||
@ -341,8 +343,8 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
if (ClosingWindowListener.checkForSave(Main.this, Main.this)) {
|
||||
setFilename(null, true);
|
||||
circuitComponent.setCircuit(new Circuit());
|
||||
setFilename(null, true);
|
||||
windowPosManager.closeAll();
|
||||
try {
|
||||
library.setRootFilePath(null);
|
||||
@ -617,7 +619,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
}
|
||||
}
|
||||
if (modified)
|
||||
circuitComponent.hasChanged();
|
||||
circuitComponent.repaintNeeded();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -641,7 +643,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
}
|
||||
}
|
||||
if (modified)
|
||||
circuitComponent.hasChanged();
|
||||
circuitComponent.repaintNeeded();
|
||||
}
|
||||
}
|
||||
}.setToolTip(Lang.get("menu_removePrefix_tt")).createJMenuItem());
|
||||
@ -670,7 +672,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
}
|
||||
}
|
||||
if (modified)
|
||||
circuitComponent.hasChanged();
|
||||
circuitComponent.repaintNeeded();
|
||||
}
|
||||
}
|
||||
}.setToolTip(Lang.get("menu_removePinNumbers_tt")).createJMenuItem());
|
||||
@ -691,7 +693,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
model.doMicroStep(false);
|
||||
circuitComponent.removeHighLighted();
|
||||
modelCreator.addNodeElementsTo(model.nodesToUpdate(), circuitComponent.getHighLighted());
|
||||
circuitComponent.hasChanged();
|
||||
circuitComponent.repaintNeeded();
|
||||
doStep.setEnabled(model.needsUpdate());
|
||||
} catch (Exception e1) {
|
||||
SwingUtilities.invokeLater(
|
||||
@ -710,7 +712,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
int i = model.runToBreak();
|
||||
circuitComponent.hasChanged();
|
||||
circuitComponent.repaintNeeded();
|
||||
statusLabel.setText(Lang.get("stat_clocks", i));
|
||||
} catch (NodeException e1) {
|
||||
stoppedState.enter();
|
||||
@ -989,7 +991,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
BurnException e = (BurnException) cause;
|
||||
circuitComponent.addHighLightedWires(e.getValues());
|
||||
}
|
||||
circuitComponent.hasChanged();
|
||||
circuitComponent.repaintNeeded();
|
||||
new ErrorMessage(message).addCause(cause).show(Main.this);
|
||||
stoppedState.enter();
|
||||
});
|
||||
@ -1062,17 +1064,28 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
}
|
||||
|
||||
private void setFilename(File filename, boolean toPrefs) {
|
||||
modifiedPrefixVisible = circuitComponent.getCircuit().isModified();
|
||||
String prefix = "";
|
||||
if (modifiedPrefixVisible)
|
||||
prefix = "*";
|
||||
this.filename = filename;
|
||||
if (filename != null) {
|
||||
this.baseFilename = filename;
|
||||
if (toPrefs)
|
||||
fileHistory.add(filename);
|
||||
setTitle(filename + " - " + Lang.get("digital"));
|
||||
setTitle(prefix + filename + " - " + Lang.get("digital"));
|
||||
} else {
|
||||
setTitle(Lang.get("digital"));
|
||||
setTitle(prefix + Lang.get("digital"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void circuitHasChanged() {
|
||||
if (!modifiedPrefixVisible)
|
||||
setFilename(filename, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the window position manager
|
||||
*/
|
||||
@ -1099,7 +1112,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
model.fireManualChangeEvent();
|
||||
model.doStep();
|
||||
});
|
||||
circuitComponent.hasChanged();
|
||||
circuitComponent.repaintNeeded();
|
||||
} catch (NodeException | RuntimeException e) {
|
||||
showErrorAndStopModel(Lang.get("msg_errorCalculatingStep"), e);
|
||||
}
|
||||
@ -1117,7 +1130,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
public void hasChanged() {
|
||||
modelCreator.addNodeElementsTo(model.nodesToUpdate(), circuitComponent.getHighLighted());
|
||||
model.fireManualChangeEvent();
|
||||
circuitComponent.hasChanged();
|
||||
circuitComponent.repaintNeeded();
|
||||
doStep.setEnabled(model.needsUpdate());
|
||||
}
|
||||
}
|
||||
@ -1180,7 +1193,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
setDebug(false);
|
||||
windowPosManager.closeAll();
|
||||
runModelState.enter(false, gifExporter);
|
||||
circuitComponent.hasChanged();
|
||||
circuitComponent.repaintNeeded();
|
||||
}
|
||||
);
|
||||
}
|
||||
@ -1234,7 +1247,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
setDebug(false);
|
||||
windowPosManager.closeAll();
|
||||
runModelState.enter(true, new RomLoader(romHex));
|
||||
circuitComponent.hasChanged();
|
||||
circuitComponent.repaintNeeded();
|
||||
});
|
||||
}
|
||||
|
||||
@ -1243,7 +1256,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
setDebug(true);
|
||||
runModelState.enter(false, new RomLoader(romHex));
|
||||
circuitComponent.hasChanged();
|
||||
circuitComponent.repaintNeeded();
|
||||
});
|
||||
}
|
||||
|
||||
@ -1263,7 +1276,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
clkVal.setBool(!clkVal.getBool());
|
||||
model.doStep();
|
||||
}
|
||||
circuitComponent.hasChanged();
|
||||
circuitComponent.repaintNeeded();
|
||||
addressPicker.getProgramROMAddress(model);
|
||||
} catch (NodeException | RuntimeException e) {
|
||||
showErrorAndStopModel(Lang.get("err_remoteExecution"), e);
|
||||
@ -1297,7 +1310,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
|
||||
public void stop() {
|
||||
SwingUtilities.invokeLater(() -> {
|
||||
stoppedState.enter();
|
||||
circuitComponent.hasChanged();
|
||||
circuitComponent.repaintNeeded();
|
||||
});
|
||||
}
|
||||
//**********************
|
||||
|
@ -87,7 +87,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
private Vector lastMousePos;
|
||||
private Sync modelSync;
|
||||
private boolean isManualScale;
|
||||
private boolean hasChanged = true;
|
||||
private boolean graphicsHasChanged = true;
|
||||
private boolean focusWasLost = false;
|
||||
private boolean lockMessageShown = false;
|
||||
private boolean antiAlias = true;
|
||||
@ -179,7 +179,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
transform.scale(f, f);
|
||||
transform.translate(-pos.x, -pos.y);
|
||||
isManualScale = true;
|
||||
hasChanged();
|
||||
repaintNeeded();
|
||||
});
|
||||
|
||||
addComponentListener(new ComponentAdapter() {
|
||||
@ -211,6 +211,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
mouseRun = new MouseControllerRun(normalCursor);
|
||||
|
||||
setCircuit(new Circuit());
|
||||
circuit.addListener(this);
|
||||
|
||||
MouseDispatcher dispatcher = new MouseDispatcher();
|
||||
addMouseMotionListener(dispatcher);
|
||||
@ -321,15 +322,15 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
undoPosition = modifications.size();
|
||||
undoAction.setEnabled(true);
|
||||
circuit.modified();
|
||||
hasChanged();
|
||||
repaintNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* invalidates the image buffer and calls repaint();
|
||||
*/
|
||||
public void hasChanged() {
|
||||
hasChanged = true;
|
||||
public void repaintNeeded() {
|
||||
graphicsHasChanged = true;
|
||||
repaint();
|
||||
}
|
||||
|
||||
@ -338,7 +339,9 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
*/
|
||||
private void undo() {
|
||||
if (undoPosition > 0) {
|
||||
circuit = new Circuit(initialCircuit);
|
||||
Circuit c = new Circuit(initialCircuit);
|
||||
c.getListenersFrom(circuit);
|
||||
circuit=c;
|
||||
undoPosition--;
|
||||
for (int i = 0; i < undoPosition; i++)
|
||||
modifications.get(i).modify(circuit);
|
||||
@ -346,7 +349,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
if (undoPosition == 0)
|
||||
undoAction.setEnabled(false);
|
||||
circuit.modified();
|
||||
hasChanged();
|
||||
repaintNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@ -360,7 +363,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
if (undoPosition == modifications.size())
|
||||
redoAction.setEnabled(false);
|
||||
undoAction.setEnabled(true);
|
||||
hasChanged();
|
||||
repaintNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@ -571,7 +574,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
if (needsNewBuffer && !isManualScale)
|
||||
fitCircuit();
|
||||
|
||||
if (hasChanged
|
||||
if (graphicsHasChanged
|
||||
|| needsNewBuffer
|
||||
|| highLighted.size() != highlightedPaintedSize) {
|
||||
|
||||
@ -596,7 +599,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
// System.out.println("repaint: " + Long.toString(time) + "ms");
|
||||
|
||||
highlightedPaintedSize = highLighted.size();
|
||||
hasChanged = false;
|
||||
graphicsHasChanged = false;
|
||||
}
|
||||
|
||||
g.drawImage(buffer, 0, 0, null);
|
||||
@ -620,7 +623,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
|
||||
@Override
|
||||
public void circuitHasChanged() {
|
||||
hasChanged = true;
|
||||
graphicsHasChanged = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -629,7 +632,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
* Therefore the double buffer is invalidated.
|
||||
*/
|
||||
public void paintImmediately() {
|
||||
hasChanged = true;
|
||||
graphicsHasChanged = true;
|
||||
paintImmediately(0, 0, getWidth(), getHeight());
|
||||
}
|
||||
|
||||
@ -672,9 +675,8 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
* @param circuit the circuit
|
||||
*/
|
||||
public void setCircuit(Circuit circuit) {
|
||||
|
||||
if (this.circuit != null) {
|
||||
this.circuit.removeListener(this);
|
||||
circuit.getListenersFrom(this.circuit);
|
||||
}
|
||||
|
||||
this.circuit = circuit;
|
||||
@ -684,8 +686,6 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
undoAction.setEnabled(false);
|
||||
redoAction.setEnabled(false);
|
||||
|
||||
circuit.addListener(this);
|
||||
|
||||
fitCircuit();
|
||||
setModeAndReset(false, NoSync.INST);
|
||||
}
|
||||
@ -718,7 +718,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
}
|
||||
if (!newTrans.equals(transform)) {
|
||||
transform = newTrans;
|
||||
hasChanged();
|
||||
repaintNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@ -733,7 +733,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
transform.scale(f, f);
|
||||
transform.translate(-dif.x, -dif.y);
|
||||
isManualScale = true;
|
||||
hasChanged();
|
||||
repaintNeeded();
|
||||
}
|
||||
|
||||
private void editAttributes(VisualElement element, MouseEvent e) {
|
||||
@ -784,7 +784,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
@Override
|
||||
public void libraryChanged(LibraryNode node) {
|
||||
circuit.clearState();
|
||||
hasChanged = true;
|
||||
graphicsHasChanged = true;
|
||||
repaint();
|
||||
}
|
||||
|
||||
@ -865,7 +865,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
transform.translate(delta.x / s, delta.y / s);
|
||||
pos = newPos;
|
||||
isManualScale = true;
|
||||
hasChanged();
|
||||
repaintNeeded();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -888,7 +888,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
cutAction.setEnabled(false);
|
||||
rotateAction.setEnabled(false);
|
||||
setCursor(mouseCursor);
|
||||
hasChanged();
|
||||
repaintNeeded();
|
||||
}
|
||||
|
||||
void clicked(MouseEvent e) {
|
||||
@ -1065,7 +1065,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
deleteAction.setActive(true);
|
||||
rotateAction.setEnabled(true);
|
||||
copyAction.setEnabled(true);
|
||||
hasChanged();
|
||||
repaintNeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1083,7 +1083,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
Vector pos = getPosVector(e);
|
||||
visualElement.setPos(raster(pos.add(delta)));
|
||||
circuit.modified();
|
||||
hasChanged();
|
||||
repaintNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1107,7 +1107,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
if (!isLocked()) {
|
||||
visualElement.rotate();
|
||||
circuit.modified();
|
||||
hasChanged();
|
||||
repaintNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
@ -1139,7 +1139,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
this.initialPos = this.pos;
|
||||
deleteAction.setActive(true);
|
||||
removeHighLighted();
|
||||
hasChanged();
|
||||
repaintNeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1159,7 +1159,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
wire.noDot();
|
||||
isManualScale = true;
|
||||
circuit.modified();
|
||||
hasChanged();
|
||||
repaintNeeded();
|
||||
}
|
||||
this.pos = pos;
|
||||
}
|
||||
@ -1472,7 +1472,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
accumulatedDelta = accumulatedDelta.add(delta);
|
||||
wasMoved = true;
|
||||
|
||||
hasChanged();
|
||||
repaintNeeded();
|
||||
lastPos = lastPos.add(delta);
|
||||
center = center.add(delta);
|
||||
}
|
||||
@ -1494,7 +1494,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
public void rotate() {
|
||||
ModifyMoveSelected.rotateElements(elements, center);
|
||||
circuit.modified();
|
||||
hasChanged();
|
||||
repaintNeeded();
|
||||
accumulatedRotate++;
|
||||
}
|
||||
}
|
||||
@ -1564,7 +1564,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
public void rotate() {
|
||||
ModifyMoveSelected.rotateElements(elements, raster(lastPos));
|
||||
circuit.modified();
|
||||
hasChanged();
|
||||
repaintNeeded();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -1635,7 +1635,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
if (manualChangeObserver != null)
|
||||
manualChangeObserver.hasChanged();
|
||||
} else
|
||||
hasChanged();
|
||||
repaintNeeded();
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user