Revision 1754 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/pickercontroller/FilePickerControllerImpl.java
FilePickerControllerImpl.java | ||
---|---|---|
1 | 1 |
package org.gvsig.tools.swing.impl.pickercontroller; |
2 | 2 |
|
3 |
import java.awt.BorderLayout; |
|
3 | 4 |
import java.awt.event.ActionEvent; |
4 | 5 |
import java.awt.event.ActionListener; |
5 | 6 |
import java.io.File; |
... | ... | |
7 | 8 |
import javax.swing.ImageIcon; |
8 | 9 |
import javax.swing.JButton; |
9 | 10 |
import javax.swing.JFileChooser; |
11 |
import javax.swing.JLabel; |
|
10 | 12 |
import javax.swing.JTextField; |
11 | 13 |
import javax.swing.filechooser.FileFilter; |
12 | 14 |
import org.apache.commons.lang3.ArrayUtils; |
... | ... | |
46 | 48 |
ImageIcon icon = new ImageIcon(imageResource); |
47 | 49 |
theme.registerDefault("tools", "picker", "picker-file", icon, imageResource); |
48 | 50 |
} |
51 |
imageResource = DatePickerControllerImpl.class.getClassLoader().getResource("org/gvsig/tools/swing/picker/picker-cleartext.png"); |
|
52 |
if (imageResource != null) { |
|
53 |
IconThemeManager iconThemeManager = ToolsSwingLocator.getIconThemeManager(); |
|
54 |
IconTheme theme = iconThemeManager.getCurrent(); |
|
55 |
ImageIcon icon = new ImageIcon(imageResource); |
|
56 |
theme.registerDefault("tools", "picker", "picker-cleartext", icon, imageResource); |
|
57 |
} |
|
49 | 58 |
} |
59 |
private final JButton btnClear; |
|
50 | 60 |
|
51 | 61 |
public FilePickerControllerImpl(JTextField txtFile, JButton btnFile, String dialogTitle) { |
52 | 62 |
this(txtFile, btnFile, dialogTitle, null, null, true); |
... | ... | |
79 | 89 |
doSelectFile(); |
80 | 90 |
} |
81 | 91 |
}); |
92 |
this.btnClear = new JButton(getIcon("picker-cleartext")); |
|
93 |
btnClear.setBorderPainted( false ); |
|
94 |
btnClear.setFocusPainted( false ); |
|
95 |
btnClear.setContentAreaFilled( false ); |
|
96 |
btnClear.setOpaque(false); |
|
97 |
btnClear.addActionListener(new ActionListener() { |
|
98 |
@Override |
|
99 |
public void actionPerformed(ActionEvent e) { |
|
100 |
doClear(); |
|
101 |
} |
|
102 |
}); |
|
82 | 103 |
this.txtFile.setEditable(false); |
104 |
this.txtFile.setLayout(new BorderLayout()); |
|
105 |
this.txtFile.add(btnClear, BorderLayout.EAST); |
|
106 |
|
|
83 | 107 |
} |
84 | 108 |
|
109 |
private void doClear() { |
|
110 |
this.set(null); |
|
111 |
} |
|
112 |
|
|
85 | 113 |
@Override |
86 | 114 |
public boolean isEmpty() { |
87 | 115 |
return this.value==null; |
... | ... | |
95 | 123 |
@Override |
96 | 124 |
public void set(File value) { |
97 | 125 |
this.value = value; |
98 |
this.txtFile.setText(value.toString()); |
|
126 |
if( value==null ) { |
|
127 |
this.txtFile.setText(""); |
|
128 |
} else { |
|
129 |
this.txtFile.setText(value.toString()); |
|
130 |
} |
|
99 | 131 |
} |
100 | 132 |
|
101 | 133 |
@Override |
102 | 134 |
public void setEnabled(boolean enabled) { |
103 | 135 |
this.btnFile.setEnabled(enabled); |
104 | 136 |
this.txtFile.setEnabled(enabled); |
137 |
this.btnClear.setEnabled(enabled); |
|
105 | 138 |
} |
106 | 139 |
|
107 | 140 |
@Override |
Also available in: Unified diff