Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / gui / panels / annotation / ConfigureLabel.java @ 40558

History | View | Annotate | Download (9.99 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
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 3
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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.app.gui.panels.annotation;
25

    
26
import java.awt.Dimension;
27
import java.awt.Rectangle;
28
import java.awt.event.ItemEvent;
29
import java.awt.event.ItemListener;
30
import java.sql.Types;
31
import java.util.ArrayList;
32
import java.util.Collection;
33
import java.util.HashMap;
34
import java.util.Iterator;
35

    
36
import javax.swing.JComboBox;
37
import javax.swing.JLabel;
38

    
39
import org.gvsig.andami.PluginServices;
40

    
41
import jwizardcomponent.JWizardComponents;
42
import jwizardcomponent.JWizardPanel;
43

    
44

    
45

    
46
//TODO comentado para que compile
47
public class ConfigureLabel extends JWizardPanel {
48

    
49
        public ConfigureLabel(JWizardComponents wizardComponents) {
50
                super(wizardComponents);
51
                // TODO Auto-generated constructor stub
52
        }
53

    
54
        public static final String TEXT_FOR_DEFAULT_VALUE = "- Default -";
55

    
56
//        private FLyrAnnotation layer;
57

    
58
        private HashMap fieldsNames = new HashMap() ;
59
        private JLabel lblDescription;
60

    
61
        private JLabel lblAngle;
62

    
63
        private JLabel lblColor;
64

    
65
        private JLabel lblSize;
66

    
67
        private JLabel lblSizeUnits;
68

    
69
        private JLabel lblFont;
70

    
71
        private JLabel lblStep1;
72

    
73
        private JLabel lblStep2;
74

    
75
        private JLabel lblStep3;
76

    
77
        private JLabel lblStep4;
78

    
79
        private JComboBox cmbAngle = null;
80
        private JComboBox cmbColor = null;
81
        private JComboBox cmbSize = null;
82
        private JComboBox cmbSizeUnits = null;
83
        private JComboBox cmbFont = null;
84

    
85

    
86

    
87
        private static final Rectangle lblDescriptionPosition = new Rectangle(4,4,355,60);
88

    
89
        private static final Rectangle lblStep1Position = new Rectangle(4,90,15,15);
90
        private static final Rectangle lblAnglePosition = new Rectangle(30,90,355,30);
91
        private static final Rectangle cmbAnglePosition = new Rectangle(30,124,170,18);
92

    
93

    
94
        private static final Rectangle lblStep2Position = new Rectangle(4,150,15,15);
95
        private static final Rectangle lblColorPosition = new Rectangle(30,150,355,30);
96
        private static final Rectangle cmbColorPosition = new Rectangle(30,184,170,18);
97

    
98
        private static final Rectangle lblStep3Position = new Rectangle(4,210,15,15);
99
        private static final Rectangle lblSizePosition = new Rectangle(30,210,355,30);
100
        private static final Rectangle cmbSizePosition = new Rectangle(30,244,170,18);
101
        private static final Rectangle lblSizeUnitsPosition = new Rectangle(204,244,80,15);
102
        private static final Rectangle cmbSizeUnitsPosition = new Rectangle(305,244,80,18);
103

    
104
        private static final Rectangle lblStep4Position = new Rectangle(4,270,15,15);
105
        private static final Rectangle lblFontPosition = new Rectangle(30,270,355,30);
106
        private static final Rectangle cmbFontPosition = new Rectangle(30,304,170,18);
107

    
108

    
109
        private void updateButtonsState() {
110
                setBackButtonEnabled(true);
111
                setNextButtonEnabled(false);
112
                setFinishButtonEnabled(checkIsOkPanelData());
113
        }
114

    
115

    
116

    
117
        protected boolean checkIsOkPanelData() {
118
                if (!((String)this.getCmbSize().getSelectedItem()).equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
119
                        return (((String)this.getCmbSizeUnits().getSelectedItem()).trim().length() > 0);
120
                }
121
                return true;
122
        }
123

    
124

    
125
        private class EventsListener implements ItemListener
126
        {
127

    
128
                public void itemStateChanged(ItemEvent e) {
129
                        updateButtonsState();
130
                }
131

    
132
        }
133

    
134
        private EventsListener eventsListener = new EventsListener();
135

    
136

    
137
//        public ConfigureLabel(JWizardComponents arg0,FLyrAnnotation layer) {
138
//                super(arg0);
139
//                this.layer =layer;
140
//                this.initialize();
141
//        }
142

    
143
        protected void initialize() {
144
                this.setLayout(null);
145
                this.setSize(new Dimension(358,263));
146
                this.addLabels();
147

    
148
                this.add(getCmbAngle(),null);
149
                this.add(getCmbColor(),null);
150
                this.add(getCmbSize(),null);
151
                this.add(getCmbSizeUnits(),null);
152
                this.add(getCmbFont(),null);
153

    
154
                checkIsOkPanelData();
155
        }
156

    
157

    
158
        protected void addLabels() {
159
                this.lblDescription = new JLabel();
160
                this.lblStep1 = new JLabel();
161
                this.lblAngle = new JLabel();
162
                this.lblStep2 = new JLabel();
163
                this.lblColor= new JLabel();
164
                this.lblStep3 = new JLabel();
165
                this.lblSize= new JLabel();
166
                this.lblSizeUnits= new JLabel();
167
                this.lblStep4 = new JLabel();
168
                this.lblFont= new JLabel();
169

    
170
                this.lblDescription.setText(PluginServices.getText(this,"descripcion_de_configuracion_capa_de_anotaciones"));
171
                this.lblStep1.setText("1.");
172
                this.lblAngle.setText(PluginServices.getText(this,"seleccione_el_campo_angulo_de_la_capa_de_anotaciones"));
173
                this.lblStep2.setText("2.");
174
                this.lblColor.setText(PluginServices.getText(this,"seleccione_el_campo_color_de_la_capa_de_anotaciones"));
175
                this.lblStep3.setText("3.");
176
                this.lblSize.setText(PluginServices.getText(this,"seleccione_el_campo_tamano_de_la_capa_de_anotaciones"));
177
                this.lblSizeUnits.setText(PluginServices.getText(this,"en_unidades"));
178
                this.lblStep4.setText("4.");
179
                this.lblFont.setText(PluginServices.getText(this,"seleccione_el_campo_fuente_de_la_capa_de_anotaciones"));
180

    
181
                //TODO: Posicionar
182
                this.lblDescription.setBounds(lblDescriptionPosition);
183
                this.lblStep1.setBounds(lblStep1Position);
184
                this.lblAngle.setBounds(lblAnglePosition);
185
                this.lblStep2.setBounds(lblStep2Position);
186
                this.lblColor.setBounds(lblColorPosition);
187
                this.lblStep3.setBounds(lblStep3Position);
188
                this.lblSize.setBounds(lblSizePosition);
189
                this.lblSizeUnits.setBounds(lblSizeUnitsPosition);
190
                this.lblStep4.setBounds(lblStep4Position);
191
                this.lblFont.setBounds(lblFontPosition);
192

    
193

    
194

    
195
                this.add(lblDescription,null);
196
                this.add(lblStep1,null);
197
                this.add(lblAngle,null);
198
                this.add(lblStep2,null);
199
                this.add(lblColor,null);
200
                this.add(lblStep3,null);
201
                this.add(lblSize,null);
202
                this.add(lblSizeUnits,null);
203
                this.add(lblStep4,null);
204
                this.add(lblFont,null);
205

    
206

    
207
        }
208

    
209
        private void fillFieldsNames(JComboBox cmb,int[] types) {
210
                cmb.addItem(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE);
211
                Collection names;
212
                if (types == null) {
213

    
214
                        String[] allNames = (String[])this.fieldsNames.get("ALL");
215
//                        if (allNames == null) {
216
//                                try {
217
//                                        SelectableDataSource dataSource = this.layer.getRecordset();
218
//
219
//                                        allNames = dataSource.getFieldNames();
220
//                                        this.fieldsNames.put("ALL",allNames);
221
//
222
//                                } catch (ReadDriverException e) {
223
//                                        e.printStackTrace();
224
//                                }
225
//                        }
226
                        for (int i=0; i < allNames.length; i++) {
227
                                cmb.addItem(allNames[i]);
228
                        }
229
                        return;
230
                }
231
                Integer typeKey;
232
                for (int i=0; i < types.length; i++) {
233
                        typeKey = new Integer(types[i]);
234
                        if (!this.fieldsNames.containsKey(typeKey)){
235
                                names = this.getFieldsFromType(types[i]);
236
                                this.fieldsNames.put(typeKey,names);
237
                        }else{
238
                                names = (Collection)this.fieldsNames.get(typeKey);
239
                        }
240
                        if (names != null) {
241
                                Iterator name = names.iterator();
242
                                while (name.hasNext()){
243
                                        cmb.addItem(name.next());
244
                                }
245
                        }
246

    
247
                }
248
        }
249
        private Collection getFieldsFromType(int type){
250
                ArrayList result = new ArrayList();
251
//                try {
252
//                        SelectableDataSource dataSource = this.layer.getRecordset();
253
//
254
//                        for (int i=0; i < dataSource.getFieldCount(); i++) {
255
//                                if (dataSource.getFieldType(i) == type){
256
//                                        result.add(dataSource.getFieldName(i));
257
//                                }
258
//                        }
259
//                } catch (ReadDriverException e) {
260
//                        e.printStackTrace();
261
//                }
262
                if (result.size() == 0){
263
                        return null;
264
                }
265
                return result;
266

    
267
        }
268

    
269
        private JComboBox getCmbAngle() {
270
                if (this.cmbAngle == null) {
271
                        this.cmbAngle= new JComboBox();
272
                        this.cmbAngle.setEditable(false);
273
                        this.cmbAngle.setBounds(cmbAnglePosition);
274
                        this.fillFieldsNames(this.cmbAngle,new int[]{Types.INTEGER,Types.DOUBLE});
275
                        this.cmbAngle.addItemListener(this.eventsListener);
276
                }
277
                return this.cmbAngle;
278
        }
279

    
280
        public String getAngleFieldName(){
281
                return (String)this.getCmbAngle().getSelectedItem();
282
        }
283

    
284
        private JComboBox getCmbColor() {
285
                if (this.cmbColor == null) {
286
                        this.cmbColor= new JComboBox();
287
                        this.cmbColor.setEditable(false);
288
                        this.cmbColor.setBounds(cmbColorPosition);
289
                        this.fillFieldsNames(this.cmbColor,new int[]{Types.INTEGER});
290
                        this.cmbColor.addItemListener(this.eventsListener);
291
                }
292
                return this.cmbColor;
293
        }
294

    
295
        public String getColorFieldName(){
296
                return (String)this.getCmbColor().getSelectedItem();
297
        }
298

    
299

    
300
        private JComboBox getCmbSize() {
301
                if (this.cmbSize == null) {
302
                        this.cmbSize= new JComboBox();
303
                        this.cmbSize.setEditable(false);
304
                        this.cmbSize.setBounds(cmbSizePosition);
305
                        this.fillFieldsNames(this.cmbSize,new int[]{Types.INTEGER,Types.DOUBLE});
306
                        this.cmbSize.addItemListener(this.eventsListener);
307
                }
308
                return this.cmbSize;
309
        }
310

    
311

    
312
        public String getSizeFieldName(){
313
                return (String)this.getCmbSize().getSelectedItem();
314
        }
315

    
316
        private JComboBox getCmbSizeUnits() {
317
                if (this.cmbSizeUnits == null) {
318
                        this.cmbSizeUnits= new JComboBox();
319
                        this.cmbSizeUnits.setEditable(false);
320
                        this.cmbSizeUnits.setBounds(cmbSizeUnitsPosition);
321
                        this.cmbSizeUnits.addItem(PluginServices.getText(this,"pixels"));
322
                        this.cmbSizeUnits.addItem(PluginServices.getText(this,"metros"));
323
                        this.cmbSizeUnits.addItemListener(this.eventsListener);
324
                }
325
                return this.cmbSizeUnits;
326
        }
327

    
328
        public boolean sizeUnitsInPixels(){
329
                return (this.getCmbSize().getSelectedIndex() == 0);
330
        }
331

    
332

    
333
        private JComboBox getCmbFont() {
334
                if (this.cmbFont == null) {
335
                        this.cmbFont= new JComboBox();
336
                        this.cmbFont.setEditable(false);
337
                        this.cmbFont.setBounds(cmbFontPosition);
338
                        this.fillFieldsNames(this.cmbFont,new int[]{Types.VARCHAR,Types.LONGVARCHAR});
339
                        this.cmbFont.addItemListener(this.eventsListener);
340
                }
341
                return this.cmbFont;
342
        }
343

    
344
        public String getFontFieldName(){
345
                return (String)this.getCmbFont().getSelectedItem();
346
        }
347

    
348

    
349
}