Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / org.gvsig.annotation / src / main / java / org / gvsig / annotation / create / AnnotationFieldSelectPanel.java @ 31277

History | View | Annotate | Download (8.02 KB)

1

    
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 *  Generalitat Valenciana
23
 *   Conselleria d'Infraestructures i Transport
24
 *   Av. Blasco Ib??ez, 50
25
 *   46010 VALENCIA
26
 *   SPAIN
27
 *
28
 *      +34 963862235
29
 *   gvsig@gva.es
30
 *      www.gvsig.gva.es
31
 *
32
 *    or
33
 *
34
 *   IVER T.I. S.A
35
 *   Salamanca 50
36
 *   46005 Valencia
37
 *   Spain
38
 *
39
 *   +34 963163400
40
 *   dac@iver.es
41
 */
42

    
43
package org.gvsig.annotation.create;
44

    
45
import java.awt.Dimension;
46
import java.awt.Rectangle;
47
import java.awt.event.ItemEvent;
48
import java.awt.event.ItemListener;
49

    
50
import javax.swing.JComboBox;
51
import javax.swing.JLabel;
52
import javax.swing.event.CaretEvent;
53
import javax.swing.event.CaretListener;
54

    
55
import jwizardcomponent.JWizardComponents;
56
import jwizardcomponent.JWizardPanel;
57

    
58
import org.gvsig.andami.PluginServices;
59
import org.gvsig.andami.messages.NotificationManager;
60
import org.gvsig.annotation.AnnotationLocator;
61
import org.gvsig.annotation.AnnotationPreferences;
62
import org.gvsig.fmap.dal.exception.DataException;
63
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
64
import org.gvsig.fmap.dal.feature.FeatureSet;
65
import org.gvsig.fmap.dal.feature.FeatureStore;
66
import org.gvsig.fmap.dal.feature.FeatureType;
67
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
68

    
69
/**
70
 * Panel to select the text field from one original shape file .
71
 *
72
 * @author Vicente Caballero Navarro
73
 */
74
public class AnnotationFieldSelectPanel extends JWizardPanel {
75
    
76
        /**
77
         * Generated serial version ID 
78
         */
79
        private static final long serialVersionUID = -5863581768438973852L;
80
        
81
        private static final Rectangle lblDescriptionPosition = new Rectangle(4, 14,355, 100);
82
    private static final Rectangle lblDuplicatePosition = new Rectangle(30, 115, 355, 30);
83
    private static final Rectangle cmbDuplicatePosition = new Rectangle(30,150, 170, 18);
84
    private static final Rectangle lblStep2Position = new Rectangle(4, 170, 15, 12);
85
    private static final Rectangle lblFieldPosition = new Rectangle(30, 170, 355, 30);
86
    private static final Rectangle cmbFieldPosition = new Rectangle(30, 204,170, 18);
87
    
88
    private FLyrVect layer;
89
    
90
    private JLabel lblDescription = null;
91
    private JLabel lblStep2 = null;
92
    private JLabel lblField = null;
93
    private JLabel lblDuplicate = null;
94
    private JComboBox cmbField = null;
95
    private JComboBox cmbDuplicate;
96
   
97
    private EventsListener eventsListener = new EventsListener();
98

    
99
        private AnnotationPreferences preferences;
100

    
101
        public AnnotationFieldSelectPanel(JWizardComponents arg0, FLyrVect lyr) {
102
        super(arg0);
103
        layer = lyr;
104
        preferences = AnnotationLocator.getAnnotationPreferences();
105
        this.initialize();
106
    }
107

    
108
    private void updateButtonsState() {
109
        try {
110
            if (getWizardComponents().getCurrentIndex() == 0) {
111
                setBackButtonEnabled(false);
112

    
113
                boolean enabled = checkIsOkPanelData();
114
                setNextButtonEnabled(enabled);
115
                setFinishButtonEnabled(enabled);
116
            }
117
        } catch (Exception e) {
118
            NotificationManager.addError(e);
119
        }
120
    }
121
   
122
    protected boolean checkIsOkPanelData() {
123
        if (((String) cmbField.getSelectedItem()).trim().length() < 1) {
124
            return false;
125
        }
126
        return true;
127
    }
128

    
129
    protected void initialize() {
130
        this.setLayout(null);
131
        this.setSize(new Dimension(358, 263));
132
        this.addLabels();
133
        this.add(getCmbField(), null);
134
        this.add(getCmbDuplicate(), null);
135
        this.cmbField.setSelectedItem(0);
136
        checkIsOkPanelData();
137
        if (!cmbField.equals(AnnotationConfigureLabelsPanel.TEXT_FOR_NO_SELECTED_VALUE))
138
                this.setFinishButtonEnabled(false);
139
    }
140

    
141
    private JComboBox getCmbField() {
142
        if (this.cmbField == null) {
143
            this.cmbField = new JComboBox();
144
            this.cmbField.setEditable(false);
145
            this.cmbField.setBounds(cmbFieldPosition);
146
            this.cmbField.addItemListener(this.eventsListener);
147
            this.cmbField. addItem(AnnotationConfigureLabelsPanel.TEXT_FOR_NO_SELECTED_VALUE);
148
            
149
            //Get the layer Fields Name to fill the COMBOBOX
150
            FeatureStore store = (FeatureStore) this.layer.getDataStore();
151
            FeatureSet features;
152
                        try {
153
                                features = store.getFeatureSet();
154
                                FeatureType type = features.getDefaultFeatureType();
155
                                 FeatureAttributeDescriptor[] fieldsNames = type.getAttributeDescriptors();
156
                    for (int i = 0; i < fieldsNames.length; i++) {
157
                            if (fieldsNames[i].getName().compareTo("GEOMETRY")!=0){
158
                                this.cmbField.addItem(fieldsNames[i].getName());
159
                            }
160
                    }
161
                   
162
                    //STARTING UP PROPERTIES 
163
                    if(this.cmbField.getSelectedIndex()!=0){
164
                            String fieldSelect;
165
                                        if (preferences.getMappedNumColumnText()>-1)
166
                                    fieldSelect = fieldsNames[preferences.getMappedNumColumnText()].getName();
167
                                        else 
168
                                                fieldSelect = fieldsNames[0].getName();
169
                            this.cmbField.setSelectedItem(fieldSelect);
170
                            setNextButtonEnabled(true);
171
                    }
172
                    else{
173
                            setNextButtonEnabled(false);
174
                    }
175
                    features.dispose();
176
                        } catch (DataException e) {
177
                                // ERROR NOTATIFICATION MANAGER
178
                                NotificationManager.addError(e);
179
                        }    
180
        }
181
        return this.cmbField;
182
    }
183

    
184
   private JComboBox getCmbDuplicate() {
185
        if (cmbDuplicate == null) {
186
            cmbDuplicate = new JComboBox();
187
            cmbDuplicate.setBounds(cmbDuplicatePosition);
188
            cmbDuplicate.addItem(PluginServices.getText(this, "duplicate.none"));
189
            cmbDuplicate.addItem(PluginServices.getText(this, "centered"));
190
            cmbDuplicate.setSelectedItem(PluginServices.getText(this, "centered"));
191
        }
192
        return cmbDuplicate;
193
    }
194

    
195
   public String getField() {
196
           preferences.setMappedNumColumnText(this.getCmbField().getItemCount());
197
        return (String) this.getCmbField().getSelectedItem();
198
    }
199

    
200
    public String getDuplicate() {
201
        return (String) this.getCmbDuplicate().getSelectedItem();
202
    }
203

    
204
    protected void addLabels() {
205
        this.lblDescription = new JLabel();
206

    
207
        this.lblStep2 = new JLabel();
208
        this.lblField = new JLabel();
209
        this.lblDuplicate = new JLabel();
210

    
211
        this.lblDuplicate.setText(PluginServices.getText(this, "duplicate"));
212
        this.lblDuplicate.setBounds(lblDuplicatePosition);
213
        this.lblDescription.setText(PluginServices.getText(this, "descripcion_de_crear_capa_de_anotaciones_nueva"));
214

    
215
        this.lblField.setText(PluginServices.getText(this,"seleccione_el_campo_de_texto_que_desea_que_se_utilize_para_mostrar_la_nueva_capa"));
216

    
217
        this.lblDescription.setBounds(lblDescriptionPosition);
218
        this.lblStep2.setBounds(lblStep2Position);
219
        this.lblField.setBounds(lblFieldPosition);
220

    
221
        this.add(lblDescription, 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
}