-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathTextWindow.java
More file actions
53 lines (43 loc) · 1.9 KB
/
TextWindow.java
File metadata and controls
53 lines (43 loc) · 1.9 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
package nodebox.client;
import nodebox.node.*;
import javax.swing.*;
import java.awt.*;
public class TextWindow extends AbstractParameterEditor {
private JTextArea textArea;
public TextWindow(Parameter parameter) {
super(parameter);
}
public Component getContentArea() {
textArea = new JTextArea(getParameter().asString());
textArea.setFont(Theme.EDITOR_FONT);
textArea.setBorder(null);
JScrollPane textScroll = new JScrollPane(textArea, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
textScroll.setBorder(BorderFactory.createEtchedBorder());
return textScroll;
}
public boolean save() {
textArea.requestFocus();
try {
NodeBoxDocument doc = NodeBoxDocument.getCurrentDocument();
if (doc == null) throw new RuntimeException("No current active document.");
doc.setParameterValue(getParameter(), textArea.getText());
return true;
} catch (IllegalArgumentException ee) {
JOptionPane.showMessageDialog(this, "Error while saving parameter: " + ee.getMessage(), "Parameter error", JOptionPane.ERROR_MESSAGE);
return false;
}
}
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 (textArea.getText().equals(getParameter().asString())) return;
textArea.setText(getParameter().asString());
}
public static void main(String[] args) {
NodeLibrary testLibrary = new NodeLibrary("test");
Node node = Node.ROOT_NODE.newInstance(testLibrary, "test");
Parameter pText = node.addParameter("text", Parameter.Type.STRING);
AbstractParameterEditor win = new TextWindow(pText);
win.setVisible(true);
}
}