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