Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / panels / annotation / ConfigureLabel.java @ 10626

History | View | Annotate | Download (9.02 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.hardcode.gdbms.driver.exceptions.ReadDriverException;
20
import com.iver.andami.PluginServices;
21
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation;
22
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
23

    
24

    
25

    
26
public class ConfigureLabel extends JWizardPanel {
27

    
28
        public static final String TEXT_FOR_DEFAULT_VALUE = "- Default -";
29

    
30
        private FLyrAnnotation layer;
31

    
32
        private HashMap fieldsNames = new HashMap() ;
33
        private JLabel lblDescription;
34

    
35
        private JLabel lblAngle;
36

    
37
        private JLabel lblColor;
38

    
39
        private JLabel lblSize;
40

    
41
        private JLabel lblSizeUnits;
42

    
43
        private JLabel lblFont;
44

    
45
        private JLabel lblStep1;
46

    
47
        private JLabel lblStep2;
48

    
49
        private JLabel lblStep3;
50

    
51
        private JLabel lblStep4;
52

    
53
        private JComboBox cmbAngle = null;
54
        private JComboBox cmbColor = null;
55
        private JComboBox cmbSize = null;
56
        private JComboBox cmbSizeUnits = null;
57
        private JComboBox cmbFont = null;
58

    
59

    
60

    
61
        private static final Rectangle lblDescriptionPosition = new Rectangle(4,4,355,60);
62

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

    
67

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

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

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

    
82

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

    
89

    
90

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

    
98

    
99
        private class EventsListener implements ItemListener
100
        {
101

    
102
                public void itemStateChanged(ItemEvent e) {
103
                        updateButtonsState();
104
                }
105

    
106
        }
107

    
108
        private EventsListener eventsListener = new EventsListener();
109

    
110

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

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

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

    
128
                checkIsOkPanelData();
129
        }
130

    
131

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

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

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

    
167

    
168

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

    
180

    
181
        }
182

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

    
188
                        String[] allNames = (String[])this.fieldsNames.get("ALL");
189
                        if (allNames == null) {
190
                                try {
191
                                        SelectableDataSource dataSource = this.layer.getRecordset();
192

    
193
                                        allNames = dataSource.getFieldNames();
194
                                        this.fieldsNames.put("ALL",allNames);
195

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

    
221
                }
222
        }
223
        private Collection getFieldsFromType(int type){
224
                ArrayList result = new ArrayList();
225
                try {
226
                        SelectableDataSource dataSource = this.layer.getRecordset();
227

    
228
                        for (int i=0; i < dataSource.getFieldCount(); i++) {
229
                                if (dataSource.getFieldType(i) == type){
230
                                        result.add(dataSource.getFieldName(i));
231
                                }
232
                        }
233
                } catch (ReadDriverException e) {
234
                        e.printStackTrace();
235
                }
236
                if (result.size() == 0){
237
                        return null;
238
                }
239
                return result;
240

    
241
        }
242

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

    
254
        public String getAngleFieldName(){
255
                return (String)this.getCmbAngle().getSelectedItem();
256
        }
257

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

    
269
        public String getColorFieldName(){
270
                return (String)this.getCmbColor().getSelectedItem();
271
        }
272

    
273

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

    
285

    
286
        public String getSizeFieldName(){
287
                return (String)this.getCmbSize().getSelectedItem();
288
        }
289

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

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

    
306

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

    
318
        public String getFontFieldName(){
319
                return (String)this.getCmbFont().getSelectedItem();
320
        }
321

    
322

    
323
}