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