Revision 11743 branches/v10/extensions/extAnnotations/src/com/iver/cit/gvsig/project/documents/gui/Annotation_ConfigureLabel.java

View differences:

Annotation_ConfigureLabel.java
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

  
1 43
package com.iver.cit.gvsig.project.documents.gui;
2 44

  
3 45
import java.awt.Dimension;
......
21 63
import com.iver.cit.gvsig.fmap.layers.Annotation_Layer;
22 64
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
23 65

  
66

  
24 67
/**
25 68
 * Configure annotation mapping.
26
 * 
69
 *
27 70
 * @author Vicente Caballero Navarro
28 71
 */
29 72
public class Annotation_ConfigureLabel extends JWizardPanel {
30
	public static final String TEXT_FOR_DEFAULT_VALUE = "- Default -";
73
    public static final String TEXT_FOR_DEFAULT_VALUE = "- Default -";
74
    private static final Rectangle lblDescriptionPosition = new Rectangle(4, 4,
75
            355, 60);
76
    private static final Rectangle lblStep1Position = new Rectangle(4, 90, 15,
77
            15);
78
    private static final Rectangle lblAnglePosition = new Rectangle(30, 90,
79
            355, 30);
80
    private static final Rectangle cmbAnglePosition = new Rectangle(30, 124,
81
            170, 18);
82
    private static final Rectangle lblStep2Position = new Rectangle(4, 150, 15,
83
            15);
84
    private static final Rectangle lblColorPosition = new Rectangle(30, 150,
85
            355, 30);
86
    private static final Rectangle cmbColorPosition = new Rectangle(30, 184,
87
            170, 18);
88
    private static final Rectangle lblStep3Position = new Rectangle(4, 210, 15,
89
            15);
90
    private static final Rectangle lblSizePosition = new Rectangle(30, 210,
91
            355, 30);
92
    private static final Rectangle cmbSizePosition = new Rectangle(30, 244,
93
            170, 18);
94
    private static final Rectangle lblSizeUnitsPosition = new Rectangle(204,
95
            244, 80, 15);
96
    private static final Rectangle cmbSizeUnitsPosition = new Rectangle(305,
97
            244, 80, 18);
98
    private static final Rectangle lblStep4Position = new Rectangle(4, 270, 15,
99
            15);
100
    private static final Rectangle lblFontPosition = new Rectangle(30, 270,
101
            355, 30);
102
    private static final Rectangle cmbFontPosition = new Rectangle(30, 304,
103
            170, 18);
104
    private Annotation_Layer layer;
105
    private HashMap fieldsNames = new HashMap();
106
    private JLabel lblDescription;
107
    private JLabel lblAngle;
108
    private JLabel lblColor;
109
    private JLabel lblSize;
110
    private JLabel lblSizeUnits;
111
    private JLabel lblFont;
112
    private JLabel lblStep1;
113
    private JLabel lblStep2;
114
    private JLabel lblStep3;
115
    private JLabel lblStep4;
116
    private JComboBox cmbAngle = null;
117
    private JComboBox cmbColor = null;
118
    private JComboBox cmbSize = null;
119
    private JComboBox cmbSizeUnits = null;
120
    private JComboBox cmbFont = null;
121
    private EventsListener eventsListener = new EventsListener();
122
    private SelectableDataSource sds;
31 123

  
32
	private static final Rectangle lblDescriptionPosition = new Rectangle(4, 4,
33
			355, 60);
124
    public Annotation_ConfigureLabel(JWizardComponents arg0,
125
        Annotation_Layer layer) {
126
        super(arg0);
127
        this.layer = layer;
34 128

  
35
	private static final Rectangle lblStep1Position = new Rectangle(4, 90, 15,
36
			15);
129
        try {
130
            if (layer.getRecordset() != null) {
131
                sds = layer.getRecordset();
132
            }
133
        } catch (DriverException e) {
134
            e.printStackTrace();
135
        }
37 136

  
38
	private static final Rectangle lblAnglePosition = new Rectangle(30, 90,
39
			355, 30);
137
        this.initialize();
138
    }
40 139

  
41
	private static final Rectangle cmbAnglePosition = new Rectangle(30, 124,
42
			170, 18);
140
    /**
141
     * DOCUMENT ME!
142
     */
143
    private void updateButtonsState() {
144
        try {
145
            if (getWizardComponents().getCurrentIndex() == 1) {
146
                setBackButtonEnabled(true);
147
                setNextButtonEnabled(false);
148
                setFinishButtonEnabled(checkIsOkPanelData());
149
            }
150
        } catch (Exception e) {
151
            e.printStackTrace();
152
        }
153
    }
43 154

  
44
	private static final Rectangle lblStep2Position = new Rectangle(4, 150, 15,
45
			15);
155
    /**
156
     * DOCUMENT ME!
157
     *
158
     * @return DOCUMENT ME!
159
     */
160
    protected boolean checkIsOkPanelData() {
161
        // if
162
        // (!((String)this.getCmbSize().getSelectedItem()).equals(Annotation_ConfigureLabel.TEXT_FOR_DEFAULT_VALUE))
163
        // {
164
        // return
165
        // (((String)this.getCmbSizeUnits().getSelectedItem()).trim().length() >
166
        // 0);
167
        // }
168
        return true;
169
    }
46 170

  
47
	private static final Rectangle lblColorPosition = new Rectangle(30, 150,
48
			355, 30);
171
    /**
172
     * DOCUMENT ME!
173
     */
174
    protected void initialize() {
175
        this.setLayout(null);
176
        this.setSize(new Dimension(358, 263));
177
        this.addLabels();
49 178

  
50
	private static final Rectangle cmbColorPosition = new Rectangle(30, 184,
51
			170, 18);
179
        this.add(getCmbAngle(), null);
180
        this.add(getCmbColor(), null);
181
        this.add(getCmbSize(), null);
52 182

  
53
	private static final Rectangle lblStep3Position = new Rectangle(4, 210, 15,
54
			15);
183
        this.add(getCmbSizeUnits(), null);
184
        this.add(getCmbFont(), null);
55 185

  
56
	private static final Rectangle lblSizePosition = new Rectangle(30, 210,
57
			355, 30);
186
        checkIsOkPanelData();
187
    }
58 188

  
59
	private static final Rectangle cmbSizePosition = new Rectangle(30, 244,
60
			170, 18);
189
    /**
190
     * DOCUMENT ME!
191
     */
192
    protected void addLabels() {
193
        this.lblDescription = new JLabel();
194
        this.lblStep1 = new JLabel();
195
        this.lblAngle = new JLabel();
196
        this.lblStep2 = new JLabel();
197
        this.lblColor = new JLabel();
198
        this.lblStep3 = new JLabel();
199
        this.lblSize = new JLabel();
61 200

  
62
	private static final Rectangle lblSizeUnitsPosition = new Rectangle(204,
63
			244, 80, 15);
201
        this.lblSizeUnits = new JLabel();
202
        this.lblStep4 = new JLabel();
203
        this.lblFont = new JLabel();
64 204

  
65
	private static final Rectangle cmbSizeUnitsPosition = new Rectangle(305,
66
			244, 80, 18);
205
        this.lblDescription.setText(PluginServices.getText(this,
206
                "descripcion_de_configuracion_capa_de_anotaciones"));
207
        this.lblStep1.setText("1.");
208
        this.lblAngle.setText(PluginServices.getText(this,
209
                "seleccione_el_campo_angulo_de_la_capa_de_anotaciones"));
210
        this.lblStep2.setText("2.");
211
        this.lblColor.setText(PluginServices.getText(this,
212
                "seleccione_el_campo_color_de_la_capa_de_anotaciones"));
213
        this.lblStep3.setText("3.");
214
        this.lblSize.setText(PluginServices.getText(this,
215
                "seleccione_el_campo_tamano_de_la_capa_de_anotaciones"));
67 216

  
68
	private static final Rectangle lblStep4Position = new Rectangle(4, 270, 15,
69
			15);
217
        this.lblSizeUnits.setText(PluginServices.getText(this, "en_unidades"));
218
        this.lblStep4.setText("4.");
219
        this.lblFont.setText(PluginServices.getText(this,
220
                "seleccione_el_campo_fuente_de_la_capa_de_anotaciones"));
70 221

  
71
	private static final Rectangle lblFontPosition = new Rectangle(30, 270,
72
			355, 30);
222
        // TODO: Posicionar
223
        this.lblDescription.setBounds(lblDescriptionPosition);
224
        this.lblStep1.setBounds(lblStep1Position);
225
        this.lblAngle.setBounds(lblAnglePosition);
226
        this.lblStep2.setBounds(lblStep2Position);
227
        this.lblColor.setBounds(lblColorPosition);
228
        this.lblStep3.setBounds(lblStep3Position);
229
        this.lblSize.setBounds(lblSizePosition);
73 230

  
74
	private static final Rectangle cmbFontPosition = new Rectangle(30, 304,
75
			170, 18);
231
        this.lblSizeUnits.setBounds(lblSizeUnitsPosition);
232
        this.lblStep4.setBounds(lblStep4Position);
233
        this.lblFont.setBounds(lblFontPosition);
76 234

  
77
	private Annotation_Layer layer;
235
        this.add(lblDescription, null);
236
        this.add(lblStep1, null);
237
        this.add(lblAngle, null);
238
        this.add(lblStep2, null);
239
        this.add(lblColor, null);
240
        this.add(lblStep3, null);
241
        this.add(lblSize, null);
78 242

  
79
	private HashMap fieldsNames = new HashMap();
243
        this.add(lblSizeUnits, null);
244
        this.add(lblStep4, null);
245
        this.add(lblFont, null);
246
    }
80 247

  
81
	private JLabel lblDescription;
248
    /**
249
     * DOCUMENT ME!
250
     *
251
     * @param cmb DOCUMENT ME!
252
     * @param types DOCUMENT ME!
253
     */
254
    private void fillFieldsNames(JComboBox cmb, int[] types) {
255
        cmb.addItem(Annotation_ConfigureLabel.TEXT_FOR_DEFAULT_VALUE);
82 256

  
83
	private JLabel lblAngle;
257
        Collection names;
84 258

  
85
	private JLabel lblColor;
259
        if (types == null) {
260
            String[] allNames = (String[]) this.fieldsNames.get("ALL");
86 261

  
87
	private JLabel lblSize;
262
            if (allNames == null) {
263
                try {
264
                    SelectableDataSource dataSource = this.layer.getRecordset();
88 265

  
89
	private JLabel lblSizeUnits;
266
                    allNames = dataSource.getFieldNames();
267
                    this.fieldsNames.put("ALL", allNames);
268
                } catch (DriverException e) {
269
                    e.printStackTrace();
270
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
271
                    e.printStackTrace();
272
                }
273
            }
90 274

  
91
	private JLabel lblFont;
275
            for (int i = 0; i < allNames.length; i++) {
276
                cmb.addItem(allNames[i]);
277
            }
92 278

  
93
	private JLabel lblStep1;
279
            return;
280
        }
94 281

  
95
	private JLabel lblStep2;
282
        Integer typeKey;
96 283

  
97
	private JLabel lblStep3;
284
        for (int i = 0; i < types.length; i++) {
285
            typeKey = new Integer(types[i]);
98 286

  
99
	private JLabel lblStep4;
287
            if (!this.fieldsNames.containsKey(typeKey)) {
288
                names = this.getFieldsFromType(types[i]);
289
                this.fieldsNames.put(typeKey, names);
290
            } else {
291
                names = (Collection) this.fieldsNames.get(typeKey);
292
            }
100 293

  
101
	private JComboBox cmbAngle = null;
294
            if (names != null) {
295
                Iterator name = names.iterator();
102 296

  
103
	private JComboBox cmbColor = null;
297
                while (name.hasNext()) {
298
                    cmb.addItem(name.next());
299
                }
300
            }
301
        }
302
    }
104 303

  
105
	private JComboBox cmbSize = null;
304
    /**
305
     * DOCUMENT ME!
306
     *
307
     * @param type DOCUMENT ME!
308
     *
309
     * @return DOCUMENT ME!
310
     */
311
    private Collection getFieldsFromType(int type) {
312
        ArrayList result = new ArrayList();
106 313

  
107
	private JComboBox cmbSizeUnits = null;
314
        try {
315
            SelectableDataSource dataSource = this.layer.getRecordset();
108 316

  
109
	private JComboBox cmbFont = null;
317
            for (int i = 0; i < dataSource.getFieldCount(); i++) {
318
                if (dataSource.getFieldType(i) == type) {
319
                    result.add(dataSource.getFieldName(i));
320
                }
321
            }
322
        } catch (DriverException e) {
323
            // TODO Auto-generated catch block
324
            e.printStackTrace();
325
        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
326
            // TODO Auto-generated catch block
327
            e.printStackTrace();
328
        }
110 329

  
111
	private EventsListener eventsListener = new EventsListener();
330
        if (result.size() == 0) {
331
            return null;
332
        }
112 333

  
113
	private SelectableDataSource sds;
334
        return result;
335
    }
114 336

  
115
	public Annotation_ConfigureLabel(JWizardComponents arg0,
116
			Annotation_Layer layer) {
117
		super(arg0);
118
		this.layer = layer;
119
		try {
120
			if (layer.getRecordset() != null)
121
				sds = layer.getRecordset();
122
		} catch (DriverException e) {
123
			e.printStackTrace();
124
		}
125
		this.initialize();
126
	}
337
    /**
338
     * DOCUMENT ME!
339
     *
340
     * @return DOCUMENT ME!
341
     */
342
    private JComboBox getCmbAngle() {
343
        if (this.cmbAngle == null) {
344
            this.cmbAngle = new JComboBox();
345
            this.cmbAngle.setEditable(false);
346
            this.cmbAngle.setBounds(cmbAnglePosition);
347
            this.fillFieldsNames(this.cmbAngle,
348
                new int[] { Types.INTEGER, Types.DOUBLE });
349
            this.cmbAngle.addItemListener(this.eventsListener);
127 350

  
128
	private void updateButtonsState() {
129
		try {
130
			if (getWizardComponents().getCurrentIndex() == 1) {
131
				setBackButtonEnabled(true);
132
				setNextButtonEnabled(false);
133
				setFinishButtonEnabled(checkIsOkPanelData());
134
			}
135
		} catch (Exception e) {
136
			e.printStackTrace();
137
		}
138
	}
351
            if ((sds != null) && (layer.getAnnotatonMapping() != null)) {
352
                int index = layer.getAnnotatonMapping().getColumnRotate();
353
                setSelectedItem(index, cmbAngle);
354
                updateButtonsState();
355
            }
356
        }
139 357

  
140
	protected boolean checkIsOkPanelData() {
141
		// if
142
		// (!((String)this.getCmbSize().getSelectedItem()).equals(Annotation_ConfigureLabel.TEXT_FOR_DEFAULT_VALUE))
143
		// {
144
		// return
145
		// (((String)this.getCmbSizeUnits().getSelectedItem()).trim().length() >
146
		// 0);
147
		// }
148
		return true;
149
	}
358
        return this.cmbAngle;
359
    }
150 360

  
151
	protected void initialize() {
152
		this.setLayout(null);
153
		this.setSize(new Dimension(358, 263));
154
		this.addLabels();
361
    /**
362
     * DOCUMENT ME!
363
     *
364
     * @return DOCUMENT ME!
365
     */
366
    public String getAngleFieldName() {
367
        return (String) this.getCmbAngle().getSelectedItem();
368
    }
155 369

  
156
		this.add(getCmbAngle(), null);
157
		this.add(getCmbColor(), null);
158
		this.add(getCmbSize(), null);
370
    /**
371
     * DOCUMENT ME!
372
     *
373
     * @return DOCUMENT ME!
374
     */
375
    private JComboBox getCmbColor() {
376
        if (this.cmbColor == null) {
377
            this.cmbColor = new JComboBox();
378
            this.cmbColor.setEditable(false);
379
            this.cmbColor.setBounds(cmbColorPosition);
380
            this.fillFieldsNames(this.cmbColor, new int[] { Types.INTEGER });
381
            this.cmbColor.addItemListener(this.eventsListener);
159 382

  
160
		this.add(getCmbSizeUnits(), null);
161
		this.add(getCmbFont(), null);
383
            if ((sds != null) && (layer.getAnnotatonMapping() != null)) {
384
                int index = layer.getAnnotatonMapping().getColumnColor();
385
                setSelectedItem(index, cmbColor);
386
            }
387
        }
162 388

  
163
		checkIsOkPanelData();
164
	}
389
        return this.cmbColor;
390
    }
165 391

  
166
	protected void addLabels() {
167
		this.lblDescription = new JLabel();
168
		this.lblStep1 = new JLabel();
169
		this.lblAngle = new JLabel();
170
		this.lblStep2 = new JLabel();
171
		this.lblColor = new JLabel();
172
		this.lblStep3 = new JLabel();
173
		this.lblSize = new JLabel();
392
    /**
393
     * DOCUMENT ME!
394
     *
395
     * @param index DOCUMENT ME!
396
     * @param cmb DOCUMENT ME!
397
     */
398
    private void setSelectedItem(int index, JComboBox cmb) {
399
        if (sds != null) {
400
            String field = null;
174 401

  
175
		this.lblSizeUnits = new JLabel();
176
		this.lblStep4 = new JLabel();
177
		this.lblFont = new JLabel();
402
            try {
403
                field = sds.getFieldName(index);
404
            } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
405
                e.printStackTrace();
406
            }
178 407

  
179
		this.lblDescription.setText(PluginServices.getText(this,
180
				"descripcion_de_configuracion_capa_de_anotaciones"));
181
		this.lblStep1.setText("1.");
182
		this.lblAngle.setText(PluginServices.getText(this,
183
				"seleccione_el_campo_angulo_de_la_capa_de_anotaciones"));
184
		this.lblStep2.setText("2.");
185
		this.lblColor.setText(PluginServices.getText(this,
186
				"seleccione_el_campo_color_de_la_capa_de_anotaciones"));
187
		this.lblStep3.setText("3.");
188
		this.lblSize.setText(PluginServices.getText(this,
189
				"seleccione_el_campo_tamano_de_la_capa_de_anotaciones"));
408
            cmb.setSelectedItem(field);
409
        }
410
    }
190 411

  
191
		this.lblSizeUnits.setText(PluginServices.getText(this, "en_unidades"));
192
		this.lblStep4.setText("4.");
193
		this.lblFont.setText(PluginServices.getText(this,
194
				"seleccione_el_campo_fuente_de_la_capa_de_anotaciones"));
412
    /**
413
     * DOCUMENT ME!
414
     *
415
     * @return DOCUMENT ME!
416
     */
417
    public String getColorFieldName() {
418
        return (String) this.getCmbColor().getSelectedItem();
419
    }
195 420

  
196
		// TODO: Posicionar
197
		this.lblDescription.setBounds(lblDescriptionPosition);
198
		this.lblStep1.setBounds(lblStep1Position);
199
		this.lblAngle.setBounds(lblAnglePosition);
200
		this.lblStep2.setBounds(lblStep2Position);
201
		this.lblColor.setBounds(lblColorPosition);
202
		this.lblStep3.setBounds(lblStep3Position);
203
		this.lblSize.setBounds(lblSizePosition);
421
    /**
422
     * DOCUMENT ME!
423
     *
424
     * @return DOCUMENT ME!
425
     */
426
    private JComboBox getCmbSize() {
427
        if (this.cmbSize == null) {
428
            this.cmbSize = new JComboBox();
429
            this.cmbSize.setEditable(false);
430
            this.cmbSize.setBounds(cmbSizePosition);
431
            this.fillFieldsNames(this.cmbSize,
432
                new int[] { Types.INTEGER, Types.DOUBLE });
433
            this.cmbSize.addItemListener(this.eventsListener);
204 434

  
205
		this.lblSizeUnits.setBounds(lblSizeUnitsPosition);
206
		this.lblStep4.setBounds(lblStep4Position);
207
		this.lblFont.setBounds(lblFontPosition);
435
            if ((sds != null) && (layer.getAnnotatonMapping() != null)) {
436
                int index = layer.getAnnotatonMapping().getColumnHeight();
437
                setSelectedItem(index, cmbSize);
438
            }
439
        }
208 440

  
209
		this.add(lblDescription, null);
210
		this.add(lblStep1, null);
211
		this.add(lblAngle, null);
212
		this.add(lblStep2, null);
213
		this.add(lblColor, null);
214
		this.add(lblStep3, null);
215
		this.add(lblSize, null);
441
        return this.cmbSize;
442
    }
216 443

  
217
		this.add(lblSizeUnits, null);
218
		this.add(lblStep4, null);
219
		this.add(lblFont, null);
220
	}
444
    /**
445
     * DOCUMENT ME!
446
     *
447
     * @return DOCUMENT ME!
448
     */
449
    public String getSizeFieldName() {
450
        return (String) this.getCmbSize().getSelectedItem();
451
    }
221 452

  
222
	private void fillFieldsNames(JComboBox cmb, int[] types) {
223
		cmb.addItem(Annotation_ConfigureLabel.TEXT_FOR_DEFAULT_VALUE);
453
    /**
454
     * DOCUMENT ME!
455
     *
456
     * @return DOCUMENT ME!
457
     */
458
    private JComboBox getCmbSizeUnits() {
459
        if (this.cmbSizeUnits == null) {
460
            this.cmbSizeUnits = new JComboBox();
461
            this.cmbSizeUnits.setEditable(false);
462
            this.cmbSizeUnits.setBounds(cmbSizeUnitsPosition);
463
            this.cmbSizeUnits.addItem(PluginServices.getText(this, "pixels"));
464
            this.cmbSizeUnits.addItem(PluginServices.getText(this, "metros"));
465
            this.cmbSizeUnits.addItemListener(this.eventsListener);
466
        }
224 467

  
225
		Collection names;
468
        return this.cmbSizeUnits;
469
    }
226 470

  
227
		if (types == null) {
228
			String[] allNames = (String[]) this.fieldsNames.get("ALL");
471
    /**
472
     * DOCUMENT ME!
473
     *
474
     * @return DOCUMENT ME!
475
     */
476
    public boolean sizeUnitsInPixels() {
477
        return (this.getCmbSizeUnits().getSelectedIndex() == 0);
478
    }
229 479

  
230
			if (allNames == null) {
231
				try {
232
					SelectableDataSource dataSource = this.layer.getRecordset();
480
    /**
481
     * DOCUMENT ME!
482
     *
483
     * @return DOCUMENT ME!
484
     */
485
    private JComboBox getCmbFont() {
486
        if (this.cmbFont == null) {
487
            this.cmbFont = new JComboBox();
488
            this.cmbFont.setEditable(false);
489
            this.cmbFont.setBounds(cmbFontPosition);
490
            this.fillFieldsNames(this.cmbFont,
491
                new int[] { Types.VARCHAR, Types.LONGVARCHAR });
492
            this.cmbFont.addItemListener(this.eventsListener);
233 493

  
234
					allNames = dataSource.getFieldNames();
235
					this.fieldsNames.put("ALL", allNames);
236
				} catch (DriverException e) {
237
					e.printStackTrace();
238
				} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
239
					e.printStackTrace();
240
				}
241
			}
494
            if ((sds != null) && (layer.getAnnotatonMapping() != null)) {
495
                int index = layer.getAnnotatonMapping().getColumnTypeFont();
496
                setSelectedItem(index, cmbFont);
497
            }
498
        }
242 499

  
243
			for (int i = 0; i < allNames.length; i++) {
244
				cmb.addItem(allNames[i]);
245
			}
500
        return this.cmbFont;
501
    }
246 502

  
247
			return;
248
		}
503
    /**
504
     * DOCUMENT ME!
505
     *
506
     * @return DOCUMENT ME!
507
     */
508
    public String getFontFieldName() {
509
        return (String) this.getCmbFont().getSelectedItem();
510
    }
249 511

  
250
		Integer typeKey;
251

  
252
		for (int i = 0; i < types.length; i++) {
253
			typeKey = new Integer(types[i]);
254

  
255
			if (!this.fieldsNames.containsKey(typeKey)) {
256
				names = this.getFieldsFromType(types[i]);
257
				this.fieldsNames.put(typeKey, names);
258
			} else {
259
				names = (Collection) this.fieldsNames.get(typeKey);
260
			}
261

  
262
			if (names != null) {
263
				Iterator name = names.iterator();
264

  
265
				while (name.hasNext()) {
266
					cmb.addItem(name.next());
267
				}
268
			}
269
		}
270
	}
271

  
272
	private Collection getFieldsFromType(int type) {
273
		ArrayList result = new ArrayList();
274

  
275
		try {
276
			SelectableDataSource dataSource = this.layer.getRecordset();
277

  
278
			for (int i = 0; i < dataSource.getFieldCount(); i++) {
279
				if (dataSource.getFieldType(i) == type) {
280
					result.add(dataSource.getFieldName(i));
281
				}
282
			}
283
		} catch (DriverException e) {
284
			// TODO Auto-generated catch block
285
			e.printStackTrace();
286
		} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
287
			// TODO Auto-generated catch block
288
			e.printStackTrace();
289
		}
290

  
291
		if (result.size() == 0) {
292
			return null;
293
		}
294

  
295
		return result;
296
	}
297

  
298
	private JComboBox getCmbAngle() {
299
		if (this.cmbAngle == null) {
300
			this.cmbAngle = new JComboBox();
301
			this.cmbAngle.setEditable(false);
302
			this.cmbAngle.setBounds(cmbAnglePosition);
303
			this.fillFieldsNames(this.cmbAngle, new int[] { Types.INTEGER,
304
					Types.DOUBLE });
305
			this.cmbAngle.addItemListener(this.eventsListener);
306

  
307
			if (sds != null && layer.getAnnotatonMapping() != null) {
308
				int index = layer.getAnnotatonMapping().getColumnRotate();
309
				setSelectedItem(index, cmbAngle);
310
				updateButtonsState();
311
			}
312
		}
313

  
314
		return this.cmbAngle;
315
	}
316

  
317
	public String getAngleFieldName() {
318
		return (String) this.getCmbAngle().getSelectedItem();
319
	}
320

  
321
	private JComboBox getCmbColor() {
322
		if (this.cmbColor == null) {
323
			this.cmbColor = new JComboBox();
324
			this.cmbColor.setEditable(false);
325
			this.cmbColor.setBounds(cmbColorPosition);
326
			this.fillFieldsNames(this.cmbColor, new int[] { Types.INTEGER });
327
			this.cmbColor.addItemListener(this.eventsListener);
328
			if (sds != null && layer.getAnnotatonMapping() != null) {
329
				int index = layer.getAnnotatonMapping().getColumnColor();
330
				setSelectedItem(index, cmbColor);
331
			}
332
		}
333

  
334
		return this.cmbColor;
335
	}
336

  
337
	private void setSelectedItem(int index, JComboBox cmb) {
338
		if (sds != null) {
339
			String field = null;
340
			try {
341
				field = sds.getFieldName(index);
342
			} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
343
				e.printStackTrace();
344
			}
345
			cmb.setSelectedItem(field);
346
		}
347
	}
348

  
349
	public String getColorFieldName() {
350
		return (String) this.getCmbColor().getSelectedItem();
351
	}
352

  
353
	private JComboBox getCmbSize() {
354
		if (this.cmbSize == null) {
355
			this.cmbSize = new JComboBox();
356
			this.cmbSize.setEditable(false);
357
			this.cmbSize.setBounds(cmbSizePosition);
358
			this.fillFieldsNames(this.cmbSize, new int[] { Types.INTEGER,
359
					Types.DOUBLE });
360
			this.cmbSize.addItemListener(this.eventsListener);
361
			if (sds != null && layer.getAnnotatonMapping() != null) {
362
				int index = layer.getAnnotatonMapping().getColumnHeight();
363
				setSelectedItem(index, cmbSize);
364
			}
365
		}
366

  
367
		return this.cmbSize;
368
	}
369

  
370
	public String getSizeFieldName() {
371
		return (String) this.getCmbSize().getSelectedItem();
372
	}
373

  
374
	private JComboBox getCmbSizeUnits() {
375
		if (this.cmbSizeUnits == null) {
376
			this.cmbSizeUnits = new JComboBox();
377
			this.cmbSizeUnits.setEditable(false);
378
			this.cmbSizeUnits.setBounds(cmbSizeUnitsPosition);
379
			this.cmbSizeUnits.addItem(PluginServices.getText(this, "pixels"));
380
			this.cmbSizeUnits.addItem(PluginServices.getText(this, "metros"));
381
			this.cmbSizeUnits.addItemListener(this.eventsListener);
382
		}
383
		return this.cmbSizeUnits;
384
	}
385

  
386
	public boolean sizeUnitsInPixels() {
387
		return (this.getCmbSizeUnits().getSelectedIndex() == 0);
388
	}
389

  
390
	private JComboBox getCmbFont() {
391
		if (this.cmbFont == null) {
392
			this.cmbFont = new JComboBox();
393
			this.cmbFont.setEditable(false);
394
			this.cmbFont.setBounds(cmbFontPosition);
395
			this.fillFieldsNames(this.cmbFont, new int[] { Types.VARCHAR,
396
					Types.LONGVARCHAR });
397
			this.cmbFont.addItemListener(this.eventsListener);
398
			if (sds != null && layer.getAnnotatonMapping() != null) {
399
				int index = layer.getAnnotatonMapping().getColumnTypeFont();
400
				setSelectedItem(index, cmbFont);
401
			}
402
		}
403

  
404
		return this.cmbFont;
405
	}
406

  
407
	public String getFontFieldName() {
408
		return (String) this.getCmbFont().getSelectedItem();
409
	}
410

  
411
	private class EventsListener implements ItemListener {
412
		public void itemStateChanged(ItemEvent e) {
413
			updateButtonsState();
414
		}
415
	}
512
    private class EventsListener implements ItemListener {
513
        public void itemStateChanged(ItemEvent e) {
514
            updateButtonsState();
515
        }
516
    }
416 517
}

Also available in: Unified diff