Statistics
| Revision:

svn-gvsig-desktop / tags / Anotaciones_Build_1 / extensions / extAnnotations / src / com / iver / cit / gvsig / project / documents / gui / Annotation_FieldSelect.java @ 11599

History | View | Annotate | Download (7.01 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
/**
23
 * Panel to select the text field.
24
 *
25
 * @author Vicente Caballero Navarro
26
 */
27
public class Annotation_FieldSelect extends JWizardPanel {
28
    private static final Rectangle lblDescriptionPosition = new Rectangle(4, 4,
29
            355, 75);
30
//    private static final Rectangle lblStep1Position = new Rectangle(4, 90, 15,
31
//            15);
32

    
33
    //        private static final Rectangle lblNewLayerNamePosition = new Rectangle(30,90,355,15);
34
//    private static final Rectangle lblInPixelsPosition = new Rectangle(30,
35
//                    80, 355, 30);
36
//    private static final Rectangle cmbInPixelsPosition = new Rectangle(30,
37
//            110, 170, 18);
38
    private static final Rectangle lblStep2Position = new Rectangle(4, 135, 15,
39
            12);
40
    private static final Rectangle lblFieldPosition = new Rectangle(30, 135,
41
            355, 30);
42
    private static final Rectangle cmbFieldPosition = new Rectangle(30, 169,
43
            170, 18);
44
    private Annotation_Layer layer;
45
    private JLabel lblDescription = null;
46

    
47
    //        private JLabel lblStep1 = null;
48
    //        private JLabel lblNewLayerName = null;
49
    private JLabel lblStep2 = null;
50
    private JLabel lblField = null;
51

    
52
    //        private JTextField txtNewLayerName = null;
53
    private JComboBox cmbField = null;
54
    private EventsListener eventsListener = new EventsListener();
55
        private JComboBox cmbInPixels;
56
        private JLabel lblInPixels = null;
57

    
58
    public Annotation_FieldSelect(JWizardComponents arg0,
59
        Annotation_Layer layer) {
60
        super(arg0);
61
        this.layer = layer;
62
        this.initialize();
63
    }
64

    
65
    private void updateButtonsState() {
66
            try {
67
                        if (getWizardComponents().getCurrentIndex()==0){
68
                        setBackButtonEnabled(false);
69

    
70
                        boolean enabled = checkIsOkPanelData();
71
                        setNextButtonEnabled(enabled);
72
                        setFinishButtonEnabled(enabled);
73
                        }
74
                } catch (Exception e) {
75
                        // TODO Auto-generated catch block
76
                        e.printStackTrace();
77
                }
78
    }
79

    
80
    protected boolean checkIsOkPanelData() {
81
        //                if (txtNewLayerName.getText().trim().length() < 1) {
82
        //                        return false;
83
        //                }
84
        if (((String) cmbField.getSelectedItem()).trim().length() < 1) {
85
            return false;
86
        }
87

    
88
        return true;
89
    }
90

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

    
96
        //                this.add(getTxtNewLayerName(),null);
97
        this.add(getCmbField(), null);
98
//        this.add(getCmbInPixels(), null);
99
        checkIsOkPanelData();
100
    }
101

    
102
    //        private JTextField getTxtNewLayerName() {
103
    //                if (this.txtNewLayerName == null) {
104
    //                        this.txtNewLayerName = new JTextField();
105
    //                        this.txtNewLayerName.setBounds(txtNewLayerNamePosition);
106
    //                        this.txtNewLayerName.setText("NuevaCapa");
107
    //                        this.txtNewLayerName.addCaretListener(eventsListener);
108
    //                }
109
    //                return this.txtNewLayerName;
110
    //        }
111
    //        public String getNewLayerName() {
112
    //                return this.getTxtNewLayerName().getText();
113
    //        }
114
    private JComboBox getCmbField() {
115
        if (this.cmbField == null) {
116
            this.cmbField = new JComboBox();
117
            this.cmbField.setEditable(false);
118
            this.cmbField.setBounds(cmbFieldPosition);
119
            this.cmbField.addItemListener(this.eventsListener);
120
            this.cmbField.addItem("");
121

    
122
            try {
123
                SelectableDataSource dataSource = this.layer.getRecordset();
124

    
125
                String[] fieldsNames = dataSource.getFieldNames();
126

    
127
                for (int i = 0; i < fieldsNames.length; i++) {
128
                    this.cmbField.addItem(fieldsNames[i]);
129
                }
130
                if (layer.getAnnotatonMapping()!=null){
131
                        String fieldSelect=dataSource.getFieldName(layer.getAnnotatonMapping().getColumnText());
132
                        this.cmbField.setSelectedItem(fieldSelect);
133
                        setNextButtonEnabled(true);
134
                }
135
            } catch (DriverException e) {
136
                e.printStackTrace();
137
            } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
138
                e.printStackTrace();
139
            }
140

    
141
        }
142

    
143
        return this.cmbField;
144
    }
145
    private JComboBox getCmbInPixels() {
146
            if (cmbInPixels==null){
147
            cmbInPixels=new JComboBox();
148
        cmbInPixels.addItem(PluginServices.getText(this,"pixels"));
149
        cmbInPixels.addItem(PluginServices.getText(this,"meters"));
150
//        cmbInPixels.setBounds(cmbInPixelsPosition);
151
//        cmbInPixels.addActionListener(new ActionListener(){
152
//                        public void actionPerformed(ActionEvent e) {
153
//                                if (e.getSource().equals(PluginServices.getText(this,"pixels"))){
154
//
155
//                                }
156
//
157
//                        }
158
//
159
//        });
160
            }
161
        return cmbInPixels;
162
        }
163
    public String getField() {
164
        return (String) this.getCmbField().getSelectedItem();
165
    }
166

    
167
    protected void addLabels() {
168
        this.lblDescription = new JLabel();
169

    
170
        //                this.lblStep1 = new JLabel();
171
        //                this.lblNewLayerName = new JLabel();
172
        this.lblStep2 = new JLabel();
173
        this.lblField = new JLabel();
174
        this.lblInPixels=new JLabel();
175

    
176
        this.lblInPixels.setText(PluginServices.getText(this,
177
                        "units_of_annotations"));
178
//        this.lblInPixels.setBounds(lblInPixelsPosition);
179
        this.lblDescription.setText(PluginServices.getText(this,
180
                "descripcion_de_crear_capa_de_anotaciones"));
181

    
182
        //                this.lblStep1.setText("1.");
183
        //                this.lblNewLayerName.setText(PluginServices.getText(this,"introduzca_el_nombre_de_la_nueva_capa_de_anotaciones"));
184
        //                this.lblStep2.setText("2.");
185
        this.lblField.setText(PluginServices.getText(this,
186
                "seleccione_el_campo_de_texto_que_desea_que_se_utilize_para_mostrar_la_nueva_capa_virtual"));
187

    
188
        this.lblDescription.setBounds(lblDescriptionPosition);
189

    
190
        //                this.lblStep1.setBounds(lblStep1Position);
191
        //                this.lblNewLayerName.setBounds(lblNewLayerNamePosition);
192
        this.lblStep2.setBounds(lblStep2Position);
193
        this.lblField.setBounds(lblFieldPosition);
194

    
195

    
196
        this.add(lblDescription, null);
197

    
198
        //                this.add(lblStep1,null);
199
        //                this.add(lblNewLayerName,null);
200
        this.add(lblStep2, null);
201
        this.add(lblField, null);
202
        this.add(lblInPixels,null);
203
    }
204

    
205
    private class EventsListener implements CaretListener, ItemListener {
206
        public void caretUpdate(CaretEvent arg0) {
207
            updateButtonsState();
208
        }
209

    
210
        public void itemStateChanged(ItemEvent e) {
211
            updateButtonsState();
212
        }
213
    }
214
}