-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathExpressionWindow.java
More file actions
71 lines (59 loc) · 2.75 KB
/
ExpressionWindow.java
File metadata and controls
71 lines (59 loc) · 2.75 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
package nodebox.client;
import nodebox.node.Node;
import nodebox.node.NodeLibrary;
import nodebox.node.Parameter;
import javax.swing.*;
import java.awt.*;
public class ExpressionWindow extends AbstractParameterEditor {
private JTextArea expressionArea;
private JTextArea errorArea;
public ExpressionWindow(Parameter parameter) {
super(parameter);
}
public Component getContentArea() {
expressionArea = new JTextArea(getParameter().getExpression());
expressionArea.setFont(Theme.EDITOR_FONT);
expressionArea.setBorder(null);
JScrollPane expressionScroll = new JScrollPane(expressionArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
expressionScroll.setBorder(BorderFactory.createEtchedBorder());
errorArea = new JTextArea();
errorArea.setFont(Theme.EDITOR_FONT);
errorArea.setBorder(null);
errorArea.setBackground(Theme.EXPRESSION_ERROR_BACKGROUND_COLOR);
errorArea.setEditable(false);
errorArea.setForeground(Theme.EXPRESSION_ERROR_FOREGROUND_COLOR);
JScrollPane errorScroll = new JScrollPane(errorArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
errorScroll.setBorder(BorderFactory.createEtchedBorder());
JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, expressionScroll, errorScroll);
split.setBorder(null);
split.setDividerLocation(150);
split.setDividerSize(2);
return split;
}
public void valueChanged(Parameter source) {
// Don't change the expression area if the expression is the same.
// This would cause an infinite loop of setExpression/valueChanged calls.
if (expressionArea.getText().equals(getParameter().getExpression())) return;
expressionArea.setText(getParameter().getExpression());
}
public boolean save() {
expressionArea.requestFocus();
NodeBoxDocument doc = NodeBoxDocument.getCurrentDocument();
if (doc == null) throw new RuntimeException("No current active document.");
doc.setParameterExpression(getParameter(), expressionArea.getText());
if (getParameter().hasExpressionError()) {
errorArea.setText(getParameter().getExpressionError().toString());
return false;
} else {
errorArea.setText("");
return true;
}
}
public static void main(String[] args) {
NodeLibrary testLibrary = new NodeLibrary("test");
Node node = Node.ROOT_NODE.newInstance(testLibrary, "test");
Parameter pX = node.addParameter("x", Parameter.Type.FLOAT);
AbstractParameterEditor win = new ExpressionWindow(pX);
win.setVisible(true);
}
}