-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathFileControl.java
More file actions
67 lines (56 loc) · 2.11 KB
/
FileControl.java
File metadata and controls
67 lines (56 loc) · 2.11 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
package nodebox.client.parameter;
import nodebox.client.FileUtils;
import nodebox.client.Theme;
import nodebox.node.Parameter;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
public class FileControl extends AbstractParameterControl implements ActionListener {
private JTextField fileField;
private JButton chooseButton;
public FileControl(Parameter parameter) {
super(parameter);
setLayout(new FlowLayout(FlowLayout.LEADING, 0, 0));
fileField = new JTextField();
fileField.putClientProperty("JComponent.sizeVariant", "small");
fileField.setPreferredSize(new Dimension(150, 19));
fileField.setEditable(false);
fileField.setFont(Theme.SMALL_BOLD_FONT);
chooseButton = new JButton("...");
chooseButton.putClientProperty("JButton.buttonType", "gradient");
chooseButton.setPreferredSize(new Dimension(30, 27));
chooseButton.addActionListener(this);
add(fileField);
add(chooseButton);
setValueForControl(parameter.getValue());
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
chooseButton.setEnabled(enabled);
}
public void setValueForControl(Object v) {
fileField.setText(v.toString());
}
public String acceptedExtensions() {
return "*";
}
public String acceptedDescription() {
return "All files";
}
public void actionPerformed(ActionEvent e) {
JFrame frame = (JFrame) SwingUtilities.getWindowAncestor(this);
File f = FileUtils.showOpenDialog(frame, parameter.asString(), acceptedExtensions(), acceptedDescription());
if (f != null) {
File libraryFile = parameter.getLibrary().getFile();
if (libraryFile != null) {
String relativePath = nodebox.util.FileUtils.getRelativePath(f, libraryFile.getParentFile());
setParameterValue(relativePath);
} else {
setParameterValue(f.getAbsolutePath());
}
}
}
}