Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / gui / styling / SymbolEditor.java @ 30011

History | View | Annotate | Download (20.2 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

    
42
/* CVS MESSAGES:
43
 *
44
 * $Id: SymbolEditor.java 30011 2009-07-17 11:07:14Z cordinyana $
45
 * $Log$
46
 * Revision 1.22  2007-09-19 15:36:36  jaume
47
 * removed unnecessary imports
48
 *
49
 * Revision 1.21  2007/09/17 09:21:45  jaume
50
 * refactored SymboSelector (added support for multishapedsymbol)
51
 *
52
 * Revision 1.20  2007/08/21 09:32:41  jvidal
53
 * javadoc
54
 *
55
 * Revision 1.19  2007/08/10 06:09:57  jaume
56
 * imports fixed
57
 *
58
 * Revision 1.18  2007/08/10 06:06:05  jaume
59
 * translations and error messages
60
 *
61
 * Revision 1.17  2007/08/03 11:29:13  jaume
62
 * refactored AbstractTypeSymbolEditorPanel class name to AbastractTypeSymbolEditor
63
 *
64
 * Revision 1.16  2007/08/01 13:01:43  jaume
65
 * refactored to be pluggable
66
 *
67
 * Revision 1.15  2007/07/30 12:56:04  jaume
68
 * organize imports, java 5 code downgraded to 1.4 and added PictureFillSymbol
69
 *
70
 * Revision 1.14  2007/07/30 06:59:51  jaume
71
 * finished (maybe) LineFillSymbol
72
 *
73
 * Revision 1.13  2007/07/26 12:28:29  jaume
74
 * maybe finished ArrowMarkerSymbol and ArrowDecoratorStyle
75
 *
76
 * Revision 1.12  2007/07/18 06:56:03  jaume
77
 * continuing with cartographic support
78
 *
79
 * Revision 1.11  2007/07/12 10:43:55  jaume
80
 * *** empty log message ***
81
 *
82
 * Revision 1.10  2007/06/29 13:07:33  jaume
83
 * +PictureLineSymbol
84
 *
85
 * Revision 1.9  2007/05/31 09:36:22  jaume
86
 * *** empty log message ***
87
 *
88
 * Revision 1.8  2007/05/29 15:47:06  jaume
89
 * *** empty log message ***
90
 *
91
 * Revision 1.7  2007/05/09 16:08:14  jaume
92
 * *** empty log message ***
93
 *
94
 * Revision 1.6  2007/05/08 15:44:07  jaume
95
 * *** empty log message ***
96
 *
97
 * Revision 1.5  2007/04/20 07:54:38  jaume
98
 * *** empty log message ***
99
 *
100
 * Revision 1.4  2007/03/28 16:44:08  jaume
101
 * *** empty log message ***
102
 *
103
 * Revision 1.3  2007/03/27 09:49:03  jaume
104
 * *** empty log message ***
105
 *
106
 * Revision 1.2  2007/03/09 11:25:00  jaume
107
 * Advanced symbology (start committing)
108
 *
109
 * Revision 1.1.2.4  2007/02/21 07:35:14  jaume
110
 * *** empty log message ***
111
 *
112
 * Revision 1.1.2.3  2007/02/09 11:00:03  jaume
113
 * *** empty log message ***
114
 *
115
 * Revision 1.1.2.2  2007/02/08 15:43:05  jaume
116
 * some bug fixes in the editor and removed unnecessary imports
117
 *
118
 * Revision 1.1.2.1  2007/01/26 13:49:03  jaume
119
 * *** empty log message ***
120
 *
121
 * Revision 1.1  2007/01/16 11:52:11  jaume
122
 * *** empty log message ***
123
 *
124
 * Revision 1.11  2007/01/10 17:05:05  jaume
125
 * moved to FMap and gvSIG
126
 *
127
 * Revision 1.10  2006/11/13 09:15:23  jaume
128
 * javadoc and some clean-up
129
 *
130
 * Revision 1.9  2006/11/06 17:08:45  jaume
131
 * *** empty log message ***
132
 *
133
 * Revision 1.8  2006/11/06 16:06:52  jaume
134
 * *** empty log message ***
135
 *
136
 * Revision 1.7  2006/11/06 07:33:54  jaume
137
 * javadoc, source style
138
 *
139
 * Revision 1.6  2006/11/02 17:19:28  jaume
140
 * *** empty log message ***
141
 *
142
 * Revision 1.5  2006/10/31 16:16:34  jaume
143
 * *** empty log message ***
144
 *
145
 * Revision 1.4  2006/10/30 19:30:35  jaume
146
 * *** empty log message ***
147
 *
148
 * Revision 1.3  2006/10/29 23:53:49  jaume
149
 * *** empty log message ***
150
 *
151
 * Revision 1.2  2006/10/27 12:41:09  jaume
152
 * GUI
153
 *
154
 * Revision 1.1  2006/10/26 16:31:21  jaume
155
 * GUI
156
 *
157
 *
158
 */
159
package org.gvsig.app.gui.styling;
160

    
161
import java.awt.BorderLayout;
162
import java.awt.Dimension;
163
import java.awt.FlowLayout;
164
import java.awt.event.ActionEvent;
165
import java.awt.event.ActionListener;
166
import java.lang.reflect.Constructor;
167
import java.util.ArrayList;
168
import java.util.Comparator;
169
import java.util.Hashtable;
170
import java.util.TreeSet;
171

    
172
import javax.swing.BorderFactory;
173
import javax.swing.JComboBox;
174
import javax.swing.JLabel;
175
import javax.swing.JPanel;
176
import javax.swing.JTabbedPane;
177

    
178
import org.gvsig.andami.PluginServices;
179
import org.gvsig.andami.messages.NotificationManager;
180
import org.gvsig.andami.ui.mdiManager.IWindow;
181
import org.gvsig.andami.ui.mdiManager.WindowInfo;
182
import org.gvsig.app.gui.JComboBoxUnits;
183
import org.gvsig.fmap.geom.Geometry;
184
import org.gvsig.fmap.mapcontext.MapContextLocator;
185
import org.gvsig.fmap.mapcontext.MapContextManager;
186
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
187
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol;
188
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
189
import org.gvsig.gui.beans.AcceptCancelPanel;
190
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.FSymbol;
191
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.text.impl.SimpleTextSymbol;
192
import org.gvsig.utils.XMLEntity;
193
import org.gvsig.utils.XMLException;
194

    
195

    
196

    
197
/**
198
 * Creates the panel that is used to control the properties of a symbol in
199
 * order to modify or check them and to create a new one.
200
 *
201
 * @author jaume dominguez faus - jaume.dominguez@iver.es
202
 *
203
 */
204
public class SymbolEditor extends JPanel implements IWindow {
205

    
206
        private static Hashtable editorsByType;
207
        private WindowInfo wi;
208
        private JPanel pnlWest = null;
209
        private JPanel pnlCenter = null;
210
        private JPanel pnlPreview = null;
211
        private JPanel pnlLayers = null;
212
        private AcceptCancelPanel okCancelPanel;
213
        private ISymbol symbol;
214
        private SymbolPreviewer symbolPreview = null;
215
        private JPanel pnlTypeAndUnits = null;
216
        private JComboBox cmbType;
217
        private JComboBoxUnits cmbUnits;
218
        private JTabbedPane tabbedPane = null;
219
        private int shapeType;
220
        private ActionListener cmbTypeActionListener;
221

    
222
        private AbstractTypeSymbolEditor[] tabs;
223
        private SymbolLayerManager layerManager;
224
        private boolean replacing = false;
225
        private JComboBoxUnitsReferenceSystem cmbUnitsReferenceSystem;
226
        
227
        private ISymbol oldSymbol;
228
        
229
        private MapContextManager mapContextManager = MapContextLocator
230
                        .getMapContextManager();
231
        /**
232
         * Constructor method
233
         *
234
         * @param symbol ISymbol
235
         * @param shapeType int
236
         */
237
        public SymbolEditor(ISymbol symbol, int shapeType) {
238
//////////        /-------------------------------------
239
                if (shapeType == Geometry.TYPES.TEXT) {
240
                        this.symbol = symbol == null ? new SimpleTextSymbol(): symbol;
241
                } else {
242
//////////        /-------------------------------------
243

    
244
                        if (!(symbol instanceof IMultiLayerSymbol)) {
245
                                // this is a simple symbol (or null one); it will be
246
                                // converted to a multilayer one to accept layer addition
247
                                IMultiLayerSymbol nSym = mapContextManager
248
                                                .createMultiLayerSymbol(shapeType);
249

    
250
                                if (!(symbol instanceof FSymbol)) {
251
                                        nSym.addLayer(symbol);
252
                                }
253

    
254
                                if (symbol instanceof CartographicSupport) {
255
                                        CartographicSupport cs = (CartographicSupport) symbol;
256
                                        CartographicSupport nCs = (CartographicSupport) nSym;
257
                                        nCs.setReferenceSystem(cs.getReferenceSystem());
258
                                        nCs.setUnit(cs.getUnit());
259
                                }
260

    
261
                                this.symbol = nSym;
262
                        } else {
263
                                this.symbol = symbol;
264
                        }
265

    
266
                        // apply units and reference system to comboboxes
267
                        if (this.symbol instanceof CartographicSupport) {
268
                                CartographicSupport cs = (CartographicSupport) this.symbol;
269
                                getCmbUnits().setSelectedUnitIndex(cs.getUnit());
270
                                getCmbUnitsReferenceSystem().
271
                                        setSelectedIndex(cs.getReferenceSystem());
272

    
273
                        }
274

    
275
                }
276
                try {
277
                        this.oldSymbol = (ISymbol) this.symbol.clone();
278
                } catch (CloneNotSupportedException e) {
279
                        NotificationManager.addWarning("Symbol layer", e);
280
                }
281
                this.shapeType = shapeType;
282
                initialize();
283
        }
284

    
285
        /**
286
         * This method initializes this
287
         *
288
         */
289
        private void initialize() {
290

    
291
                cmbTypeActionListener = new ActionListener() {
292
                        int prevIndex = -2;
293

    
294
                        public void actionPerformed(ActionEvent e) {
295
                                int index = getCmbType().getSelectedIndex();
296
                                if (prevIndex != index) {
297
                                        // needs to refresh
298
                                        prevIndex = index;
299

    
300
                                        AbstractTypeSymbolEditor options = (AbstractTypeSymbolEditor) getCmbType()
301
                                                        .getSelectedItem();
302

    
303
//////////                        /-------------------------------------
304
                                        if (layerManager!=null) {
305
//////////                        /-------------------------------------
306
                                                        ISymbol l = layerManager.getSelectedLayer();
307

    
308
                                                // if the symbol is not null and is it managed by the "options" class
309
                                                // refresh the controls
310
                                                if (l != null
311
                                                                && l.getClass().equals(options.getSymbolClass())) {
312
                                                        if (l instanceof CartographicSupport) {
313
                                                                CartographicSupport cs = (CartographicSupport) l;
314
                                                                getCmbUnits().setSelectedUnitIndex(cs.getUnit());
315
                                                                getCmbUnitsReferenceSystem().setSelectedIndex(cs.getReferenceSystem());
316
                                                        }
317
                                                        options.refreshControls(l);
318
                                                }
319

    
320
                                                replaceOptions(options);
321
//////////                        /-------------------------------------
322
                                        } else {
323
                                                replaceOptions(options);
324
                                        }
325
//////////                        /-------------------------------------
326

    
327
                                }
328
                        }
329
                };
330

    
331
                Comparator tabComparator = new Comparator() {
332
                        public int compare(Object o1, Object o2) {
333
                                if (!(o1 instanceof AbstractTypeSymbolEditor || o1 instanceof AbstractTypeSymbolEditor)) {
334
                                        throw new IllegalArgumentException(PluginServices.getText(
335
                                                        this, "trying_to_add_a_non_TypeSymbolEditor_panel"));
336
                                }
337
                                AbstractTypeSymbolEditor pnl1 = (
338
                                                AbstractTypeSymbolEditor) o1, pnl2 = (AbstractTypeSymbolEditor) o2;
339
                                int result = pnl1.getName().compareTo(pnl2.getName());
340
                                if (result == 0) {
341
                                        throw new IllegalArgumentException(PluginServices.getText(
342
                                                        this, "two_panels_with_the_same_name"));
343
                                }
344
                                return result;
345
                        }
346
                };
347

    
348

    
349
                TreeSet set = new TreeSet(tabComparator);
350
                ArrayList editors = (ArrayList) editorsByType.get(new Integer(shapeType));
351
                Class[] constrLocator = new Class[] {SymbolEditor.class};
352
                Object[] constrInitargs = new Object[] { this };
353
                for (int i = 0; i < editors.size(); i++) {
354
                        Class editorClass = (Class) editors.get(i);
355
                        try {
356
                                Constructor c = editorClass.getConstructor(constrLocator);
357
                                set.add(c.newInstance(constrInitargs));
358
                        } catch (Exception e) {
359
                                NotificationManager.addError(PluginServices.getText(this, "failed_installing_symbol_editor")+" "
360
                                                +editorClass.getName(), e);
361
                        }
362
                };
363
                 tabs = (AbstractTypeSymbolEditor[]) set
364
                                .toArray(new AbstractTypeSymbolEditor[0]);
365

    
366
                this.setLayout(new BorderLayout());
367
                this.add(getPnlWest(), BorderLayout.WEST);
368
                this.add(getPnlCenter(), BorderLayout.CENTER);
369
                this.add(getOkCancelPanel(), BorderLayout.SOUTH);
370

    
371
                cmbTypeActionListener.actionPerformed(null);
372
                refresh();
373
        }
374
        /**
375
         * Returns an array of tabs. The value of this array will depend on the
376
         * symbol selected. For example, if the symbol is composed by lines this
377
         * method will return tha tabs that allow the user to modify a simple line
378
         * symbol(in this case simple line and arrow decorator tabs)
379
         * @param sym
380
         * @return tabs[] AbstractTypeSymbolEditor[]
381
         */
382
        private AbstractTypeSymbolEditor getOptionsForSymbol(ISymbol sym) {
383
                if (sym == null) {
384
                        return tabs[0];
385
                }
386
                for (int i = 0; i < tabs.length; i++) {
387
                        if (tabs[i].getSymbolClass().equals(sym.getClass())) {
388
                                return tabs[i];
389
                        }
390
                }
391
                return tabs[0];
392
        }
393
        /**
394
         * Initializes the OkCancel panel where the accept and cancel buttons
395
         * will be placed
396
         * @return okCancelPanel AcceptCancelPanel
397
         */
398
        private AcceptCancelPanel getOkCancelPanel() {
399
                if (okCancelPanel == null) {
400
                        ActionListener action = new ActionListener() {
401
                                public void actionPerformed(ActionEvent e) {
402
                                        if ("CANCEL".equals(e.getActionCommand())) {
403
                                                symbol = oldSymbol;
404
                                        }
405
                                        PluginServices.getMDIManager().closeWindow(
406
                                                        SymbolEditor.this);
407
                                }
408
                        };
409
                        okCancelPanel = new AcceptCancelPanel(action, action);
410
                }
411
                return okCancelPanel;
412
        }
413

    
414
        public WindowInfo getWindowInfo() {
415
                if (wi == null) {
416
                        wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
417
                        wi.setWidth(650);
418
                        wi.setHeight(400);
419
                        wi.setTitle(PluginServices.getText(this, "symbol_property_editor"));
420
                }
421
                return wi;
422
        }
423

    
424
        public ISymbol getSymbol() {
425
                if (symbol instanceof CartographicSupport) {
426
                        CartographicSupport cs = (CartographicSupport) symbol;
427
                        cs.setUnit(getUnit());
428
                        cs.setReferenceSystem(getReferenceSystem());
429
                }
430
//
431
//                if (symbol instanceof MultiLayerLineSymbol) {
432
//                        MultiLayerLineSymbol mLineSym = (MultiLayerLineSymbol) symbol;
433
//                        double lineWidth = 0;
434
//                        for (int i = 0; i < mLineSym.getLayerCount(); i++) {
435
//                                lineWidth = Math.max(lineWidth, ((ILineSymbol) mLineSym.getLayer(i)).getLineWidth());
436
//                        }
437
//
438
//                        if (mLineSym.getLineWidth() != lineWidth)
439
//                                mLineSym.setLineWidth(lineWidth);
440
//                }
441
                return symbol;
442
        }
443
        /**
444
         * Initializes the west panel
445
         * @return
446
         */
447
        private JPanel getPnlWest() {
448
                if (pnlWest == null) {
449
                        pnlWest = new JPanel();
450
                        pnlWest.setLayout(new BorderLayout());
451
                        pnlWest.add(getPnlPreview(), java.awt.BorderLayout.NORTH);
452
//////////        /-------------------------------------
453
                        if (symbol instanceof IMultiLayerSymbol) {
454
//////////                /-------------------------------------
455

    
456

    
457
                                pnlWest.add(getPnlLayers(), java.awt.BorderLayout.SOUTH);
458

    
459
//////////                /-------------------------------------
460
                        } // otherwise, no layer manager needed
461
//////////        /-------------------------------------
462
                }
463
                return pnlWest;
464
        }
465
        /**
466
         * Initializes the center panel that shows the properties of a symbol.
467
         *
468
         * @return pnlCenter JPanel
469
         */
470
        private JPanel getPnlCenter() {
471
                if (pnlCenter == null) {
472
                        pnlCenter = new JPanel(new BorderLayout());
473
                        pnlCenter.setBorder(BorderFactory.createTitledBorder(null,
474
                                        PluginServices.getText(this, "properties")));
475
                        pnlCenter.add(getPnlTypeAndUnits(), java.awt.BorderLayout.NORTH);
476
                }
477
                return pnlCenter;
478
        }
479
        /**
480
         * Initializes the preview panel that allows the user to see a previsualization
481
         * of the final symbol
482
         *
483
         * @return pnlPreview JPanel
484
         */
485
        private JPanel getPnlPreview() {
486
                if (pnlPreview == null) {
487
                        pnlPreview = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
488
                        pnlPreview.setBorder(BorderFactory.createTitledBorder(null,
489
                                        PluginServices.getText(this, "preview")));
490
                        pnlPreview.add(getSymbolPreviewer());
491
                }
492
                return pnlPreview;
493
        }
494
        /**
495
         * Initializes the Layers panel that shows the different layers created that
496
         * compose a symbol.
497
         * @return pnlLayers JPanel
498
         */
499
        private JPanel getPnlLayers() {
500
                if (pnlLayers == null) {
501
                        pnlLayers = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
502
                        pnlLayers.setBorder(BorderFactory.createTitledBorder(null,
503
                                        PluginServices.getText(this, "layers")));
504
                        pnlLayers.add(getLayerManager());
505
                }
506
                return pnlLayers;
507
        }
508
        /**
509
         * Obtains the layer manager used in the panel that shows the different layers
510
         * that compose the symbol.
511
         *
512
         * @return layerManager SymbolLayerManager
513
         */
514
        private SymbolLayerManager getLayerManager() {
515
                if (layerManager == null) {
516
                        layerManager = new SymbolLayerManager(this);
517
                }
518
                return layerManager;
519
        }
520
        /**
521
         * Obtains the symbol previewer used in the panel that shows the previsualization
522
         * of the final symbol.
523
         *
524
         * @return symbolPreview getSymbolPreviewer
525
         */
526
        private SymbolPreviewer getSymbolPreviewer() {
527
                if (symbolPreview == null) {
528
                        symbolPreview = new SymbolPreviewer();
529
                        symbolPreview.setPreferredSize(new Dimension(150, 100));
530

    
531
                }
532
                return symbolPreview;
533
        }
534
        /**
535
         * Initializes the type and units panel where two Jcomboboxes will be placed
536
         * in order to change the type and the units used in the map.
537
         *
538
         * @return pnlTypeAndUnits JPanel
539
         */
540
        private JPanel getPnlTypeAndUnits() {
541
                if (pnlTypeAndUnits == null) {
542
                        pnlTypeAndUnits = new JPanel();
543
                        pnlTypeAndUnits.setLayout(new BorderLayout());
544
                        JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING));
545
                        aux.add(new JLabel(PluginServices.getText(this, "type")));
546
                        aux.add(getCmbType());
547
                        pnlTypeAndUnits.add(aux, BorderLayout.WEST);
548

    
549
                        aux = new JPanel(new FlowLayout(FlowLayout.LEADING));
550
                        aux.add(new JLabel(PluginServices.getText(this, "units")));
551
                        aux.add(getCmbUnits());
552
                        aux.add(getCmbUnitsReferenceSystem());
553
                        pnlTypeAndUnits.add(aux, BorderLayout.EAST);
554

    
555
                }
556
                return pnlTypeAndUnits;
557
        }
558
        /**
559
         * Obtains the JCombobox to select the reference unit to be used in the
560
         * final representation of the map in this case there are two options (in
561
         * the paper and in the map).
562
         * @return
563
         */
564
        private JComboBoxUnitsReferenceSystem getCmbUnitsReferenceSystem() {
565
                if (cmbUnitsReferenceSystem == null) {
566
                        cmbUnitsReferenceSystem = new JComboBoxUnitsReferenceSystem();
567

    
568
                }
569

    
570
                return cmbUnitsReferenceSystem;
571
        }
572
        /**
573
         * Returns the Jcombobox used to select the reference unit (centimeters,
574
         * milimeters and so on) to be used in the final representation of the map.
575
         *
576
         * @return cmbUnits JUnitsComboBox
577
         */
578
        private JComboBoxUnits getCmbUnits() {
579
                if (cmbUnits == null) {
580
                        cmbUnits = new JComboBoxUnits();
581
                }
582
                return cmbUnits;
583
        }
584
        /**
585
         * Returns the option selected in the reference unit Jcombobox
586
         *
587
         */
588
        public int getUnit() {
589
                return getCmbUnits().getSelectedUnitIndex();
590
        }
591

    
592
        public int getReferenceSystem() {
593
                return getCmbUnitsReferenceSystem().getSelectedIndex();
594
        }
595
        /**
596
         * Returns the Jcombobox used in the panel to select the type of symbol.
597
         *
598
         * @return cmbType JComboBox
599
         */
600
        private JComboBox getCmbType() {
601
                if (cmbType == null) {
602
                        cmbType = new JComboBox(tabs);
603
                        cmbType.addActionListener(cmbTypeActionListener);
604
                }
605
                return cmbType;
606
        }
607
        /**
608
         * Sets a layer to a symbol in order to create a final symbol composed
609
         * by different layers.
610
         *
611
         * @param layer
612
         */
613
        protected void setLayerToSymbol(ISymbol layer) {
614
                int i = getLayerManager().getSelectedLayerIndex();
615
                IMultiLayerSymbol s = (IMultiLayerSymbol) symbol;
616
                if (i >= 0 && i < s.getLayerCount()) {
617
                        s.setLayer(s.getLayerCount() - 1 - i, layer);
618

    
619
                }
620
                refresh();
621
        }
622

    
623
        public void refresh() {
624
                getSymbolPreviewer().setSymbol(symbol);
625
                doLayout();
626
                repaint();
627
        }
628

    
629
        /**
630
         * <p>
631
         * Returns the type of the symbol that this panels is created for.<br>
632
         * </p>
633
         * <p>
634
         * Possible values returned by this method are
635
         * <ol>
636
         * <li> <b> Geometry.TYPES.POINT </b>, for maker symbols </li>
637
         * <li> <b> Geometry.TYPES.SURFACE </b>, for fill symbols </li>
638
         * <li> <b> Geometry.TYPES.CURVE </b>, for line symbols (not yet implemented) </li>
639
         * <li> <b> Geometry.TYPES.TEXT </b>, for text symbols (not yet implemented) </li>
640
         * <li> maybe some other in the future </li>
641
         * </ol>
642
         * </p>
643
         *
644
         * @return
645
         */
646
        public int getShapeType() {
647
                return shapeType;
648
        }
649
        /**
650
         * Obtains a new layer
651
         *
652
         * @return sym ISymbol
653
         */
654
        public ISymbol getNewLayer() {
655
                ISymbol sym = ((AbstractTypeSymbolEditor) getCmbType().getSelectedItem())
656
                                .getLayer();
657

    
658
                return sym;
659
        }
660

    
661
        private void replaceOptions(AbstractTypeSymbolEditor options) {
662
                if (!replacing) {
663
                        replacing = true;
664
                        if (tabbedPane != null) {
665
                                getPnlCenter().remove(tabbedPane);
666
                        }
667
                        JPanel[] tabs = options.getTabs();
668
                        tabbedPane = new JTabbedPane();
669
                        tabbedPane.setPreferredSize(new Dimension(300, 300));
670
                        for (int i = 0; i < tabs.length; i++) {
671
                                tabbedPane.addTab(tabs[i].getName(), tabs[i]);
672
                        }
673
                        getPnlCenter().add(tabbedPane, BorderLayout.CENTER);
674
                        getPnlCenter().doLayout();
675
                        replacing = false;
676
                }
677
        }
678

    
679

    
680
        public void setOptionsPageFor(ISymbol symbol) {
681
                AbstractTypeSymbolEditor options = getOptionsForSymbol(symbol);
682

    
683
                options.refreshControls(symbol);
684
                getCmbType().setSelectedItem(options);
685
        }
686
        /**
687
         * Obtains the units to be used for the reference system.
688
         *
689
         */
690
        public int getUnitsReferenceSystem() {
691
                return cmbUnitsReferenceSystem.getSelectedIndex();
692
        }
693

    
694
        public static void addSymbolEditorPanel(Class abstractTypeSymbolEditorPanelClass, int shapeType) {
695
                if (editorsByType == null) {
696
                        editorsByType = new Hashtable();
697
                }
698

    
699
                Integer key = new Integer(shapeType);
700
                ArrayList l = (ArrayList) editorsByType.get(key);
701
                if (l == null) {
702
                        l = new ArrayList();
703
                }
704
                l.add(abstractTypeSymbolEditorPanelClass);
705

    
706
                editorsByType.put(key, l);
707
        }
708

    
709
        public Object getWindowProfile() {
710
                return WindowInfo.DIALOG_PROFILE;
711
        }
712

    
713
}