testdata in non modal dialog

This commit is contained in:
hneemann 2016-07-07 17:44:03 +02:00
parent 8849ff9fdd
commit 34c009186c
9 changed files with 124 additions and 33 deletions

View File

@ -161,10 +161,10 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
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 class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
ToolTipAction runTests = new ToolTipAction(Lang.get("menu_runTests"), ICON_TEST) {
@Override
public void actionPerformed(ActionEvent e) {
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();
}
startTests();
}
}.setToolTip(Lang.get("menu_runTests_tt"));
@ -535,6 +519,29 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
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
*

View File

@ -56,7 +56,7 @@ public class AttributeDialog extends JDialog {
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 class AttributeDialog extends JDialog {
return changed;
}
/**
* @return the dialogs parent
*/
public Component getDialogParent() {
return parent;
}
private static final class EditorHolder<T> {
private final Editor<T> e;
private final Key<T> key;

View File

@ -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<Drawable> 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 class CircuitComponent extends JComponent {
setToolTipText("");
}
/**
* @return the main frame
*/
public Main getMain() {
return parent;
}
@Override
public String getToolTipText(MouseEvent event) {
Vector pos = getPosVector(event);

View File

@ -22,6 +22,7 @@ public interface Editor<T> {
* @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);
}

View File

@ -76,8 +76,11 @@ public final class EditorFactory {
* @param <T> the type to edit
*/
public static abstract class LabelEditor<T> implements Editor<T> {
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 final class EditorFactory {
panel.add(component, DialogLayout.INPUT);
}
/**
* @return the containing dialog
*/
public AttributeDialog getAttributeDialog() {
return attributeDialog;
}
/**
* returns the editor component
*
@ -174,7 +184,7 @@ public final class EditorFactory {
}
@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);
}
}

View File

@ -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<TestData> 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 class TestDataDialog extends JDialog {
}
}.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 class TestDataDialog extends JDialog {
pack();
setLocationRelativeTo(parent);
}
}

View File

@ -2,12 +2,12 @@ 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.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 @@ import java.awt.event.ActionEvent;
public class TestDataEditor extends EditorFactory.LabelEditor<TestData> {
private final TestData data;
private JButton editButton;
private final Key<TestData> key;
/**
* Creates a new editor
@ -24,8 +24,9 @@ public class TestDataEditor extends EditorFactory.LabelEditor<TestData> {
* @param data the data to edit
* @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.key = key;
}
@Override
@ -35,12 +36,24 @@ public class TestDataEditor extends EditorFactory.LabelEditor<TestData> {
@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(editButton, data).setVisible(true);
new TestDataDialog(panel, data).setVisible(true);
}
}.createJButton();
return editButton;
}.createJButton());
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;
}
}

View File

@ -14,6 +14,9 @@
<string name="btn_save">Speichern</string>
<string name="btn_create">Erzeugen</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="digital">Digital</string>
<string name="expression">Ausdruck</string>

View File

@ -14,6 +14,9 @@
<string name="btn_save">Save</string>
<string name="btn_create">Create</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="digital">Digital</string>
<string name="expression">Expression</string>