Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / extGeocoding / src / org / gvsig / geocoding / gui / newpattern / SimpleRangePanel.java @ 27277

History | View | Annotate | Download (6.39 KB)

1 27277 vsanjaime
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
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., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 Prodevelop S.L. main developer
26
 */
27
28
package org.gvsig.geocoding.gui.newpattern;
29
30
import java.util.List;
31
32
import javax.swing.DefaultComboBoxModel;
33
import javax.swing.JComboBox;
34
import javax.swing.JLabel;
35
import javax.swing.JPanel;
36
37
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor;
38
import org.gvsig.geocoding.extension.GeocoController;
39
40
/**
41
 * Simple Range panel
42
 *
43
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
44
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicente Sanjaime Calvet</a>
45
 */
46
public class SimpleRangePanel extends JPanel {
47
48
        private static final long serialVersionUID = 1L;
49
50
        private JComboBox jComboFromNum;
51
        private JComboBox jComboToNum;
52
        private JLabel jLabFromNum;
53
        private JLabel jLabToNum;
54
55
        /**
56
         * Constructor
57
         */
58
        public SimpleRangePanel(GeocoController control,
59
                        List<FeatureAttributeDescriptor> fields) {
60
                initComponents();
61
                // Fill two combos with the fields of datasource
62
                if (fields != null) {
63
                        fillCombos(fields);
64
                }
65
66
        }
67
68
        /**
69
         * Initialize panel components
70
         */
71
        private void initComponents() {
72
                java.awt.GridBagConstraints gridBagConstraints;
73
74
                jLabFromNum = new javax.swing.JLabel();
75
                jComboFromNum = new javax.swing.JComboBox();
76
                jLabToNum = new javax.swing.JLabel();
77
                jComboToNum = new javax.swing.JComboBox();
78
79
                setMinimumSize(new java.awt.Dimension(500, 40));
80
                setPreferredSize(new java.awt.Dimension(500, 40));
81
                setLayout(new java.awt.GridBagLayout());
82
83
                jLabFromNum.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
84
                jLabFromNum.setText("FromNumber");
85
                jLabFromNum.setFocusable(false);
86
                jLabFromNum.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
87
                jLabFromNum.setMinimumSize(new java.awt.Dimension(70, 14));
88
                jLabFromNum.setPreferredSize(new java.awt.Dimension(70, 14));
89
                gridBagConstraints = new java.awt.GridBagConstraints();
90
                gridBagConstraints.gridx = 0;
91
                gridBagConstraints.gridy = 0;
92
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
93
                gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
94
                add(jLabFromNum, gridBagConstraints);
95
96
                jComboFromNum.setModel(new javax.swing.DefaultComboBoxModel(
97
                                new String[] { "" }));
98
                jComboFromNum.setMinimumSize(new java.awt.Dimension(150, 20));
99
                jComboFromNum.setOpaque(false);
100
                jComboFromNum.setPreferredSize(new java.awt.Dimension(150, 20));
101
                jComboFromNum.addActionListener(new java.awt.event.ActionListener() {
102
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
103
                                evFromNum(evt);
104
                        }
105
                });
106
                gridBagConstraints = new java.awt.GridBagConstraints();
107
                gridBagConstraints.gridx = 1;
108
                gridBagConstraints.gridy = 0;
109
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
110
                gridBagConstraints.weightx = 1.0;
111
                gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 15);
112
                add(jComboFromNum, gridBagConstraints);
113
114
                jLabToNum.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
115
                jLabToNum.setText("ToNumber");
116
                jLabToNum.setFocusable(false);
117
                jLabToNum.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
118
                jLabToNum.setMinimumSize(new java.awt.Dimension(70, 14));
119
                jLabToNum.setPreferredSize(new java.awt.Dimension(70, 14));
120
                gridBagConstraints = new java.awt.GridBagConstraints();
121
                gridBagConstraints.gridx = 2;
122
                gridBagConstraints.gridy = 0;
123
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
124
                add(jLabToNum, gridBagConstraints);
125
126
                jComboToNum.setModel(new javax.swing.DefaultComboBoxModel(
127
                                new String[] { "" }));
128
                jComboToNum.setMinimumSize(new java.awt.Dimension(150, 20));
129
                jComboToNum.setPreferredSize(new java.awt.Dimension(150, 20));
130
                jComboToNum.addActionListener(new java.awt.event.ActionListener() {
131
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
132
                                evToNum(evt);
133
                        }
134
                });
135
                gridBagConstraints = new java.awt.GridBagConstraints();
136
                gridBagConstraints.gridx = 3;
137
                gridBagConstraints.gridy = 0;
138
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
139
                gridBagConstraints.weightx = 1.0;
140
                gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
141
                add(jComboToNum, gridBagConstraints);
142
        }
143
144
        /**
145
         * Change value of FromNum
146
         *
147
         * @param evt
148
         */
149
        private void evFromNum(java.awt.event.ActionEvent evt) {
150
                // TODO add your handling code here:
151
        }
152
153
        /**
154
         * Change Value of ToNum
155
         *
156
         * @param evt
157
         */
158
        private void evToNum(java.awt.event.ActionEvent evt) {
159
                // TODO add your handling code here:
160
        }
161
162
        /**
163
         * Fill panel combos
164
         *
165
         * @param fields
166
         */
167
        private void fillCombos(List<FeatureAttributeDescriptor> fields) {
168
                if (fields != null) {
169
                        DefaultComboBoxModel model = new DefaultComboBoxModel();
170
                        for (FeatureAttributeDescriptor field : fields) {
171
                                ComboDesc desc = new ComboDesc(field);
172
                                model.addElement(desc);
173
                        }
174
                        jComboFromNum.setModel(model);
175
                        DefaultComboBoxModel model2 = new DefaultComboBoxModel();
176
                        for (FeatureAttributeDescriptor field2 : fields) {
177
                                ComboDesc desc2 = new ComboDesc(field2);
178
                                model2.addElement(desc2);
179
                        }
180
                        jComboToNum.setModel(model2);
181
                }
182
        }
183
184
        /**
185
         * Get description FromMun Combo
186
         *
187
         * @return
188
         */
189
        public FeatureAttributeDescriptor getDescriptorFronMun() {
190
191
                return (FeatureAttributeDescriptor) jComboFromNum.getSelectedItem();
192
        }
193
194
        /**
195
         * Get description ToMun Combo
196
         *
197
         * @return
198
         */
199
        public FeatureAttributeDescriptor getDescriptorToMun() {
200
201
                return (FeatureAttributeDescriptor) jComboToNum.getSelectedItem();
202
        }
203
204
        /**
205
         *
206
         * @param desc
207
         */
208
        public void setComboValues(List<FeatureAttributeDescriptor> desc) {
209
                fillCombos(desc);
210
                this.validate();
211
        }
212
213
}