root / branches / v2_0_0_prep / extensions / org.gvsig.annotation / src / main / java / org / gvsig / annotation / create / AnnotationConfigureLabelsPanel.java @ 31277
History | View | Annotate | Download (16.4 KB)
1 |
|
---|---|
2 |
/* 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 |
|
43 |
package org.gvsig.annotation.create; |
44 |
|
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 |
import jwizardcomponent.JWizardComponents; |
59 |
import jwizardcomponent.JWizardPanel; |
60 |
|
61 |
import org.gvsig.andami.PluginServices; |
62 |
import org.gvsig.andami.messages.NotificationManager; |
63 |
import org.gvsig.annotation.AnnotationLocator; |
64 |
import org.gvsig.annotation.AnnotationPreferences; |
65 |
import org.gvsig.fmap.dal.exception.DataException; |
66 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
67 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
68 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
69 |
import org.gvsig.fmap.dal.feature.FeatureType; |
70 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
71 |
|
72 |
/**
|
73 |
* Configure annotation mapping.
|
74 |
*
|
75 |
* @author Vicente Caballero Navarro
|
76 |
* Migrated to gvSIG 2.0 by Carlos S?nchez Peri??n
|
77 |
*/
|
78 |
public class AnnotationConfigureLabelsPanel extends JWizardPanel { |
79 |
/**
|
80 |
* Generated Serial Version ID
|
81 |
*/
|
82 |
private static final long serialVersionUID = 2781251924798045780L; |
83 |
|
84 |
public static final String TEXT_FOR_DEFAULT_VALUE = " Default "; |
85 |
public static final Object TEXT_FOR_NO_SELECTED_VALUE = " Not Selected"; |
86 |
|
87 |
private static final Rectangle lblDescriptionPosition = new Rectangle(4, 4, 355, 60); |
88 |
private static final Rectangle lblStep1Position = new Rectangle(4, 90, 15,15); |
89 |
private static final Rectangle lblAnglePosition = new Rectangle(30, 90, 355, 30); |
90 |
private static final Rectangle cmbAnglePosition = new Rectangle(30, 124, 170, 18); |
91 |
private static final Rectangle lblStep2Position = new Rectangle(4, 150, 15,15); |
92 |
private static final Rectangle lblColorPosition = new Rectangle(30, 150, 355, 30); |
93 |
private static final Rectangle cmbColorPosition = new Rectangle(30, 184,170, 18); |
94 |
private static final Rectangle lblStep3Position = new Rectangle(4, 210, 15, 15); |
95 |
private static final Rectangle lblSizePosition = new Rectangle(30, 210, 355, 30); |
96 |
private static final Rectangle cmbSizePosition = new Rectangle(30, 244,170, 18); |
97 |
private static final Rectangle lblSizeUnitsPosition = new Rectangle(204, 244, 80, 15); |
98 |
private static final Rectangle cmbSizeUnitsPosition = new Rectangle(305, 244, 80, 18); |
99 |
private static final Rectangle lblStep4Position = new Rectangle(4, 270, 15,15); |
100 |
private static final Rectangle lblFontPosition = new Rectangle(30, 270, 355, 30); |
101 |
private static final Rectangle cmbFontPosition = new Rectangle(30, 304, 170, 18); |
102 |
|
103 |
private FLyrVect layer;
|
104 |
|
105 |
@SuppressWarnings("unchecked") |
106 |
private HashMap<Comparable, Object> fieldsNames = new HashMap<Comparable, Object>(); |
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 |
|
124 |
private AnnotationPreferences preferences=null; |
125 |
|
126 |
public AnnotationConfigureLabelsPanel(JWizardComponents arg0, FLyrVect lyr) {
|
127 |
super(arg0);
|
128 |
layer = lyr; |
129 |
preferences=AnnotationLocator.getAnnotationPreferences(); |
130 |
this.initialize();
|
131 |
} |
132 |
|
133 |
private void updateButtonsState() { |
134 |
try {
|
135 |
if (getWizardComponents().getCurrentIndex() == 1) { |
136 |
setBackButtonEnabled(true);
|
137 |
setNextButtonEnabled(false);
|
138 |
setFinishButtonEnabled(checkIsOkPanelData()); |
139 |
} |
140 |
} catch (Exception e) { |
141 |
NotificationManager.addError(e); |
142 |
} |
143 |
} |
144 |
|
145 |
protected boolean checkIsOkPanelData() { |
146 |
if(!((String)this.getCmbSize().getSelectedItem()).equals(AnnotationConfigureLabelsPanel.TEXT_FOR_DEFAULT_VALUE)) |
147 |
{ |
148 |
return (((String)this.getCmbSizeUnits().getSelectedItem()).trim().length() >0); |
149 |
} |
150 |
return true; |
151 |
} |
152 |
|
153 |
protected void initialize() { |
154 |
this.setLayout(null); |
155 |
this.setSize(new Dimension(358, 263)); |
156 |
this.addLabels();
|
157 |
|
158 |
this.add(getCmbAngle(), null); |
159 |
this.add(getCmbColor(), null); |
160 |
this.add(getCmbSize(), null); |
161 |
|
162 |
this.add(getCmbSizeUnits(), null); |
163 |
this.add(getCmbFont(), null); |
164 |
|
165 |
checkIsOkPanelData(); |
166 |
} |
167 |
|
168 |
protected void addLabels() { |
169 |
this.lblDescription = new JLabel(); |
170 |
this.lblStep1 = new JLabel(); |
171 |
this.lblAngle = new JLabel(); |
172 |
this.lblStep2 = new JLabel(); |
173 |
this.lblColor = new JLabel(); |
174 |
this.lblStep3 = new JLabel(); |
175 |
this.lblSize = new JLabel(); |
176 |
|
177 |
this.lblSizeUnits = new JLabel(); |
178 |
this.lblStep4 = new JLabel(); |
179 |
this.lblFont = new JLabel(); |
180 |
|
181 |
this.lblDescription.setText(PluginServices.getText(this, |
182 |
"descripcion_de_configuracion_capa_de_anotaciones"));
|
183 |
this.lblStep1.setText("1."); |
184 |
this.lblAngle.setText(PluginServices.getText(this, |
185 |
"seleccione_el_campo_angulo_de_la_capa_de_anotaciones"));
|
186 |
this.lblStep2.setText("2."); |
187 |
this.lblColor.setText(PluginServices.getText(this, |
188 |
"seleccione_el_campo_color_de_la_capa_de_anotaciones"));
|
189 |
this.lblStep3.setText("3."); |
190 |
this.lblSize.setText(PluginServices.getText(this, |
191 |
"seleccione_el_campo_tamano_de_la_capa_de_anotaciones"));
|
192 |
|
193 |
this.lblSizeUnits.setText(PluginServices.getText(this, "en_unidades")); |
194 |
this.lblStep4.setText("4."); |
195 |
this.lblFont.setText(PluginServices.getText(this, |
196 |
"seleccione_el_campo_fuente_de_la_capa_de_anotaciones"));
|
197 |
|
198 |
// TODO: Posicionar
|
199 |
this.lblDescription.setBounds(lblDescriptionPosition);
|
200 |
this.lblStep1.setBounds(lblStep1Position);
|
201 |
this.lblAngle.setBounds(lblAnglePosition);
|
202 |
this.lblStep2.setBounds(lblStep2Position);
|
203 |
this.lblColor.setBounds(lblColorPosition);
|
204 |
this.lblStep3.setBounds(lblStep3Position);
|
205 |
this.lblSize.setBounds(lblSizePosition);
|
206 |
|
207 |
this.lblSizeUnits.setBounds(lblSizeUnitsPosition);
|
208 |
this.lblStep4.setBounds(lblStep4Position);
|
209 |
this.lblFont.setBounds(lblFontPosition);
|
210 |
|
211 |
this.add(lblDescription, null); |
212 |
this.add(lblStep1, null); |
213 |
this.add(lblAngle, null); |
214 |
this.add(lblStep2, null); |
215 |
this.add(lblColor, null); |
216 |
this.add(lblStep3, null); |
217 |
this.add(lblSize, null); |
218 |
|
219 |
this.add(lblSizeUnits, null); |
220 |
this.add(lblStep4, null); |
221 |
this.add(lblFont, null); |
222 |
} |
223 |
|
224 |
/**
|
225 |
* Fill annotation layer new fields
|
226 |
* @param cmb Combobox
|
227 |
* @param types The fields with right type
|
228 |
*/
|
229 |
@SuppressWarnings("unchecked") |
230 |
private void fillFieldsNames(JComboBox cmb, int[] types) { |
231 |
cmb.addItem(AnnotationConfigureLabelsPanel.TEXT_FOR_DEFAULT_VALUE); |
232 |
|
233 |
Collection<String> names; |
234 |
|
235 |
if (types == null) { |
236 |
String[] allNames = (String[]) this.fieldsNames.get("ALL"); |
237 |
|
238 |
if (allNames == null) { |
239 |
FeatureStore store = (FeatureStore) this.layer.getDataStore();
|
240 |
FeatureSet features; |
241 |
try {
|
242 |
features = store.getFeatureSet(); |
243 |
FeatureType type = features.getDefaultFeatureType(); |
244 |
FeatureAttributeDescriptor[] fieldsNames = type.getAttributeDescriptors();
|
245 |
allNames=new String[fieldsNames.length]; |
246 |
for (int i = 0; i < fieldsNames.length; i++) { |
247 |
if(fieldsNames[i].getName().compareTo("GEOMETRY")!=0) |
248 |
allNames[i]=fieldsNames[i].getName(); |
249 |
} |
250 |
this.fieldsNames.put("ALL", allNames); |
251 |
} catch (DataException e) {
|
252 |
// ERROR NOTATIFICATION MANAGER
|
253 |
NotificationManager.addError(e); |
254 |
} |
255 |
} |
256 |
|
257 |
for (int i = 0; i < allNames.length; i++) { |
258 |
cmb.addItem(allNames[i]); |
259 |
} |
260 |
return;
|
261 |
} |
262 |
|
263 |
Integer typeKey;
|
264 |
|
265 |
for (int i = 0; i < types.length; i++) { |
266 |
typeKey = new Integer(types[i]); |
267 |
|
268 |
if (!this.fieldsNames.containsKey(typeKey)) { |
269 |
names = this.getFieldsFromType(types[i]);
|
270 |
this.fieldsNames.put(typeKey, names);
|
271 |
} else {
|
272 |
names = (Collection<String>) this.fieldsNames.get(typeKey); |
273 |
} |
274 |
|
275 |
if (names != null) { |
276 |
Iterator<String> name = names.iterator(); |
277 |
|
278 |
while (name.hasNext()) {
|
279 |
cmb.addItem(name.next()); |
280 |
} |
281 |
} |
282 |
} |
283 |
} |
284 |
|
285 |
/**
|
286 |
* DOCUMENT ME!
|
287 |
*
|
288 |
* @param type DOCUMENT ME!
|
289 |
*
|
290 |
* @return DOCUMENT ME!
|
291 |
*/
|
292 |
private Collection<String> getFieldsFromType(int type) { |
293 |
ArrayList<String> result = new ArrayList<String>(); |
294 |
@SuppressWarnings("unused") |
295 |
String[] allNames = null; |
296 |
FeatureStore store = (FeatureStore) this.layer.getDataStore();
|
297 |
FeatureSet features; |
298 |
try {
|
299 |
features = store.getFeatureSet(); |
300 |
FeatureType types = features.getDefaultFeatureType(); |
301 |
FeatureAttributeDescriptor[] fieldsNames = types.getAttributeDescriptors();
|
302 |
for (int i = 0; i < fieldsNames.length; i++) { |
303 |
if (fieldsNames[i].getDataType() == type) {
|
304 |
result.add(fieldsNames[i].getName()); |
305 |
} |
306 |
} |
307 |
//IF dispose the store we will have to open the store again.
|
308 |
store.dispose(); |
309 |
} catch (DataException e) {
|
310 |
// ERROR NOTATIFICATION MANAGER
|
311 |
NotificationManager.addError(e); |
312 |
} |
313 |
if (result.size() == 0) { |
314 |
return null; |
315 |
} |
316 |
return result;
|
317 |
} |
318 |
|
319 |
/**
|
320 |
* DOCUMENT ME!
|
321 |
*
|
322 |
* @return DOCUMENT ME!
|
323 |
*/
|
324 |
private JComboBox getCmbAngle() { |
325 |
if (this.cmbAngle == null) { |
326 |
this.cmbAngle = new JComboBox(); |
327 |
this.cmbAngle.setEditable(false); |
328 |
this.cmbAngle.setBounds(cmbAnglePosition);
|
329 |
this.fillFieldsNames(this.cmbAngle,new int[] { Types.INTEGER, Types.DOUBLE }); |
330 |
this.cmbAngle.addItemListener(this.eventsListener); |
331 |
|
332 |
//Si se ha seleccionado ya
|
333 |
if (layer != null) { |
334 |
int index;
|
335 |
if (preferences.getMappedNumColumnText()>-1) |
336 |
index = preferences.getMappedColumnNumRotate(); |
337 |
else
|
338 |
index=0;
|
339 |
setSelectedItem(index, cmbAngle); |
340 |
updateButtonsState(); |
341 |
} |
342 |
} |
343 |
return this.cmbAngle; |
344 |
} |
345 |
|
346 |
/**
|
347 |
* DOCUMENT ME!
|
348 |
*
|
349 |
* @return DOCUMENT ME!
|
350 |
*/
|
351 |
public String getAngleFieldName() { |
352 |
return (String) this.getCmbAngle().getSelectedItem(); |
353 |
} |
354 |
|
355 |
/**
|
356 |
* DOCUMENT ME!
|
357 |
*
|
358 |
* @return DOCUMENT ME!
|
359 |
*/
|
360 |
private JComboBox getCmbColor() { |
361 |
if (this.cmbColor == null) { |
362 |
this.cmbColor = new JComboBox(); |
363 |
this.cmbColor.setEditable(false); |
364 |
this.cmbColor.setBounds(cmbColorPosition);
|
365 |
this.fillFieldsNames(this.cmbColor, new int[] { Types.INTEGER }); |
366 |
this.cmbColor.addItemListener(this.eventsListener); |
367 |
|
368 |
if (layer != null) { |
369 |
int index;
|
370 |
if (preferences.getMappedNumColumnColor()>-1) |
371 |
index = preferences.getMappedNumColumnColor(); |
372 |
else
|
373 |
index=0;
|
374 |
setSelectedItem(index, cmbColor); |
375 |
} |
376 |
} |
377 |
|
378 |
return this.cmbColor; |
379 |
} |
380 |
|
381 |
/**
|
382 |
* DOCUMENT ME!
|
383 |
*
|
384 |
* @param index DOCUMENT ME!
|
385 |
* @param cmb DOCUMENT ME!
|
386 |
*/
|
387 |
private void setSelectedItem(int index, JComboBox cmb) { |
388 |
FeatureStore store = (FeatureStore) this.layer.getDataStore();
|
389 |
FeatureSet features; |
390 |
String field = null; |
391 |
try {
|
392 |
features = store.getFeatureSet(); |
393 |
FeatureType types = features.getDefaultFeatureType(); |
394 |
FeatureAttributeDescriptor[] fieldsNames = types.getAttributeDescriptors();
|
395 |
if (index<0) |
396 |
field=AnnotationConfigureLabelsPanel.TEXT_FOR_DEFAULT_VALUE; |
397 |
else
|
398 |
field=fieldsNames[index].getName(); |
399 |
features.dispose(); |
400 |
} catch (DataException e) {
|
401 |
// ERROR NOTATIFICATION MANAGER
|
402 |
NotificationManager.addError(e); |
403 |
} |
404 |
cmb.setSelectedItem(field); |
405 |
} |
406 |
|
407 |
/**
|
408 |
* DOCUMENT ME!
|
409 |
*
|
410 |
* @return DOCUMENT ME!
|
411 |
*/
|
412 |
public String getColorFieldName() { |
413 |
return (String) this.getCmbColor().getSelectedItem(); |
414 |
} |
415 |
|
416 |
/**
|
417 |
* DOCUMENT ME!
|
418 |
*
|
419 |
* @return DOCUMENT ME!
|
420 |
*/
|
421 |
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 |
|
430 |
if (layer != null) { |
431 |
int index;
|
432 |
if (preferences.getMappedColumnNumHeight()>-1) |
433 |
index = preferences.getMappedColumnNumHeight(); |
434 |
else
|
435 |
index=0;
|
436 |
setSelectedItem(index, cmbSize); |
437 |
} |
438 |
} |
439 |
|
440 |
return this.cmbSize; |
441 |
} |
442 |
|
443 |
/**
|
444 |
* DOCUMENT ME!
|
445 |
*
|
446 |
* @return DOCUMENT ME!
|
447 |
*/
|
448 |
public String getSizeFieldName() { |
449 |
return (String) this.getCmbSize().getSelectedItem(); |
450 |
} |
451 |
|
452 |
/**
|
453 |
*
|
454 |
* @return
|
455 |
*/
|
456 |
private JComboBox getCmbSizeUnits() { |
457 |
if (this.cmbSizeUnits == null) { |
458 |
this.cmbSizeUnits = new JComboBox(); |
459 |
this.cmbSizeUnits.setEditable(false); |
460 |
this.cmbSizeUnits.setBounds(cmbSizeUnitsPosition);
|
461 |
this.cmbSizeUnits.addItem(PluginServices.getText(this, "pixels")); |
462 |
this.cmbSizeUnits.addItem(PluginServices.getText(this, "metros")); |
463 |
this.cmbSizeUnits.addItemListener(this.eventsListener); |
464 |
} |
465 |
|
466 |
return this.cmbSizeUnits; |
467 |
} |
468 |
|
469 |
/**
|
470 |
* Check if the size is in pixels then return true if yes.
|
471 |
* @return boolean
|
472 |
*/
|
473 |
public boolean sizeUnitsInPixels() { |
474 |
return (this.getCmbSizeUnits().getSelectedIndex() == 0); |
475 |
} |
476 |
|
477 |
/**
|
478 |
* Combo to Select the Font
|
479 |
* @return JComboBox
|
480 |
*/
|
481 |
private JComboBox getCmbFont() { |
482 |
if (this.cmbFont == null) { |
483 |
this.cmbFont = new JComboBox(); |
484 |
this.cmbFont.setEditable(false); |
485 |
this.cmbFont.setBounds(cmbFontPosition);
|
486 |
this.fillFieldsNames(this.cmbFont, |
487 |
new int[] { Types.VARCHAR, Types.LONGVARCHAR }); |
488 |
this.cmbFont.addItemListener(this.eventsListener); |
489 |
|
490 |
if (layer != null) { |
491 |
int index;
|
492 |
if (preferences.getMappedColumnNumTypeFont()>-1) |
493 |
index = preferences.getMappedColumnNumTypeFont(); |
494 |
else
|
495 |
index=0;
|
496 |
setSelectedItem(index, cmbFont); |
497 |
} |
498 |
} |
499 |
return this.cmbFont; |
500 |
} |
501 |
|
502 |
/**
|
503 |
* Return the Font Field
|
504 |
* @return String name
|
505 |
*/
|
506 |
public String getFontFieldName() { |
507 |
return (String) this.getCmbFont().getSelectedItem(); |
508 |
} |
509 |
|
510 |
private class EventsListener implements ItemListener { |
511 |
public void itemStateChanged(ItemEvent e) { |
512 |
updateButtonsState(); |
513 |
} |
514 |
} |
515 |
} |