gvsig-raster / org.gvsig.raster.wms / trunk / org.gvsig.raster.wms / org.gvsig.raster.wms.app.wmsclient / src / main / java / org / gvsig / raster / wms / app / wmsclient / gui / panel / DimensionPanel.java @ 2484
History | View | Annotate | Download (20.6 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.wms.app.wmsclient.gui.panel; |
24 |
|
25 |
import java.util.Hashtable; |
26 |
import java.util.Iterator; |
27 |
import java.util.Vector; |
28 |
|
29 |
import javax.swing.ButtonGroup; |
30 |
import javax.swing.JButton; |
31 |
import javax.swing.JEditorPane; |
32 |
import javax.swing.JLabel; |
33 |
import javax.swing.JList; |
34 |
import javax.swing.JPanel; |
35 |
import javax.swing.JRadioButton; |
36 |
import javax.swing.JScrollPane; |
37 |
import javax.swing.JTextField; |
38 |
|
39 |
import org.gvsig.andami.PluginServices; |
40 |
import org.gvsig.gui.beans.DefaultBean; |
41 |
import org.gvsig.gui.beans.Pager; |
42 |
import org.gvsig.gui.beans.listeners.BeanListener; |
43 |
import org.gvsig.raster.wms.io.time.RemoteTimeDimension; |
44 |
|
45 |
|
46 |
/**
|
47 |
* This is the Dimensions tab of the WMS wizard.
|
48 |
*
|
49 |
* @author jaume
|
50 |
*
|
51 |
*/
|
52 |
public class DimensionPanel extends DefaultBean { |
53 |
private static final long serialVersionUID = 1L; |
54 |
static private final int SINGLE_VALUE = 0; |
55 |
static private final int MULTIPLE_VALUE = 1; |
56 |
static private final int INTERVAL = 2; |
57 |
private final String bgColor0 = "\"#FEEDD6\""; // light salmon |
58 |
private final String bgColor2 = "\"#F2FEFF\""; // light blue |
59 |
private Pager pager = null; |
60 |
private JPanel valueEditionPanel = null; |
61 |
private JRadioButton rdBtnSingle = null; |
62 |
private JRadioButton rdBtnMultiple = null; |
63 |
private JRadioButton rdBtnInterval = null; |
64 |
private JButton btnAdd = null; |
65 |
private JTextField txt = null; |
66 |
private JScrollPane scrlDimension = null; |
67 |
private JList lstDimensions = null; |
68 |
private JPanel editionPanel = null; |
69 |
private JScrollPane scrDimInfo = null; |
70 |
private JEditorPane infoEditor = null; |
71 |
private JPanel valuePanel = null; |
72 |
private JButton btnSet = null; |
73 |
private JButton btnClear = null; |
74 |
private JLabel lblValue = null; |
75 |
private JLabel lblValueText = null; |
76 |
private int currentSelectedValue; |
77 |
private int mode; |
78 |
private boolean incomplete = true; |
79 |
private boolean userEdits = false; |
80 |
private RemoteTimeDimension[] dim; |
81 |
private RemoteTimeDimension currentDimension;
|
82 |
private Hashtable<String, Value> settings = new Hashtable<String, Value>(); |
83 |
|
84 |
/**
|
85 |
* Will contain the settings for a getMap query which are just text. Since
|
86 |
* only one Dimension definition expression is allowed the key for this hash
|
87 |
* map is the dimension name.
|
88 |
*
|
89 |
* <b>key:</b> dimension name as string <br>
|
90 |
* <b>value:</b> dimension value as string
|
91 |
*/
|
92 |
private Vector<Integer> indices = new Vector<Integer>(); |
93 |
|
94 |
/**
|
95 |
* This is the default constructor
|
96 |
*/
|
97 |
public DimensionPanel() {
|
98 |
super();
|
99 |
initialize(); |
100 |
} |
101 |
|
102 |
/**
|
103 |
* This method initializes this
|
104 |
*
|
105 |
* @return void
|
106 |
*/
|
107 |
private void initialize() { |
108 |
this.setLayout(null); |
109 |
this.setSize(475, 427); |
110 |
this.setBorder(javax.swing.BorderFactory.createTitledBorder(null, |
111 |
PluginServices.getText(this, "dimension"), |
112 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
113 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
114 |
this.add(getValuePanel(), null); |
115 |
this.add(getEditionPanel(), null); |
116 |
} |
117 |
|
118 |
/**
|
119 |
* This method initializes jPanel
|
120 |
*
|
121 |
* @return javax.swing.JPanel
|
122 |
*/
|
123 |
private Pager getJPanel() {
|
124 |
if (pager == null) { |
125 |
pager = new Pager(Pager.HORIZONTAL);
|
126 |
pager.setBounds(5, 20, 240, 50); |
127 |
pager.addListener(new BeanListener() {
|
128 |
public void beanValueChanged(Object value) { |
129 |
currentSelectedValue = ((Integer) value).intValue();
|
130 |
lblValueText.setText(currentDimension |
131 |
.valueAt(currentSelectedValue)); |
132 |
} |
133 |
}); |
134 |
} |
135 |
return pager;
|
136 |
} |
137 |
|
138 |
/**
|
139 |
* This method initializes jPanel1
|
140 |
*
|
141 |
* @return javax.swing.JPanel
|
142 |
*/
|
143 |
private JPanel getJPanel1() { |
144 |
if (valueEditionPanel == null) { |
145 |
ButtonGroup group = new ButtonGroup(); |
146 |
lblValueText = new JLabel(); |
147 |
lblValueText.setBounds(54, 4, 190, 20); |
148 |
lblValueText.setText("");
|
149 |
lblValue = new JLabel(); |
150 |
lblValue.setBounds(7, 4, 45, 20); |
151 |
lblValue.setText(PluginServices.getText(this, "value") + ":"); |
152 |
lblValue.setFont(new java.awt.Font("MS Sans Serif", |
153 |
java.awt.Font.BOLD, 11));
|
154 |
valueEditionPanel = new JPanel(); |
155 |
valueEditionPanel.setLayout(null);
|
156 |
valueEditionPanel.setBounds(228, 12, 245, 214); |
157 |
valueEditionPanel.add(getRdBtnSingleValue(), null);
|
158 |
valueEditionPanel.add(getRdBtnMultipleValue(), null);
|
159 |
valueEditionPanel.add(getRdBtnInterval(), null);
|
160 |
valueEditionPanel.add(getBtnAdd(), null);
|
161 |
valueEditionPanel.add(getTxt(), null);
|
162 |
valueEditionPanel.add(getBtnSet(), null);
|
163 |
valueEditionPanel.add(getBtnClear(), null);
|
164 |
valueEditionPanel.add(getJPanel(), null);
|
165 |
valueEditionPanel.add(lblValue, null);
|
166 |
valueEditionPanel.add(lblValueText, null);
|
167 |
group.add(getRdBtnSingleValue()); |
168 |
group.add(getRdBtnMultipleValue()); |
169 |
group.add(getRdBtnInterval()); |
170 |
} |
171 |
return valueEditionPanel;
|
172 |
} |
173 |
|
174 |
/**
|
175 |
* This method initializes jRadioButton
|
176 |
*
|
177 |
* @return javax.swing.JRadioButton
|
178 |
*/
|
179 |
private JRadioButton getRdBtnSingleValue() { |
180 |
if (rdBtnSingle == null) { |
181 |
rdBtnSingle = new JRadioButton(); |
182 |
rdBtnSingle.setBounds(7, 70, 180, 20); |
183 |
rdBtnSingle.addActionListener(new java.awt.event.ActionListener() {
|
184 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
185 |
mode = SINGLE_VALUE; |
186 |
txt.setText("");
|
187 |
} |
188 |
}); |
189 |
rdBtnSingle.setText(PluginServices.getText(this, "single_value")); |
190 |
} |
191 |
return rdBtnSingle;
|
192 |
} |
193 |
|
194 |
/**
|
195 |
* This method initializes jRadioButton1
|
196 |
*
|
197 |
* @return javax.swing.JRadioButton
|
198 |
*/
|
199 |
private JRadioButton getRdBtnMultipleValue() { |
200 |
if (rdBtnMultiple == null) { |
201 |
rdBtnMultiple = new JRadioButton(); |
202 |
rdBtnMultiple.setBounds(7, 89, 180, 20); |
203 |
rdBtnMultiple |
204 |
.addActionListener(new java.awt.event.ActionListener() {
|
205 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
206 |
mode = MULTIPLE_VALUE; |
207 |
txt.setText("");
|
208 |
} |
209 |
}); |
210 |
rdBtnMultiple.setText(PluginServices |
211 |
.getText(this, "multiple_value")); |
212 |
} |
213 |
return rdBtnMultiple;
|
214 |
} |
215 |
|
216 |
/**
|
217 |
* This method initializes jRadioButton2
|
218 |
*
|
219 |
* @return javax.swing.JRadioButton
|
220 |
*/
|
221 |
private JRadioButton getRdBtnInterval() { |
222 |
if (rdBtnInterval == null) { |
223 |
rdBtnInterval = new JRadioButton(); |
224 |
rdBtnInterval.setBounds(7, 108, 180, 20); |
225 |
rdBtnInterval |
226 |
.addActionListener(new java.awt.event.ActionListener() {
|
227 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
228 |
mode = INTERVAL; |
229 |
txt.setText("");
|
230 |
} |
231 |
}); |
232 |
rdBtnInterval.setText(PluginServices.getText(this, "interval")); |
233 |
} |
234 |
return rdBtnInterval;
|
235 |
} |
236 |
|
237 |
/**
|
238 |
* This method initializes btnAdd
|
239 |
*
|
240 |
* @return javax.swing.JButton
|
241 |
*/
|
242 |
private JButton getBtnAdd() { |
243 |
if (btnAdd == null) { |
244 |
btnAdd = new JButton(); |
245 |
btnAdd.setBounds(7, 130, 110, 20); |
246 |
btnAdd.addActionListener(new java.awt.event.ActionListener() {
|
247 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
248 |
execute("add");
|
249 |
} |
250 |
}); |
251 |
btnAdd.setText(PluginServices.getText(this, "add")); |
252 |
} |
253 |
return btnAdd;
|
254 |
} |
255 |
|
256 |
private boolean execute(String actionCommand) { |
257 |
boolean b = true; |
258 |
if (actionCommand.equals("add")) { |
259 |
if (lblValueText.getText() != null && !lblValueText.equals("")) { |
260 |
Integer newIndex = new Integer(currentSelectedValue); |
261 |
switch (mode) {
|
262 |
case SINGLE_VALUE:
|
263 |
txt.setText(lblValueText.getText()); |
264 |
indices.clear(); |
265 |
indices.add(newIndex); |
266 |
break;
|
267 |
case MULTIPLE_VALUE:
|
268 |
String oldText = txt.getText();
|
269 |
if (oldText == null || oldText.equals("")) |
270 |
txt.setText(lblValueText.getText()); |
271 |
else
|
272 |
txt.setText(oldText + "," + lblValueText.getText());
|
273 |
indices.add(newIndex); |
274 |
break;
|
275 |
case INTERVAL:
|
276 |
if (txt.getText().indexOf("/") == -1) { |
277 |
txt.setText(lblValueText.getText() + "/");
|
278 |
indices.add(newIndex); |
279 |
indices.add(newIndex); |
280 |
incomplete = true;
|
281 |
} else {
|
282 |
if (incomplete) {
|
283 |
txt.setText(txt.getText() + lblValueText.getText()); |
284 |
indices.set(1, newIndex);
|
285 |
incomplete = false;
|
286 |
} |
287 |
} |
288 |
break;
|
289 |
} |
290 |
} |
291 |
} else if (actionCommand.equals("clear")) { |
292 |
txt.setText("");
|
293 |
incomplete = true;
|
294 |
userEdits = false;
|
295 |
indices.clear(); |
296 |
if(currentDimension != null) |
297 |
settings.remove(currentDimension.getName()); |
298 |
callValueChanged(getDimensions()); |
299 |
} else if (actionCommand.equals("set")) { |
300 |
|
301 |
/*
|
302 |
* Two kinds of input data is accepted: - An array of Integer
|
303 |
* representing points which are computed and obtained from the
|
304 |
* application. This ensures that it is a valid value. Depending on
|
305 |
* what is being inserted (single value, interval, or multiple
|
306 |
* values) the array will contain one, two or more Integer.
|
307 |
* - An user custom expression. The user decides to type-in its own
|
308 |
* expression, and the application assumes that that expression is
|
309 |
* correct and just uses it.
|
310 |
*/
|
311 |
int type;
|
312 |
Object val;
|
313 |
if (userEdits) {
|
314 |
type = Value.EXPR; |
315 |
val = txt.getText(); |
316 |
} else {
|
317 |
type = Value.INDEXES; |
318 |
val = (Integer[]) indices.toArray(new Integer[0]); |
319 |
} |
320 |
//settings.put(currentDimension, new Value(type, mode, val));
|
321 |
if ((type == Value.EXPR && !((String) val).equals("")) || |
322 |
(type == Value.INDEXES && ((Integer[]) val).length > 0)){ |
323 |
settings.put(currentDimension.getName(), new Value(type, mode, val, currentDimension));
|
324 |
|
325 |
} |
326 |
callValueChanged(getDimensions()); |
327 |
} |
328 |
refreshInfo(); |
329 |
|
330 |
return b;
|
331 |
} |
332 |
|
333 |
private void refreshInfo() { |
334 |
String font = "Arial"; |
335 |
|
336 |
String tableRows = ""; |
337 |
boolean switchColor = false; |
338 |
Iterator<String> it = settings.keySet().iterator(); |
339 |
while (it.hasNext()) {
|
340 |
String name = (String) it.next(); |
341 |
Value val = (Value) settings.get(name); |
342 |
|
343 |
String dimValue;
|
344 |
if (val != null) { |
345 |
if (val.type == Value.INDEXES) {
|
346 |
Integer[] ints = val.getIndexes(); |
347 |
String separator = val.getMode() == MULTIPLE_VALUE ? "," : "/"; |
348 |
String s = ""; |
349 |
for (int j = 0; j < ints.length; j++) { |
350 |
s += currentDimension.valueAt(ints[j].intValue()); |
351 |
if (j < ints.length - 1) |
352 |
s += separator; |
353 |
} |
354 |
dimValue = s; |
355 |
} else
|
356 |
dimValue = val.getExpr(); |
357 |
} else
|
358 |
dimValue = PluginServices.getText(this, "none_selected"); |
359 |
|
360 |
RemoteTimeDimension d = val.getOwner(); |
361 |
// Handle units and unit symbols
|
362 |
String unitSymbol = (d !=null) ? d.getUnitSymbol() : null; |
363 |
String unit = (d !=null) ? d.getUnit() : null; |
364 |
if (unit != null && !unit.equals("")) |
365 |
unit = PluginServices.getText(this, "in") + " " + unit; |
366 |
else
|
367 |
unit = "";
|
368 |
|
369 |
if (unitSymbol != null && !unitSymbol.equals("")) |
370 |
unitSymbol = " (" + unitSymbol + ")"; |
371 |
else
|
372 |
unitSymbol = "";
|
373 |
|
374 |
String color = switchColor ? bgColor0 : bgColor2;
|
375 |
|
376 |
tableRows += " <tr valign=\"top\" bgcolor="
|
377 |
+ color |
378 |
+ ">"
|
379 |
+ " <td width=\"92\" height=\"18\" bgcolor=\"#D6D6D6\" align=\"right\"><font face=\""
|
380 |
+ font + "\" size=\"3\">" + " <b>" + name |
381 |
+ "</b>" + " " + unit + unitSymbol + "</font>" + " </td>" |
382 |
+ " <td width=\"268\"><font face=\"" + font
|
383 |
+ "\" size=\"3\">" + dimValue + "</font></td>" + " </tr>"; |
384 |
switchColor = !switchColor; |
385 |
} |
386 |
|
387 |
String html = "<html>" |
388 |
+ "<body>"
|
389 |
+ "<table align=\"center\" width=\"437\" height=\"156\" border=\"0\" cellpadding=\"4\" cellspacing=\"4\">"
|
390 |
+ tableRows + "</table>" + "</body>" + "</html>"; |
391 |
getInfoEditor().setContentType("text/html");
|
392 |
getInfoEditor().setText(html); |
393 |
} |
394 |
|
395 |
/**
|
396 |
* This method initializes txt
|
397 |
*
|
398 |
* @return javax.swing.JTextField
|
399 |
*/
|
400 |
private JTextField getTxt() { |
401 |
if (txt == null) { |
402 |
txt = new JTextField(); |
403 |
txt.setBounds(7, 162, 234, 22); |
404 |
txt.addKeyListener(new java.awt.event.KeyAdapter() {
|
405 |
public void keyTyped(java.awt.event.KeyEvent e) { |
406 |
userEdits = true;
|
407 |
} |
408 |
}); |
409 |
} |
410 |
return txt;
|
411 |
} |
412 |
|
413 |
/**
|
414 |
* This method initializes scrlDimension
|
415 |
*
|
416 |
* @return javax.swing.JScrollPane
|
417 |
*/
|
418 |
private JScrollPane getScrlDimension() { |
419 |
if (scrlDimension == null) { |
420 |
scrlDimension = new JScrollPane(); |
421 |
scrlDimension.setBounds(5, 17, 220, 209); |
422 |
scrlDimension.setViewportView(getLstDimensions()); |
423 |
} |
424 |
return scrlDimension;
|
425 |
} |
426 |
|
427 |
/**
|
428 |
* This method initializes jList
|
429 |
*
|
430 |
* @return javax.swing.JList
|
431 |
*/
|
432 |
private JList getLstDimensions() { |
433 |
if (lstDimensions == null) { |
434 |
lstDimensions = new JList(); |
435 |
lstDimensions |
436 |
.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
437 |
lstDimensions |
438 |
.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
|
439 |
public void valueChanged(javax.swing.event.ListSelectionEvent e) { |
440 |
try{
|
441 |
if (currentDimension != dim[lstDimensions.getSelectedIndex()]) {
|
442 |
indices.clear(); |
443 |
currentDimension = dim[lstDimensions.getSelectedIndex()]; |
444 |
} |
445 |
} catch (ArrayIndexOutOfBoundsException ex) {} |
446 |
refreshEditionPanel(); |
447 |
} |
448 |
}); |
449 |
} |
450 |
return lstDimensions;
|
451 |
} |
452 |
|
453 |
protected void refreshEditionPanel() { |
454 |
//Value val = (Value) settings.get(currentDimension);
|
455 |
Value val = (Value) settings.get(currentDimension.getName()); |
456 |
if (val == null) { |
457 |
lblValueText.setText(currentDimension.valueAt(0));
|
458 |
getRdBtnSingleValue().setEnabled(true);
|
459 |
} else {
|
460 |
int m = val.getMode();
|
461 |
String separator;
|
462 |
|
463 |
if (m == MULTIPLE_VALUE) {
|
464 |
getRdBtnMultipleValue().setSelected(true);
|
465 |
separator = ",";
|
466 |
} else {
|
467 |
separator = "/";
|
468 |
if (m == SINGLE_VALUE)
|
469 |
getRdBtnSingleValue().setSelected(true);
|
470 |
else
|
471 |
getRdBtnInterval().setSelected(true);
|
472 |
} |
473 |
|
474 |
// text of VALUE
|
475 |
if (val.type == Value.EXPR) {
|
476 |
txt.setText(val.getExpr()); |
477 |
} else {
|
478 |
Integer[] ints = val.getIndexes(); |
479 |
String s = ""; |
480 |
for (int i = 0; i < ints.length; i++) { |
481 |
s += currentDimension.valueAt(ints[i].intValue()); |
482 |
if (i < ints.length - 1) |
483 |
s += separator; |
484 |
} |
485 |
txt.setText(s); |
486 |
} |
487 |
} |
488 |
pager.setItemCount(currentDimension.valueCount()); |
489 |
pager.setValue(0, true); |
490 |
} |
491 |
|
492 |
/**
|
493 |
* This method initializes editionPanel
|
494 |
*
|
495 |
* @return javax.swing.JPanel
|
496 |
*/
|
497 |
private JPanel getEditionPanel() { |
498 |
if (editionPanel == null) { |
499 |
editionPanel = new JPanel(); |
500 |
editionPanel |
501 |
.setBorder(javax.swing.BorderFactory |
502 |
.createTitledBorder( |
503 |
null,
|
504 |
PluginServices.getText(this,
|
505 |
"settings_editor"),
|
506 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
507 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, |
508 |
null, null)); |
509 |
|
510 |
editionPanel.setLayout(null);
|
511 |
editionPanel.setBounds(9, 150, 480, 232); |
512 |
editionPanel.add(getJPanel1(), null);
|
513 |
editionPanel.add(getScrlDimension(), null);
|
514 |
|
515 |
} |
516 |
return editionPanel;
|
517 |
} |
518 |
|
519 |
/**
|
520 |
* This method initializes scrDimInfo
|
521 |
*
|
522 |
* @return javax.swing.JScrollPane
|
523 |
*/
|
524 |
private JScrollPane getScrDimInfo() { |
525 |
if (scrDimInfo == null) { |
526 |
scrDimInfo = new JScrollPane(); |
527 |
scrDimInfo.setBounds(6, 17, 466, 113); |
528 |
scrDimInfo.setViewportView(getInfoEditor()); |
529 |
} |
530 |
return scrDimInfo;
|
531 |
} |
532 |
|
533 |
/**
|
534 |
* This method initializes infoEditor
|
535 |
*
|
536 |
* @return javax.swing.JEditorPane
|
537 |
*/
|
538 |
private JEditorPane getInfoEditor() { |
539 |
if (infoEditor == null) { |
540 |
infoEditor = new JEditorPane(); |
541 |
infoEditor.setEditable(false);
|
542 |
} |
543 |
return infoEditor;
|
544 |
} |
545 |
|
546 |
/**
|
547 |
* This method initializes valuePanel
|
548 |
*
|
549 |
* @return javax.swing.JPanel
|
550 |
*/
|
551 |
private JPanel getValuePanel() { |
552 |
if (valuePanel == null) { |
553 |
|
554 |
valuePanel = new JPanel(); |
555 |
valuePanel.setLayout(null);
|
556 |
valuePanel.setBounds(8, 17, 480, 137); |
557 |
valuePanel.add(getScrDimInfo(), null);
|
558 |
valuePanel.setBorder(javax.swing.BorderFactory.createTitledBorder( |
559 |
null, PluginServices.getText(this, "settings"), |
560 |
javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, |
561 |
javax.swing.border.TitledBorder.DEFAULT_POSITION, null,
|
562 |
null));
|
563 |
|
564 |
} |
565 |
return valuePanel;
|
566 |
} |
567 |
|
568 |
/**
|
569 |
* This method initializes btnSet
|
570 |
*
|
571 |
* @return javax.swing.JButton
|
572 |
*/
|
573 |
private JButton getBtnSet() { |
574 |
if (btnSet == null) { |
575 |
btnSet = new JButton(); |
576 |
btnSet.setBounds(7, 188, 110, 20); |
577 |
btnSet.setText(PluginServices.getText(this, "set")); |
578 |
btnSet.addActionListener(new java.awt.event.ActionListener() {
|
579 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
580 |
execute("set");
|
581 |
} |
582 |
}); |
583 |
} |
584 |
return btnSet;
|
585 |
} |
586 |
|
587 |
/**
|
588 |
* This method initializes btnClear
|
589 |
*
|
590 |
* @return javax.swing.JButton
|
591 |
*/
|
592 |
private JButton getBtnClear() { |
593 |
if (btnClear == null) { |
594 |
btnClear = new JButton(); |
595 |
btnClear.setBounds(107, 130, 110, 20); |
596 |
btnClear.setText(PluginServices.getText(this, "clear")); |
597 |
btnClear.addActionListener(new java.awt.event.ActionListener() {
|
598 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
599 |
execute("clear");
|
600 |
} |
601 |
}); |
602 |
} |
603 |
return btnClear;
|
604 |
} |
605 |
|
606 |
public void addDimension(RemoteTimeDimension d) throws IllegalArgumentException { |
607 |
d.compile(); |
608 |
|
609 |
if (dim == null) { |
610 |
dim = new RemoteTimeDimension[] { d }; |
611 |
} else {
|
612 |
|
613 |
Vector<RemoteTimeDimension> v = new Vector<RemoteTimeDimension>(); |
614 |
for (int i = 0; i < dim.length; i++) { |
615 |
v.add(dim[i]); |
616 |
} |
617 |
if (v.contains(d))
|
618 |
return;
|
619 |
v.add(d); |
620 |
dim = (RemoteTimeDimension[]) v.toArray(new RemoteTimeDimension[0]); |
621 |
} |
622 |
String[] texts = new String[dim.length]; |
623 |
for (int i = 0; i < texts.length; i++) { |
624 |
texts[i] = dim[i].getName(); |
625 |
} |
626 |
getLstDimensions().setListData(texts); |
627 |
refreshInfo(); |
628 |
} |
629 |
|
630 |
public Vector<String> getDimensions() { |
631 |
if (settings.isEmpty())
|
632 |
return null; |
633 |
Vector<String> v = new Vector<String>(); |
634 |
Iterator<String> it = settings.keySet().iterator(); |
635 |
while (it.hasNext()) {
|
636 |
Object key = it.next();
|
637 |
Value val = ((Value) settings.get(key)); |
638 |
|
639 |
if (val.getType() == Value.EXPR)
|
640 |
v.add((String)key + "=" + (String) val.getValue()); |
641 |
else {
|
642 |
String values = ""; |
643 |
String separator = (val.getMode() == MULTIPLE_VALUE) ? "," : "/"; |
644 |
Integer[] indexes = val.getIndexes(); |
645 |
for (int j = 0; j < indexes.length; j++) { |
646 |
values += val.getOwner().valueAt(indexes[j].intValue()); |
647 |
if (j < indexes.length - 1) |
648 |
values += separator; |
649 |
} |
650 |
v.add((String)key + "=" + values); |
651 |
} |
652 |
} |
653 |
return v;
|
654 |
} |
655 |
|
656 |
/**
|
657 |
* Sets the value for a Dimension given by the dimension name. The value is
|
658 |
* set as a plain text expressions and the panel will not keep track of what
|
659 |
* position represents this value.
|
660 |
*
|
661 |
* @param name
|
662 |
* @param value
|
663 |
*/
|
664 |
public void setDimensionValue(String name, String value) { |
665 |
for (int i = 0; dim!=null && i < dim.length; i++) { |
666 |
if (dim[i].getName().equals(name)) {
|
667 |
int myMode;
|
668 |
if (value.indexOf(",") != -1) |
669 |
myMode = MULTIPLE_VALUE; |
670 |
else if (value.indexOf("/") != -1) |
671 |
myMode = INTERVAL; |
672 |
else
|
673 |
myMode = SINGLE_VALUE; |
674 |
Value val = new Value(Value.EXPR, myMode, value, null); |
675 |
//settings.put(dim[i], val);
|
676 |
settings.put(name, val); |
677 |
} |
678 |
} |
679 |
refreshInfo(); |
680 |
} |
681 |
|
682 |
private class Value { |
683 |
public static final int INDEXES = 0; |
684 |
public static final int EXPR = 1; |
685 |
private int type; |
686 |
private int valueMode; |
687 |
private Object value; |
688 |
private RemoteTimeDimension owner;
|
689 |
|
690 |
|
691 |
|
692 |
public Value(int type, int mode, Object value, RemoteTimeDimension owner) { |
693 |
this.type = type;
|
694 |
this.valueMode = mode;
|
695 |
this.owner = owner;
|
696 |
this.value = value;
|
697 |
} |
698 |
|
699 |
/**
|
700 |
* Returns the type of the contained value.<br>
|
701 |
* Possible values are:
|
702 |
* <ol>
|
703 |
* <li> <b>Value.INDEXES</b>, which means that the value is an Integer
|
704 |
* array that should be used to compute the actual value by using the
|
705 |
* method IFMapWMSDimension.valueAt(int i). </li>
|
706 |
* <li> <b>Value.EXPR</b>. If the value type is this, then the value is
|
707 |
* a plain String that can be directly used as much it should represent
|
708 |
* a valid value for the WMS server. </li>
|
709 |
* </ol>
|
710 |
*
|
711 |
* @return int
|
712 |
*/
|
713 |
public int getType() { |
714 |
return type;
|
715 |
} |
716 |
|
717 |
/**
|
718 |
* Array of indexes that compose this value expression. Use it only when
|
719 |
* type is INDEXES.
|
720 |
* @return
|
721 |
*/
|
722 |
public Integer[] getIndexes() { |
723 |
return (Integer[]) value; |
724 |
} |
725 |
|
726 |
/**
|
727 |
* Expression of this value, if its type is EXPR
|
728 |
* @return
|
729 |
*/
|
730 |
public String getExpr() { |
731 |
return (String) value; |
732 |
} |
733 |
|
734 |
/**
|
735 |
* The mode of the value.
|
736 |
* @return one of DimensionPanel.SINGLE_VALUE, DimensionPanel.MULTIPLE_VALUE
|
737 |
* or DimensionPanel.INTERVAL
|
738 |
*/
|
739 |
public int getMode() { |
740 |
return valueMode;
|
741 |
} |
742 |
|
743 |
public Object getValue() { |
744 |
return value;
|
745 |
} |
746 |
/**
|
747 |
* Returns a reference to the IFMapDimension that owns this dimension.
|
748 |
*/
|
749 |
public RemoteTimeDimension getOwner() {
|
750 |
return owner;
|
751 |
} |
752 |
|
753 |
} |
754 |
|
755 |
} |