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 6117 jaume
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 23383 vcaballero
//TODO comentado para que compile
23 6117 jaume
public class ConfigureLabel extends JWizardPanel {
24 6218 caballero
25 23383 vcaballero
        public ConfigureLabel(JWizardComponents wizardComponents) {
26
                super(wizardComponents);
27
                // TODO Auto-generated constructor stub
28
        }
29
30 6117 jaume
        public static final String TEXT_FOR_DEFAULT_VALUE = "- Default -";
31 6218 caballero
32 23383 vcaballero
//        private FLyrAnnotation layer;
33 6218 caballero
34 6117 jaume
        private HashMap fieldsNames = new HashMap() ;
35
        private JLabel lblDescription;
36 6218 caballero
37 6117 jaume
        private JLabel lblAngle;
38 6218 caballero
39 6117 jaume
        private JLabel lblColor;
40 6218 caballero
41 6117 jaume
        private JLabel lblSize;
42 6218 caballero
43 6117 jaume
        private JLabel lblSizeUnits;
44 6218 caballero
45 6117 jaume
        private JLabel lblFont;
46 6218 caballero
47 6117 jaume
        private JLabel lblStep1;
48 6218 caballero
49 6117 jaume
        private JLabel lblStep2;
50 6218 caballero
51 6117 jaume
        private JLabel lblStep3;
52 6218 caballero
53 6117 jaume
        private JLabel lblStep4;
54 6218 caballero
55 6117 jaume
        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 6218 caballero
61
62
63 6117 jaume
        private static final Rectangle lblDescriptionPosition = new Rectangle(4,4,355,60);
64 6218 caballero
65 6117 jaume
        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 6218 caballero
69
70 6117 jaume
        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 6218 caballero
74 6117 jaume
        private static final Rectangle lblStep3Position = new Rectangle(4,210,15,15);
75
        private static final Rectangle lblSizePosition = new Rectangle(30,210,355,30);
76 6218 caballero
        private static final Rectangle cmbSizePosition = new Rectangle(30,244,170,18);
77 6117 jaume
        private static final Rectangle lblSizeUnitsPosition = new Rectangle(204,244,80,15);
78
        private static final Rectangle cmbSizeUnitsPosition = new Rectangle(305,244,80,18);
79 6218 caballero
80 6117 jaume
        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 6218 caballero
84
85 6117 jaume
        private void updateButtonsState() {
86
                setBackButtonEnabled(true);
87
                setNextButtonEnabled(false);
88
                setFinishButtonEnabled(checkIsOkPanelData());
89
        }
90
91 6218 caballero
92
93 6117 jaume
        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 6218 caballero
101 6117 jaume
        private class EventsListener implements ItemListener
102
        {
103 6218 caballero
104 6117 jaume
                public void itemStateChanged(ItemEvent e) {
105
                        updateButtonsState();
106
                }
107
108
        }
109 6218 caballero
110 6117 jaume
        private EventsListener eventsListener = new EventsListener();
111
112
113 23383 vcaballero
//        public ConfigureLabel(JWizardComponents arg0,FLyrAnnotation layer) {
114
//                super(arg0);
115
//                this.layer =layer;
116
//                this.initialize();
117
//        }
118 6218 caballero
119 6117 jaume
        protected void initialize() {
120
                this.setLayout(null);
121
                this.setSize(new Dimension(358,263));
122 6218 caballero
                this.addLabels();
123
124 6117 jaume
                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 6218 caballero
130 6117 jaume
                checkIsOkPanelData();
131
        }
132
133
134 6218 caballero
        protected void addLabels() {
135 6117 jaume
                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 6218 caballero
146
                this.lblDescription.setText(PluginServices.getText(this,"descripcion_de_configuracion_capa_de_anotaciones"));
147 6117 jaume
                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 6218 caballero
157 6117 jaume
                //TODO: Posicionar
158 6218 caballero
                this.lblDescription.setBounds(lblDescriptionPosition);
159 6117 jaume
                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 6218 caballero
169
170
171 6117 jaume
                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 6218 caballero
182
183 6117 jaume
        }
184 6218 caballero
185 6117 jaume
        private void fillFieldsNames(JComboBox cmb,int[] types) {
186
                cmb.addItem(ConfigureLabel.TEXT_FOR_DEFAULT_VALUE);
187
                Collection names;
188
                if (types == null) {
189 6218 caballero
190 6117 jaume
                        String[] allNames = (String[])this.fieldsNames.get("ALL");
191 23383 vcaballero
//                        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 6117 jaume
                        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 6218 caballero
                        typeKey = new Integer(types[i]);
210 6117 jaume
                        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 6218 caballero
                                Iterator name = names.iterator();
218 6117 jaume
                                while (name.hasNext()){
219
                                        cmb.addItem(name.next());
220
                                }
221
                        }
222 6218 caballero
223
                }
224 6117 jaume
        }
225
        private Collection getFieldsFromType(int type){
226
                ArrayList result = new ArrayList();
227 23383 vcaballero
//                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 6117 jaume
                if (result.size() == 0){
239
                        return null;
240 6218 caballero
                }
241 6117 jaume
                return result;
242 6218 caballero
243 6117 jaume
        }
244 6218 caballero
245 6117 jaume
        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 6218 caballero
                        this.cmbAngle.addItemListener(this.eventsListener);
252 6117 jaume
                }
253
                return this.cmbAngle;
254
        }
255 6218 caballero
256 6117 jaume
        public String getAngleFieldName(){
257 6218 caballero
                return (String)this.getCmbAngle().getSelectedItem();
258 6117 jaume
        }
259 6218 caballero
260 6117 jaume
        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 6218 caballero
                return (String)this.getCmbColor().getSelectedItem();
273 6117 jaume
        }
274
275 6218 caballero
276 6117 jaume
        private JComboBox getCmbSize() {
277
                if (this.cmbSize == null) {
278
                        this.cmbSize= new JComboBox();
279
                        this.cmbSize.setEditable(false);
280 6218 caballero
                        this.cmbSize.setBounds(cmbSizePosition);
281 6117 jaume
                        this.fillFieldsNames(this.cmbSize,new int[]{Types.INTEGER,Types.DOUBLE});
282 6218 caballero
                        this.cmbSize.addItemListener(this.eventsListener);
283 6117 jaume
                }
284
                return this.cmbSize;
285
        }
286 6218 caballero
287
288 6117 jaume
        public String getSizeFieldName(){
289 6218 caballero
                return (String)this.getCmbSize().getSelectedItem();
290 6117 jaume
        }
291 6218 caballero
292 6117 jaume
        private JComboBox getCmbSizeUnits() {
293
                if (this.cmbSizeUnits == null) {
294
                        this.cmbSizeUnits= new JComboBox();
295
                        this.cmbSizeUnits.setEditable(false);
296 6218 caballero
                        this.cmbSizeUnits.setBounds(cmbSizeUnitsPosition);
297 6117 jaume
                        this.cmbSizeUnits.addItem(PluginServices.getText(this,"pixels"));
298 6218 caballero
                        this.cmbSizeUnits.addItem(PluginServices.getText(this,"metros"));
299
                        this.cmbSizeUnits.addItemListener(this.eventsListener);
300 6117 jaume
                }
301
                return this.cmbSizeUnits;
302
        }
303 6218 caballero
304 6117 jaume
        public boolean sizeUnitsInPixels(){
305 12537 jaume
                return (this.getCmbSize().getSelectedIndex() == 0);
306 6117 jaume
        }
307 6218 caballero
308
309 6117 jaume
        private JComboBox getCmbFont() {
310
                if (this.cmbFont == null) {
311
                        this.cmbFont= new JComboBox();
312
                        this.cmbFont.setEditable(false);
313 6218 caballero
                        this.cmbFont.setBounds(cmbFontPosition);
314
                        this.fillFieldsNames(this.cmbFont,new int[]{Types.VARCHAR,Types.LONGVARCHAR});
315 6117 jaume
                        this.cmbFont.addItemListener(this.eventsListener);
316
                }
317
                return this.cmbFont;
318
        }
319 6218 caballero
320 6117 jaume
        public String getFontFieldName(){
321 6218 caballero
                return (String)this.getCmbFont().getSelectedItem();
322 6117 jaume
        }
323
324 6218 caballero
325 6117 jaume
}