Statistics
| Revision:

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

History | View | Annotate | Download (10.1 KB)

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

    
3
import java.sql.Types;
4

    
5
import javax.swing.ButtonGroup;
6
import javax.swing.JButton;
7
import javax.swing.JComboBox;
8
import javax.swing.JLabel;
9
import javax.swing.JPanel;
10
import javax.swing.JRadioButton;
11
import javax.swing.JTextField;
12

    
13
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
14
import com.iver.andami.PluginServices;
15
import com.iver.andami.ui.mdiManager.IWindow;
16
import com.iver.andami.ui.mdiManager.WindowInfo;
17
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation;
18
import com.iver.cit.gvsig.fmap.layers.MappingAnnotation;
19
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
20

    
21
public class MappingFieldsToAnotation extends JPanel implements IWindow{
22

    
23
        private JComboBox cmbText = null;
24
        private JComboBox cmbAngle = null;
25
        private JLabel jLabel = null;
26
        private JLabel jLabel1 = null;
27
        private JLabel jLabel2 = null;
28
        private JComboBox cmbColor = null;
29
        private JLabel jLabel3 = null;
30
        private JComboBox cmbHeight = null;
31
        private JLabel jLabel4 = null;
32
        private JComboBox cmbFont = null;
33
        private JButton bOk = null;
34
        private JButton bCancel = null;
35
        private SelectableDataSource sds=null;
36
        private FLyrAnnotation la;
37
        private int[] mapText;
38
        private int[] mapAngle;
39
        private int[] mapColor;
40
        private int[] mapHeight;
41
        private int[] mapFont;
42
        private JPanel jPanel = null;
43
        private JLabel jLabel5 = null;
44
        private JTextField txtName = null;
45
        //private JCheckBox chbPixels = null;
46
        private JRadioButton rbMapUnits = null;
47
        private JRadioButton rbPixels = null;
48
        private boolean isOk=false;
49
        /**
50
         * This is the default constructor
51
         */
52
        public MappingFieldsToAnotation(FLyrAnnotation la) {
53
                super();
54
                this.la=la;
55
                try {
56
                        this.sds=la.getRecordset();
57
                        initialize();
58
                } catch (ReadDriverException e) {
59
                        e.printStackTrace();
60
                }
61

    
62
        }
63

    
64
        /**
65
         * This method initializes this
66
         *
67
         * @return void
68
         */
69
        private void initialize() {
70
                jLabel4 = new JLabel();
71
                jLabel4.setBounds(new java.awt.Rectangle(15,259,166,20));
72
                jLabel4.setText("fuente");
73
                jLabel3 = new JLabel();
74
                jLabel3.setBounds(new java.awt.Rectangle(15,197,166,20));
75
                jLabel3.setText("alto");
76
                jLabel2 = new JLabel();
77
                jLabel2.setBounds(new java.awt.Rectangle(15,135,166,20));
78
                jLabel2.setText("color");
79
                jLabel1 = new JLabel();
80
                jLabel1.setBounds(new java.awt.Rectangle(15,73,166,20));
81
                jLabel1.setText("angulo");
82
                jLabel = new JLabel();
83
                jLabel.setBounds(new java.awt.Rectangle(15,11,166,20));
84
                jLabel.setText("texto");
85
                this.setLayout(null);
86
                this.setSize(544, 368);
87
                this.add(getCmbText(), null);
88
                this.add(getCmbAngle(), null);
89
                this.add(jLabel, null);
90
                this.add(jLabel1, null);
91
                this.add(jLabel2, null);
92
                this.add(getCmbColor(), null);
93
                this.add(jLabel3, null);
94
                this.add(getCmbHeight(), null);
95
                this.add(jLabel4, null);
96
                this.add(getCmbFont(), null);
97
                this.add(getBOk(), null);
98
                this.add(getBCancel(), null);
99
                this.add(getJPanel(), null);
100
        }
101

    
102
        public WindowInfo getWindowInfo() {
103
                WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
104
                m_viewinfo.setTitle(PluginServices.getText(this,
105
                                "indexar_campos"));
106

    
107
                return m_viewinfo;
108
        }
109

    
110
        /**
111
         * This method initializes cmbOrigin
112
         *
113
         * @return javax.swing.JComboBox
114
         */
115
        private JComboBox getCmbText() {
116
                if (cmbText == null) {
117
                        cmbText = new JComboBox();
118
                        try {
119
                                mapText=new int[sds.getFieldCount()];
120
                                int num=-1;
121
                                for (int i = 0; i < sds.getFieldCount(); i++) {
122
                                        cmbText.addItem(sds.getFieldName(i));
123
                                        num++;
124
                                        mapText[i]=num;
125
                                }
126
                                //cmbText.addItem("- Defaulf -");
127
                        } catch (ReadDriverException e) {
128
                                e.printStackTrace();
129
                        }
130
                        cmbText.setBounds(new java.awt.Rectangle(15,42,166,20));
131

    
132
                }
133
                return cmbText;
134
        }
135

    
136
        /**
137
         * This method initializes cmbEnd
138
         *
139
         * @return javax.swing.JComboBox
140
         */
141
        private JComboBox getCmbAngle() {
142
                if (cmbAngle == null) {
143
                        cmbAngle = new JComboBox();
144
                        try {
145
                                mapAngle=new int[sds.getFieldCount()];
146
                                int num=-1;
147
                        for (int i = 0; i < sds.getFieldCount(); i++) {
148
                                if (sds.getFieldType(i) == Types.DOUBLE){
149
                                        cmbAngle.addItem(sds.getFieldName(i));
150
                                        num++;
151
                                        mapAngle[i]=num;
152
                                }
153
                        }
154
                        cmbAngle.addItem("- Default -");
155
                        cmbAngle.setSelectedItem("- Default -");
156
                        } catch (ReadDriverException e) {
157
                                e.printStackTrace();
158
                        }
159
                        cmbAngle.setBounds(new java.awt.Rectangle(15,104,166,20));
160
                }
161
                return cmbAngle;
162
        }
163

    
164
        /**
165
         * This method initializes cmbColor
166
         *
167
         * @return javax.swing.JComboBox
168
         */
169
        private JComboBox getCmbColor() {
170
                if (cmbColor == null) {
171
                        cmbColor = new JComboBox();
172
                        cmbColor.setBounds(new java.awt.Rectangle(15,166,166,20));
173
                        try {
174
                                mapColor=new int[sds.getFieldCount()];
175
                                int num=-1;
176
                                for (int i = 0; i < sds.getFieldCount(); i++) {
177
                                        if (sds.getFieldType(i) == Types.DOUBLE){
178
                                                cmbColor.addItem(sds.getFieldName(i));
179
                                                num++;
180
                                                mapColor[i]=num;
181
                                        }
182
                                }
183
                                cmbColor.addItem("- Default -");
184
                                cmbColor.setSelectedItem("- Default -");
185
                        } catch (ReadDriverException e) {
186
                                e.printStackTrace();
187
                        }
188
                }
189
                return cmbColor;
190
        }
191

    
192
        /**
193
         * This method initializes cmbHeight
194
         *
195
         * @return javax.swing.JComboBox
196
         */
197
        private JComboBox getCmbHeight() {
198
                if (cmbHeight == null) {
199
                        cmbHeight = new JComboBox();
200
                        try {
201
                                mapHeight=new int[sds.getFieldCount()];
202
                                int num=-1;
203
                                for (int i = 0; i < sds.getFieldCount(); i++) {
204
                                        if (sds.getFieldType(i) == Types.DOUBLE){
205
                                                cmbHeight.addItem(sds.getFieldName(i));
206
                                                num++;
207
                                                mapHeight[i]=num;
208
                                        }
209
                                }
210
                                cmbHeight.addItem("- Default -");
211
                                cmbHeight.setSelectedItem("- Default -");
212
                        } catch (ReadDriverException e) {
213
                                e.printStackTrace();
214
                        }
215
                        cmbHeight.setBounds(new java.awt.Rectangle(15,228,166,20));
216
                }
217
                return cmbHeight;
218
        }
219

    
220
        /**
221
         * This method initializes cmbFont
222
         *
223
         * @return javax.swing.JComboBox
224
         */
225
        private JComboBox getCmbFont() {
226
                if (cmbFont == null) {
227
                        cmbFont = new JComboBox();
228
                        try {
229
                                mapFont=new int[sds.getFieldCount()];
230
                                int num=-1;
231
                                for (int i = 0; i < sds.getFieldCount(); i++) {
232
                                        if (sds.getFieldType(i) == Types.VARCHAR){
233
                                                cmbFont.addItem(sds.getFieldName(i));
234
                                                num++;
235
                                                mapFont[i]=num;
236
                                        }
237
                                }
238
                                cmbFont.addItem("- Default -");
239
                                cmbFont.setSelectedItem("- Default -");
240
                        } catch (ReadDriverException e) {
241
                                e.printStackTrace();
242
                        }
243
                        cmbFont.setBounds(new java.awt.Rectangle(15,290,166,20));
244
                }
245
                return cmbFont;
246
        }
247

    
248
        /**
249
         * This method initializes bOk
250
         *
251
         * @return javax.swing.JButton
252
         */
253
        private JButton getBOk() {
254
                if (bOk == null) {
255
                        bOk = new JButton();
256
                        bOk.setBounds(new java.awt.Rectangle(119,326,92,24));
257
                        bOk.setText("Aceptar");
258
                        bOk.addActionListener(new java.awt.event.ActionListener() {
259
                                public void actionPerformed(java.awt.event.ActionEvent e) {
260
                                        MappingAnnotation mapping=new MappingAnnotation();
261
                                        if (getCmbText().getSelectedItem().equals(""))
262
                                                mapping.setColumnText(-1);
263
                                        else
264
                                                mapping.setColumnText(mapText[getCmbText().getSelectedIndex()]);
265
                                        if (!getCmbAngle().getSelectedItem().equals("- Default -"))
266
                                                mapping.setColumnRotate(mapAngle[getCmbAngle().getSelectedIndex()]);
267
                                        if (!getCmbColor().getSelectedItem().equals("- Default -"))
268
                                                mapping.setColumnColor(mapColor[getCmbColor().getSelectedIndex()]);
269
                                        if (!getCmbHeight().getSelectedItem().equals("- Default -"))
270
                                                mapping.setColumnHeight(mapHeight[getCmbHeight().getSelectedIndex()]);
271
                                        if (!getCmbFont().getSelectedItem().equals("- Default -"))
272
                                                mapping.setColumnTypeFont(mapFont[getCmbFont().getSelectedIndex()]);
273
                                        //Falta el estilo, si es necesario.
274
                                        la.setInPixels(rbPixels.isSelected());
275
                                        la.setMapping(mapping);
276
                                        la.setName(getTxtName().getText());
277
                                        isOk=true;
278
                                        PluginServices.getMDIManager().closeWindow(MappingFieldsToAnotation.this);
279
                                }
280
                        });
281
                }
282
                return bOk;
283
        }
284

    
285
        /**
286
         * This method initializes bCancel
287
         *
288
         * @return javax.swing.JButton
289
         */
290
        private JButton getBCancel() {
291
                if (bCancel == null) {
292
                        bCancel = new JButton();
293
                        bCancel.setBounds(new java.awt.Rectangle(330,325,93,25));
294
                        bCancel.setText("cancelar");
295
                        bCancel.addActionListener(new java.awt.event.ActionListener() {
296
                                public void actionPerformed(java.awt.event.ActionEvent e) {
297
                                        isOk=false;
298
                                        PluginServices.getMDIManager().closeWindow(MappingFieldsToAnotation.this);
299
                                }
300
                        });
301
                }
302
                return bCancel;
303
        }
304

    
305
        /**
306
         * This method initializes jPanel
307
         *
308
         * @return javax.swing.JPanel
309
         */
310
        private JPanel getJPanel() {
311
                if (jPanel == null) {
312
                        jLabel5 = new JLabel();
313
                        jLabel5.setBounds(new java.awt.Rectangle(15,10,228,22));
314
                        jLabel5.setText("nombre");
315
                        jPanel = new JPanel();
316
                        jPanel.setLayout(null);
317
                        jPanel.setBounds(new java.awt.Rectangle(234,14,251,141));
318
                        jPanel.add(jLabel5, null);
319
                        jPanel.add(getTxtName(), null);
320
                        //jPanel.add(getChbPixels(), null);
321
                        jPanel.add(getRbMapUnits(), null);
322
                        jPanel.add(getRbPixels(), null);
323
                        ButtonGroup bg=new ButtonGroup();
324
                        bg.add(getRbMapUnits());
325
                        bg.add(getRbPixels());
326
                }
327
                return jPanel;
328
        }
329

    
330
        /**
331
         * This method initializes txtName
332
         *
333
         * @return javax.swing.JTextField
334
         */
335
        private JTextField getTxtName() {
336
                if (txtName == null) {
337
                        txtName = new JTextField();
338
                        //txtName.setText(la.get.getName());
339
                        txtName.setBounds(new java.awt.Rectangle(15,42,227,22));
340
                }
341
                return txtName;
342
        }
343

    
344
        /**
345
         * This method initializes chbPixels
346
         *
347
         * @return javax.swing.JCheckBox
348
         */
349
        /*private JCheckBox getChbPixels() {
350
                if (chbPixels == null) {
351
                        chbPixels = new JCheckBox();
352
                        chbPixels.setBounds(new java.awt.Rectangle(15,138,226,25));
353
                        chbPixels.setText("pixels");
354
                }
355
                return chbPixels;
356
        }
357
*/
358
        /**
359
         * This method initializes rbMapUnits
360
         *
361
         * @return javax.swing.JRadioButton
362
         */
363
        private JRadioButton getRbMapUnits() {
364
                if (rbMapUnits == null) {
365
                        rbMapUnits = new JRadioButton();
366
                        rbMapUnits.setBounds(new java.awt.Rectangle(15,74,167,22));
367
                        rbMapUnits.setText("unidades_mapa");
368
                }
369
                return rbMapUnits;
370
        }
371

    
372
        /**
373
         * This method initializes rbPixels
374
         *
375
         * @return javax.swing.JRadioButton
376
         */
377
        private JRadioButton getRbPixels() {
378
                if (rbPixels == null) {
379
                        rbPixels = new JRadioButton();
380
                        rbPixels.setBounds(new java.awt.Rectangle(15,106,167,22));
381
                        rbPixels.setText("pixels");
382
                        rbPixels.setSelected(true);
383
                }
384
                return rbPixels;
385
        }
386

    
387
        public boolean isOk() {
388
                return isOk;
389
        }
390

    
391
}  //  @jve:decl-index=0:visual-constraint="-150,10"