Statistics
| Revision:

root / branches / v10 / extensions / extAnnotations / src / com / iver / cit / gvsig / project / documents / gui / Annotation_FieldSelect.java @ 11613

History | View | Annotate | Download (6.48 KB)

1
package com.iver.cit.gvsig.project.documents.gui;
2

    
3
import java.awt.Dimension;
4
import java.awt.Rectangle;
5
import java.awt.event.ItemEvent;
6
import java.awt.event.ItemListener;
7

    
8
import javax.swing.JComboBox;
9
import javax.swing.JLabel;
10
import javax.swing.event.CaretEvent;
11
import javax.swing.event.CaretListener;
12

    
13
import jwizardcomponent.JWizardComponents;
14
import jwizardcomponent.JWizardPanel;
15

    
16
import com.iver.andami.PluginServices;
17
import com.iver.cit.gvsig.fmap.DriverException;
18
import com.iver.cit.gvsig.fmap.layers.Annotation_Layer;
19
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
20

    
21
/**
22
 * Panel to select the text field.
23
 * 
24
 * @author Vicente Caballero Navarro
25
 */
26
public class Annotation_FieldSelect extends JWizardPanel {
27
        private static final Rectangle lblDescriptionPosition = new Rectangle(4, 4,
28
                        355, 75);
29

    
30
        // private static final Rectangle lblStep1Position = new Rectangle(4, 90,
31
        // 15,
32
        // 15);
33

    
34
        // private static final Rectangle lblNewLayerNamePosition = new
35
        // Rectangle(30,90,355,15);
36
        private static final Rectangle lblDuplicatePosition = new Rectangle(30, 80,
37
                        355, 30);
38

    
39
        private static final Rectangle cmbDuplicatePosition = new Rectangle(30,
40
                        110, 170, 18);
41

    
42
        private static final Rectangle lblStep2Position = new Rectangle(4, 135, 15,
43
                        12);
44

    
45
        private static final Rectangle lblFieldPosition = new Rectangle(30, 135,
46
                        355, 30);
47

    
48
        private static final Rectangle cmbFieldPosition = new Rectangle(30, 169,
49
                        170, 18);
50

    
51
        private Annotation_Layer layer;
52

    
53
        private JLabel lblDescription = null;
54

    
55
        // private JLabel lblStep1 = null;
56
        // private JLabel lblNewLayerName = null;
57
        private JLabel lblStep2 = null;
58

    
59
        private JLabel lblField = null;
60

    
61
        // private JTextField txtNewLayerName = null;
62
        private JComboBox cmbField = null;
63

    
64
        private EventsListener eventsListener = new EventsListener();
65

    
66
        private JComboBox cmbDuplicate;
67

    
68
        private JLabel lblDuplicate = null;
69

    
70
        public Annotation_FieldSelect(JWizardComponents arg0, Annotation_Layer layer) {
71
                super(arg0);
72
                this.layer = layer;
73
                this.initialize();
74
        }
75

    
76
        private void updateButtonsState() {
77
                try {
78
                        if (getWizardComponents().getCurrentIndex() == 0) {
79
                                setBackButtonEnabled(false);
80

    
81
                                boolean enabled = checkIsOkPanelData();
82
                                setNextButtonEnabled(enabled);
83
                                setFinishButtonEnabled(enabled);
84
                        }
85
                } catch (Exception e) {
86
                        // TODO Auto-generated catch block
87
                        e.printStackTrace();
88
                }
89
        }
90

    
91
        protected boolean checkIsOkPanelData() {
92
                // if (txtNewLayerName.getText().trim().length() < 1) {
93
                // return false;
94
                // }
95
                if (((String) cmbField.getSelectedItem()).trim().length() < 1) {
96
                        return false;
97
                }
98

    
99
                return true;
100
        }
101

    
102
        protected void initialize() {
103
                this.setLayout(null);
104
                this.setSize(new Dimension(358, 263));
105
                this.addLabels();
106

    
107
                // this.add(getTxtNewLayerName(),null);
108
                this.add(getCmbField(), null);
109
                this.add(getCmbDuplicate(), null);
110
                checkIsOkPanelData();
111
        }
112

    
113
        // private JTextField getTxtNewLayerName() {
114
        // if (this.txtNewLayerName == null) {
115
        // this.txtNewLayerName = new JTextField();
116
        // this.txtNewLayerName.setBounds(txtNewLayerNamePosition);
117
        // this.txtNewLayerName.setText("NuevaCapa");
118
        // this.txtNewLayerName.addCaretListener(eventsListener);
119
        // }
120
        // return this.txtNewLayerName;
121
        // }
122
        // public String getNewLayerName() {
123
        // return this.getTxtNewLayerName().getText();
124
        // }
125
        private JComboBox getCmbField() {
126
                if (this.cmbField == null) {
127
                        this.cmbField = new JComboBox();
128
                        this.cmbField.setEditable(false);
129
                        this.cmbField.setBounds(cmbFieldPosition);
130
                        this.cmbField.addItemListener(this.eventsListener);
131
                        this.cmbField.addItem("");
132

    
133
                        try {
134
                                SelectableDataSource dataSource = this.layer.getRecordset();
135

    
136
                                String[] fieldsNames = dataSource.getFieldNames();
137

    
138
                                for (int i = 0; i < fieldsNames.length; i++) {
139
                                        this.cmbField.addItem(fieldsNames[i]);
140
                                }
141
                                if (layer.getAnnotatonMapping() != null) {
142
                                        String fieldSelect = dataSource.getFieldName(layer
143
                                                        .getAnnotatonMapping().getColumnText());
144
                                        this.cmbField.setSelectedItem(fieldSelect);
145
                                        setNextButtonEnabled(true);
146
                                }
147
                        } catch (DriverException e) {
148
                                e.printStackTrace();
149
                        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
150
                                e.printStackTrace();
151
                        }
152

    
153
                }
154

    
155
                return this.cmbField;
156
        }
157

    
158
        private JComboBox getCmbDuplicate() {
159
                if (cmbDuplicate == null) {
160
                        cmbDuplicate = new JComboBox();
161
                        cmbDuplicate.setBounds(cmbDuplicatePosition);
162
                        cmbDuplicate.addItem(PluginServices.getText(this, "none"));
163
                        cmbDuplicate.addItem(PluginServices.getText(this, "centered"));
164
                        cmbDuplicate.setSelectedItem(PluginServices.getText(this,
165
                                        "centered"));
166
                        // cmbInPixels.setBounds(cmbInPixelsPosition);
167
                        // cmbInPixels.addActionListener(new ActionListener(){
168
                        // public void actionPerformed(ActionEvent e) {
169
                        // if (e.getSource().equals(PluginServices.getText(this,"pixels"))){
170
                        //
171
                        // }
172
                        //
173
                        // }
174
                        //
175
                        // });
176
                }
177
                return cmbDuplicate;
178
        }
179

    
180
        public String getField() {
181
                return (String) this.getCmbField().getSelectedItem();
182
        }
183

    
184
        public String getDuplicate() {
185
                return (String) this.getCmbDuplicate().getSelectedItem();
186
        }
187

    
188
        protected void addLabels() {
189
                this.lblDescription = new JLabel();
190

    
191
                // this.lblStep1 = new JLabel();
192
                // this.lblNewLayerName = new JLabel();
193
                this.lblStep2 = new JLabel();
194
                this.lblField = new JLabel();
195
                this.lblDuplicate = new JLabel();
196

    
197
                this.lblDuplicate.setText(PluginServices.getText(this, "duplicate"));
198
                this.lblDuplicate.setBounds(lblDuplicatePosition);
199
                this.lblDescription.setText(PluginServices.getText(this,
200
                                "descripcion_de_crear_capa_de_anotaciones_nueva"));
201

    
202
                // this.lblStep1.setText("1.");
203
                // this.lblNewLayerName.setText(PluginServices.getText(this,"introduzca_el_nombre_de_la_nueva_capa_de_anotaciones"));
204
                // this.lblStep2.setText("2.");
205
                this.lblField
206
                                .setText(PluginServices
207
                                                .getText(
208
                                                                this,
209
                                                                "seleccione_el_campo_de_texto_que_desea_que_se_utilize_para_mostrar_la_nueva_capa"));
210

    
211
                this.lblDescription.setBounds(lblDescriptionPosition);
212

    
213
                // this.lblStep1.setBounds(lblStep1Position);
214
                // this.lblNewLayerName.setBounds(lblNewLayerNamePosition);
215
                this.lblStep2.setBounds(lblStep2Position);
216
                this.lblField.setBounds(lblFieldPosition);
217

    
218
                this.add(lblDescription, null);
219

    
220
                // this.add(lblStep1,null);
221
                // this.add(lblNewLayerName,null);
222
                this.add(lblStep2, null);
223
                this.add(lblField, null);
224
                this.add(lblDuplicate, null);
225
        }
226

    
227
        private class EventsListener implements CaretListener, ItemListener {
228
                public void caretUpdate(CaretEvent arg0) {
229
                        updateButtonsState();
230
                }
231

    
232
                public void itemStateChanged(ItemEvent e) {
233
                        updateButtonsState();
234
                }
235
        }
236
}