Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / panels / annotation / SelectAnnotationLayerNameAndField.java @ 6117

History | View | Annotate | Download (5 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.util.HashMap;
8
import java.util.Map;
9
10
import javax.swing.ComboBoxModel;
11
import javax.swing.JComboBox;
12
import javax.swing.JLabel;
13
import javax.swing.JTextField;
14
import javax.swing.event.CaretEvent;
15
import javax.swing.event.CaretListener;
16
17
import com.iver.andami.PluginServices;
18
import com.iver.cit.gvsig.fmap.DriverException;
19
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation;
20
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
21
22
import jwizardcomponent.JWizardComponents;
23
import jwizardcomponent.JWizardPanel;
24
25
public class SelectAnnotationLayerNameAndField extends JWizardPanel {
26
        private FLyrAnnotation layer;
27
28
        private JLabel lblDescription = null;
29
        private JLabel lblStep1 = null;
30
        private JLabel lblNewLayerName = null;
31
        private JLabel lblStep2 = null;
32
        private JLabel lblField = null;
33
34
        private JTextField txtNewLayerName = null;
35
        private JComboBox cmbField = null;
36
37
38
        private static final Rectangle lblDescriptionPosition = new Rectangle(4,4,355,75);
39
40
        private static final Rectangle lblStep1Position = new Rectangle(4,90,15,15);
41
        private static final Rectangle lblNewLayerNamePosition = new Rectangle(30,90,355,15);
42
        private static final Rectangle txtNewLayerNamePosition = new Rectangle(30,109,250,18);
43
44
45
        private static final Rectangle lblStep2Position = new Rectangle(4,135,15,12);
46
        private static final Rectangle lblFieldPosition = new Rectangle(30,135,355,30);
47
        private static final Rectangle cmbFieldPosition = new Rectangle(30,169,170,18);
48
49
50
51
52
        private class EventsListener implements CaretListener,ItemListener
53
        {
54
                public void caretUpdate(CaretEvent arg0) {
55
                        updateButtonsState();
56
                }
57
58
                public void itemStateChanged(ItemEvent e) {
59
                        updateButtonsState();
60
                }
61
62
        }
63
64
65
        private void updateButtonsState() {
66
                setBackButtonEnabled(false);
67
                boolean enabled =checkIsOkPanelData();
68
                setNextButtonEnabled(enabled);
69
                setFinishButtonEnabled(enabled);
70
        }
71
72
73
        private EventsListener eventsListener = new EventsListener();
74
75
76
        protected boolean checkIsOkPanelData() {
77
                if (txtNewLayerName.getText().trim().length() < 1) {
78
                        return false;
79
                }
80
                if (((String)cmbField.getSelectedItem()).trim().length() < 1) {
81
                        return false;
82
                }
83
                return true;
84
        }
85
86
87
        public SelectAnnotationLayerNameAndField(JWizardComponents arg0,FLyrAnnotation layer) {
88
                super(arg0);
89
                this.layer =layer;
90
                this.initialize();
91
        }
92
93
        protected void initialize() {
94
                this.setLayout(null);
95
                this.setSize(new Dimension(358,263));
96
                this.addLabels();
97
98
                this.add(getTxtNewLayerName(),null);
99
                this.add(getCmbField(),null);
100
101
                checkIsOkPanelData();
102
        }
103
104
        private JTextField getTxtNewLayerName() {
105
                if (this.txtNewLayerName == null) {
106
                        this.txtNewLayerName = new JTextField();
107
                        this.txtNewLayerName.setBounds(txtNewLayerNamePosition);
108
                        this.txtNewLayerName.setText("NuevaCapa");
109
                        this.txtNewLayerName.addCaretListener(eventsListener);
110
                }
111
                return this.txtNewLayerName;
112
        }
113
114
        public String getNewLayerName() {
115
                return this.getTxtNewLayerName().getText();
116
        }
117
118
119
        private JComboBox getCmbField() {
120
                if (this.cmbField == null) {
121
                        this.cmbField = new JComboBox();
122
                        this.cmbField.setEditable(false);
123
                        this.cmbField.setBounds(cmbFieldPosition);
124
                        this.cmbField.addItemListener(this.eventsListener);
125
                        this.cmbField.addItem("");
126
127
128
                        try {
129
                                SelectableDataSource dataSource = this.layer.getRecordset();
130
131
                                String[] fieldsNames = dataSource.getFieldNames();
132
133
                                for (int i=0; i < fieldsNames.length; i++) {
134
                                        this.cmbField.addItem(fieldsNames[i]);
135
                                }
136
137
                        } catch (DriverException e) {
138
                                // TODO Auto-generated catch block
139
                                e.printStackTrace();
140
                        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
141
                                // TODO Auto-generated catch block
142
                                e.printStackTrace();
143
                        }
144
145
                }
146
                return this.cmbField;
147
        }
148
149
        public String getField() {
150
                return (String)this.getCmbField().getSelectedItem();
151
        }
152
153
154
        protected void addLabels() {
155
                this.lblDescription = new JLabel();
156
                this.lblStep1 = new JLabel();
157
                this.lblNewLayerName = new JLabel();
158
                this.lblStep2 = new JLabel();
159
                this.lblField= new JLabel();
160
161
                this.lblDescription.setText(PluginServices.getText(this,"descripcion_de_crear_capa_de_anotaciones"));
162
                this.lblStep1.setText("1.");
163
                this.lblNewLayerName.setText(PluginServices.getText(this,"introduzca_el_nombre_de_la_nueva_capa_de_anotaciones"));
164
                this.lblStep2.setText("2.");
165
                this.lblField.setText(PluginServices.getText(this,"seleccione_el_campo_de_texto_que_desea_que_se_utilize_para_mostrar_la_nueva_capa_virtual"));
166
167
                this.lblDescription.setBounds(lblDescriptionPosition);
168
                this.lblStep1.setBounds(lblStep1Position);
169
                this.lblNewLayerName.setBounds(lblNewLayerNamePosition);
170
                this.lblStep2.setBounds(lblStep2Position);
171
                this.lblField.setBounds(lblFieldPosition);
172
173
174
                this.add(lblDescription,null);
175
                this.add(lblStep1,null);
176
                this.add(lblNewLayerName,null);
177
                this.add(lblStep2,null);
178
                this.add(lblField,null);
179
180
        }
181
182
183
184
}