Revision 270 org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.serv/org.gvsig.tools.swing.serv.field/src/main/java/org/gvsig/tools/swing/serv/field/component/JFileDynfieldComponent.java
JFileDynfieldComponent.java | ||
---|---|---|
55 | 55 |
* |
56 | 56 |
*/ |
57 | 57 |
public class JFileDynfieldComponent extends AbstractReturnComponentLauncher |
58 |
implements JDynFieldComponent, FocusListener, KeyListener {
|
|
58 |
implements JDynFieldComponent, FocusListener, KeyListener {
|
|
59 | 59 |
|
60 | 60 |
private JTextField tfFile; |
61 | 61 |
private JPanel panel; |
... | ... | |
69 | 69 |
* @throws ServiceException |
70 | 70 |
*/ |
71 | 71 |
public JFileDynfieldComponent(ValueField parent, DynField dynField) |
72 |
throws ServiceException {
|
|
73 |
super(dynField, parent, "...");
|
|
72 |
throws ServiceException {
|
|
73 |
super(dynField, parent, "...");
|
|
74 | 74 |
} |
75 | 75 |
|
76 | 76 |
/* |
... | ... | |
80 | 80 |
*/ |
81 | 81 |
@Override |
82 | 82 |
protected void afterUI() { |
83 |
// TODO Auto-generated method stub
|
|
83 |
// TODO Auto-generated method stub
|
|
84 | 84 |
|
85 | 85 |
} |
86 | 86 |
|
... | ... | |
89 | 89 |
* @return |
90 | 90 |
*/ |
91 | 91 |
private ResultProvider createFileChooser() { |
92 |
return new JFileChooser(this.getDynField().getType());
|
|
92 |
return new JFileChooser(this.getDynField().getType());
|
|
93 | 93 |
} |
94 | 94 |
|
95 | 95 |
/* |
... | ... | |
98 | 98 |
* @see java.awt.event.FocusListener#focusGained(java.awt.event.FocusEvent) |
99 | 99 |
*/ |
100 | 100 |
public void focusGained(FocusEvent e) { |
101 |
previousText = tfFile.getText();
|
|
101 |
previousText = tfFile.getText();
|
|
102 | 102 |
} |
103 | 103 |
|
104 | 104 |
/* |
... | ... | |
107 | 107 |
* @see java.awt.event.FocusListener#focusLost(java.awt.event.FocusEvent) |
108 | 108 |
*/ |
109 | 109 |
public void focusLost(FocusEvent e) { |
110 |
// if (!this.isValid())
|
|
111 |
// tfFile.setText(previousText);
|
|
112 |
previousText = tfFile.getText();
|
|
113 |
this.file = new File(previousText);
|
|
114 |
this.fireValueChangedEvent();
|
|
110 |
// if (!this.isValid())
|
|
111 |
// tfFile.setText(previousText);
|
|
112 |
previousText = tfFile.getText();
|
|
113 |
this.file = new File(previousText);
|
|
114 |
this.fireValueChangedEvent();
|
|
115 | 115 |
} |
116 | 116 |
|
117 | 117 |
/* |
... | ... | |
120 | 120 |
* @see |
121 | 121 |
* org.gvsig.tools.swing.api.dynobject.dynfield.JComponent#getComponent() |
122 | 122 |
*/ |
123 |
public JComponent asJComponent() {
|
|
124 |
return panel;
|
|
123 |
public JComponent asJComponent() {
|
|
124 |
return panel;
|
|
125 | 125 |
} |
126 | 126 |
|
127 | 127 |
/* |
... | ... | |
130 | 130 |
* @see org.gvsig.tools.swing.api.dynobject.dynfield.ValueField#getValue() |
131 | 131 |
*/ |
132 | 132 |
public Object getValue() { |
133 |
return file;
|
|
133 |
return file;
|
|
134 | 134 |
} |
135 | 135 |
|
136 | 136 |
/* |
... | ... | |
140 | 140 |
*/ |
141 | 141 |
@Override |
142 | 142 |
protected void initData() { |
143 |
previousText = "";
|
|
143 |
previousText = "";
|
|
144 | 144 |
} |
145 | 145 |
|
146 | 146 |
@Override |
147 | 147 |
protected void initUI() { |
148 |
tfFile = new JTextField();
|
|
149 |
tfFile.addKeyListener(this);
|
|
150 |
fc = this.createFileChooser();
|
|
151 |
fc.alignToField(this);
|
|
152 |
panel = this.createBoxLayout(tfFile, this.getButton(), 1, 1, null);
|
|
148 |
tfFile = new JTextField();
|
|
149 |
tfFile.addKeyListener(this);
|
|
150 |
fc = this.createFileChooser();
|
|
151 |
fc.alignToField(this);
|
|
152 |
panel = this.createBoxLayout(tfFile, this.getButton(), 1, 1, null);
|
|
153 | 153 |
} |
154 | 154 |
|
155 | 155 |
/* |
156 | 156 |
* (non-Javadoc) |
157 | 157 |
* |
158 | 158 |
* @see |
159 |
* |
|
159 | 160 |
* org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#isMandatory |
160 | 161 |
* () |
161 | 162 |
*/ |
162 | 163 |
@Override |
163 | 164 |
public boolean isMandatory() { |
164 |
return this.getDynField().isMandatory();
|
|
165 |
return this.getDynField().isMandatory();
|
|
165 | 166 |
} |
166 | 167 |
|
167 | 168 |
/* |
... | ... | |
172 | 173 |
* java.lang.Object) |
173 | 174 |
*/ |
174 | 175 |
public void onResult(int returnVal, Object result) { |
175 |
if (returnVal == ResultProvider.RETURN_OK) {
|
|
176 |
file = (File) result;
|
|
177 |
this.refresh();
|
|
178 |
this.fireValueChangedEvent();
|
|
179 |
}
|
|
176 |
if (returnVal == ResultProvider.RETURN_OK) {
|
|
177 |
file = (File) result;
|
|
178 |
this.refresh();
|
|
179 |
this.fireValueChangedEvent();
|
|
180 |
}
|
|
180 | 181 |
} |
181 | 182 |
|
182 | 183 |
/** |
183 | 184 |
* |
184 | 185 |
*/ |
185 | 186 |
private void refresh() { |
186 |
if (file != null)
|
|
187 |
tfFile.setText(file.getAbsolutePath());
|
|
188 |
else
|
|
189 |
tfFile.setText("");
|
|
187 |
if (file != null)
|
|
188 |
tfFile.setText(file.getAbsolutePath());
|
|
189 |
else
|
|
190 |
tfFile.setText("");
|
|
190 | 191 |
} |
191 | 192 |
|
192 | 193 |
/* |
193 | 194 |
* (non-Javadoc) |
194 | 195 |
* |
195 | 196 |
* @see |
197 |
* |
|
196 | 198 |
* org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#requestFocus |
197 | 199 |
* () |
198 | 200 |
*/ |
199 | 201 |
public void requestFocus() { |
200 |
tfFile.requestFocus();
|
|
202 |
tfFile.requestFocus();
|
|
201 | 203 |
} |
202 | 204 |
|
203 | 205 |
/* |
204 | 206 |
* (non-Javadoc) |
205 | 207 |
* |
206 | 208 |
* @see |
209 |
* |
|
207 | 210 |
* org.gvsig.tools.swing.api.dynobject.dynfield.JDynFieldComponent#setEnabled |
208 | 211 |
* (boolean) |
209 | 212 |
*/ |
210 | 213 |
public void setEnabled(boolean isEnabled) { |
211 |
tfFile.setEnabled(isEnabled);
|
|
212 |
this.getButton().setEnabled(isEnabled);
|
|
214 |
tfFile.setEnabled(isEnabled);
|
|
215 |
this.getButton().setEnabled(isEnabled);
|
|
213 | 216 |
} |
214 | 217 |
|
215 | 218 |
/* |
... | ... | |
220 | 223 |
*/ |
221 | 224 |
@Override |
222 | 225 |
protected void setJDynFieldComponentListeners() { |
223 |
tfFile.addFocusListener(this);
|
|
224 |
fc.addResultListener(this);
|
|
226 |
tfFile.addFocusListener(this);
|
|
227 |
fc.addResultListener(this);
|
|
225 | 228 |
} |
226 | 229 |
|
227 | 230 |
/* |
... | ... | |
231 | 234 |
*/ |
232 | 235 |
@Override |
233 | 236 |
protected void setReadOnly() { |
234 |
tfFile.setEditable(false);
|
|
237 |
tfFile.setEditable(false);
|
|
235 | 238 |
} |
236 | 239 |
|
237 | 240 |
/* |
... | ... | |
242 | 245 |
* .lang.Object) |
243 | 246 |
*/ |
244 | 247 |
protected void setNullValue() { |
245 |
file = null;
|
|
246 |
this.refresh();
|
|
248 |
file = null;
|
|
249 |
this.refresh();
|
|
247 | 250 |
} |
248 | 251 |
|
249 | 252 |
protected void setNonNullValue(Object value) { |
250 |
file = (File) value;
|
|
251 |
this.refresh();
|
|
253 |
file = (File) value;
|
|
254 |
this.refresh();
|
|
252 | 255 |
} |
253 | 256 |
|
254 | 257 |
/* |
... | ... | |
258 | 261 |
* showResultProviderDialog() |
259 | 262 |
*/ |
260 | 263 |
public void showResultProviderDialog() { |
261 |
fc.showDialog();
|
|
264 |
fc.showDialog();
|
|
262 | 265 |
} |
263 | 266 |
|
264 |
/* (non-Javadoc) |
|
267 |
/* |
|
268 |
* (non-Javadoc) |
|
269 |
* |
|
265 | 270 |
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent) |
266 | 271 |
*/ |
267 | 272 |
public void keyPressed(KeyEvent e) { |
268 |
// TODO Auto-generated method stub
|
|
269 |
|
|
273 |
// TODO Auto-generated method stub
|
|
274 |
|
|
270 | 275 |
} |
271 | 276 |
|
272 |
/* (non-Javadoc) |
|
277 |
/* |
|
278 |
* (non-Javadoc) |
|
279 |
* |
|
273 | 280 |
* @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent) |
274 | 281 |
*/ |
275 | 282 |
public void keyReleased(KeyEvent e) { |
276 |
// TODO Auto-generated method stub
|
|
277 |
|
|
283 |
// TODO Auto-generated method stub
|
|
284 |
|
|
278 | 285 |
} |
279 | 286 |
|
280 |
/* (non-Javadoc) |
|
287 |
/* |
|
288 |
* (non-Javadoc) |
|
289 |
* |
|
281 | 290 |
* @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent) |
282 | 291 |
*/ |
283 | 292 |
public void keyTyped(KeyEvent e) { |
284 |
String path = this.tfFile.getText();
|
|
285 |
file = new File(path);
|
|
286 |
this.fireValueChangedEvent();
|
|
293 |
String path = this.tfFile.getText();
|
|
294 |
file = new File(path);
|
|
295 |
this.fireValueChangedEvent();
|
|
287 | 296 |
} |
288 | 297 |
|
289 |
/* (non-Javadoc) |
|
298 |
/* |
|
299 |
* (non-Javadoc) |
|
300 |
* |
|
290 | 301 |
* @see org.gvsig.tools.swing.spi.AbstractJDynFieldComponent#isValid() |
291 | 302 |
*/ |
292 | 303 |
@Override |
293 | 304 |
public boolean isValid() { |
294 |
String path = this.tfFile.getText(); |
|
295 |
File f = new File(path); |
|
296 |
if (f!=null) return true; |
|
297 |
if (this.getDynField().isMandatory()) |
|
298 |
return false; |
|
299 |
else |
|
300 |
return true; |
|
305 |
String path = this.tfFile.getText(); |
|
306 |
File f = new File(path); |
|
307 |
if (f != null) |
|
308 |
return true; |
|
309 |
if (this.getDynField().isMandatory()) |
|
310 |
return false; |
|
311 |
else |
|
312 |
return true; |
|
301 | 313 |
} |
302 | 314 |
|
303 | 315 |
} |
Also available in: Unified diff