Statistics
| Revision:

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

History | View | Annotate | Download (4.73 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

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

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

    
17
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
18
import com.iver.andami.PluginServices;
19
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation;
20
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource;
21

    
22
public class SelectAnnotationLayerNameAndField extends JWizardPanel {
23
        private FLyrAnnotation layer;
24

    
25
        private JLabel lblDescription = null;
26
        private JLabel lblStep1 = null;
27
        private JLabel lblNewLayerName = null;
28
        private JLabel lblStep2 = null;
29
        private JLabel lblField = null;
30

    
31
        private JTextField txtNewLayerName = null;
32
        private JComboBox cmbField = null;
33

    
34

    
35
        private static final Rectangle lblDescriptionPosition = new Rectangle(4,4,355,75);
36

    
37
        private static final Rectangle lblStep1Position = new Rectangle(4,90,15,15);
38
        private static final Rectangle lblNewLayerNamePosition = new Rectangle(30,90,355,15);
39
        private static final Rectangle txtNewLayerNamePosition = new Rectangle(30,109,250,18);
40

    
41

    
42
        private static final Rectangle lblStep2Position = new Rectangle(4,135,15,12);
43
        private static final Rectangle lblFieldPosition = new Rectangle(30,135,355,30);
44
        private static final Rectangle cmbFieldPosition = new Rectangle(30,169,170,18);
45

    
46

    
47

    
48

    
49
        private class EventsListener implements CaretListener,ItemListener
50
        {
51
                public void caretUpdate(CaretEvent arg0) {
52
                        updateButtonsState();
53
                }
54

    
55
                public void itemStateChanged(ItemEvent e) {
56
                        updateButtonsState();
57
                }
58

    
59
        }
60

    
61

    
62
        private void updateButtonsState() {
63
                setBackButtonEnabled(false);
64
                boolean enabled =checkIsOkPanelData();
65
                setNextButtonEnabled(enabled);
66
                setFinishButtonEnabled(enabled);
67
        }
68

    
69

    
70
        private EventsListener eventsListener = new EventsListener();
71

    
72

    
73
        protected boolean checkIsOkPanelData() {
74
                if (txtNewLayerName.getText().trim().length() < 1) {
75
                        return false;
76
                }
77
                if (((String)cmbField.getSelectedItem()).trim().length() < 1) {
78
                        return false;
79
                }
80
                return true;
81
        }
82

    
83

    
84
        public SelectAnnotationLayerNameAndField(JWizardComponents arg0,FLyrAnnotation layer) {
85
                super(arg0);
86
                this.layer =layer;
87
                this.initialize();
88
        }
89

    
90
        protected void initialize() {
91
                this.setLayout(null);
92
                this.setSize(new Dimension(358,263));
93
                this.addLabels();
94

    
95
                this.add(getTxtNewLayerName(),null);
96
                this.add(getCmbField(),null);
97

    
98
                checkIsOkPanelData();
99
        }
100

    
101
        private JTextField getTxtNewLayerName() {
102
                if (this.txtNewLayerName == null) {
103
                        this.txtNewLayerName = new JTextField();
104
                        this.txtNewLayerName.setBounds(txtNewLayerNamePosition);
105
                        this.txtNewLayerName.setText("NuevaCapa");
106
                        this.txtNewLayerName.addCaretListener(eventsListener);
107
                }
108
                return this.txtNewLayerName;
109
        }
110

    
111
        public String getNewLayerName() {
112
                return this.getTxtNewLayerName().getText();
113
        }
114

    
115

    
116
        private JComboBox getCmbField() {
117
                if (this.cmbField == null) {
118
                        this.cmbField = new JComboBox();
119
                        this.cmbField.setEditable(false);
120
                        this.cmbField.setBounds(cmbFieldPosition);
121
                        this.cmbField.addItemListener(this.eventsListener);
122
                        this.cmbField.addItem("");
123

    
124

    
125
                        try {
126
                                SelectableDataSource dataSource = this.layer.getRecordset();
127

    
128
                                String[] fieldsNames = dataSource.getFieldNames();
129

    
130
                                for (int i=0; i < fieldsNames.length; i++) {
131
                                        this.cmbField.addItem(fieldsNames[i]);
132
                                }
133

    
134
                        } catch (ReadDriverException e) {
135
                                // TODO Auto-generated catch block
136
                                e.printStackTrace();
137
                        }
138

    
139
                }
140
                return this.cmbField;
141
        }
142

    
143
        public String getField() {
144
                return (String)this.getCmbField().getSelectedItem();
145
        }
146

    
147

    
148
        protected void addLabels() {
149
                this.lblDescription = new JLabel();
150
                this.lblStep1 = new JLabel();
151
                this.lblNewLayerName = new JLabel();
152
                this.lblStep2 = new JLabel();
153
                this.lblField= new JLabel();
154

    
155
                this.lblDescription.setText(PluginServices.getText(this,"descripcion_de_crear_capa_de_anotaciones"));
156
                this.lblStep1.setText("1.");
157
                this.lblNewLayerName.setText(PluginServices.getText(this,"introduzca_el_nombre_de_la_nueva_capa_de_anotaciones"));
158
                this.lblStep2.setText("2.");
159
                this.lblField.setText(PluginServices.getText(this,"seleccione_el_campo_de_texto_que_desea_que_se_utilize_para_mostrar_la_nueva_capa_virtual"));
160

    
161
                this.lblDescription.setBounds(lblDescriptionPosition);
162
                this.lblStep1.setBounds(lblStep1Position);
163
                this.lblNewLayerName.setBounds(lblNewLayerNamePosition);
164
                this.lblStep2.setBounds(lblStep2Position);
165
                this.lblField.setBounds(lblFieldPosition);
166

    
167

    
168
                this.add(lblDescription,null);
169
                this.add(lblStep1,null);
170
                this.add(lblNewLayerName,null);
171
                this.add(lblStep2,null);
172
                this.add(lblField,null);
173

    
174
        }
175

    
176

    
177

    
178
}