root / trunk / extensions / extAnnotations / src / com / iver / cit / gvsig / project / documents / gui / Annotation_ConfigureLabel.java @ 13881
History | View | Annotate | Download (15.1 KB)
1 | 11536 | caballero | |
---|---|---|---|
2 | 13512 | caballero | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 | *
|
||
4 | * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
19 | *
|
||
20 | * For more information, contact:
|
||
21 | *
|
||
22 | * Generalitat Valenciana
|
||
23 | * Conselleria d'Infraestructures i Transport
|
||
24 | * Av. Blasco Ib??ez, 50
|
||
25 | * 46010 VALENCIA
|
||
26 | * SPAIN
|
||
27 | *
|
||
28 | * +34 963862235
|
||
29 | * gvsig@gva.es
|
||
30 | * www.gvsig.gva.es
|
||
31 | *
|
||
32 | * or
|
||
33 | *
|
||
34 | * IVER T.I. S.A
|
||
35 | * Salamanca 50
|
||
36 | * 46005 Valencia
|
||
37 | * Spain
|
||
38 | *
|
||
39 | * +34 963163400
|
||
40 | * dac@iver.es
|
||
41 | */
|
||
42 | 11536 | caballero | |
43 | 13512 | caballero | package com.iver.cit.gvsig.project.documents.gui; |
44 | 11536 | caballero | |
45 | import java.awt.Dimension; |
||
46 | import java.awt.Rectangle; |
||
47 | import java.awt.event.ItemEvent; |
||
48 | import java.awt.event.ItemListener; |
||
49 | import java.sql.Types; |
||
50 | import java.util.ArrayList; |
||
51 | import java.util.Collection; |
||
52 | import java.util.HashMap; |
||
53 | import java.util.Iterator; |
||
54 | |||
55 | import javax.swing.JComboBox; |
||
56 | import javax.swing.JLabel; |
||
57 | |||
58 | 13512 | caballero | import jwizardcomponent.JWizardComponents; |
59 | import jwizardcomponent.JWizardPanel; |
||
60 | 11536 | caballero | |
61 | 13512 | caballero | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
62 | import com.iver.andami.PluginServices; |
||
63 | import com.iver.andami.messages.NotificationManager; |
||
64 | import com.iver.cit.gvsig.fmap.layers.Annotation_Layer; |
||
65 | import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
||
66 | |||
67 | |||
68 | 11536 | caballero | /**
|
69 | * Configure annotation mapping.
|
||
70 | *
|
||
71 | * @author Vicente Caballero Navarro
|
||
72 | */
|
||
73 | public class Annotation_ConfigureLabel extends JWizardPanel { |
||
74 | public static final String TEXT_FOR_DEFAULT_VALUE = "- Default -"; |
||
75 | private static final Rectangle lblDescriptionPosition = new Rectangle(4, 4, |
||
76 | 355, 60); |
||
77 | private static final Rectangle lblStep1Position = new Rectangle(4, 90, 15, |
||
78 | 15);
|
||
79 | private static final Rectangle lblAnglePosition = new Rectangle(30, 90, |
||
80 | 355, 30); |
||
81 | private static final Rectangle cmbAnglePosition = new Rectangle(30, 124, |
||
82 | 170, 18); |
||
83 | private static final Rectangle lblStep2Position = new Rectangle(4, 150, 15, |
||
84 | 15);
|
||
85 | private static final Rectangle lblColorPosition = new Rectangle(30, 150, |
||
86 | 355, 30); |
||
87 | private static final Rectangle cmbColorPosition = new Rectangle(30, 184, |
||
88 | 170, 18); |
||
89 | private static final Rectangle lblStep3Position = new Rectangle(4, 210, 15, |
||
90 | 15);
|
||
91 | private static final Rectangle lblSizePosition = new Rectangle(30, 210, |
||
92 | 355, 30); |
||
93 | private static final Rectangle cmbSizePosition = new Rectangle(30, 244, |
||
94 | 170, 18); |
||
95 | private static final Rectangle lblSizeUnitsPosition = new Rectangle(204, |
||
96 | 244, 80, 15); |
||
97 | private static final Rectangle cmbSizeUnitsPosition = new Rectangle(305, |
||
98 | 244, 80, 18); |
||
99 | private static final Rectangle lblStep4Position = new Rectangle(4, 270, 15, |
||
100 | 15);
|
||
101 | private static final Rectangle lblFontPosition = new Rectangle(30, 270, |
||
102 | 355, 30); |
||
103 | private static final Rectangle cmbFontPosition = new Rectangle(30, 304, |
||
104 | 170, 18); |
||
105 | private Annotation_Layer layer;
|
||
106 | private HashMap fieldsNames = new HashMap(); |
||
107 | private JLabel lblDescription; |
||
108 | private JLabel lblAngle; |
||
109 | private JLabel lblColor; |
||
110 | private JLabel lblSize; |
||
111 | private JLabel lblSizeUnits; |
||
112 | private JLabel lblFont; |
||
113 | private JLabel lblStep1; |
||
114 | private JLabel lblStep2; |
||
115 | private JLabel lblStep3; |
||
116 | private JLabel lblStep4; |
||
117 | private JComboBox cmbAngle = null; |
||
118 | private JComboBox cmbColor = null; |
||
119 | private JComboBox cmbSize = null; |
||
120 | private JComboBox cmbSizeUnits = null; |
||
121 | private JComboBox cmbFont = null; |
||
122 | private EventsListener eventsListener = new EventsListener(); |
||
123 | 13512 | caballero | private SelectableDataSource sds;
|
124 | 11536 | caballero | |
125 | public Annotation_ConfigureLabel(JWizardComponents arg0,
|
||
126 | Annotation_Layer layer) { |
||
127 | super(arg0);
|
||
128 | this.layer = layer;
|
||
129 | 13512 | caballero | |
130 | 11536 | caballero | try {
|
131 | 13512 | caballero | if (layer.getRecordset() != null) { |
132 | sds = layer.getRecordset(); |
||
133 | } |
||
134 | } catch (ReadDriverException e) {
|
||
135 | NotificationManager.addError(e); |
||
136 | 11536 | caballero | } |
137 | 13512 | caballero | |
138 | 11536 | caballero | this.initialize();
|
139 | } |
||
140 | |||
141 | 13512 | caballero | /**
|
142 | * DOCUMENT ME!
|
||
143 | */
|
||
144 | 11536 | caballero | private void updateButtonsState() { |
145 | 13512 | caballero | try {
|
146 | if (getWizardComponents().getCurrentIndex() == 1) { |
||
147 | setBackButtonEnabled(true);
|
||
148 | setNextButtonEnabled(false);
|
||
149 | setFinishButtonEnabled(checkIsOkPanelData()); |
||
150 | } |
||
151 | } catch (Exception e) { |
||
152 | NotificationManager.addError(e); |
||
153 | } |
||
154 | 11536 | caballero | } |
155 | |||
156 | 13512 | caballero | /**
|
157 | * DOCUMENT ME!
|
||
158 | *
|
||
159 | * @return DOCUMENT ME!
|
||
160 | */
|
||
161 | 11536 | caballero | protected boolean checkIsOkPanelData() { |
162 | 13512 | caballero | // if
|
163 | // (!((String)this.getCmbSize().getSelectedItem()).equals(Annotation_ConfigureLabel.TEXT_FOR_DEFAULT_VALUE))
|
||
164 | // {
|
||
165 | // return
|
||
166 | // (((String)this.getCmbSizeUnits().getSelectedItem()).trim().length() >
|
||
167 | // 0);
|
||
168 | // }
|
||
169 | 11536 | caballero | return true; |
170 | } |
||
171 | |||
172 | 13512 | caballero | /**
|
173 | * DOCUMENT ME!
|
||
174 | */
|
||
175 | 11536 | caballero | protected void initialize() { |
176 | this.setLayout(null); |
||
177 | this.setSize(new Dimension(358, 263)); |
||
178 | this.addLabels();
|
||
179 | |||
180 | this.add(getCmbAngle(), null); |
||
181 | this.add(getCmbColor(), null); |
||
182 | this.add(getCmbSize(), null); |
||
183 | |||
184 | 13512 | caballero | this.add(getCmbSizeUnits(), null); |
185 | 11536 | caballero | this.add(getCmbFont(), null); |
186 | |||
187 | checkIsOkPanelData(); |
||
188 | } |
||
189 | |||
190 | 13512 | caballero | /**
|
191 | * DOCUMENT ME!
|
||
192 | */
|
||
193 | 11536 | caballero | protected void addLabels() { |
194 | this.lblDescription = new JLabel(); |
||
195 | this.lblStep1 = new JLabel(); |
||
196 | this.lblAngle = new JLabel(); |
||
197 | this.lblStep2 = new JLabel(); |
||
198 | this.lblColor = new JLabel(); |
||
199 | this.lblStep3 = new JLabel(); |
||
200 | this.lblSize = new JLabel(); |
||
201 | |||
202 | 13512 | caballero | this.lblSizeUnits = new JLabel(); |
203 | 11536 | caballero | this.lblStep4 = new JLabel(); |
204 | this.lblFont = new JLabel(); |
||
205 | |||
206 | this.lblDescription.setText(PluginServices.getText(this, |
||
207 | "descripcion_de_configuracion_capa_de_anotaciones"));
|
||
208 | this.lblStep1.setText("1."); |
||
209 | this.lblAngle.setText(PluginServices.getText(this, |
||
210 | "seleccione_el_campo_angulo_de_la_capa_de_anotaciones"));
|
||
211 | this.lblStep2.setText("2."); |
||
212 | this.lblColor.setText(PluginServices.getText(this, |
||
213 | "seleccione_el_campo_color_de_la_capa_de_anotaciones"));
|
||
214 | this.lblStep3.setText("3."); |
||
215 | this.lblSize.setText(PluginServices.getText(this, |
||
216 | "seleccione_el_campo_tamano_de_la_capa_de_anotaciones"));
|
||
217 | |||
218 | 13512 | caballero | this.lblSizeUnits.setText(PluginServices.getText(this, "en_unidades")); |
219 | 11536 | caballero | this.lblStep4.setText("4."); |
220 | this.lblFont.setText(PluginServices.getText(this, |
||
221 | "seleccione_el_campo_fuente_de_la_capa_de_anotaciones"));
|
||
222 | |||
223 | 13512 | caballero | // TODO: Posicionar
|
224 | 11536 | caballero | this.lblDescription.setBounds(lblDescriptionPosition);
|
225 | this.lblStep1.setBounds(lblStep1Position);
|
||
226 | this.lblAngle.setBounds(lblAnglePosition);
|
||
227 | this.lblStep2.setBounds(lblStep2Position);
|
||
228 | this.lblColor.setBounds(lblColorPosition);
|
||
229 | this.lblStep3.setBounds(lblStep3Position);
|
||
230 | this.lblSize.setBounds(lblSizePosition);
|
||
231 | |||
232 | this.lblSizeUnits.setBounds(lblSizeUnitsPosition);
|
||
233 | this.lblStep4.setBounds(lblStep4Position);
|
||
234 | this.lblFont.setBounds(lblFontPosition);
|
||
235 | |||
236 | this.add(lblDescription, null); |
||
237 | this.add(lblStep1, null); |
||
238 | this.add(lblAngle, null); |
||
239 | this.add(lblStep2, null); |
||
240 | this.add(lblColor, null); |
||
241 | this.add(lblStep3, null); |
||
242 | this.add(lblSize, null); |
||
243 | |||
244 | 13512 | caballero | this.add(lblSizeUnits, null); |
245 | 11536 | caballero | this.add(lblStep4, null); |
246 | this.add(lblFont, null); |
||
247 | } |
||
248 | |||
249 | 13512 | caballero | /**
|
250 | * DOCUMENT ME!
|
||
251 | *
|
||
252 | * @param cmb DOCUMENT ME!
|
||
253 | * @param types DOCUMENT ME!
|
||
254 | */
|
||
255 | 11536 | caballero | private void fillFieldsNames(JComboBox cmb, int[] types) { |
256 | cmb.addItem(Annotation_ConfigureLabel.TEXT_FOR_DEFAULT_VALUE); |
||
257 | |||
258 | Collection names;
|
||
259 | |||
260 | if (types == null) { |
||
261 | String[] allNames = (String[]) this.fieldsNames.get("ALL"); |
||
262 | |||
263 | if (allNames == null) { |
||
264 | try {
|
||
265 | SelectableDataSource dataSource = this.layer.getRecordset();
|
||
266 | |||
267 | allNames = dataSource.getFieldNames(); |
||
268 | this.fieldsNames.put("ALL", allNames); |
||
269 | 13512 | caballero | } catch (ReadDriverException e) {
|
270 | NotificationManager.addError(e); |
||
271 | } |
||
272 | 11536 | caballero | } |
273 | |||
274 | for (int i = 0; i < allNames.length; i++) { |
||
275 | cmb.addItem(allNames[i]); |
||
276 | } |
||
277 | |||
278 | return;
|
||
279 | } |
||
280 | |||
281 | Integer typeKey;
|
||
282 | |||
283 | for (int i = 0; i < types.length; i++) { |
||
284 | typeKey = new Integer(types[i]); |
||
285 | |||
286 | if (!this.fieldsNames.containsKey(typeKey)) { |
||
287 | names = this.getFieldsFromType(types[i]);
|
||
288 | this.fieldsNames.put(typeKey, names);
|
||
289 | } else {
|
||
290 | names = (Collection) this.fieldsNames.get(typeKey); |
||
291 | } |
||
292 | |||
293 | if (names != null) { |
||
294 | Iterator name = names.iterator();
|
||
295 | |||
296 | while (name.hasNext()) {
|
||
297 | cmb.addItem(name.next()); |
||
298 | } |
||
299 | } |
||
300 | } |
||
301 | } |
||
302 | |||
303 | 13512 | caballero | /**
|
304 | * DOCUMENT ME!
|
||
305 | *
|
||
306 | * @param type DOCUMENT ME!
|
||
307 | *
|
||
308 | * @return DOCUMENT ME!
|
||
309 | */
|
||
310 | 11536 | caballero | private Collection getFieldsFromType(int type) { |
311 | ArrayList result = new ArrayList(); |
||
312 | |||
313 | try {
|
||
314 | SelectableDataSource dataSource = this.layer.getRecordset();
|
||
315 | |||
316 | for (int i = 0; i < dataSource.getFieldCount(); i++) { |
||
317 | if (dataSource.getFieldType(i) == type) {
|
||
318 | result.add(dataSource.getFieldName(i)); |
||
319 | } |
||
320 | } |
||
321 | 13512 | caballero | } catch (ReadDriverException e) {
|
322 | NotificationManager.addError(e); |
||
323 | } |
||
324 | 11536 | caballero | |
325 | if (result.size() == 0) { |
||
326 | return null; |
||
327 | } |
||
328 | |||
329 | return result;
|
||
330 | } |
||
331 | |||
332 | 13512 | caballero | /**
|
333 | * DOCUMENT ME!
|
||
334 | *
|
||
335 | * @return DOCUMENT ME!
|
||
336 | */
|
||
337 | 11536 | caballero | private JComboBox getCmbAngle() { |
338 | if (this.cmbAngle == null) { |
||
339 | this.cmbAngle = new JComboBox(); |
||
340 | this.cmbAngle.setEditable(false); |
||
341 | this.cmbAngle.setBounds(cmbAnglePosition);
|
||
342 | this.fillFieldsNames(this.cmbAngle, |
||
343 | new int[] { Types.INTEGER, Types.DOUBLE }); |
||
344 | this.cmbAngle.addItemListener(this.eventsListener); |
||
345 | |||
346 | 13512 | caballero | if ((sds != null) && (layer.getAnnotatonMapping() != null)) { |
347 | int index = layer.getAnnotatonMapping().getColumnRotate();
|
||
348 | setSelectedItem(index, cmbAngle); |
||
349 | updateButtonsState(); |
||
350 | 11536 | caballero | } |
351 | } |
||
352 | |||
353 | return this.cmbAngle; |
||
354 | } |
||
355 | |||
356 | 13512 | caballero | /**
|
357 | * DOCUMENT ME!
|
||
358 | *
|
||
359 | * @return DOCUMENT ME!
|
||
360 | */
|
||
361 | 11536 | caballero | public String getAngleFieldName() { |
362 | return (String) this.getCmbAngle().getSelectedItem(); |
||
363 | } |
||
364 | |||
365 | 13512 | caballero | /**
|
366 | * DOCUMENT ME!
|
||
367 | *
|
||
368 | * @return DOCUMENT ME!
|
||
369 | */
|
||
370 | 11536 | caballero | private JComboBox getCmbColor() { |
371 | if (this.cmbColor == null) { |
||
372 | this.cmbColor = new JComboBox(); |
||
373 | this.cmbColor.setEditable(false); |
||
374 | this.cmbColor.setBounds(cmbColorPosition);
|
||
375 | this.fillFieldsNames(this.cmbColor, new int[] { Types.INTEGER }); |
||
376 | this.cmbColor.addItemListener(this.eventsListener); |
||
377 | 13512 | caballero | |
378 | if ((sds != null) && (layer.getAnnotatonMapping() != null)) { |
||
379 | int index = layer.getAnnotatonMapping().getColumnColor();
|
||
380 | setSelectedItem(index, cmbColor); |
||
381 | 11536 | caballero | } |
382 | } |
||
383 | |||
384 | return this.cmbColor; |
||
385 | } |
||
386 | 13512 | caballero | |
387 | /**
|
||
388 | * DOCUMENT ME!
|
||
389 | *
|
||
390 | * @param index DOCUMENT ME!
|
||
391 | * @param cmb DOCUMENT ME!
|
||
392 | */
|
||
393 | private void setSelectedItem(int index, JComboBox cmb) { |
||
394 | if (sds != null) { |
||
395 | String field = null; |
||
396 | |||
397 | try {
|
||
398 | field = sds.getFieldName(index); |
||
399 | } catch (ReadDriverException e) {
|
||
400 | NotificationManager.addError(e); |
||
401 | 11536 | caballero | } |
402 | 13512 | caballero | |
403 | cmb.setSelectedItem(field); |
||
404 | 11536 | caballero | } |
405 | } |
||
406 | 13512 | caballero | |
407 | /**
|
||
408 | * DOCUMENT ME!
|
||
409 | *
|
||
410 | * @return DOCUMENT ME!
|
||
411 | */
|
||
412 | 11536 | caballero | public String getColorFieldName() { |
413 | return (String) this.getCmbColor().getSelectedItem(); |
||
414 | } |
||
415 | |||
416 | 13512 | caballero | /**
|
417 | * DOCUMENT ME!
|
||
418 | *
|
||
419 | * @return DOCUMENT ME!
|
||
420 | */
|
||
421 | 11536 | caballero | private JComboBox getCmbSize() { |
422 | if (this.cmbSize == null) { |
||
423 | this.cmbSize = new JComboBox(); |
||
424 | this.cmbSize.setEditable(false); |
||
425 | this.cmbSize.setBounds(cmbSizePosition);
|
||
426 | this.fillFieldsNames(this.cmbSize, |
||
427 | new int[] { Types.INTEGER, Types.DOUBLE }); |
||
428 | this.cmbSize.addItemListener(this.eventsListener); |
||
429 | 13512 | caballero | |
430 | if ((sds != null) && (layer.getAnnotatonMapping() != null)) { |
||
431 | int index = layer.getAnnotatonMapping().getColumnHeight();
|
||
432 | setSelectedItem(index, cmbSize); |
||
433 | 11536 | caballero | } |
434 | } |
||
435 | |||
436 | return this.cmbSize; |
||
437 | } |
||
438 | |||
439 | 13512 | caballero | /**
|
440 | * DOCUMENT ME!
|
||
441 | *
|
||
442 | * @return DOCUMENT ME!
|
||
443 | */
|
||
444 | 11536 | caballero | public String getSizeFieldName() { |
445 | return (String) this.getCmbSize().getSelectedItem(); |
||
446 | } |
||
447 | |||
448 | 13512 | caballero | /**
|
449 | * DOCUMENT ME!
|
||
450 | *
|
||
451 | * @return DOCUMENT ME!
|
||
452 | */
|
||
453 | private JComboBox getCmbSizeUnits() { |
||
454 | if (this.cmbSizeUnits == null) { |
||
455 | this.cmbSizeUnits = new JComboBox(); |
||
456 | this.cmbSizeUnits.setEditable(false); |
||
457 | this.cmbSizeUnits.setBounds(cmbSizeUnitsPosition);
|
||
458 | this.cmbSizeUnits.addItem(PluginServices.getText(this, "pixels")); |
||
459 | this.cmbSizeUnits.addItem(PluginServices.getText(this, "metros")); |
||
460 | this.cmbSizeUnits.addItemListener(this.eventsListener); |
||
461 | } |
||
462 | |||
463 | return this.cmbSizeUnits; |
||
464 | } |
||
465 | |||
466 | /**
|
||
467 | * DOCUMENT ME!
|
||
468 | *
|
||
469 | * @return DOCUMENT ME!
|
||
470 | */
|
||
471 | 11536 | caballero | public boolean sizeUnitsInPixels() { |
472 | return (this.getCmbSizeUnits().getSelectedIndex() == 0); |
||
473 | } |
||
474 | |||
475 | 13512 | caballero | /**
|
476 | * DOCUMENT ME!
|
||
477 | *
|
||
478 | * @return DOCUMENT ME!
|
||
479 | */
|
||
480 | 11536 | caballero | private JComboBox getCmbFont() { |
481 | if (this.cmbFont == null) { |
||
482 | this.cmbFont = new JComboBox(); |
||
483 | this.cmbFont.setEditable(false); |
||
484 | this.cmbFont.setBounds(cmbFontPosition);
|
||
485 | this.fillFieldsNames(this.cmbFont, |
||
486 | new int[] { Types.VARCHAR, Types.LONGVARCHAR }); |
||
487 | this.cmbFont.addItemListener(this.eventsListener); |
||
488 | 13512 | caballero | |
489 | if ((sds != null) && (layer.getAnnotatonMapping() != null)) { |
||
490 | int index = layer.getAnnotatonMapping().getColumnTypeFont();
|
||
491 | setSelectedItem(index, cmbFont); |
||
492 | 11536 | caballero | } |
493 | } |
||
494 | |||
495 | return this.cmbFont; |
||
496 | } |
||
497 | |||
498 | 13512 | caballero | /**
|
499 | * DOCUMENT ME!
|
||
500 | *
|
||
501 | * @return DOCUMENT ME!
|
||
502 | */
|
||
503 | 11536 | caballero | public String getFontFieldName() { |
504 | return (String) this.getCmbFont().getSelectedItem(); |
||
505 | } |
||
506 | |||
507 | private class EventsListener implements ItemListener { |
||
508 | public void itemStateChanged(ItemEvent e) { |
||
509 | updateButtonsState(); |
||
510 | } |
||
511 | } |
||
512 | } |