From 34c009186cdb0deaf22b0f40838af6d658cbbbd3 Mon Sep 17 00:00:00 2001 From: hneemann Date: Thu, 7 Jul 2016 17:44:03 +0200 Subject: [PATCH] testdata in non modal dialog --- .../java/de/neemann/digital/gui/Main.java | 45 +++++++++++-------- .../gui/components/AttributeDialog.java | 9 +++- .../gui/components/CircuitComponent.java | 11 ++++- .../digital/gui/components/Editor.java | 3 +- .../digital/gui/components/EditorFactory.java | 14 +++++- .../gui/components/test/TestDataDialog.java | 42 ++++++++++++++++- .../gui/components/test/TestDataEditor.java | 27 ++++++++--- src/main/resources/lang/lang_de.xml | 3 ++ src/main/resources/lang/lang_en.xml | 3 ++ 9 files changed, 124 insertions(+), 33 deletions(-) diff --git a/src/main/java/de/neemann/digital/gui/Main.java b/src/main/java/de/neemann/digital/gui/Main.java index ac60044a0..d087e28da 100644 --- a/src/main/java/de/neemann/digital/gui/Main.java +++ b/src/main/java/de/neemann/digital/gui/Main.java @@ -161,10 +161,10 @@ private Main(Component parent, File fileToOpen, SavedListener savedListener, Cir final boolean normalMode = savedListener == null; if (circuit != null) { - circuitComponent = new CircuitComponent(library, shapeFactory, savedListener); + circuitComponent = new CircuitComponent(this, library, shapeFactory, savedListener); SwingUtilities.invokeLater(() -> circuitComponent.setCircuit(circuit)); } else { - circuitComponent = new CircuitComponent(library, shapeFactory, savedListener); + circuitComponent = new CircuitComponent(this, library, shapeFactory, savedListener); if (fileToOpen != null) { SwingUtilities.invokeLater(() -> loadFile(fileToOpen, false)); } else { @@ -470,23 +470,7 @@ public void actionPerformed(ActionEvent e) { ToolTipAction runTests = new ToolTipAction(Lang.get("menu_runTests"), ICON_TEST) { @Override public void actionPerformed(ActionEvent e) { - try { - ArrayList tsl = new ArrayList<>(); - for (VisualElement el : circuitComponent.getCircuit().getElements()) - if (el.equalsDescription(TestCaseElement.TESTCASEDESCRIPTION)) - tsl.add(new TestResultDialog.TestSet( - el.getElementAttributes().get(TestCaseElement.TESTDATA), - el.getElementAttributes().getCleanLabel())); - - if (tsl.isEmpty()) - throw new DataException(Lang.get("err_noTestData")); - - windowPosManager.register("testcase", new TestResultDialog(Main.this, tsl, circuitComponent.getCircuit(), library)).setVisible(true); - - circuitComponent.getCircuit().clearState(); - } catch (Exception e1) { - new ErrorMessage(Lang.get("msg_runningTestError")).addCause(e1).show(); - } + startTests(); } }.setToolTip(Lang.get("menu_runTests_tt")); @@ -535,6 +519,29 @@ public void actionPerformed(ActionEvent e) { toolBar.add(runTests.createJButtonNoText()); } + /** + * starts the tests + */ + public void startTests() { + try { + ArrayList tsl = new ArrayList<>(); + for (VisualElement el : circuitComponent.getCircuit().getElements()) + if (el.equalsDescription(TestCaseElement.TESTCASEDESCRIPTION)) + tsl.add(new TestResultDialog.TestSet( + el.getElementAttributes().get(TestCaseElement.TESTDATA), + el.getElementAttributes().getCleanLabel())); + + if (tsl.isEmpty()) + throw new DataException(Lang.get("err_noTestData")); + + windowPosManager.register("testcase", new TestResultDialog(Main.this, tsl, circuitComponent.getCircuit(), library)).setVisible(true); + + circuitComponent.getCircuit().clearState(); + } catch (Exception e1) { + new ErrorMessage(Lang.get("msg_runningTestError")).addCause(e1).show(); + } + } + /** * Creates the analyse menu * diff --git a/src/main/java/de/neemann/digital/gui/components/AttributeDialog.java b/src/main/java/de/neemann/digital/gui/components/AttributeDialog.java index df79344d0..1cbc7df5d 100644 --- a/src/main/java/de/neemann/digital/gui/components/AttributeDialog.java +++ b/src/main/java/de/neemann/digital/gui/components/AttributeDialog.java @@ -56,7 +56,7 @@ public AttributeDialog(Component parent, Point pos, java.util.List list, El for (Key key : list) { Editor e = EditorFactory.INSTANCE.create(key, elementAttributes.get(key)); editors.add(new EditorHolder(e, key)); - e.addToPanel(panel, key, elementAttributes); + e.addToPanel(panel, key, elementAttributes, this); } JButton okButton = new JButton(new AbstractAction(Lang.get("ok")) { @@ -123,6 +123,13 @@ public boolean showDialog() { return changed; } + /** + * @return the dialogs parent + */ + public Component getDialogParent() { + return parent; + } + private static final class EditorHolder { private final Editor e; private final Key key; diff --git a/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java b/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java index de746062f..291d8cbc4 100644 --- a/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java +++ b/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java @@ -49,6 +49,7 @@ public class CircuitComponent extends JComponent { public static final Icon ICON_DELETE = IconCreator.create("delete.png"); private static final String DEL_ACTION = "myDelAction"; + private final Main parent; private final ElementLibrary library; private final SavedListener parentsSavedListener; private final HashSet highLighted; @@ -80,7 +81,8 @@ public class CircuitComponent extends JComponent { * @param library the library used to edit the attributes of the elements * @param shapeFactory the shapeFactory used for copied elements */ - public CircuitComponent(ElementLibrary library, ShapeFactory shapeFactory, SavedListener parentsSavedListener) { + public CircuitComponent(Main parent, ElementLibrary library, ShapeFactory shapeFactory, SavedListener parentsSavedListener) { + this.parent = parent; this.library = library; this.parentsSavedListener = parentsSavedListener; highLighted = new HashSet<>(); @@ -176,6 +178,13 @@ public void actionPerformed(ActionEvent e) { setToolTipText(""); } + /** + * @return the main frame + */ + public Main getMain() { + return parent; + } + @Override public String getToolTipText(MouseEvent event) { Vector pos = getPosVector(event); diff --git a/src/main/java/de/neemann/digital/gui/components/Editor.java b/src/main/java/de/neemann/digital/gui/components/Editor.java index b76d5289e..d9dd58dc1 100644 --- a/src/main/java/de/neemann/digital/gui/components/Editor.java +++ b/src/main/java/de/neemann/digital/gui/components/Editor.java @@ -22,6 +22,7 @@ public interface Editor { * @param panel the panel to add the components to * @param key the key which is to edit * @param elementAttributes the attributes + * @param dialog the containing dialog */ - void addToPanel(JPanel panel, Key key, ElementAttributes elementAttributes); + void addToPanel(JPanel panel, Key key, ElementAttributes elementAttributes, AttributeDialog dialog); } diff --git a/src/main/java/de/neemann/digital/gui/components/EditorFactory.java b/src/main/java/de/neemann/digital/gui/components/EditorFactory.java index 919bd3f8c..81530ef70 100644 --- a/src/main/java/de/neemann/digital/gui/components/EditorFactory.java +++ b/src/main/java/de/neemann/digital/gui/components/EditorFactory.java @@ -76,8 +76,11 @@ public Editor create(Key key, T value) { * @param the type to edit */ public static abstract class LabelEditor implements Editor { + private AttributeDialog attributeDialog; + @Override - public void addToPanel(JPanel panel, Key key, ElementAttributes elementAttributes) { + public void addToPanel(JPanel panel, Key key, ElementAttributes elementAttributes, AttributeDialog attributeDialog) { + this.attributeDialog = attributeDialog; JLabel label = new JLabel(key.getName() + ": "); label.setToolTipText(key.getDescription()); panel.add(label, DialogLayout.LABEL); @@ -86,6 +89,13 @@ public void addToPanel(JPanel panel, Key key, ElementAttributes elementAttribute panel.add(component, DialogLayout.INPUT); } + /** + * @return the containing dialog + */ + public AttributeDialog getAttributeDialog() { + return attributeDialog; + } + /** * returns the editor component * @@ -174,7 +184,7 @@ public Boolean getValue() { } @Override - public void addToPanel(JPanel panel, Key key, ElementAttributes elementAttributes) { + public void addToPanel(JPanel panel, Key key, ElementAttributes elementAttributes, AttributeDialog attributeDialog) { panel.add(bool, DialogLayout.BOTH); } } diff --git a/src/main/java/de/neemann/digital/gui/components/test/TestDataDialog.java b/src/main/java/de/neemann/digital/gui/components/test/TestDataDialog.java index 3fa0f5111..cda9ca62d 100644 --- a/src/main/java/de/neemann/digital/gui/components/test/TestDataDialog.java +++ b/src/main/java/de/neemann/digital/gui/components/test/TestDataDialog.java @@ -1,5 +1,8 @@ package de.neemann.digital.gui.components.test; +import de.neemann.digital.core.element.ElementAttributes; +import de.neemann.digital.core.element.Key; +import de.neemann.digital.gui.components.CircuitComponent; import de.neemann.digital.gui.components.table.ShowStringDialog; import de.neemann.digital.lang.Lang; import de.neemann.gui.ErrorMessage; @@ -22,8 +25,23 @@ public class TestDataDialog extends JDialog { * @param parent the parent component * @param data the data to edit */ - public TestDataDialog(JComponent parent, TestData data) { - super(SwingUtilities.getWindowAncestor(parent), Lang.get("key_Testdata"), ModalityType.APPLICATION_MODAL); + public TestDataDialog(Component parent, TestData data) { + this(parent, data, null, null); + } + + + /** + * Creates a new data dialog + * + * @param parent the parent component + * @param data the data to edit + * @param key the key for the apply button + * @param elementAttributes the attributes to store the values + */ + public TestDataDialog(Component parent, TestData data, Key key, ElementAttributes elementAttributes) { + super(SwingUtilities.getWindowAncestor(parent), + Lang.get("key_Testdata"), + key == null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS); setDefaultCloseOperation(DISPOSE_ON_CLOSE); JTextArea text = new JTextArea(data.getDataString(), 30, 50); @@ -46,6 +64,25 @@ public void actionPerformed(ActionEvent e) { } }.createJButton()); + if (key!=null && elementAttributes!=null) { + buttons.add(new ToolTipAction(Lang.get("menu_runTests")) { + @Override + public void actionPerformed(ActionEvent e) { + try { + data.setDataString(text.getText()); + elementAttributes.set(key, data); + if (parent instanceof CircuitComponent) { + CircuitComponent cc = (CircuitComponent) parent; + cc.getMain().startTests(); + } + } catch (DataException e1) { + new ErrorMessage(e1.getMessage()).show(TestDataDialog.this); + } + } + }.createJButton()); + + } + buttons.add(new ToolTipAction(Lang.get("ok")) { @Override public void actionPerformed(ActionEvent e) { @@ -63,4 +100,5 @@ public void actionPerformed(ActionEvent e) { pack(); setLocationRelativeTo(parent); } + } diff --git a/src/main/java/de/neemann/digital/gui/components/test/TestDataEditor.java b/src/main/java/de/neemann/digital/gui/components/test/TestDataEditor.java index 981909324..0c8ac8b67 100644 --- a/src/main/java/de/neemann/digital/gui/components/test/TestDataEditor.java +++ b/src/main/java/de/neemann/digital/gui/components/test/TestDataEditor.java @@ -2,12 +2,12 @@ import de.neemann.digital.core.element.ElementAttributes; import de.neemann.digital.core.element.Key; -import de.neemann.digital.core.memory.DataField; import de.neemann.digital.gui.components.EditorFactory; import de.neemann.digital.lang.Lang; import de.neemann.gui.ToolTipAction; import javax.swing.*; +import java.awt.*; import java.awt.event.ActionEvent; /** @@ -16,7 +16,7 @@ public class TestDataEditor extends EditorFactory.LabelEditor { private final TestData data; - private JButton editButton; + private final Key key; /** * Creates a new editor @@ -24,8 +24,9 @@ public class TestDataEditor extends EditorFactory.LabelEditor { * @param data the data to edit * @param key the data key */ - public TestDataEditor(TestData data, Key key) { + public TestDataEditor(TestData data, Key key) { this.data = new TestData(data); + this.key = key; } @Override @@ -35,12 +36,24 @@ public TestData getValue() { @Override protected JComponent getComponent(ElementAttributes elementAttributes) { - editButton = new ToolTipAction(Lang.get("btn_edit")) { + JPanel panel = new JPanel(new FlowLayout()); + + panel.add(new ToolTipAction(Lang.get("btn_edit")) { + @Override + public void actionPerformed(ActionEvent e) { + new TestDataDialog(panel, data).setVisible(true); + } + }.createJButton()); + + panel.add(new ToolTipAction(Lang.get("btn_editDetached")) { @Override public void actionPerformed(ActionEvent e) { - new TestDataDialog(editButton, data).setVisible(true); + getAttributeDialog().dispose(); + new TestDataDialog(getAttributeDialog().getDialogParent(), data, key, elementAttributes).setVisible(true); } - }.createJButton(); - return editButton; + }.setToolTip(Lang.get("btn_editDetached_tt")) + .createJButton()); + + return panel; } } diff --git a/src/main/resources/lang/lang_de.xml b/src/main/resources/lang/lang_de.xml index 3375484b6..95fdf1cd6 100644 --- a/src/main/resources/lang/lang_de.xml +++ b/src/main/resources/lang/lang_de.xml @@ -14,6 +14,9 @@ Speichern Erzeugen Erzeugt eine Schaltung in einem eigenen Fenster. + Permanent Bearbeiten + Öffnet den Bearbeitendialog nicht modal. + Übernehmen Abbrechen Digital Ausdruck diff --git a/src/main/resources/lang/lang_en.xml b/src/main/resources/lang/lang_en.xml index 171515b2c..d8a109919 100644 --- a/src/main/resources/lang/lang_en.xml +++ b/src/main/resources/lang/lang_en.xml @@ -14,6 +14,9 @@ Save Create Create a circuit in a seperate window + Edit detached + Opens the dialog as a non modal dialog + apply Cancel Digital Expression