Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / gui / panels / annotation / ConfigureLabel.java @ 24962

History | View | Annotate | Download (9.06 KB)

1
package com.iver.cit.gvsig.gui.panels.annotation;
2

    
3
import java.awt.Dimension;
4
import java.awt.Rectangle;
5
import java.awt.event.ItemEvent;
6
import java.awt.event.ItemListener;
7
import java.sql.Types;
8
import java.util.ArrayList;
9
import java.util.Collection;
10
import java.util.HashMap;
11
import java.util.Iterator;
12

    
13
import javax.swing.JComboBox;
14
import javax.swing.JLabel;
15

    
16
import jwizardcomponent.JWizardComponents;
17
import jwizardcomponent.JWizardPanel;
18

    
19
import com.iver.andami.PluginServices;
20

    
21

    
22
//TODO comentado para que compile
23
public class ConfigureLabel extends JWizardPanel {
24

    
25
        public ConfigureLabel(JWizardComponents wizardComponents) {
26
                super(wizardComponents);
27
                // TODO Auto-generated constructor stub
28
        }
29

    
30
        public static final String TEXT_FOR_DEFAULT_VALUE = "- Default -";
31

    
32
//        private FLyrAnnotation layer;
33

    
34
        private HashMap fieldsNames = new HashMap() ;
35
        private JLabel lblDescription;
36

    
37
        private JLabel lblAngle;
38

    
39
        private JLabel lblColor;
40

    
41
        private JLabel lblSize;
42

    
43
        private JLabel lblSizeUnits;
44

    
45
        private JLabel lblFont;
46

    
47
        private JLabel lblStep1;
48

    
49
        private JLabel lblStep2;
50

    
51
        private JLabel lblStep3;
52

    
53
        private JLabel lblStep4;
54

    
55
        private JComboBox cmbAngle = null;
56
        private JComboBox cmbColor = null;
57
        private JComboBox cmbSize = null;
58
        private JComboBox cmbSizeUnits = null;
59
        private JComboBox cmbFont = null;
60

    
61

    
62

    
63
        private static final Rectangle lblDescriptionPosition = new Rectangle(4,4,355,60);
64

    
65
        private static final Rectangle lblStep1Position = new Rectangle(4,90,15,15);
66
        private static final Rectangle lblAnglePosition = new Rectangle(30,90,355,30);
67
        private static final Rectangle cmbAnglePosition = new Rectangle(30,124,170,18);
68

    
69

    
70
        private static final Rectangle lblStep2Position = new Rectangle(4,150,15,15);
71
        private static final Rectangle lblColorPosition = new Rectangle(30,150,355,30);
72
        private static final Rectangle cmbColorPosition = new Rectangle(30,184,170,18);
73

    
74
        private static final Rectangle lblStep3Position = new Rectangle(4,210,15,15);
75
        private static final Rectangle lblSizePosition = new Rectangle(30,210,355,30);
76
        private static final Rectangle cmbSizePosition = new Rectangle(30,244,170,18);
77
        private static final Rectangle lblSizeUnitsPosition = new Rectangle(204,244,80,15);
78
        private static final Rectangle cmbSizeUnitsPosition = new Rectangle(305,244,80,18);
79

    
80
        private static final Rectangle lblStep4Position = new Rectangle(4,270,15,15);
81
        private static final Rectangle lblFontPosition = new Rectangle(30,270,355,30);
82
        private static final Rectangle cmbFontPosition = new Rectangle(30,304,170,18);
83

    
84

    
85
        private void updateButtonsState() {
86
                setBackButtonEnabled(true);
87
                setNextButtonEnabled(false);
88
                setFinishButtonEnabled(checkIsOkPanelData());
89
        }
90

    
91

    
92

    
93
        protected boolean checkIsOkPanelData() {
94
                if (!((String)this.getCmbSize().getSelectedItem()).equals(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE)) {
95
                        return (((String)this.getCmbSizeUnits().getSelectedItem()).trim().length() > 0);
96
                }
97
                return true;
98
        }
99

    
100

    
101
        private class EventsListener implements ItemListener
102
        {
103

    
104
                public void itemStateChanged(ItemEvent e) {
105
                        updateButtonsState();
106
                }
107

    
108
        }
109

    
110
        private EventsListener eventsListener = new EventsListener();
111

    
112

    
113
//        public ConfigureLabel(JWizardComponents arg0,FLyrAnnotation layer) {
114
//                super(arg0);
115
//                this.layer =layer;
116
//                this.initialize();
117
//        }
118

    
119
        protected void initialize() {
120
                this.setLayout(null);
121
                this.setSize(new Dimension(358,263));
122
                this.addLabels();
123

    
124
                this.add(getCmbAngle(),null);
125
                this.add(getCmbColor(),null);
126
                this.add(getCmbSize(),null);
127
                this.add(getCmbSizeUnits(),null);
128
                this.add(getCmbFont(),null);
129

    
130
                checkIsOkPanelData();
131
        }
132

    
133

    
134
        protected void addLabels() {
135
                this.lblDescription = new JLabel();
136
                this.lblStep1 = new JLabel();
137
                this.lblAngle = new JLabel();
138
                this.lblStep2 = new JLabel();
139
                this.lblColor= new JLabel();
140
                this.lblStep3 = new JLabel();
141
                this.lblSize= new JLabel();
142
                this.lblSizeUnits= new JLabel();
143
                this.lblStep4 = new JLabel();
144
                this.lblFont= new JLabel();
145

    
146
                this.lblDescription.setText(PluginServices.getText(this,"descripcion_de_configuracion_capa_de_anotaciones"));
147
                this.lblStep1.setText("1.");
148
                this.lblAngle.setText(PluginServices.getText(this,"seleccione_el_campo_angulo_de_la_capa_de_anotaciones"));
149
                this.lblStep2.setText("2.");
150
                this.lblColor.setText(PluginServices.getText(this,"seleccione_el_campo_color_de_la_capa_de_anotaciones"));
151
                this.lblStep3.setText("3.");
152
                this.lblSize.setText(PluginServices.getText(this,"seleccione_el_campo_tamano_de_la_capa_de_anotaciones"));
153
                this.lblSizeUnits.setText(PluginServices.getText(this,"en_unidades"));
154
                this.lblStep4.setText("4.");
155
                this.lblFont.setText(PluginServices.getText(this,"seleccione_el_campo_fuente_de_la_capa_de_anotaciones"));
156

    
157
                //TODO: Posicionar
158
                this.lblDescription.setBounds(lblDescriptionPosition);
159
                this.lblStep1.setBounds(lblStep1Position);
160
                this.lblAngle.setBounds(lblAnglePosition);
161
                this.lblStep2.setBounds(lblStep2Position);
162
                this.lblColor.setBounds(lblColorPosition);
163
                this.lblStep3.setBounds(lblStep3Position);
164
                this.lblSize.setBounds(lblSizePosition);
165
                this.lblSizeUnits.setBounds(lblSizeUnitsPosition);
166
                this.lblStep4.setBounds(lblStep4Position);
167
                this.lblFont.setBounds(lblFontPosition);
168

    
169

    
170

    
171
                this.add(lblDescription,null);
172
                this.add(lblStep1,null);
173
                this.add(lblAngle,null);
174
                this.add(lblStep2,null);
175
                this.add(lblColor,null);
176
                this.add(lblStep3,null);
177
                this.add(lblSize,null);
178
                this.add(lblSizeUnits,null);
179
                this.add(lblStep4,null);
180
                this.add(lblFont,null);
181

    
182

    
183
        }
184

    
185
        private void fillFieldsNames(JComboBox cmb,int[] types) {
186
                cmb.addItem(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE);
187
                Collection names;
188
                if (types == null) {
189

    
190
                        String[] allNames = (String[])this.fieldsNames.get("ALL");
191
//                        if (allNames == null) {
192
//                                try {
193
//                                        SelectableDataSource dataSource = this.layer.getRecordset();
194
//
195
//                                        allNames = dataSource.getFieldNames();
196
//                                        this.fieldsNames.put("ALL",allNames);
197
//
198
//                                } catch (ReadDriverException e) {
199
//                                        e.printStackTrace();
200
//                                }
201
//                        }
202
                        for (int i=0; i < allNames.length; i++) {
203
                                cmb.addItem(allNames[i]);
204
                        }
205
                        return;
206
                }
207
                Integer typeKey;
208
                for (int i=0; i < types.length; i++) {
209
                        typeKey = new Integer(types[i]);
210
                        if (!this.fieldsNames.containsKey(typeKey)){
211
                                names = this.getFieldsFromType(types[i]);
212
                                this.fieldsNames.put(typeKey,names);
213
                        }else{
214
                                names = (Collection)this.fieldsNames.get(typeKey);
215
                        }
216
                        if (names != null) {
217
                                Iterator name = names.iterator();
218
                                while (name.hasNext()){
219
                                        cmb.addItem(name.next());
220
                                }
221
                        }
222

    
223
                }
224
        }
225
        private Collection getFieldsFromType(int type){
226
                ArrayList result = new ArrayList();
227
//                try {
228
//                        SelectableDataSource dataSource = this.layer.getRecordset();
229
//
230
//                        for (int i=0; i < dataSource.getFieldCount(); i++) {
231
//                                if (dataSource.getFieldType(i) == type){
232
//                                        result.add(dataSource.getFieldName(i));
233
//                                }
234
//                        }
235
//                } catch (ReadDriverException e) {
236
//                        e.printStackTrace();
237
//                }
238
                if (result.size() == 0){
239
                        return null;
240
                }
241
                return result;
242

    
243
        }
244

    
245
        private JComboBox getCmbAngle() {
246
                if (this.cmbAngle == null) {
247
                        this.cmbAngle= new JComboBox();
248
                        this.cmbAngle.setEditable(false);
249
                        this.cmbAngle.setBounds(cmbAnglePosition);
250
                        this.fillFieldsNames(this.cmbAngle,new int[]{Types.INTEGER,Types.DOUBLE});
251
                        this.cmbAngle.addItemListener(this.eventsListener);
252
                }
253
                return this.cmbAngle;
254
        }
255

    
256
        public String getAngleFieldName(){
257
                return (String)this.getCmbAngle().getSelectedItem();
258
        }
259

    
260
        private JComboBox getCmbColor() {
261
                if (this.cmbColor == null) {
262
                        this.cmbColor= new JComboBox();
263
                        this.cmbColor.setEditable(false);
264
                        this.cmbColor.setBounds(cmbColorPosition);
265
                        this.fillFieldsNames(this.cmbColor,new int[]{Types.INTEGER});
266
                        this.cmbColor.addItemListener(this.eventsListener);
267
                }
268
                return this.cmbColor;
269
        }
270

    
271
        public String getColorFieldName(){
272
                return (String)this.getCmbColor().getSelectedItem();
273
        }
274

    
275

    
276
        private JComboBox getCmbSize() {
277
                if (this.cmbSize == null) {
278
                        this.cmbSize= new JComboBox();
279
                        this.cmbSize.setEditable(false);
280
                        this.cmbSize.setBounds(cmbSizePosition);
281
                        this.fillFieldsNames(this.cmbSize,new int[]{Types.INTEGER,Types.DOUBLE});
282
                        this.cmbSize.addItemListener(this.eventsListener);
283
                }
284
                return this.cmbSize;
285
        }
286

    
287

    
288
        public String getSizeFieldName(){
289
                return (String)this.getCmbSize().getSelectedItem();
290
        }
291

    
292
        private JComboBox getCmbSizeUnits() {
293
                if (this.cmbSizeUnits == null) {
294
                        this.cmbSizeUnits= new JComboBox();
295
                        this.cmbSizeUnits.setEditable(false);
296
                        this.cmbSizeUnits.setBounds(cmbSizeUnitsPosition);
297
                        this.cmbSizeUnits.addItem(PluginServices.getText(this,"pixels"));
298
                        this.cmbSizeUnits.addItem(PluginServices.getText(this,"metros"));
299
                        this.cmbSizeUnits.addItemListener(this.eventsListener);
300
                }
301
                return this.cmbSizeUnits;
302
        }
303

    
304
        public boolean sizeUnitsInPixels(){
305
                return (this.getCmbSize().getSelectedIndex() == 0);
306
        }
307

    
308

    
309
        private JComboBox getCmbFont() {
310
                if (this.cmbFont == null) {
311
                        this.cmbFont= new JComboBox();
312
                        this.cmbFont.setEditable(false);
313
                        this.cmbFont.setBounds(cmbFontPosition);
314
                        this.fillFieldsNames(this.cmbFont,new int[]{Types.VARCHAR,Types.LONGVARCHAR});
315
                        this.cmbFont.addItemListener(this.eventsListener);
316
                }
317
                return this.cmbFont;
318
        }
319

    
320
        public String getFontFieldName(){
321
                return (String)this.getCmbFont().getSelectedItem();
322
        }
323

    
324

    
325
}