Statistics
| Revision:

svn-gvsig-desktop / branches / v05 / extensions / extWMS / src / com / iver / cit / gvsig / gui / panels / DimensionPanel.java @ 3855

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 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();
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
                } else if (actionCommand.equals("set")) {
316
                        
317
                        /*
318
                         * Two kinds of input data is accepted: - An array of Integer
319
                         * representing points which are computed and obtained from the
320
                         * application. This ensures that it is a valid value. Depending on
321
                         * what is being inserted (single value, interval, or multiple
322
                         * values) the array will contain one, two or more Integer.
323
                         *  - An user custom expression. The user decides to type-in its own
324
                         * expression, and the application assumes that that expression is
325
                         * correct and just uses it.
326
                         */
327
                        int type;
328
                        Object val;
329
                        if (userEdits) {
330
                                type = Value.EXPR;
331
                                val = txt.getText();
332
                        } else {
333
                                type = Value.INDEXES;
334
                                val = (Integer[]) indices.toArray(new Integer[0]);
335
                        }
336
                        //settings.put(currentDimension, new Value(type, mode, val));
337
                        if ((type == Value.EXPR && !((String) val).equals(""))        ||
338
                                (type == Value.INDEXES && ((Integer[]) val).length>0)){
339
                                settings.put(currentDimension.getName(), new Value(type, mode, val, currentDimension));
340
                                refreshInfo();
341
                                callValueChanged(getDimensions());
342
                        }
343
                }
344
                return b;
345
        }
346

    
347
        private void refreshInfo() {
348
                String font = "Arial";
349

    
350
                String tableRows = "";
351
                boolean switchColor = false;
352
                Iterator it = settings.keySet().iterator();
353
                int i = 0;
354
                while (it.hasNext()) {
355
                        String name = (String) it.next();
356
                        Value val = (Value) settings.get(name);
357
//                for (int i = 0; i < dim.length; i++) {
358
//                        Value val = (Value) settings.get(dim[i]);
359
                        String dimValue;
360
                        if (val != null) {
361
                                if (val.type == Value.INDEXES) {
362
                                        Integer[] ints = val.getIndexes();
363
                                        String separator = val.getMode() == MULTIPLE_VALUE ? "," : "/";
364
                                        String s = "";
365
                                        for (int j = 0; j < ints.length; j++) {
366
                                                s += currentDimension.valueAt(ints[j].intValue());
367
                                                if (j < ints.length - 1)
368
                                                        s += separator;
369
                                        }
370
                                        dimValue = s;
371
                                } else
372
                                        dimValue = val.getExpr();
373
                        } else
374
                                dimValue = PluginServices.getText(this, "none_selected");
375

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

    
385
                        if (unitSymbol != null && !unitSymbol.equals(""))
386
                                unitSymbol = " (" + unitSymbol + ")";
387
                        else
388
                                unitSymbol = "";
389

    
390
                        String color = switchColor ? bgColor0 : bgColor2;
391

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

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

    
411
        /**
412
         * This method initializes txt
413
         * 
414
         * @return javax.swing.JTextField
415
         */
416
        private JTextField getTxt() {
417
                if (txt == null) {
418
                        txt = new JTextField();
419
                        txt.setBounds(8, 152, 180, 22);
420
                        txt.addKeyListener(new java.awt.event.KeyAdapter() {
421
                                public void keyTyped(java.awt.event.KeyEvent e) {
422
                                        userEdits = true;
423
                                }
424
                        });
425
                }
426
                return txt;
427
        }
428

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

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

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

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

    
505
        }
506

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

    
525
                        editionPanel.setLayout(null);
526
                        editionPanel.setBounds(9, 169, 457, 220);
527
                        editionPanel.add(getJPanel1(), null);
528
                        editionPanel.add(getScrlDimension(), null);
529

    
530
                }
531
                return editionPanel;
532
        }
533

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

    
548
        /**
549
         * This method initializes infoEditor
550
         * 
551
         * @return javax.swing.JEditorPane
552
         */
553
        private JEditorPane getInfoEditor() {
554
                if (infoEditor == null) {
555
                        infoEditor = new JEditorPane();
556
                        infoEditor.setEditable(false);
557
                }
558
                return infoEditor;
559
        }
560

    
561
        /**
562
         * This method initializes valuePanel
563
         * 
564
         * @return javax.swing.JPanel
565
         */
566
        private JPanel getValuePanel() {
567
                if (valuePanel == null) {
568

    
569
                        valuePanel = new JPanel();
570
                        valuePanel.setLayout(null);
571
                        valuePanel.setBounds(8, 17, 457, 148);
572
                        valuePanel.add(getScrDimInfo(), null);
573
                        valuePanel.setBorder(javax.swing.BorderFactory.createTitledBorder(
574
                                        null, PluginServices.getText(this, "settings"),
575
                                        javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION,
576
                                        javax.swing.border.TitledBorder.DEFAULT_POSITION, null,
577
                                        null));
578

    
579
                }
580
                return valuePanel;
581
        }
582

    
583
        /**
584
         * This method initializes btnSet
585
         * 
586
         * @return javax.swing.JButton
587
         */
588
        private JButton getBtnSet() {
589
                if (btnSet == null) {
590
                        btnSet = new JButton();
591
                        btnSet.setBounds(7, 177, 90, 23);
592
                        btnSet.setText(PluginServices.getText(this, "set"));
593
                        btnSet.addActionListener(new java.awt.event.ActionListener() {
594
                                public void actionPerformed(java.awt.event.ActionEvent e) {
595
                                        execute("set");
596
                                }
597
                        });
598
                }
599
                return btnSet;
600
        }
601

    
602
        /**
603
         * This method initializes btnClear
604
         * 
605
         * @return javax.swing.JButton
606
         */
607
        private JButton getBtnClear() {
608
                if (btnClear == null) {
609
                        btnClear = new JButton();
610
                        btnClear.setBounds(97, 127, 90, 23);
611
                        btnClear.setText(PluginServices.getText(this, "clear"));
612
                        btnClear.addActionListener(new java.awt.event.ActionListener() {
613
                                public void actionPerformed(java.awt.event.ActionEvent e) {
614
                                        execute("clear");
615
                                }
616
                        });
617
                }
618
                return btnClear;
619
        }
620

    
621
        public void addDimension(IFMapWMSDimension d) {
622
                if (dim == null) {
623
                        dim = new IFMapWMSDimension[] { d };
624
                } else {
625

    
626
                        Vector v = new Vector();
627
                        for (int i = 0; i < dim.length; i++) {
628
                                v.add(dim[i]);
629
                        }
630
                        if (v.contains(d))
631
                                return;
632
                        v.add(d);
633
                        dim = (IFMapWMSDimension[]) v.toArray(new IFMapWMSDimension[0]);
634
                }
635
                String[] texts = new String[dim.length];
636
                for (int i = 0; i < texts.length; i++) {
637
                        texts[i] = dim[i].getName();
638
                }
639
                getLstDimensions().setListData(texts);
640
                refreshInfo();
641
        }
642

    
643
        public Vector getDimensions() {
644
                if (settings.isEmpty())
645
                        return null;
646
                Vector v = new Vector();
647
                Iterator it = settings.keySet().iterator();
648
                int i = 0;
649
                while (it.hasNext()) {
650
                        Object key = it.next();
651
                        Value val = ((Value) settings.get(key));
652

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

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

    
701
        private class Value {
702
                public static final int INDEXES = 0;
703
                public static final int EXPR = 1;
704
                private int type;
705
                private int valueMode;
706
                private Object value;
707
                private IFMapWMSDimension owner;
708

    
709
                
710
                
711
                public Value(int type, int mode, Object value, IFMapWMSDimension owner) {
712
                        this.type = type;
713
                        this.valueMode = mode;
714
                        this.owner = owner;
715
                        this.value = value;
716
                }
717

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

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

    
745
                /**
746
                 * Expression of this value, if its type is EXPR 
747
                 * @return
748
                 */
749
                public String getExpr() {
750
                        return (String) value;
751
                }
752

    
753
                /**
754
                 * The mode of the value.
755
                 * @return one of DimensionPanel.SINGLE_VALUE, DimensionPanel.MULTIPLE_VALUE
756
                 *            or DimensionPanel.INTERVAL
757
                 */
758
                public int getMode() {
759
                        return valueMode;
760
                }
761

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

    
772
        }
773
}