-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathNodeAttributesDialog.java
More file actions
194 lines (156 loc) · 6.2 KB
/
NodeAttributesDialog.java
File metadata and controls
194 lines (156 loc) · 6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
package nodebox.client;
import nodebox.node.Node;
import nodebox.node.Parameter;
import nodebox.node.Port;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
public class NodeAttributesDialog extends JDialog {
private NodeBoxDocument document;
private Node node;
private OKAction okAction = new OKAction();
private CancelAction cancelAction = new CancelAction();
private boolean changed = false;
public NodeAttributesDialog(NodeBoxDocument document) {
super(document, document.getActiveNode().getName() + " Metadata");
this.document = document;
this.node = document.getActiveNode();
NodeAttributesEditor editor = new NodeAttributesEditor(this);
getContentPane().add(editor);
setResizable(false);
setModal(true);
setModalityType(Dialog.ModalityType.DOCUMENT_MODAL);
JButton cancelButton = new JButton(cancelAction);
JButton okButton = new JButton(okAction);
JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));
bottomPanel.add(Box.createHorizontalGlue());
bottomPanel.add(cancelButton);
bottomPanel.add(okButton);
getContentPane().add(bottomPanel, BorderLayout.SOUTH);
getRootPane().setDefaultButton(okButton);
KeyStroke escapeStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
getRootPane().registerKeyboardAction(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (changed) {
NodeAttributesDialog.this.document.stopEdits();
NodeAttributesDialog.this.document.undo();
}
dispose();
}
}, escapeStroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
}
public Node getNode() {
return document.getActiveNode();
}
public void addParameter(Node node, String parameterName) {
onChanged();
document.addParameter(node, parameterName);
}
public void removeParameter(Node node, String parameterName) {
onChanged();
document.removeParameter(node, parameterName);
}
public void addPort(Node node, String portName, Port.Cardinality cardinality) {
onChanged();
document.addPort(node, portName, cardinality);
}
public void setNodeExported(boolean exported) {
onChanged();
document.setNodeExported(node, exported);
}
public void setPortName(Port port, String name) {
//document.setPortName(port, name);
}
public void setPortCardinality(Port port, Port.Cardinality cardinality) {
//document.setPortCardinality(port, cardinality);
}
public void setParameterLabel(Parameter parameter, String label) {
onChanged();
document.setParameterLabel(parameter, label);
}
public void setParameterHelpText(Parameter parameter, String helpText) {
onChanged();
document.setParameterHelpText(parameter, helpText);
}
public void setParameterWidget(Parameter parameter, Parameter.Widget widget) {
onChanged();
document.setParameterWidget(parameter, widget);
}
public void setParameterValue(Parameter parameter, Object value) {
onChanged();
document.setParameterValue(parameter, value);
}
public void setParameterEnableExpression(Parameter parameter, String enableExpression) {
onChanged();
document.setParameterEnableExpression(parameter, enableExpression);
}
public void setParameterBoundingMethod(Parameter parameter, Parameter.BoundingMethod method) {
onChanged();
document.setParameterBoundingMethod(parameter, method);
}
public void setParameterMinimumValue(Parameter parameter, Float minimumValue) {
onChanged();
document.setParameterMinimumValue(parameter, minimumValue);
}
public void setParameterMaximumValue(Parameter parameter, Float maximumValue) {
onChanged();
document.setParameterMaximumValue(parameter, maximumValue);
}
public void setParameterDisplayLevel(Parameter parameter, Parameter.DisplayLevel displayLevel) {
onChanged();
document.setParameterDisplayLevel(parameter, displayLevel);
}
public void addParameterMenuItem(Parameter parameter, String key, String label) {
onChanged();
document.addParameterMenuItem(parameter, key, label);
}
public void removeParameterMenuItem(Parameter parameter, Parameter.MenuItem menuItem) {
onChanged();
document.removeParameterMenuItem(parameter, menuItem);
}
public void moveParameterMenuItemDown(Parameter parameter, int itemIndex) {
onChanged();
document.moveParameterMenuItemDown(parameter, itemIndex);
}
public void moveParameterMenuItemUp(Parameter parameter, int itemIndex) {
onChanged();
document.moveParameterMenuItemUp(parameter, itemIndex);
}
public void updateParameterMenuItem(Parameter parameter, int itemIndex, String key, String label) {
onChanged();
document.updateParameterMenuItem(parameter, itemIndex, key, label);
}
private void onChanged() {
if (! changed) {
document.startEdits("Node Metadata");
changed = true;
}
}
public class OKAction extends AbstractAction {
public OKAction() {
putValue(NAME, "Ok");
putValue(ACCELERATOR_KEY, PlatformUtils.getKeyStroke(KeyEvent.VK_ENTER));
}
public void actionPerformed(ActionEvent e) {
if (changed) {
document.stopEdits();
}
NodeAttributesDialog.this.dispose();
}
}
public class CancelAction extends AbstractAction {
public CancelAction() {
putValue(NAME, "Cancel");
putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));
}
public void actionPerformed(ActionEvent e) {
if (changed) {
document.stopEdits();
document.undo();
}
NodeAttributesDialog.this.dispose();
}
}}