-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathTextControl.java
More file actions
59 lines (50 loc) · 2.06 KB
/
TextControl.java
File metadata and controls
59 lines (50 loc) · 2.06 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
package nodebox.client.parameter;
import nodebox.client.NodeBoxDocument;
import nodebox.client.TextWindow;
import nodebox.client.Theme;
import nodebox.node.Parameter;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class TextControl extends AbstractParameterControl implements ActionListener {
private JTextField textField;
private JButton externalWindowButton;
public TextControl(Parameter parameter) {
super(parameter);
setLayout(new BorderLayout(0, 0));
textField = new JTextField();
textField.putClientProperty("JComponent.sizeVariant", "small");
textField.setFont(Theme.SMALL_BOLD_FONT);
textField.addActionListener(this);
externalWindowButton = new JButton("...");
externalWindowButton.putClientProperty("JComponent.sizeVariant", "small");
externalWindowButton.putClientProperty("JButton.buttonType", "gradient");
externalWindowButton.setFont(Theme.SMALL_BOLD_FONT);
externalWindowButton.addActionListener(this);
add(textField, BorderLayout.CENTER);
add(externalWindowButton, BorderLayout.EAST);
setValueForControl(parameter.getValue());
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
textField.setEnabled(enabled);
externalWindowButton.setEnabled(enabled);
}
public void setValueForControl(Object v) {
textField.setText(v.toString());
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == textField) {
setParameterValue(textField.getText());
} else if (e.getSource() == externalWindowButton) {
NodeBoxDocument doc = NodeBoxDocument.getCurrentDocument();
if (doc == null) throw new RuntimeException("No current active document.");
TextWindow window = new TextWindow(parameter);
window.setLocationRelativeTo(this);
window.setVisible(true);
doc.addParameterEditor(window);
}
}
}