Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extWMS / src / com / iver / cit / gvsig / gui / panels / DimensionPanel.java @ 4620

History | View | Annotate | Download (20.8 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 org.gvsig.gui.beans.DefaultBean;
58
import org.gvsig.gui.beans.Pager;
59
import org.gvsig.gui.beans.listeners.BeanListener;
60

    
61
import com.iver.andami.PluginServices;
62
import com.iver.cit.gvsig.fmap.layers.IFMapWMSDimension;
63

    
64
/**
65
 * This is the Dimensions tab of the WMS wizard.
66
 * 
67
 * @author jaume
68
 * 
69
 */
70
public class DimensionPanel extends DefaultBean {
71
        static private final int SINGLE_VALUE = 0;
72
        static private final int MULTIPLE_VALUE = 1;
73
        static private final int INTERVAL = 2;
74
        private final String bgColor0 = "\"#FEEDD6\""; // light salmon
75
        private final String bgColor2 = "\"#F2FEFF\""; // light blue
76
        private Pager pager = null;
77
        private JPanel valueEditionPanel = null;
78
        private JRadioButton rdBtnSingle = null;
79
        private JRadioButton rdBtnMultiple = null;
80
        private JRadioButton rdBtnInterval = null;
81
        private JButton btnAdd = null;
82
        private JTextField txt = null;
83
        private JScrollPane scrlDimension = null;
84
        private JList lstDimensions = null;
85
        private JPanel editionPanel = null;
86
        private JScrollPane scrDimInfo = null;
87
        private JEditorPane infoEditor = null;
88
        private JPanel valuePanel = null;
89
        private JButton btnSet = null;
90
        private JButton btnClear = null;
91
        private JLabel lblValue = null;
92
        private JLabel lblValueText = null;
93
        private int currentSelectedValue;
94
        private int mode;
95
        private boolean incomplete = true;
96
        private boolean userEdits = false;
97
        private IFMapWMSDimension[] dim;
98
        private IFMapWMSDimension currentDimension;
99
        /**
100
         * <b>key:</b> FMapWMSDimension <br>
101
         * <b>value:</b> value
102
         */
103
        private Hashtable settings = new Hashtable();
104

    
105
        /**
106
         * Will contain the settings for a getMap query which are just text. Since
107
         * only one Dimension definition expression is allowed the key for this hash
108
         * map is the dimension name.
109
         * 
110
         * <b>key:</b> dimension name as string <br>
111
         * <b>value:</b> dimension value as string
112
         */
113
        private Vector indices = new Vector();
114

    
115
        /**
116
         * This is the default constructor
117
         */
118
        public DimensionPanel() {
119
                super();
120
                initialize();
121
        }
122

    
123
        /**
124
         * This method initializes this
125
         * 
126
         * @return void
127
         */
128
        private void initialize() {
129
                this.setLayout(null);
130
                this.setSize(475, 399);
131
                this.setBorder(javax.swing.BorderFactory.createTitledBorder(null,
132
                                PluginServices.getText(this, "dimension"),
133
                                javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
134
                                javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null));
135
                this.add(getValuePanel(), null);
136
                this.add(getEditionPanel(), null);
137
        }
138

    
139
        /**
140
         * This method initializes jPanel
141
         * 
142
         * @return javax.swing.JPanel
143
         */
144
        private Pager getJPanel() {
145
                if (pager == null) {
146
                        pager = new Pager(Pager.HORIZONTAL);
147
                        pager.setBounds(5, 20, 240, 50);
148
                        pager.addListener(new BeanListener() {
149
                                public void beanValueChanged(Object value) {
150
                                        currentSelectedValue = ((Integer) value).intValue();
151
                                        lblValueText.setText(currentDimension
152
                                                        .valueAt(currentSelectedValue));
153
                                }
154
                        });
155
                }
156
                return pager;
157
        }
158

    
159
        /**
160
         * This method initializes jPanel1
161
         * 
162
         * @return javax.swing.JPanel
163
         */
164
        private JPanel getJPanel1() {
165
                if (valueEditionPanel == null) {
166
                        ButtonGroup group = new ButtonGroup();
167
                        lblValueText = new JLabel();
168
                        lblValueText.setBounds(54, 4, 190, 20);
169
                        lblValueText.setText("");
170
                        lblValue = new JLabel();
171
                        lblValue.setBounds(7, 4, 45, 20);
172
                        lblValue.setText(PluginServices.getText(this, "value") + ":");
173
                        lblValue.setFont(new java.awt.Font("MS Sans Serif",
174
                                        java.awt.Font.BOLD, 11));
175
                        valueEditionPanel = new JPanel();
176
                        valueEditionPanel.setLayout(null);
177
                        valueEditionPanel.setBounds(206, 12, 245, 200);
178
                        valueEditionPanel.add(getRdBtnSingleValue(), null);
179
                        valueEditionPanel.add(getRdBtnMultipleValue(), null);
180
                        valueEditionPanel.add(getRdBtnInterval(), null);
181
                        valueEditionPanel.add(getBtnAdd(), null);
182
                        valueEditionPanel.add(getTxt(), null);
183
                        valueEditionPanel.add(getBtnSet(), null);
184
                        valueEditionPanel.add(getBtnClear(), null);
185
                        valueEditionPanel.add(getJPanel(), null);
186
                        valueEditionPanel.add(lblValue, null);
187
                        valueEditionPanel.add(lblValueText, null);
188
                        group.add(getRdBtnSingleValue());
189
                        group.add(getRdBtnMultipleValue());
190
                        group.add(getRdBtnInterval());
191
                }
192
                return valueEditionPanel;
193
        }
194

    
195
        /**
196
         * This method initializes jRadioButton
197
         * 
198
         * @return javax.swing.JRadioButton
199
         */
200
        private JRadioButton getRdBtnSingleValue() {
201
                if (rdBtnSingle == null) {
202
                        rdBtnSingle = new JRadioButton();
203
                        rdBtnSingle.setBounds(7, 70, 180, 20);
204
                        rdBtnSingle.addActionListener(new java.awt.event.ActionListener() {
205
                                public void actionPerformed(java.awt.event.ActionEvent e) {
206
                                        mode = SINGLE_VALUE;
207
                                        txt.setText("");
208
                                }
209
                        });
210
                        rdBtnSingle.setText(PluginServices.getText(this, "single_value"));
211
                }
212
                return rdBtnSingle;
213
        }
214

    
215
        /**
216
         * This method initializes jRadioButton1
217
         * 
218
         * @return javax.swing.JRadioButton
219
         */
220
        private JRadioButton getRdBtnMultipleValue() {
221
                if (rdBtnMultiple == null) {
222
                        rdBtnMultiple = new JRadioButton();
223
                        rdBtnMultiple.setBounds(7, 89, 180, 20);
224
                        rdBtnMultiple
225
                                        .addActionListener(new java.awt.event.ActionListener() {
226
                                                public void actionPerformed(java.awt.event.ActionEvent e) {
227
                                                        mode = MULTIPLE_VALUE;
228
                                                        txt.setText("");
229
                                                }
230
                                        });
231
                        rdBtnMultiple.setText(PluginServices
232
                                        .getText(this, "multiple_value"));
233
                }
234
                return rdBtnMultiple;
235
        }
236

    
237
        /**
238
         * This method initializes jRadioButton2
239
         * 
240
         * @return javax.swing.JRadioButton
241
         */
242
        private JRadioButton getRdBtnInterval() {
243
                if (rdBtnInterval == null) {
244
                        rdBtnInterval = new JRadioButton();
245
                        rdBtnInterval.setBounds(7, 108, 180, 20);
246
                        rdBtnInterval
247
                                        .addActionListener(new java.awt.event.ActionListener() {
248
                                                public void actionPerformed(java.awt.event.ActionEvent e) {
249
                                                        mode = INTERVAL;
250
                                                        txt.setText("");
251
                                                }
252
                                        });
253
                        rdBtnInterval.setText(PluginServices.getText(this, "interval"));
254
                }
255
                return rdBtnInterval;
256
        }
257

    
258
        /**
259
         * This method initializes btnAdd
260
         * 
261
         * @return javax.swing.JButton
262
         */
263
        private JButton getBtnAdd() {
264
                if (btnAdd == null) {
265
                        btnAdd = new JButton();
266
                        btnAdd.setBounds(7, 130, 110, 20);
267
                        btnAdd.addActionListener(new java.awt.event.ActionListener() {
268
                                public void actionPerformed(java.awt.event.ActionEvent e) {
269
                                        execute("add");
270
                                }
271
                        });
272
                        btnAdd.setText(PluginServices.getText(this, "add"));
273
                }
274
                return btnAdd;
275
        }
276

    
277
        private boolean execute(String actionCommand) {
278
                boolean b = true;
279
                if (actionCommand.equals("add")) {
280
                        if (lblValueText.getText() != null && !lblValueText.equals("")) {
281
                                Integer newIndex = new Integer(currentSelectedValue);
282
                                switch (mode) {
283
                                case SINGLE_VALUE:
284
                                        txt.setText(lblValueText.getText());
285
                                        indices.clear();
286
                                        indices.add(newIndex);
287
                                        break;
288
                                case MULTIPLE_VALUE:
289
                                        String oldText = txt.getText();
290
                                        if (oldText == null || oldText.equals(""))
291
                                                txt.setText(lblValueText.getText());
292
                                        else
293
                                                txt.setText(oldText + "," + lblValueText.getText());
294
                                        indices.add(newIndex);
295
                                        break;
296
                                case INTERVAL:
297
                                        if (txt.getText().indexOf("/") == -1) {
298
                                                txt.setText(lblValueText.getText() + "/");
299
                                                indices.add(newIndex);
300
                                                incomplete = true;
301
                                        } else {
302
                                                if (incomplete) {
303
                                                        txt.setText(txt.getText() + lblValueText.getText());
304
                                                        indices.set(1, newIndex);
305
                                                        incomplete = false;
306
                                                }
307
                                        }
308
                                        break;
309
                                }
310
                        }
311
                } else if (actionCommand.equals("clear")) {
312
                        txt.setText("");
313
                        incomplete = true;
314
                        userEdits = false;
315
                        indices.clear();
316
                        settings.remove(currentDimension.getName());
317
                        callValueChanged(getDimensions());
318
                } else if (actionCommand.equals("set")) {
319
                        
320
                        /*
321
                         * Two kinds of input data is accepted: - An array of Integer
322
                         * representing points which are computed and obtained from the
323
                         * application. This ensures that it is a valid value. Depending on
324
                         * what is being inserted (single value, interval, or multiple
325
                         * values) the array will contain one, two or more Integer.
326
                         *  - An user custom expression. The user decides to type-in its own
327
                         * expression, and the application assumes that that expression is
328
                         * correct and just uses it.
329
                         */
330
                        int type;
331
                        Object val;
332
                        if (userEdits) {
333
                                type = Value.EXPR;
334
                                val = txt.getText();
335
                        } else {
336
                                type = Value.INDEXES;
337
                                val = (Integer[]) indices.toArray(new Integer[0]);
338
                        }
339
                        //settings.put(currentDimension, new Value(type, mode, val));
340
                        if ((type == Value.EXPR && !((String) val).equals(""))        ||
341
                                (type == Value.INDEXES && ((Integer[]) val).length>0)){
342
                                settings.put(currentDimension.getName(), new Value(type, mode, val, currentDimension));
343
                                
344
                        }
345
                        callValueChanged(getDimensions());
346
                }
347
                refreshInfo();
348
                
349
                return b;
350
        }
351

    
352
        private void refreshInfo() {
353
                String font = "Arial";
354

    
355
                String tableRows = "";
356
                boolean switchColor = false;
357
                Iterator it = settings.keySet().iterator();
358
                int i = 0;
359
                while (it.hasNext()) {
360
                        String name = (String) it.next();
361
                        Value val = (Value) settings.get(name);
362

    
363
                        String dimValue;
364
                        if (val != null) {
365
                                if (val.type == Value.INDEXES) {
366
                                        Integer[] ints = val.getIndexes();
367
                                        String separator = val.getMode() == MULTIPLE_VALUE ? "," : "/";
368
                                        String s = "";
369
                                        for (int j = 0; j < ints.length; j++) {
370
                                                s += currentDimension.valueAt(ints[j].intValue());
371
                                                if (j < ints.length - 1)
372
                                                        s += separator;
373
                                        }
374
                                        dimValue = s;
375
                                } else
376
                                        dimValue = val.getExpr();
377
                        } else
378
                                dimValue = PluginServices.getText(this, "none_selected");
379

    
380
                        IFMapWMSDimension d = val.getOwner();
381
                        // Handle units and unit symbols
382
                        String unitSymbol = (d !=null) ? d.getUnitSymbol() : null;
383
                        String unit = (d !=null) ? d.getUnit() : null;
384
                        if (unit != null && !unit.equals(""))
385
                                unit = PluginServices.getText(this, "in") + " " + unit;
386
                        else
387
                                unit = "";
388

    
389
                        if (unitSymbol != null && !unitSymbol.equals(""))
390
                                unitSymbol = " (" + unitSymbol + ")";
391
                        else
392
                                unitSymbol = "";
393

    
394
                        String color = switchColor ? bgColor0 : bgColor2;
395

    
396
                        tableRows += "  <tr valign=\"top\" bgcolor="
397
                                        + color
398
                                        + ">"
399
                                        + "    <td width=\"92\" height=\"18\" bgcolor=\"#D6D6D6\" align=\"right\"><font face=\""
400
                                        + font + "\" size=\"3\">" + "                <b>" + name
401
                                        + "</b>" + " " + unit + unitSymbol + "</font>" + "         </td>"
402
                                        + "    <td width=\"268\"><font face=\"" + font
403
                                        + "\" size=\"3\">" + dimValue + "</font></td>" + "  </tr>";
404
                        switchColor = !switchColor;
405
                }
406

    
407
                String html = "<html>"
408
                                + "<body>"
409
                                + "<table align=\"center\" width=\"437\" height=\"156\" border=\"0\" cellpadding=\"4\" cellspacing=\"4\">"
410
                                + tableRows + "</table>" + "</body>" + "</html>";
411
                getInfoEditor().setContentType("text/html");
412
                getInfoEditor().setText(html);
413
        }
414

    
415
        /**
416
         * This method initializes txt
417
         * 
418
         * @return javax.swing.JTextField
419
         */
420
        private JTextField getTxt() {
421
                if (txt == null) {
422
                        txt = new JTextField();
423
                        txt.setBounds(7, 153, 234, 22);
424
                        txt.addKeyListener(new java.awt.event.KeyAdapter() {
425
                                public void keyTyped(java.awt.event.KeyEvent e) {
426
                                        userEdits = true;
427
                                }
428
                        });
429
                }
430
                return txt;
431
        }
432

    
433
        /**
434
         * This method initializes scrlDimension
435
         * 
436
         * @return javax.swing.JScrollPane
437
         */
438
        private JScrollPane getScrlDimension() {
439
                if (scrlDimension == null) {
440
                        scrlDimension = new JScrollPane();
441
                        scrlDimension.setBounds(5, 17, 200, 196);
442
                        scrlDimension.setViewportView(getLstDimensions());
443
                }
444
                return scrlDimension;
445
        }
446

    
447
        /**
448
         * This method initializes jList
449
         * 
450
         * @return javax.swing.JList
451
         */
452
        private JList getLstDimensions() {
453
                if (lstDimensions == null) {
454
                        lstDimensions = new JList();
455
                        lstDimensions
456
                                        .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
457
                        lstDimensions
458
                                        .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
459
                                                public void valueChanged(javax.swing.event.ListSelectionEvent e) {
460
                                                        try{
461
                                                                if (currentDimension != dim[lstDimensions.getSelectedIndex()]) {
462
                                                                        indices.clear();
463
                                                                        currentDimension = dim[lstDimensions.getSelectedIndex()];
464
                                                                }
465
                                                        } catch (ArrayIndexOutOfBoundsException ex) {}
466
                                                        refreshEditionPanel();
467
                                                }
468
                                        });
469
                }
470
                return lstDimensions;
471
        }
472

    
473
        protected void refreshEditionPanel() {
474
                //Value val = (Value) settings.get(currentDimension);
475
                Value val = (Value) settings.get(currentDimension.getName());
476
                if (val == null) {
477
                        lblValueText.setText(currentDimension.valueAt(0));
478
                        getRdBtnSingleValue().setEnabled(true);
479
                } else {
480
                        int m = val.getMode();
481
                        String separator;
482

    
483
                        if (m == MULTIPLE_VALUE) {
484
                                getRdBtnMultipleValue().setSelected(true);
485
                                separator = ",";
486
                        } else {
487
                                separator = "/";
488
                                if (m == SINGLE_VALUE)
489
                                        getRdBtnSingleValue().setSelected(true);
490
                                else
491
                                        getRdBtnInterval().setSelected(true);
492
                        }
493
                        
494
                        // text of VALUE
495
                        if (val.type == Value.EXPR) {
496
                                txt.setText(val.getExpr());
497
                        } else {
498
                                Integer[] ints = val.getIndexes();
499
                                String s = "";
500
                                for (int i = 0; i < ints.length; i++) {
501
                                        s += currentDimension.valueAt(ints[i].intValue());
502
                                        if (i < ints.length - 1)
503
                                                s += separator;
504
                                }
505
                                txt.setText(s);
506
                        }
507
                }
508
                pager.setItemCount(currentDimension.valueCount());
509
                pager.setValue(0, true);
510
        }
511

    
512
        /**
513
         * This method initializes editionPanel
514
         * 
515
         * @return javax.swing.JPanel
516
         */
517
        private JPanel getEditionPanel() {
518
                if (editionPanel == null) {
519
                        editionPanel = new JPanel();
520
                        editionPanel
521
                                        .setBorder(javax.swing.BorderFactory
522
                                                        .createTitledBorder(
523
                                                                        null,
524
                                                                        PluginServices.getText(this,
525
                                                                                        "settings_editor"),
526
                                                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
527
                                                                        javax.swing.border.TitledBorder.DEFAULT_POSITION,
528
                                                                        null, null));
529

    
530
                        editionPanel.setLayout(null);
531
                        editionPanel.setBounds(9, 169, 457, 220);
532
                        editionPanel.add(getJPanel1(), null);
533
                        editionPanel.add(getScrlDimension(), null);
534

    
535
                }
536
                return editionPanel;
537
        }
538

    
539
        /**
540
         * This method initializes scrDimInfo
541
         * 
542
         * @return javax.swing.JScrollPane
543
         */
544
        private JScrollPane getScrDimInfo() {
545
                if (scrDimInfo == null) {
546
                        scrDimInfo = new JScrollPane();
547
                        scrDimInfo.setBounds(6, 17, 445, 123);
548
                        scrDimInfo.setViewportView(getInfoEditor());
549
                }
550
                return scrDimInfo;
551
        }
552

    
553
        /**
554
         * This method initializes infoEditor
555
         * 
556
         * @return javax.swing.JEditorPane
557
         */
558
        private JEditorPane getInfoEditor() {
559
                if (infoEditor == null) {
560
                        infoEditor = new JEditorPane();
561
                        infoEditor.setEditable(false);
562
                }
563
                return infoEditor;
564
        }
565

    
566
        /**
567
         * This method initializes valuePanel
568
         * 
569
         * @return javax.swing.JPanel
570
         */
571
        private JPanel getValuePanel() {
572
                if (valuePanel == null) {
573

    
574
                        valuePanel = new JPanel();
575
                        valuePanel.setLayout(null);
576
                        valuePanel.setBounds(8, 17, 457, 148);
577
                        valuePanel.add(getScrDimInfo(), null);
578
                        valuePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
579
                                        null, PluginServices.getText(this, "settings"),
580
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
581
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null,
582
                                        null));
583

    
584
                }
585
                return valuePanel;
586
        }
587

    
588
        /**
589
         * This method initializes btnSet
590
         * 
591
         * @return javax.swing.JButton
592
         */
593
        private JButton getBtnSet() {
594
                if (btnSet == null) {
595
                        btnSet = new JButton();
596
                        btnSet.setBounds(7, 178, 110, 20);
597
                        btnSet.setText(PluginServices.getText(this, "set"));
598
                        btnSet.addActionListener(new java.awt.event.ActionListener() {
599
                                public void actionPerformed(java.awt.event.ActionEvent e) {
600
                                        execute("set");
601
                                }
602
                        });
603
                }
604
                return btnSet;
605
        }
606

    
607
        /**
608
         * This method initializes btnClear
609
         * 
610
         * @return javax.swing.JButton
611
         */
612
        private JButton getBtnClear() {
613
                if (btnClear == null) {
614
                        btnClear = new JButton();
615
                        btnClear.setBounds(131, 130, 110, 20);
616
                        btnClear.setText(PluginServices.getText(this, "clear"));
617
                        btnClear.addActionListener(new java.awt.event.ActionListener() {
618
                                public void actionPerformed(java.awt.event.ActionEvent e) {
619
                                        execute("clear");
620
                                }
621
                        });
622
                }
623
                return btnClear;
624
        }
625

    
626
        public void addDimension(IFMapWMSDimension d) throws IllegalArgumentException {
627
                d.compile();
628
                
629
                if (dim == null) {
630
                        dim = new IFMapWMSDimension[] { d };
631
                } else {
632

    
633
                        Vector v = new Vector();
634
                        for (int i = 0; i < dim.length; i++) {
635
                                v.add(dim[i]);
636
                        }
637
                        if (v.contains(d))
638
                                return;
639
                        v.add(d);
640
                        dim = (IFMapWMSDimension[]) v.toArray(new IFMapWMSDimension[0]);
641
                }
642
                String[] texts = new String[dim.length];
643
                for (int i = 0; i < texts.length; i++) {
644
                        texts[i] = dim[i].getName();
645
                }
646
                getLstDimensions().setListData(texts);
647
                refreshInfo();
648
        }
649

    
650
        public Vector getDimensions() {
651
                if (settings.isEmpty())
652
                        return null;
653
                Vector v = new Vector();
654
                Iterator it = settings.keySet().iterator();
655
                int i = 0;
656
                while (it.hasNext()) {
657
                        Object key = it.next();
658
                        Value val = ((Value) settings.get(key));
659

    
660
                        if (val.getType() == Value.EXPR)
661
                                v.add((String)key + "="
662
                                                + (String) val.getValue());
663
                        else {
664
                                String values = "";
665
                                String separator = (val.getMode() == MULTIPLE_VALUE) ? ","        : "/";
666
                                Integer[] indexes = val.getIndexes();
667
                                for (int j = 0; j < indexes.length; j++) {
668
                                        values += val.getOwner().valueAt(indexes[j].intValue());
669
                                        if (j < indexes.length - 1)
670
                                                values += separator;
671
                                }
672
                                v.add((String)key + "=" + values);
673
                        }
674
                        i++;
675
                }
676
                return v;
677
        }
678

    
679
        /**
680
         * Sets the value for a Dimension given by the dimension name. The value is
681
         * set as a plain text expressions and the panel will not keep track of what
682
         * position represents this value.
683
         * 
684
         * @param name
685
         * @param value
686
         */
687
        public void setDimensionValue(String name, String value) {
688
                for (int i = 0; dim!=null && i < dim.length; i++) {
689
                        if (dim[i].getName().equals(name)) {
690
                                int myMode;
691
                                if (value.indexOf(",") != -1)
692
                                        myMode = MULTIPLE_VALUE;
693
                                else if (value.indexOf("/") != -1)
694
                                        myMode = INTERVAL;
695
                                else
696
                                        myMode = SINGLE_VALUE;
697
                                Value val = new Value(Value.EXPR, myMode, value, null);
698
                                //settings.put(dim[i], val);
699
                                settings.put(name, val);
700
                        }
701
                }
702
                refreshInfo();
703
        }
704

    
705
        private class Value {
706
                public static final int INDEXES = 0;
707
                public static final int EXPR = 1;
708
                private int type;
709
                private int valueMode;
710
                private Object value;
711
                private IFMapWMSDimension owner;
712

    
713
                
714
                
715
                public Value(int type, int mode, Object value, IFMapWMSDimension owner) {
716
                        this.type = type;
717
                        this.valueMode = mode;
718
                        this.owner = owner;
719
                        this.value = value;
720
                }
721

    
722
                /**
723
                 * Returns the type of the contained value.<br>
724
                 * Possible values are:
725
                 * <ol>
726
                 * <li> <b>Value.INDEXES</b>, which means that the value is an Integer
727
                 * array that should be used to compute the actual value by using the
728
                 * method IFMapWMSDimension.valueAt(int i). </li>
729
                 * <li> <b>Value.EXPR</b>. If the value type is this, then the value is
730
                 * a plain String that can be directly used as much it should represent
731
                 * a valid value for the WMS server. </li>
732
                 * </ol>
733
                 * 
734
                 * @return int
735
                 */
736
                public int getType() {
737
                        return type;
738
                }
739

    
740
                /**
741
                 * Array of indexes that compose this value expression. Use it only when
742
                 * type is INDEXES.
743
                 * @return
744
                 */
745
                public Integer[] getIndexes() {
746
                        return (Integer[]) value;
747
                }
748

    
749
                /**
750
                 * Expression of this value, if its type is EXPR 
751
                 * @return
752
                 */
753
                public String getExpr() {
754
                        return (String) value;
755
                }
756

    
757
                /**
758
                 * The mode of the value.
759
                 * @return one of DimensionPanel.SINGLE_VALUE, DimensionPanel.MULTIPLE_VALUE
760
                 *            or DimensionPanel.INTERVAL
761
                 */
762
                public int getMode() {
763
                        return valueMode;
764
                }
765

    
766
                public Object getValue() {
767
                        return value;
768
                }
769
                /**
770
                 * Returns a reference to the IFMapDimension that owns this dimension.
771
                 */
772
                public IFMapWMSDimension getOwner() {
773
                        return owner;
774
                }
775

    
776
        }
777
}