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 / TimePanel.java @ 1362

History | View | Annotate | Download (7.07 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.util.ArrayList;
26

    
27
import javax.swing.JButton;
28
import javax.swing.JList;
29
import javax.swing.JPanel;
30

    
31

    
32
/**
33
 * Time Panel
34
 * @author Nacho Brodin (nachobrodin@gmail.com)
35
 */
36
public class TimePanel extends JPanel {
37
        private static final long   serialVersionUID   = 1L;
38
        private JList               lstSelectedTimes   = null;
39
        private JList               lstTimes           = null;
40
        //private JScrollPane         jScrollPane4       = null;
41
        //private JPanel              timesPanel         = null;
42
        private JButton             btnDelTime         = null;
43
        private JButton             btnAddTime         = null;
44
        //private JScrollPane         jScrollPane3       = null;
45
        private WCSParamsPanel      parent             = null;
46
        
47
        public TimePanel() {
48
                init();
49
        }
50
        
51
        public void init() {
52
                
53
        }
54
        
55
        /**
56
         * Sets the parent panel
57
         * @param parent
58
         */
59
        public void setWCSParamsPanel(WCSParamsPanel parent) {
60
                this.parent = parent;
61
        }
62
        
63
        /**
64
         * This method initializes panelTemps
65
         *
66
         * @return javax.swing.JPanel
67
         */
68
        /*private JPanel getTimePanel() {
69
                if (timesPanel == null) {
70
                        timesPanel = new JPanel();
71
                        timesPanel.setLayout(null);
72
                        timesPanel.setBounds(5, 17, 464, 374);
73
                        timesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
74
                                        null, PluginServices.getText(this, "seleccionar_tiempo"),
75
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
76
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
77
                        timesPanel.add(getBtnAddTime(), null);
78
                        timesPanel.add(getBtnDelTime(), null);
79
                        timesPanel.add(getJScrollPane3(), null);
80
                        timesPanel.add(getJScrollPane4(), null);
81
                        timesPanel.setLayout(null);
82
                        timesPanel.setBounds(5, 17, 464, 374);
83
                        timesPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
84
                                        null, PluginServices.getText(this, "seleccionar_tiempo"),
85
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
86
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
87
                        timesPanel.add(getBtnAddTime(), null);
88
                        timesPanel.add(getBtnDelTime(), null);
89
                        timesPanel.add(getJScrollPane3(), null);
90
                        timesPanel.add(getJScrollPane4(), null);
91
                }
92
                return timesPanel;
93
        }*/
94
        
95
        /**
96
         * This method initializes jScrollPane3
97
         *
98
         * @return javax.swing.JScrollPane
99
         */
100
        /*private JScrollPane getJScrollPane3() {
101
                if (jScrollPane3 == null) {
102
                        jScrollPane3 = new JScrollPane();
103
                        jScrollPane3.setViewportView(getLstTimes());
104
                }
105
                return jScrollPane3;
106
        }*/
107
        
108
        /**
109
         * This method initializes jButton2
110
         */
111
        public JButton getBtnAddTime() {
112
                if (btnAddTime == null) {
113
                        btnAddTime = new JButton();
114
                        btnAddTime.setText(">");
115
                        btnAddTime.addActionListener(
116
                                new java.awt.event.ActionListener() {
117
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
118
                                                addTime();
119
                                        }
120
                                });
121
                }
122
                return btnAddTime;
123
        }
124
        
125
        /**
126
         * This method initializes btnDelTemps
127
         *
128
         * @return org.gvsig.gui.beans.swing.JButton
129
         */
130
        public JButton getBtnDelTime() {
131
                if (btnDelTime == null) {
132
                        btnDelTime = new JButton();
133
                        btnDelTime.setText("<");
134
                        btnDelTime.addActionListener(
135
                                new java.awt.event.ActionListener() {
136
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
137
                                                delTime();
138
                                        }
139
                                });
140
                }
141
                return btnDelTime;
142
        }
143
        
144
        /**
145
         * This method initializes jScrollPane4
146
         *
147
         * @return javax.swing.JScrollPane
148
         */
149
        /*private JScrollPane getJScrollPane4() {
150
                if (jScrollPane4 == null) {
151
                        jScrollPane4 = new JScrollPane();
152
                        jScrollPane4.setViewportView(getLstSelectedTimes());
153
                }
154
                return jScrollPane4;
155
        }*/
156
        
157
        /**
158
         * This method initializes lstSelectedTimes
159
         *
160
         * @return javax.swing.JList
161
         */
162
        public JList getLstSelectedTimes() {
163
                if (lstSelectedTimes == null) {
164
                        lstSelectedTimes = new JList();
165
                        lstSelectedTimes.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
166
                                public void valueChanged(javax.swing.event.ListSelectionEvent e) {
167
                                        parent.fireWizardComplete(parent.isCorrectlyConfigured());
168
                                }
169
                        });
170
                }
171
                return lstSelectedTimes;
172
        }
173
        
174
        /**
175
         * Returns the time positions or null if none.
176
         * @return String
177
         */
178
        public String getTime() {
179
                String[] ss = new String[getLstSelectedTimes().getModel().getSize()];
180
                for (int i = 0; i < ss.length; i++) {
181
                        ss[i] = (String) getLstSelectedTimes().getModel().getElementAt(i);
182
                }
183
                String s = null;
184
                if (ss.length > 0){
185
                        s = ss[0];
186
                        for (int i = 1; i < ss.length; i++) {
187
                                s += ","+ ss[i];
188
                        }
189
                }
190
                System.out.println(s);
191
                return s;
192
        }
193
        
194
        /**
195
         * This method initializes lstTemps
196
         *
197
         * @return javax.swing.JList
198
         */
199
        public JList getLstTimes() {
200
                if (lstTimes == null) {
201
                        lstTimes = new JList();
202
                }
203
                return lstTimes;
204
        }
205
        
206
        /**
207
         * Adds the selected items from the time list to the selected times list.
208
         */
209
        @SuppressWarnings("unchecked")
210
        public void addTime() {
211
                ArrayList times = new ArrayList();
212
                for (int i = 0; i < getLstSelectedTimes()
213
                                .getModel().getSize(); i++) {
214
                        times.add(getLstSelectedTimes().getModel().getElementAt(i));
215
                }
216

    
217
                Object[] obj = getLstTimes().getSelectedValues();
218
                for (int i = 0; i < obj.length; i++) {
219
                        if (!times.contains(obj[i])) {
220
                                times.add(obj[i]);
221
                        }
222
                }
223
                getLstSelectedTimes()
224
                                .setListData(times.toArray());
225
                parent.fireWizardComplete(parent.isCorrectlyConfigured());
226
        }
227

    
228
        /**
229
         * Removes the selected items from the selected times list.
230
         */
231
        @SuppressWarnings("unchecked")
232
        public void delTime() {
233
                ArrayList tiempos = new ArrayList();
234
                Object[] obj = getLstSelectedTimes()
235
                                .getSelectedValues();
236
                for (int i = 0; i < getLstSelectedTimes().getModel().getSize(); i++) {
237
                        tiempos.add(getLstSelectedTimes().getModel().getElementAt(i));
238
                }
239

    
240
                for (int j = 0; j < obj.length; j++) {
241
                        if (tiempos.contains(obj[j])) {
242
                                tiempos.remove(obj[j]);
243
                        }
244
                }
245
                obj = new Object[tiempos.size()];
246
                for (int i = 0; i < obj.length; i++) {
247
                        obj[i] = tiempos.get(i);
248
                }
249
                getLstSelectedTimes().setListData(tiempos.toArray());
250
                parent.fireWizardComplete(parent.isCorrectlyConfigured());
251
        }
252
        
253
        /**
254
         * True if the TIME parameter is required, else false.
255
         *
256
         * True si se requiere especificar una posici?n para el tiempo.
257
         * (jo crec que a?? no val per a res, per? per si de cas la tinc)
258
         *
259
         * @return
260
         */
261
        public boolean timeRequired() {
262
                return getLstTimes().getModel().getSize() > 0;
263
        }
264
}
265