Statistics
| Revision:

gvsig-raster / org.gvsig.raster.wcs / trunk / org.gvsig.raster.wcs / org.gvsig.raster.wcs.app / org.gvsig.raster.wcs.app.wcsclient / src / main / java / org / gvsig / raster / wcs / app / wcsclient / gui / panel / ParameterPanel.java @ 418

History | View | Annotate | Download (5.86 KB)

1
/* 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
package org.gvsig.raster.wcs.app.wcsclient.gui.panel;
24

    
25
import java.awt.GridBagConstraints;
26
import java.awt.GridBagLayout;
27

    
28
import javax.swing.JComboBox;
29
import javax.swing.JPanel;
30
import javax.swing.JScrollPane;
31

    
32
import org.gvsig.andami.PluginServices;
33
import org.gvsig.fmap.dal.coverage.datastruct.FMapWCSParameter;
34
import org.gvsig.gui.beans.controls.dnd.JDnDList;
35
import org.gvsig.gui.beans.controls.dnd.JDnDListModel;
36

    
37

    
38
/**
39
 * Parameter Panel
40
 * @author Nacho Brodin (nachobrodin@gmail.com)
41
 */
42
public class ParameterPanel extends JPanel {
43
        private static final long serialVersionUID = 1L;
44
        private JComboBox cmbParam = null;
45
        private JDnDList lstParamValues = null;
46
        private JScrollPane jScrollPane5 = null;
47
        private WCSParamsPanel parent = null;
48
        
49
        public ParameterPanel() {
50
                init();
51
        }
52
        
53
        /**
54
         * Sets the parent panel
55
         * @param parent
56
         */
57
        public void setWCSParamsPanel(WCSParamsPanel parent) {
58
                this.parent = parent;
59
        }
60
        
61
        public void init() {
62
                setLayout(new GridBagLayout());
63
                setBorder(javax.swing.BorderFactory.createTitledBorder(
64
                                null, PluginServices.getText(this, "seleccionar_parametros"),
65
                                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
66
                                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
67
                
68
                GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
69
                
70
                gridBagConstraints1.fill = GridBagConstraints.HORIZONTAL;
71
                gridBagConstraints1.anchor = GridBagConstraints.NORTH;
72
                gridBagConstraints1.weightx = 1.0;
73
                gridBagConstraints1.insets = new java.awt.Insets(2, 2, 2, 2);
74
                gridBagConstraints1.gridx = 0;
75
                add(getCmbParam(), gridBagConstraints1);
76
                
77
                gridBagConstraints1.fill = GridBagConstraints.BOTH;
78
                gridBagConstraints1.anchor = GridBagConstraints.CENTER;
79
                gridBagConstraints1.weightx = 1.0;
80
                gridBagConstraints1.weighty = 1.0;
81
                gridBagConstraints1.insets = new java.awt.Insets(2, 2, 2, 2);
82
                gridBagConstraints1.gridx = 1;
83
                add(getJScrollPane5(), gridBagConstraints1);
84
        }
85
        
86
        /**
87
         * This method initializes cmbParam
88
         *
89
         * @return javax.swing.JComboBox
90
         */
91
        public JComboBox getCmbParam() {
92
                if (cmbParam == null) {
93
                        cmbParam = new JComboBox();
94
                        cmbParam.setEditable(false);
95
                        cmbParam.addItemListener(new java.awt.event.ItemListener() {
96
                                public void itemStateChanged(java.awt.event.ItemEvent e) {
97
                                        FMapWCSParameter p = (FMapWCSParameter) cmbParam.getSelectedItem();
98
                                        if (p!=null) {
99
                                                getSingleParamValuesList().setListData(p.getValueList().toArray());
100
                                        }
101
                                        parent.fireWizardComplete(parent.isCorrectlyConfigured());
102
                                }
103
                        });
104
                }
105
                return cmbParam;
106
        }
107
        
108
        /**
109
         * This method initializes jScrollPane5
110
         *
111
         * @return javax.swing.JScrollPane
112
         */
113
        public JScrollPane getJScrollPane5() {
114
                if (jScrollPane5 == null) {
115
                        jScrollPane5 = new JScrollPane();
116
                        jScrollPane5.setViewportView(getSingleParamValuesList());
117
                }
118
                return jScrollPane5;
119
        }
120
        
121
        /**
122
         * This method initializes lstParamValues
123
         *
124
         * @return javax.swing.JList
125
         */
126
        public JDnDList getSingleParamValuesList() {
127
                if (lstParamValues == null) {
128
                        lstParamValues = new JDnDList();
129
                        lstParamValues.setModel(new JDnDListModel());
130
                        lstParamValues.setSelectionMode(javax.swing.ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
131
                        lstParamValues.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
132
                                public void valueChanged(javax.swing.event.ListSelectionEvent e) {
133
                                        parent.fireWizardComplete(parent.isCorrectlyConfigured());
134
                                }
135
                        });
136
                }
137
                return lstParamValues;
138
        }
139
        
140
        /**
141
         * Returns the parameter's name's index within the cmbBox.
142
         *
143
         * Devuelve la posicion que ocupa el nombre dle par?metro en el comboBox
144
         * de par?metros
145
         *
146
         * @param nParam
147
         * @return The index if it exists, -1 if it not exists.
148
         */
149
        public int getParamIndex(String nParam) {
150
                for (int i = 0; i < getCmbParam().getModel().getSize(); i++) {
151
                        if (nParam.equals(((FMapWCSParameter)getCmbParam().getItemAt(i)).getName())) {
152
                                return i;
153
                        }
154
                }
155
                return -1;
156
        }
157
        
158
        /**
159
         * Returns the position for the parameter's value within the parameter
160
         * values list.
161
         *
162
         * Devuelve la posicion que ocupa el valor para parametro
163
         * en la lista de valores para par?metro
164
         *
165
         * @param valor
166
         * @return The index if it exists, -1 if it not exists.
167
         */
168
        public int getValueIndex(String valor) {
169
                for (int i = 0; i < getSingleParamValuesList().getModel().getSize(); i++){
170
                        if (valor.equals(getSingleParamValuesList().getModel().getElementAt(i))) {
171
                                return i;
172
                        }
173
                }
174
                return -1;
175
        }
176
        
177
        /**
178
         * Extracts the parameter query string.
179
         * @return
180
         */
181
        public String getParameterString() {
182
                FMapWCSParameter p = (FMapWCSParameter) getCmbParam().getSelectedItem();
183
                if (p == null) {
184
                        return null;
185
                }
186
                // TODO missing intervals!!!
187
                if (p.getType() == FMapWCSParameter.VALUE_LIST) {
188
                        Object[] v = getSingleParamValuesList().getSelectedValues();
189
                        /*if(v.length == 1)
190
                                return p.getName() + "=" + (String) v[0];*/
191
                        if (p != null && v.length > 0) {
192
                                String s = p.getName() + "=" + (String) v[0];
193
                                for (int i = 1; i < v.length; i++) {
194
                                        s += "," + v[i];
195
                                }
196
                                return s;
197
                        }
198
                }
199
                return null;
200
        } 
201
}
202