mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 23:36:27 -04:00
AttributeDialog bound to parent frame
This commit is contained in:
parent
0e0c9a2d2c
commit
574254aa17
@ -19,6 +19,7 @@ import de.neemann.digital.draw.shapes.ShapeFactory;
|
|||||||
import de.neemann.digital.gui.components.AttributeDialog;
|
import de.neemann.digital.gui.components.AttributeDialog;
|
||||||
import de.neemann.digital.lang.Lang;
|
import de.neemann.digital.lang.Lang;
|
||||||
|
|
||||||
|
import java.awt.*;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@ -84,8 +85,8 @@ public class Circuit implements Drawable {
|
|||||||
return attributes;
|
return attributes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void editAttributes() {
|
public void editAttributes(Component parent) {
|
||||||
if (new AttributeDialog(null, ATTR_LIST, getAttributes()).showDialog()) {
|
if (new AttributeDialog(parent, null, ATTR_LIST, getAttributes()).showDialog()) {
|
||||||
if (attributes.isEmpty())
|
if (attributes.isEmpty())
|
||||||
attributes = null;
|
attributes = null;
|
||||||
modified();
|
modified();
|
||||||
|
@ -62,6 +62,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
private File filename;
|
private File filename;
|
||||||
private Model model;
|
private Model model;
|
||||||
private ModelDescription modelDescription;
|
private ModelDescription modelDescription;
|
||||||
|
private boolean modelHasRunningClocks;
|
||||||
|
|
||||||
public Main() {
|
public Main() {
|
||||||
this(null, null, null);
|
this(null, null, null);
|
||||||
@ -196,7 +197,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
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) {
|
||||||
circuitComponent.getCircuit().editAttributes();
|
circuitComponent.getCircuit().editAttributes(Main.this);
|
||||||
}
|
}
|
||||||
}.setToolTip(Lang.get("menu_editAttributes_tt"));
|
}.setToolTip(Lang.get("menu_editAttributes_tt"));
|
||||||
|
|
||||||
@ -247,9 +248,8 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
ToolTipAction runFast = new ToolTipAction(Lang.get("menu_fast"), iconFast) {
|
ToolTipAction runFast = new ToolTipAction(Lang.get("menu_fast"), iconFast) {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
if (model == null) {
|
if (model == null || modelHasRunningClocks) {
|
||||||
createAndStartModel(false);
|
createAndStartModel(false);
|
||||||
circuitComponent.setManualChangeObserver(null);
|
|
||||||
if (model.getBreaks().size() != 1 || model.getClocks().size() != 1) {
|
if (model.getBreaks().size() != 1 || model.getClocks().size() != 1) {
|
||||||
clearModelDescription();
|
clearModelDescription();
|
||||||
circuitComponent.setModeAndReset(CircuitComponent.Mode.part);
|
circuitComponent.setModeAndReset(CircuitComponent.Mode.part);
|
||||||
@ -341,10 +341,11 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
model = null;
|
model = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setModelDescription(ModelDescription md) throws NodeException, PinException {
|
private void setModelDescription(ModelDescription md, boolean runClock) throws NodeException, PinException {
|
||||||
if (modelDescription != null)
|
if (modelDescription != null)
|
||||||
modelDescription.highLightOff();
|
modelDescription.highLightOff();
|
||||||
|
|
||||||
|
modelHasRunningClocks = runClock;
|
||||||
modelDescription = md;
|
modelDescription = md;
|
||||||
|
|
||||||
if (model != null)
|
if (model != null)
|
||||||
@ -358,7 +359,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
|||||||
try {
|
try {
|
||||||
circuitComponent.setModeAndReset(CircuitComponent.Mode.running);
|
circuitComponent.setModeAndReset(CircuitComponent.Mode.running);
|
||||||
|
|
||||||
setModelDescription(new ModelDescription(circuitComponent.getCircuit(), library));
|
setModelDescription(new ModelDescription(circuitComponent.getCircuit(), library), runClock);
|
||||||
modelDescription.connectToGui(circuitComponent);
|
modelDescription.connectToGui(circuitComponent);
|
||||||
|
|
||||||
if (runClock)
|
if (runClock)
|
||||||
|
@ -18,8 +18,8 @@ public class AttributeDialog extends JDialog {
|
|||||||
private final ArrayList<EditorHolder> editors;
|
private final ArrayList<EditorHolder> editors;
|
||||||
private boolean changed = false;
|
private boolean changed = false;
|
||||||
|
|
||||||
public AttributeDialog(Point pos, ArrayList<AttributeKey> list, ElementAttributes elementAttributes) {
|
public AttributeDialog(Component parent, Point pos, ArrayList<AttributeKey> list, ElementAttributes elementAttributes) {
|
||||||
super((Frame) null, Lang.get("attr_dialogTitle"), true);
|
super(SwingUtilities.getWindowAncestor(parent), Lang.get("attr_dialogTitle"), ModalityType.APPLICATION_MODAL);
|
||||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||||
|
|
||||||
JPanel panel = new JPanel(new DialogLayout());
|
JPanel panel = new JPanel(new DialogLayout());
|
||||||
@ -91,7 +91,7 @@ public class AttributeDialog extends JDialog {
|
|||||||
list.add(AttributeKey.Color);
|
list.add(AttributeKey.Color);
|
||||||
list.add(AttributeKey.Signed);
|
list.add(AttributeKey.Signed);
|
||||||
ElementAttributes values = new ElementAttributes();
|
ElementAttributes values = new ElementAttributes();
|
||||||
AttributeDialog d = new AttributeDialog(null, list, values);
|
AttributeDialog d = new AttributeDialog(null, null, list, values);
|
||||||
d.showDialog();
|
d.showDialog();
|
||||||
System.out.println(values);
|
System.out.println(values);
|
||||||
}
|
}
|
||||||
|
@ -339,7 +339,7 @@ public class CircuitComponent extends JComponent implements Observer {
|
|||||||
if (list.size() > 0) {
|
if (list.size() > 0) {
|
||||||
Point p = new Point(e.getX(), e.getY());
|
Point p = new Point(e.getX(), e.getY());
|
||||||
SwingUtilities.convertPointToScreen(p, CircuitComponent.this);
|
SwingUtilities.convertPointToScreen(p, CircuitComponent.this);
|
||||||
if (new AttributeDialog(p, list, vp.getElementAttributes()).showDialog()) {
|
if (new AttributeDialog(this, p, list, vp.getElementAttributes()).showDialog()) {
|
||||||
circuit.modified();
|
circuit.modified();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import de.neemann.digital.core.element.Rotation;
|
|||||||
import de.neemann.digital.core.memory.DataField;
|
import de.neemann.digital.core.memory.DataField;
|
||||||
import de.neemann.digital.lang.Lang;
|
import de.neemann.digital.lang.Lang;
|
||||||
import de.neemann.gui.ErrorMessage;
|
import de.neemann.gui.ErrorMessage;
|
||||||
|
import de.neemann.gui.ToolTipAction;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -154,7 +155,7 @@ public final class EditorFactory {
|
|||||||
@Override
|
@Override
|
||||||
public Component getComponent(ElementAttributes attr) {
|
public Component getComponent(ElementAttributes attr) {
|
||||||
JPanel panel = new JPanel(new FlowLayout());
|
JPanel panel = new JPanel(new FlowLayout());
|
||||||
panel.add(new JButton(new AbstractAction(Lang.get("btn_edit")) {
|
panel.add(new ToolTipAction(Lang.get("btn_edit")) {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
DataEditor de = new DataEditor(panel, data, attr);
|
DataEditor de = new DataEditor(panel, data, attr);
|
||||||
@ -162,8 +163,8 @@ public final class EditorFactory {
|
|||||||
data = de.getDataField();
|
data = de.getDataField();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}.createJButton());
|
||||||
panel.add(new JButton(new AbstractAction(Lang.get("btn_load")) {
|
panel.add(new ToolTipAction(Lang.get("btn_load")) {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
JFileChooser fc = new JFileChooser();
|
JFileChooser fc = new JFileChooser();
|
||||||
@ -177,7 +178,21 @@ public final class EditorFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}));
|
}.createJButton());
|
||||||
|
panel.add(new ToolTipAction(Lang.get("btn_reload")) {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
try {
|
||||||
|
data = new DataField(attr.getFile("lastDataFile"));
|
||||||
|
} catch (IOException e1) {
|
||||||
|
new ErrorMessage(Lang.get("msg_errorReadingFile")).addCause(e1).show(panel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.setActive(attr.getFile("lastDataFile") != null)
|
||||||
|
.setToolTip(Lang.get("btn_reload_tt"))
|
||||||
|
.createJButton()
|
||||||
|
);
|
||||||
return panel;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user