mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-14 07:17:13 -04:00
testdata in non modal dialog
This commit is contained in:
parent
8849ff9fdd
commit
34c009186c
@ -161,10 +161,10 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
|
|||||||
final boolean normalMode = savedListener == null;
|
final boolean normalMode = savedListener == null;
|
||||||
|
|
||||||
if (circuit != null) {
|
if (circuit != null) {
|
||||||
circuitComponent = new CircuitComponent(library, shapeFactory, savedListener);
|
circuitComponent = new CircuitComponent(this, library, shapeFactory, savedListener);
|
||||||
SwingUtilities.invokeLater(() -> circuitComponent.setCircuit(circuit));
|
SwingUtilities.invokeLater(() -> circuitComponent.setCircuit(circuit));
|
||||||
} else {
|
} else {
|
||||||
circuitComponent = new CircuitComponent(library, shapeFactory, savedListener);
|
circuitComponent = new CircuitComponent(this, library, shapeFactory, savedListener);
|
||||||
if (fileToOpen != null) {
|
if (fileToOpen != null) {
|
||||||
SwingUtilities.invokeLater(() -> loadFile(fileToOpen, false));
|
SwingUtilities.invokeLater(() -> loadFile(fileToOpen, false));
|
||||||
} else {
|
} else {
|
||||||
@ -470,23 +470,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
|
|||||||
ToolTipAction runTests = new ToolTipAction(Lang.get("menu_runTests"), ICON_TEST) {
|
ToolTipAction runTests = new ToolTipAction(Lang.get("menu_runTests"), ICON_TEST) {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
try {
|
startTests();
|
||||||
ArrayList<TestResultDialog.TestSet> 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();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}.setToolTip(Lang.get("menu_runTests_tt"));
|
}.setToolTip(Lang.get("menu_runTests_tt"));
|
||||||
|
|
||||||
@ -535,6 +519,29 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
|
|||||||
toolBar.add(runTests.createJButtonNoText());
|
toolBar.add(runTests.createJButtonNoText());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* starts the tests
|
||||||
|
*/
|
||||||
|
public void startTests() {
|
||||||
|
try {
|
||||||
|
ArrayList<TestResultDialog.TestSet> 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
|
* Creates the analyse menu
|
||||||
*
|
*
|
||||||
|
@ -56,7 +56,7 @@ public class AttributeDialog extends JDialog {
|
|||||||
for (Key key : list) {
|
for (Key key : list) {
|
||||||
Editor e = EditorFactory.INSTANCE.create(key, elementAttributes.get(key));
|
Editor e = EditorFactory.INSTANCE.create(key, elementAttributes.get(key));
|
||||||
editors.add(new EditorHolder(e, 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")) {
|
JButton okButton = new JButton(new AbstractAction(Lang.get("ok")) {
|
||||||
@ -123,6 +123,13 @@ public class AttributeDialog extends JDialog {
|
|||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the dialogs parent
|
||||||
|
*/
|
||||||
|
public Component getDialogParent() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
private static final class EditorHolder<T> {
|
private static final class EditorHolder<T> {
|
||||||
private final Editor<T> e;
|
private final Editor<T> e;
|
||||||
private final Key<T> key;
|
private final Key<T> key;
|
||||||
|
@ -49,6 +49,7 @@ public class CircuitComponent extends JComponent {
|
|||||||
public static final Icon ICON_DELETE = IconCreator.create("delete.png");
|
public static final Icon ICON_DELETE = IconCreator.create("delete.png");
|
||||||
private static final String DEL_ACTION = "myDelAction";
|
private static final String DEL_ACTION = "myDelAction";
|
||||||
|
|
||||||
|
private final Main parent;
|
||||||
private final ElementLibrary library;
|
private final ElementLibrary library;
|
||||||
private final SavedListener parentsSavedListener;
|
private final SavedListener parentsSavedListener;
|
||||||
private final HashSet<Drawable> highLighted;
|
private final HashSet<Drawable> highLighted;
|
||||||
@ -80,7 +81,8 @@ public class CircuitComponent extends JComponent {
|
|||||||
* @param library the library used to edit the attributes of the elements
|
* @param library the library used to edit the attributes of the elements
|
||||||
* @param shapeFactory the shapeFactory used for copied 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.library = library;
|
||||||
this.parentsSavedListener = parentsSavedListener;
|
this.parentsSavedListener = parentsSavedListener;
|
||||||
highLighted = new HashSet<>();
|
highLighted = new HashSet<>();
|
||||||
@ -176,6 +178,13 @@ public class CircuitComponent extends JComponent {
|
|||||||
setToolTipText("");
|
setToolTipText("");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the main frame
|
||||||
|
*/
|
||||||
|
public Main getMain() {
|
||||||
|
return parent;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getToolTipText(MouseEvent event) {
|
public String getToolTipText(MouseEvent event) {
|
||||||
Vector pos = getPosVector(event);
|
Vector pos = getPosVector(event);
|
||||||
|
@ -22,6 +22,7 @@ public interface Editor<T> {
|
|||||||
* @param panel the panel to add the components to
|
* @param panel the panel to add the components to
|
||||||
* @param key the key which is to edit
|
* @param key the key which is to edit
|
||||||
* @param elementAttributes the attributes
|
* @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);
|
||||||
}
|
}
|
||||||
|
@ -76,8 +76,11 @@ public final class EditorFactory {
|
|||||||
* @param <T> the type to edit
|
* @param <T> the type to edit
|
||||||
*/
|
*/
|
||||||
public static abstract class LabelEditor<T> implements Editor<T> {
|
public static abstract class LabelEditor<T> implements Editor<T> {
|
||||||
|
private AttributeDialog attributeDialog;
|
||||||
|
|
||||||
@Override
|
@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() + ": ");
|
JLabel label = new JLabel(key.getName() + ": ");
|
||||||
label.setToolTipText(key.getDescription());
|
label.setToolTipText(key.getDescription());
|
||||||
panel.add(label, DialogLayout.LABEL);
|
panel.add(label, DialogLayout.LABEL);
|
||||||
@ -86,6 +89,13 @@ public final class EditorFactory {
|
|||||||
panel.add(component, DialogLayout.INPUT);
|
panel.add(component, DialogLayout.INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the containing dialog
|
||||||
|
*/
|
||||||
|
public AttributeDialog getAttributeDialog() {
|
||||||
|
return attributeDialog;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the editor component
|
* returns the editor component
|
||||||
*
|
*
|
||||||
@ -174,7 +184,7 @@ public final class EditorFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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);
|
panel.add(bool, DialogLayout.BOTH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package de.neemann.digital.gui.components.test;
|
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.gui.components.table.ShowStringDialog;
|
||||||
import de.neemann.digital.lang.Lang;
|
import de.neemann.digital.lang.Lang;
|
||||||
import de.neemann.gui.ErrorMessage;
|
import de.neemann.gui.ErrorMessage;
|
||||||
@ -22,8 +25,23 @@ public class TestDataDialog extends JDialog {
|
|||||||
* @param parent the parent component
|
* @param parent the parent component
|
||||||
* @param data the data to edit
|
* @param data the data to edit
|
||||||
*/
|
*/
|
||||||
public TestDataDialog(JComponent parent, TestData data) {
|
public TestDataDialog(Component parent, TestData data) {
|
||||||
super(SwingUtilities.getWindowAncestor(parent), Lang.get("key_Testdata"), ModalityType.APPLICATION_MODAL);
|
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<TestData> key, ElementAttributes elementAttributes) {
|
||||||
|
super(SwingUtilities.getWindowAncestor(parent),
|
||||||
|
Lang.get("key_Testdata"),
|
||||||
|
key == null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS);
|
||||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||||
|
|
||||||
JTextArea text = new JTextArea(data.getDataString(), 30, 50);
|
JTextArea text = new JTextArea(data.getDataString(), 30, 50);
|
||||||
@ -46,6 +64,25 @@ public class TestDataDialog extends JDialog {
|
|||||||
}
|
}
|
||||||
}.createJButton());
|
}.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")) {
|
buttons.add(new ToolTipAction(Lang.get("ok")) {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
@ -63,4 +100,5 @@ public class TestDataDialog extends JDialog {
|
|||||||
pack();
|
pack();
|
||||||
setLocationRelativeTo(parent);
|
setLocationRelativeTo(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,12 +2,12 @@ package de.neemann.digital.gui.components.test;
|
|||||||
|
|
||||||
import de.neemann.digital.core.element.ElementAttributes;
|
import de.neemann.digital.core.element.ElementAttributes;
|
||||||
import de.neemann.digital.core.element.Key;
|
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.gui.components.EditorFactory;
|
||||||
import de.neemann.digital.lang.Lang;
|
import de.neemann.digital.lang.Lang;
|
||||||
import de.neemann.gui.ToolTipAction;
|
import de.neemann.gui.ToolTipAction;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -16,7 +16,7 @@ import java.awt.event.ActionEvent;
|
|||||||
public class TestDataEditor extends EditorFactory.LabelEditor<TestData> {
|
public class TestDataEditor extends EditorFactory.LabelEditor<TestData> {
|
||||||
|
|
||||||
private final TestData data;
|
private final TestData data;
|
||||||
private JButton editButton;
|
private final Key<TestData> key;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new editor
|
* Creates a new editor
|
||||||
@ -24,8 +24,9 @@ public class TestDataEditor extends EditorFactory.LabelEditor<TestData> {
|
|||||||
* @param data the data to edit
|
* @param data the data to edit
|
||||||
* @param key the data key
|
* @param key the data key
|
||||||
*/
|
*/
|
||||||
public TestDataEditor(TestData data, Key<DataField> key) {
|
public TestDataEditor(TestData data, Key<TestData> key) {
|
||||||
this.data = new TestData(data);
|
this.data = new TestData(data);
|
||||||
|
this.key = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -35,12 +36,24 @@ public class TestDataEditor extends EditorFactory.LabelEditor<TestData> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected JComponent getComponent(ElementAttributes elementAttributes) {
|
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
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
new TestDataDialog(editButton, data).setVisible(true);
|
new TestDataDialog(panel, data).setVisible(true);
|
||||||
}
|
}
|
||||||
}.createJButton();
|
}.createJButton());
|
||||||
return editButton;
|
|
||||||
|
panel.add(new ToolTipAction(Lang.get("btn_editDetached")) {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
getAttributeDialog().dispose();
|
||||||
|
new TestDataDialog(getAttributeDialog().getDialogParent(), data, key, elementAttributes).setVisible(true);
|
||||||
|
}
|
||||||
|
}.setToolTip(Lang.get("btn_editDetached_tt"))
|
||||||
|
.createJButton());
|
||||||
|
|
||||||
|
return panel;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,9 @@
|
|||||||
<string name="btn_save">Speichern</string>
|
<string name="btn_save">Speichern</string>
|
||||||
<string name="btn_create">Erzeugen</string>
|
<string name="btn_create">Erzeugen</string>
|
||||||
<string name="btn_create_tt">Erzeugt eine Schaltung in einem eigenen Fenster.</string>
|
<string name="btn_create_tt">Erzeugt eine Schaltung in einem eigenen Fenster.</string>
|
||||||
|
<string name="btn_editDetached">Permanent Bearbeiten</string>
|
||||||
|
<string name="btn_editDetached_tt">Öffnet den Bearbeitendialog nicht modal.</string>
|
||||||
|
<string name="apply">Übernehmen</string>
|
||||||
<string name="cancel">Abbrechen</string>
|
<string name="cancel">Abbrechen</string>
|
||||||
<string name="digital">Digital</string>
|
<string name="digital">Digital</string>
|
||||||
<string name="expression">Ausdruck</string>
|
<string name="expression">Ausdruck</string>
|
||||||
|
@ -14,6 +14,9 @@
|
|||||||
<string name="btn_save">Save</string>
|
<string name="btn_save">Save</string>
|
||||||
<string name="btn_create">Create</string>
|
<string name="btn_create">Create</string>
|
||||||
<string name="btn_create_tt">Create a circuit in a seperate window</string>
|
<string name="btn_create_tt">Create a circuit in a seperate window</string>
|
||||||
|
<string name="btn_editDetached">Edit detached</string>
|
||||||
|
<string name="btn_editDetached_tt">Opens the dialog as a non modal dialog</string>
|
||||||
|
<string name="apply">apply</string>
|
||||||
<string name="cancel">Cancel</string>
|
<string name="cancel">Cancel</string>
|
||||||
<string name="digital">Digital</string>
|
<string name="digital">Digital</string>
|
||||||
<string name="expression">Expression</string>
|
<string name="expression">Expression</string>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user