removed SwingUtilities.getWindowAncestor() from AttributeDialog.

This commit is contained in:
hneemann 2018-01-22 18:57:10 +01:00
parent e7a0b19ae7
commit 02000b8cca
5 changed files with 31 additions and 37 deletions

View File

@ -611,7 +611,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
ToolTipAction editAttributes = new ToolTipAction(Lang.get("menu_editAttributes")) {
@Override
public void actionPerformed(ActionEvent e) {
circuitComponent.editCircuitAttributes(Main.this);
circuitComponent.editCircuitAttributes();
}
}.setToolTip(Lang.get("menu_editAttributes_tt"));
@ -1611,7 +1611,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
*/
public static class MainBuilder {
private File fileToOpen;
private Component parent;
private Window parent;
private ElementLibrary library;
private Circuit circuit;
private boolean allowAllFileActions = true;
@ -1641,7 +1641,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS
* @param parent the parent component
* @return this for chained calls
*/
public MainBuilder setParent(Component parent) {
public MainBuilder setParent(Window parent) {
this.parent = parent;
return this;
}

View File

@ -29,7 +29,7 @@ import java.util.HashMap;
public class AttributeDialog extends JDialog {
private final java.util.List<EditorHolder> editors;
private final JPanel panel;
private final Component parent;
private final Window parent;
private final Point pos;
private final ElementAttributes originalAttributes;
private final ElementAttributes modifiedAttributes;
@ -47,7 +47,7 @@ public class AttributeDialog extends JDialog {
* @param list the list of keys which are to edit
* @param elementAttributes the data stored
*/
public AttributeDialog(Component parent, java.util.List<Key> list, ElementAttributes elementAttributes) {
public AttributeDialog(Window parent, java.util.List<Key> list, ElementAttributes elementAttributes) {
this(parent, null, list, elementAttributes, false);
}
@ -59,7 +59,7 @@ public class AttributeDialog extends JDialog {
* @param list the list of keys which are to edit
* @param elementAttributes the data stored
*/
public AttributeDialog(Component parent, Point pos, java.util.List<Key> list, ElementAttributes elementAttributes) {
public AttributeDialog(Window parent, Point pos, java.util.List<Key> list, ElementAttributes elementAttributes) {
this(parent, pos, list, elementAttributes, false);
}
@ -72,8 +72,8 @@ public class AttributeDialog extends JDialog {
* @param elementAttributes the initial data to modify
* @param addCheckBoxes th true check boxes behind the attributes are added
*/
public AttributeDialog(Component parent, Point pos, java.util.List<Key> list, ElementAttributes elementAttributes, boolean addCheckBoxes) {
super(SwingUtilities.getWindowAncestor(parent), Lang.get("attr_dialogTitle"), ModalityType.APPLICATION_MODAL);
public AttributeDialog(Window parent, Point pos, java.util.List<Key> list, ElementAttributes elementAttributes, boolean addCheckBoxes) {
super(parent, Lang.get("attr_dialogTitle"), ModalityType.APPLICATION_MODAL);
this.parent = parent;
this.pos = pos;
this.originalAttributes = elementAttributes;
@ -228,7 +228,7 @@ public class AttributeDialog extends JDialog {
/**
* @return the dialogs parent
*/
public Component getDialogParent() {
public Window getDialogParent() {
return parent;
}
@ -246,8 +246,6 @@ public class AttributeDialog extends JDialog {
public Main getMain() { // ToDo: is a hack! find a better solution for getting the main frame
if (parent instanceof Main)
return (Main) parent;
if (parent instanceof CircuitComponent)
return ((CircuitComponent) parent).getMain();
return null;
}

View File

@ -391,20 +391,17 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
/**
* Opens the attribute editor
*
* @param parent the parent component
*/
public void editCircuitAttributes(Component parent) {
editCircuitAttributes(parent, ATTR_LIST);
public void editCircuitAttributes() {
editCircuitAttributes(ATTR_LIST);
}
/**
* Opens the attribute editor
*
* @param parent the parent component
* @param attrList the list of keys to edit
*/
public void editCircuitAttributes(Component parent, java.util.List<Key> attrList) {
public void editCircuitAttributes(java.util.List<Key> attrList) {
ElementAttributes modifiedAttributes = new AttributeDialog(parent, attrList, circuit.getAttributes()).showDialog();
if (modifiedAttributes != null)
modify(new ModifyCircuitAttributes(modifiedAttributes));
@ -976,14 +973,14 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
if (list.size() > 0) {
Point p = new Point(e.getX(), e.getY());
SwingUtilities.convertPointToScreen(p, CircuitComponent.this);
AttributeDialog attributeDialog = new AttributeDialog(this, p, list, element.getElementAttributes()).setVisualElement(element);
AttributeDialog attributeDialog = new AttributeDialog(parent, p, list, element.getElementAttributes()).setVisualElement(element);
if (elementType instanceof ElementLibrary.ElementTypeDescriptionCustom) {
attributeDialog.addButton(Lang.get("attr_openCircuitLabel"), new ToolTipAction(Lang.get("attr_openCircuit")) {
@Override
public void actionPerformed(ActionEvent e) {
attributeDialog.dispose();
new Main.MainBuilder()
.setParent(CircuitComponent.this)
.setParent(parent)
.setFileToOpen(((ElementLibrary.ElementTypeDescriptionCustom) elementType).getFile())
.setLibrary(library)
.denyMostFileActions()
@ -1125,7 +1122,7 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe
}
if (keyList.size() > 0) {
AttributeDialog ad = new AttributeDialog(this, null, keyList, attr, true);
AttributeDialog ad = new AttributeDialog(parent, null, keyList, attr, true);
for (Map.Entry<Key, Boolean> u : useKeyMap.entrySet())
ad.getCheckBoxes().get(u.getKey()).setSelected(u.getValue());
ElementAttributes mod = ad.showDialog();

View File

@ -35,8 +35,8 @@ public class TestCaseDescriptionDialog extends JDialog {
* @param data the data to edit
* @param element the element to be modified
*/
public TestCaseDescriptionDialog(Component parent, TestCaseDescription data, VisualElement element) {
super(SwingUtilities.getWindowAncestor(parent),
public TestCaseDescriptionDialog(Window parent, TestCaseDescription data, VisualElement element) {
super(parent,
Lang.get("key_Testdata"),
element == null ? ModalityType.APPLICATION_MODAL : ModalityType.MODELESS);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
@ -72,8 +72,8 @@ public class TestCaseDescriptionDialog extends JDialog {
buttons.add(new ToolTipAction(Lang.get("btn_addTransitions")) {
@Override
public void actionPerformed(ActionEvent e) {
if (parent instanceof CircuitComponent) {
CircuitComponent cc = (CircuitComponent) parent;
if (parent instanceof Main) {
CircuitComponent cc = ((Main) parent).getCircuitComponent();
try {
Transitions tr = new Transitions(text.getText(), cc.getCircuit().getInputNames());
if (tr.isNew()) {
@ -93,9 +93,9 @@ public class TestCaseDescriptionDialog extends JDialog {
public void actionPerformed(ActionEvent e) {
try {
data.setDataString(text.getText());
if (parent instanceof CircuitComponent) {
if (parent instanceof Main) {
CircuitComponent cc = ((Main) parent).getCircuitComponent();
element.getElementAttributes().set(TestCaseElement.TESTDATA, data);
CircuitComponent cc = (CircuitComponent) parent;
cc.getMain().startTests();
}
} catch (ParserException | IOException e1) {
@ -112,8 +112,8 @@ public class TestCaseDescriptionDialog extends JDialog {
data.setDataString(text.getText());
if (element != null
&& !initialDataString.equals(data.getDataString())
&& parent instanceof CircuitComponent) {
CircuitComponent cc = (CircuitComponent) parent;
&& parent instanceof Main) {
CircuitComponent cc = ((Main) parent).getCircuitComponent();
cc.modify(new ModifyAttribute<>(element, TestCaseElement.TESTDATA, new TestCaseDescription(data)));
}
dispose();

View File

@ -19,7 +19,6 @@ import java.awt.event.ActionEvent;
public class TestCaseDescriptionEditor extends EditorFactory.LabelEditor<TestCaseDescription> {
private final TestCaseDescription data;
private final Key<TestCaseDescription> key;
/**
* Creates a new editor
@ -29,7 +28,6 @@ public class TestCaseDescriptionEditor extends EditorFactory.LabelEditor<TestCas
*/
public TestCaseDescriptionEditor(TestCaseDescription data, Key<TestCaseDescription> key) {
this.data = new TestCaseDescription(data);
this.key = key;
}
@Override
@ -44,7 +42,7 @@ public class TestCaseDescriptionEditor extends EditorFactory.LabelEditor<TestCas
panel.add(new ToolTipAction(Lang.get("btn_edit")) {
@Override
public void actionPerformed(ActionEvent e) {
new TestCaseDescriptionDialog(panel, data, null).setVisible(true);
new TestCaseDescriptionDialog(SwingUtilities.getWindowAncestor(panel), data, null).setVisible(true);
}
}.createJButton());
@ -53,12 +51,13 @@ public class TestCaseDescriptionEditor extends EditorFactory.LabelEditor<TestCas
public void actionPerformed(ActionEvent e) {
try {
getAttributeDialog().fireOk();
VisualElement visualElement = TestCaseDescriptionEditor.this.getAttributeDialog().getVisualElement();
TestCaseDescriptionDialog dialog = new TestCaseDescriptionDialog(getAttributeDialog().getDialogParent(), data, visualElement);
Main main = getAttributeDialog().getMain();
if (main != null)
main.getWindowPosManager().register("testdata", dialog);
dialog.setVisible(true);
VisualElement visualElement = TestCaseDescriptionEditor.this.getAttributeDialog().getVisualElement();
Main main = getAttributeDialog().getMain();
if (main != null) {
TestCaseDescriptionDialog dialog = new TestCaseDescriptionDialog(main, data, visualElement);
main.getWindowPosManager().register("testdata", dialog);
dialog.setVisible(true);
}
} catch (EditorParseException e1) {
e1.printStackTrace();
}