mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-26 14:31:02 -04:00
implemented undo for test data
This commit is contained in:
parent
cc69fa0096
commit
096ac11054
@ -239,4 +239,19 @@ public class ElementAttributes {
|
||||
attributes = null;
|
||||
fireValueChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ElementAttributes that = (ElementAttributes) o;
|
||||
|
||||
return attributes != null ? attributes.equals(that.attributes) : that.attributes == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return attributes != null ? attributes.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package de.neemann.digital.gui.components;
|
||||
|
||||
import de.neemann.digital.core.element.ElementAttributes;
|
||||
import de.neemann.digital.core.element.Key;
|
||||
import de.neemann.digital.draw.elements.VisualElement;
|
||||
import de.neemann.digital.gui.Main;
|
||||
import de.neemann.digital.lang.Lang;
|
||||
import de.neemann.gui.ErrorMessage;
|
||||
@ -30,6 +31,7 @@ public class AttributeDialog extends JDialog {
|
||||
private final Point pos;
|
||||
private final ElementAttributes elementAttributes;
|
||||
private final JPanel buttonPanel;
|
||||
private VisualElement visualElement;
|
||||
private boolean changed = false;
|
||||
|
||||
/**
|
||||
@ -174,6 +176,24 @@ public class AttributeDialog extends JDialog {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the visual element of this dialog, maybe null
|
||||
*/
|
||||
public VisualElement getVisualElement() {
|
||||
return visualElement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the visual element of this dialog
|
||||
*
|
||||
* @param visualElement the visual element which attributes are edited
|
||||
* @return this for chained calls
|
||||
*/
|
||||
public AttributeDialog setVisualElement(VisualElement visualElement) {
|
||||
this.visualElement = visualElement;
|
||||
return this;
|
||||
}
|
||||
|
||||
private static final class EditorHolder<T> {
|
||||
private final Editor<T> e;
|
||||
private final Key<T> key;
|
||||
|
@ -3,10 +3,7 @@ package de.neemann.digital.gui.components;
|
||||
import de.neemann.digital.core.NodeException;
|
||||
import de.neemann.digital.core.ObservableValue;
|
||||
import de.neemann.digital.core.Observer;
|
||||
import de.neemann.digital.core.element.ElementTypeDescription;
|
||||
import de.neemann.digital.core.element.ImmutableList;
|
||||
import de.neemann.digital.core.element.Key;
|
||||
import de.neemann.digital.core.element.Keys;
|
||||
import de.neemann.digital.core.element.*;
|
||||
import de.neemann.digital.draw.elements.*;
|
||||
import de.neemann.digital.gui.components.modification.*;
|
||||
import de.neemann.digital.draw.graphics.*;
|
||||
@ -709,15 +706,15 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
hasChanged();
|
||||
}
|
||||
|
||||
private void editAttributes(VisualElement vp, MouseEvent e) {
|
||||
String name = vp.getElementName();
|
||||
private void editAttributes(VisualElement element, MouseEvent e) {
|
||||
String name = element.getElementName();
|
||||
try {
|
||||
ElementTypeDescription elementType = library.getElementType(name);
|
||||
ArrayList<Key> list = elementType.getAttributeList();
|
||||
if (list.size() > 0) {
|
||||
Point p = new Point(e.getX(), e.getY());
|
||||
SwingUtilities.convertPointToScreen(p, CircuitComponent.this);
|
||||
AttributeDialog attributeDialog = new AttributeDialog(this, p, list, vp.getElementAttributes());
|
||||
AttributeDialog attributeDialog = new AttributeDialog(this, p, list, element.getElementAttributes()).setVisualElement(element);
|
||||
if (elementType instanceof ElementLibrary.ElementTypeDescriptionCustom) {
|
||||
attributeDialog.addButton(Lang.get("attr_openCircuitLabel"), new ToolTipAction(Lang.get("attr_openCircuit")) {
|
||||
@Override
|
||||
@ -737,14 +734,17 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent actionEvent) {
|
||||
try {
|
||||
new ElementHelpDialog(attributeDialog, elementType, vp.getElementAttributes()).setVisible(true);
|
||||
new ElementHelpDialog(attributeDialog, elementType, element.getElementAttributes()).setVisible(true);
|
||||
} catch (PinException | NodeException e1) {
|
||||
new ErrorMessage(Lang.get("msg_creatingHelp")).addCause(e1).show(CircuitComponent.this);
|
||||
}
|
||||
}
|
||||
}.setToolTip(Lang.get("attr_help_tt")));
|
||||
|
||||
ElementAttributes oldValues = new ElementAttributes(element.getElementAttributes());
|
||||
if (attributeDialog.showDialog())
|
||||
addModificationAlreadyMade(new ModifyAttributes(vp));
|
||||
if (!oldValues.equals(element.getElementAttributes()))
|
||||
addModificationAlreadyMade(new ModifyAttributes(element));
|
||||
}
|
||||
} catch (ElementNotFoundException ex) {
|
||||
// do nothing if element not found!
|
||||
|
@ -1,12 +1,13 @@
|
||||
package de.neemann.digital.gui.components.testing;
|
||||
|
||||
import de.neemann.digital.core.element.ElementAttributes;
|
||||
import de.neemann.digital.core.element.Key;
|
||||
import de.neemann.digital.draw.elements.PinException;
|
||||
import de.neemann.digital.draw.elements.VisualElement;
|
||||
import de.neemann.digital.gui.Main;
|
||||
import de.neemann.digital.gui.components.CircuitComponent;
|
||||
import de.neemann.digital.gui.components.modification.ModifyAttribute;
|
||||
import de.neemann.digital.gui.components.table.ShowStringDialog;
|
||||
import de.neemann.digital.lang.Lang;
|
||||
import de.neemann.digital.testing.TestCaseElement;
|
||||
import de.neemann.digital.testing.TestData;
|
||||
import de.neemann.digital.testing.Transitions;
|
||||
import de.neemann.digital.testing.parser.ParserException;
|
||||
@ -29,28 +30,19 @@ public class TestDataDialog extends JDialog {
|
||||
/**
|
||||
* Creates a new data dialog
|
||||
*
|
||||
* @param parent the parent component
|
||||
* @param data the data to edit
|
||||
* @param parent the parent component
|
||||
* @param data the data to edit
|
||||
* @param element the element to be modified
|
||||
*/
|
||||
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) {
|
||||
public TestDataDialog(Component parent, TestData data, VisualElement element) {
|
||||
super(SwingUtilities.getWindowAncestor(parent),
|
||||
Lang.get("key_Testdata"),
|
||||
key == null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS);
|
||||
element == null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS);
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
|
||||
|
||||
String initialDataString = data.getDataString();
|
||||
|
||||
JTextArea text = new JTextArea(data.getDataString(), 30, 50);
|
||||
text.setFont(new Font(Font.MONOSPACED, Font.PLAIN, Screen.getInstance().getFontSize()));
|
||||
|
||||
@ -90,16 +82,15 @@ public class TestDataDialog extends JDialog {
|
||||
}.setToolTip(Lang.get("btn_addTransitions_tt")).createJButton());
|
||||
}
|
||||
|
||||
if (key != null && elementAttributes != null) {
|
||||
if (element != 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) {
|
||||
element.getElementAttributes().set(TestCaseElement.TESTDATA, data);
|
||||
CircuitComponent cc = (CircuitComponent) parent;
|
||||
cc.getCircuit().modified();
|
||||
cc.getMain().startTests();
|
||||
}
|
||||
} catch (ParserException | IOException e1) {
|
||||
@ -114,12 +105,11 @@ public class TestDataDialog extends JDialog {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
data.setDataString(text.getText());
|
||||
if (key != null && elementAttributes != null) {
|
||||
elementAttributes.set(key, data);
|
||||
if (parent instanceof CircuitComponent) {
|
||||
CircuitComponent cc = (CircuitComponent) parent;
|
||||
cc.getCircuit().modified();
|
||||
}
|
||||
if (element != null
|
||||
&& !initialDataString.equals(data.getDataString())
|
||||
&& parent instanceof CircuitComponent) {
|
||||
CircuitComponent cc = (CircuitComponent) parent;
|
||||
cc.modify(new ModifyAttribute<>(element, TestCaseElement.TESTDATA, new TestData(data)));
|
||||
}
|
||||
dispose();
|
||||
} catch (ParserException | IOException e1) {
|
||||
|
@ -2,6 +2,7 @@ package de.neemann.digital.gui.components.testing;
|
||||
|
||||
import de.neemann.digital.core.element.ElementAttributes;
|
||||
import de.neemann.digital.core.element.Key;
|
||||
import de.neemann.digital.draw.elements.VisualElement;
|
||||
import de.neemann.digital.gui.Main;
|
||||
import de.neemann.digital.gui.components.EditorFactory;
|
||||
import de.neemann.digital.lang.Lang;
|
||||
@ -43,7 +44,7 @@ public class TestDataEditor extends EditorFactory.LabelEditor<TestData> {
|
||||
panel.add(new ToolTipAction(Lang.get("btn_edit")) {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
new TestDataDialog(panel, data).setVisible(true);
|
||||
new TestDataDialog(panel, data, null).setVisible(true);
|
||||
}
|
||||
}.createJButton());
|
||||
|
||||
@ -51,7 +52,8 @@ public class TestDataEditor extends EditorFactory.LabelEditor<TestData> {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
getAttributeDialog().fireOk();
|
||||
TestDataDialog dialog = new TestDataDialog(getAttributeDialog().getDialogParent(), data, key, elementAttributes);
|
||||
VisualElement visualElement = TestDataEditor.this.getAttributeDialog().getVisualElement();
|
||||
TestDataDialog dialog = new TestDataDialog(getAttributeDialog().getDialogParent(), data, visualElement);
|
||||
Main main = getAttributeDialog().getMain();
|
||||
if (main != null)
|
||||
main.getWindowPosManager().register("testdata", dialog);
|
||||
|
@ -88,4 +88,19 @@ public class TestData {
|
||||
check();
|
||||
return names;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
TestData testData = (TestData) o;
|
||||
|
||||
return dataString != null ? dataString.equals(testData.dataString) : testData.dataString == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return dataString != null ? dataString.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user