Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.library / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / SymbolEditor.java @ 40560

History | View | Annotate | Download (21.4 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/* CVS MESSAGES:
25
 *
26
 * $Id: SymbolEditor.java 30892 2009-09-21 12:02:19Z cordinyana $
27
 * $Log$
28
 * Revision 1.22  2007-09-19 15:36:36  jaume
29
 * removed unnecessary imports
30
 *
31
 * Revision 1.21  2007/09/17 09:21:45  jaume
32
 * refactored SymboSelector (added support for multishapedsymbol)
33
 *
34
 * Revision 1.20  2007/08/21 09:32:41  jvidal
35
 * javadoc
36
 *
37
 * Revision 1.19  2007/08/10 06:09:57  jaume
38
 * imports fixed
39
 *
40
 * Revision 1.18  2007/08/10 06:06:05  jaume
41
 * translations and error messages
42
 *
43
 * Revision 1.17  2007/08/03 11:29:13  jaume
44
 * refactored AbstractTypeSymbolEditorPanel class name to AbastractTypeSymbolEditor
45
 *
46
 * Revision 1.16  2007/08/01 13:01:43  jaume
47
 * refactored to be pluggable
48
 *
49
 * Revision 1.15  2007/07/30 12:56:04  jaume
50
 * organize imports, java 5 code downgraded to 1.4 and added PictureFillSymbol
51
 *
52
 * Revision 1.14  2007/07/30 06:59:51  jaume
53
 * finished (maybe) LineFillSymbol
54
 *
55
 * Revision 1.13  2007/07/26 12:28:29  jaume
56
 * maybe finished ArrowMarkerSymbol and ArrowDecoratorStyle
57
 *
58
 * Revision 1.12  2007/07/18 06:56:03  jaume
59
 * continuing with cartographic support
60
 *
61
 * Revision 1.11  2007/07/12 10:43:55  jaume
62
 * *** empty log message ***
63
 *
64
 * Revision 1.10  2007/06/29 13:07:33  jaume
65
 * +PictureLineSymbol
66
 *
67
 * Revision 1.9  2007/05/31 09:36:22  jaume
68
 * *** empty log message ***
69
 *
70
 * Revision 1.8  2007/05/29 15:47:06  jaume
71
 * *** empty log message ***
72
 *
73
 * Revision 1.7  2007/05/09 16:08:14  jaume
74
 * *** empty log message ***
75
 *
76
 * Revision 1.6  2007/05/08 15:44:07  jaume
77
 * *** empty log message ***
78
 *
79
 * Revision 1.5  2007/04/20 07:54:38  jaume
80
 * *** empty log message ***
81
 *
82
 * Revision 1.4  2007/03/28 16:44:08  jaume
83
 * *** empty log message ***
84
 *
85
 * Revision 1.3  2007/03/27 09:49:03  jaume
86
 * *** empty log message ***
87
 *
88
 * Revision 1.2  2007/03/09 11:25:00  jaume
89
 * Advanced symbology (start committing)
90
 *
91
 * Revision 1.1.2.4  2007/02/21 07:35:14  jaume
92
 * *** empty log message ***
93
 *
94
 * Revision 1.1.2.3  2007/02/09 11:00:03  jaume
95
 * *** empty log message ***
96
 *
97
 * Revision 1.1.2.2  2007/02/08 15:43:05  jaume
98
 * some bug fixes in the editor and removed unnecessary imports
99
 *
100
 * Revision 1.1.2.1  2007/01/26 13:49:03  jaume
101
 * *** empty log message ***
102
 *
103
 * Revision 1.1  2007/01/16 11:52:11  jaume
104
 * *** empty log message ***
105
 *
106
 * Revision 1.11  2007/01/10 17:05:05  jaume
107
 * moved to FMap and gvSIG
108
 *
109
 * Revision 1.10  2006/11/13 09:15:23  jaume
110
 * javadoc and some clean-up
111
 *
112
 * Revision 1.9  2006/11/06 17:08:45  jaume
113
 * *** empty log message ***
114
 *
115
 * Revision 1.8  2006/11/06 16:06:52  jaume
116
 * *** empty log message ***
117
 *
118
 * Revision 1.7  2006/11/06 07:33:54  jaume
119
 * javadoc, source style
120
 *
121
 * Revision 1.6  2006/11/02 17:19:28  jaume
122
 * *** empty log message ***
123
 *
124
 * Revision 1.5  2006/10/31 16:16:34  jaume
125
 * *** empty log message ***
126
 *
127
 * Revision 1.4  2006/10/30 19:30:35  jaume
128
 * *** empty log message ***
129
 *
130
 * Revision 1.3  2006/10/29 23:53:49  jaume
131
 * *** empty log message ***
132
 *
133
 * Revision 1.2  2006/10/27 12:41:09  jaume
134
 * GUI
135
 *
136
 * Revision 1.1  2006/10/26 16:31:21  jaume
137
 * GUI
138
 *
139
 *
140
 */
141
package org.gvsig.app.gui.styling;
142

    
143
import java.awt.BorderLayout;
144
import java.awt.Dimension;
145
import java.awt.FlowLayout;
146
import java.awt.event.ActionEvent;
147
import java.awt.event.ActionListener;
148
import java.lang.reflect.Constructor;
149
import java.util.ArrayList;
150
import java.util.Comparator;
151
import java.util.Hashtable;
152
import java.util.Iterator;
153
import java.util.List;
154
import java.util.TreeSet;
155

    
156
import javax.swing.BorderFactory;
157
import javax.swing.JComboBox;
158
import javax.swing.JLabel;
159
import javax.swing.JPanel;
160
import javax.swing.JTabbedPane;
161

    
162
import org.slf4j.Logger;
163
import org.slf4j.LoggerFactory;
164

    
165
import org.gvsig.andami.PluginServices;
166
import org.gvsig.andami.messages.NotificationManager;
167
import org.gvsig.andami.ui.mdiManager.IWindow;
168
import org.gvsig.andami.ui.mdiManager.WindowInfo;
169
import org.gvsig.app.gui.JComboBoxUnits;
170
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
171
import org.gvsig.fmap.geom.GeometryLocator;
172
import org.gvsig.fmap.geom.GeometryManager;
173
import org.gvsig.fmap.geom.type.GeometryType;
174
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
175
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
176
import org.gvsig.fmap.mapcontext.MapContextLocator;
177
import org.gvsig.fmap.mapcontext.MapContextManager;
178
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
179
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol;
180
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
181
import org.gvsig.gui.beans.AcceptCancelPanel;
182
import org.gvsig.i18n.Messages;
183

    
184
/**
185
 * Creates the panel that is used to control the properties of a symbol in
186
 * order to modify or check them and to create a new one.
187
 *
188
 * @author jaume dominguez faus - jaume.dominguez@iver.es
189
 *
190
 */
191
public class SymbolEditor extends JPanel implements IWindow {
192
        private static final long serialVersionUID = 9209260593958625497L;
193
        
194
        private static final GeometryManager GEOMETRY_MANAGER = 
195
            GeometryLocator.getGeometryManager();
196
        
197
        private static final Logger LOG =
198
            LoggerFactory.getLogger(SymbolEditor.class);
199
        
200
        private static Hashtable editorsByType;
201
        private WindowInfo wi;
202
        private JPanel pnlWest = null;
203
        private JPanel pnlCenter = null;
204
        private JPanel pnlPreview = null;
205
        private JPanel pnlLayers = null;
206
        private AcceptCancelPanel okCancelPanel;
207
        private ISymbol symbol;
208
        private SymbolPreviewer symbolPreview = null;
209
        private JPanel pnlTypeAndUnits = null;
210
        private JComboBox cmbType;
211
        private JComboBoxUnits cmbUnits;
212
        private JTabbedPane tabbedPane = null;
213
        private GeometryType shapeType;
214
        private ActionListener cmbTypeActionListener;
215

    
216
        private AbstractTypeSymbolEditor[] tabs;
217
        private SymbolLayerManager layerManager;
218
        private boolean replacing = false;
219
        private JComboBoxUnitsReferenceSystem cmbUnitsReferenceSystem;
220
        
221
        private ISymbol oldSymbol;
222
        
223
        private MapContextManager mapContextManager = MapContextLocator
224
                        .getMapContextManager();
225
        
226
        
227
        public SymbolEditor(ISymbol symbol, GeometryType geometryType) {
228
            super();
229
            initialize(symbol, geometryType);
230
        }        
231
        
232
        public SymbolEditor(ISymbol symbol, int shapeType) {
233
            super();
234
            try {
235
            GeometryType geometryType = GEOMETRY_MANAGER.getGeometryType(shapeType, SUBTYPES.GEOM2D);
236
            initialize(symbol, geometryType);
237
        } catch (GeometryTypeNotSupportedException e1) {
238
            LOG.error("Impossible to get the geometry type", e1);
239
        } catch (GeometryTypeNotValidException e1) {
240
            LOG.error("Impossible to get the geometry type", e1);
241
        }           
242
        }   
243
            
244
        
245
        /**
246
         * Constructor method
247
         *
248
         * @param symbol ISymbol
249
         * @param shapeType int
250
         */
251
        private void initialize(ISymbol symbol, GeometryType shapeType) {
252
//////////        /-------------------------------------
253
//      removing the Geometry.TYPES.TEXT: this code can not be executed
254
//                if (shapeType == Geometry.TYPES.TEXT) {
255
////                        this.symbol = symbol == null ? new SimpleTextSymbol(): symbol;
256
//                        this.symbol = symbol == null ? SymbologyLocator.getSymbologyManager().createSimpleTextSymbol(): symbol;
257
//                } else {
258
//////////        /-------------------------------------
259

    
260
                        if (!(symbol instanceof IMultiLayerSymbol)) {
261
                                // this is a simple symbol (or null one); it will be
262
                                // converted to a multilayer one to accept layer addition
263
                                IMultiLayerSymbol nSym =
264
                                                mapContextManager.getSymbolManager()
265
                                                .createMultiLayerSymbol(shapeType.getType());
266

    
267
//                                if (!(symbol instanceof FSymbol)) {
268
                                        nSym.addLayer(symbol);
269
//                                }
270

    
271
                                if (symbol instanceof CartographicSupport) {
272
                                        CartographicSupport cs = (CartographicSupport) symbol;
273
                                        CartographicSupport nCs = (CartographicSupport) nSym;
274
                                        nCs.setReferenceSystem(cs.getReferenceSystem());
275
                                        nCs.setUnit(cs.getUnit());
276
                                }
277

    
278
                                this.symbol = nSym;
279
                        } else {
280
                                this.symbol = symbol;
281
                        }
282

    
283
                        // apply units and reference system to comboboxes
284
                        if (this.symbol instanceof CartographicSupport) {
285
                                CartographicSupport cs = (CartographicSupport) this.symbol;
286
                                getCmbUnits().setSelectedUnitIndex(cs.getUnit());
287
                                getCmbUnitsReferenceSystem().
288
                                        setSelectedIndex(cs.getReferenceSystem());
289

    
290
                        }
291

    
292
//                }
293
                try {
294
                        this.oldSymbol = (ISymbol) this.symbol.clone();
295
                } catch (CloneNotSupportedException e) {
296
                        NotificationManager.addWarning("Symbol layer", e);
297
                }
298
                this.shapeType = shapeType;
299
                initialize();
300
        }
301

    
302
        /**
303
         * This method initializes this
304
         *
305
         */
306
        private void initialize() {
307

    
308
                cmbTypeActionListener = new ActionListener() {
309
                        int prevIndex = -2;
310

    
311
                        public void actionPerformed(ActionEvent e) {
312
                                int index = getCmbType().getSelectedIndex();
313
                                if (prevIndex != index) {
314
                                        // needs to refresh
315
                                        prevIndex = index;
316

    
317
                                        AbstractTypeSymbolEditor options = (AbstractTypeSymbolEditor) getCmbType()
318
                                                        .getSelectedItem();
319

    
320
//////////                        /-------------------------------------
321
                                        if (layerManager!=null) {
322
//////////                        /-------------------------------------
323
                                                        ISymbol l = layerManager.getSelectedLayer();
324

    
325
                                                // if the symbol is not null and is it managed by the "options" class
326
                                                // refresh the controls
327
                                                if (l != null
328
//                                                                && l.getClass().equals(options.getSymbolClass())) {
329
                                                                && options.canManageSymbol(l)) {
330
                                                        if (l instanceof CartographicSupport) {
331
                                                                CartographicSupport cs = (CartographicSupport) l;
332
                                                                getCmbUnits().setSelectedUnitIndex(cs.getUnit());
333
                                                                getCmbUnitsReferenceSystem().setSelectedIndex(cs.getReferenceSystem());
334
                                                        }
335
                                                        options.refreshControls(l);
336
                                                }
337

    
338
                                                replaceOptions(options);
339
//////////                        /-------------------------------------
340
                                        } else {
341
                                                replaceOptions(options);
342
                                        }
343
//////////                        /-------------------------------------
344

    
345
                                }
346
                        }
347
                };
348

    
349
                Comparator tabComparator = new Comparator() {
350
                        public int compare(Object o1, Object o2) {
351
                                AbstractTypeSymbolEditor pnl1 = (AbstractTypeSymbolEditor) o1;
352
                                AbstractTypeSymbolEditor pnl2 = (AbstractTypeSymbolEditor) o2;
353
                                int result = pnl1.getName().compareTo(pnl2.getName());
354
                                return result;
355
                        }
356
                };
357

    
358

    
359
                TreeSet set = new TreeSet(tabComparator);
360
                List editors = getSymbolsByType(shapeType);
361
                Class[] constrLocator = new Class[] {SymbolEditor.class};
362
                Object[] constrInitargs = new Object[] { this };
363
                for (int i = 0; i < editors.size(); i++) {
364
                        Class editorClass = (Class) editors.get(i);
365
                        try {
366
                                Constructor c = editorClass.getConstructor(constrLocator);
367
                                AbstractTypeSymbolEditor instance = (AbstractTypeSymbolEditor) c.newInstance(constrInitargs); 
368
                                set.add(instance);
369
                        } catch (Exception e) {
370
                                NotificationManager.addError(Messages.getText("failed_installing_symbol_editor")+" "
371
                                                +editorClass.getName(), e);
372
                        }
373
                };
374
                 tabs = (AbstractTypeSymbolEditor[]) set
375
                                .toArray(new AbstractTypeSymbolEditor[0]);
376

    
377
                this.setLayout(new BorderLayout());
378
                this.add(getPnlWest(), BorderLayout.WEST);
379
                this.add(getPnlCenter(), BorderLayout.CENTER);
380
                this.add(getOkCancelPanel(), BorderLayout.SOUTH);
381

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

    
426
        public WindowInfo getWindowInfo() {
427
                if (wi == null) {
428
                        wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
429
                        wi.setWidth(650);
430
                        wi.setHeight(400);
431
                        wi.setTitle(Messages.getText("symbol_property_editor"));
432
                }
433
                return wi;
434
        }
435

    
436
        public ISymbol getSymbol() {
437
                if (symbol instanceof CartographicSupport) {
438
                        CartographicSupport cs = (CartographicSupport) symbol;
439
                        cs.setUnit(getUnit());
440
                        cs.setReferenceSystem(getReferenceSystem());
441
                }
442
//
443
//                if (symbol instanceof MultiLayerLineSymbol) {
444
//                        MultiLayerLineSymbol mLineSym = (MultiLayerLineSymbol) symbol;
445
//                        double lineWidth = 0;
446
//                        for (int i = 0; i < mLineSym.getLayerCount(); i++) {
447
//                                lineWidth = Math.max(lineWidth, ((ILineSymbol) mLineSym.getLayer(i)).getLineWidth());
448
//                        }
449
//
450
//                        if (mLineSym.getLineWidth() != lineWidth)
451
//                                mLineSym.setLineWidth(lineWidth);
452
//                }
453
                return symbol;
454
        }
455
        /**
456
         * Initializes the west panel
457
         * @return
458
         */
459
        private JPanel getPnlWest() {
460
                if (pnlWest == null) {
461
                        pnlWest = new JPanel();
462
                        pnlWest.setLayout(new BorderLayout());
463
                        pnlWest.add(getPnlPreview(), java.awt.BorderLayout.NORTH);
464
//////////        /-------------------------------------
465
                        if (symbol instanceof IMultiLayerSymbol) {
466
//////////                /-------------------------------------
467

    
468

    
469
                                pnlWest.add(getPnlLayers(), java.awt.BorderLayout.SOUTH);
470

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

    
543
                }
544
                return symbolPreview;
545
        }
546
        /**
547
         * Initializes the type and units panel where two Jcomboboxes will be placed
548
         * in order to change the type and the units used in the map.
549
         *
550
         * @return pnlTypeAndUnits JPanel
551
         */
552
        private JPanel getPnlTypeAndUnits() {
553
                if (pnlTypeAndUnits == null) {
554
                        pnlTypeAndUnits = new JPanel();
555
                        pnlTypeAndUnits.setLayout(new BorderLayout());
556
                        JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING));
557
                        aux.add(new JLabel(Messages.getText("type")));
558
                        aux.add(getCmbType());
559
                        pnlTypeAndUnits.add(aux, BorderLayout.WEST);
560

    
561
                        aux = new JPanel(new FlowLayout(FlowLayout.LEADING));
562
                        aux.add(new JLabel(Messages.getText("units")));
563
                        aux.add(getCmbUnits());
564
                        aux.add(getCmbUnitsReferenceSystem());
565
                        pnlTypeAndUnits.add(aux, BorderLayout.EAST);
566

    
567
                }
568
                return pnlTypeAndUnits;
569
        }
570
        /**
571
         * Obtains the JCombobox to select the reference unit to be used in the
572
         * final representation of the map in this case there are two options (in
573
         * the paper and in the map).
574
         * @return
575
         */
576
        private JComboBoxUnitsReferenceSystem getCmbUnitsReferenceSystem() {
577
                if (cmbUnitsReferenceSystem == null) {
578
                        cmbUnitsReferenceSystem = new JComboBoxUnitsReferenceSystem();
579

    
580
                }
581

    
582
                return cmbUnitsReferenceSystem;
583
        }
584
        /**
585
         * Returns the Jcombobox used to select the reference unit (centimeters,
586
         * milimeters and so on) to be used in the final representation of the map.
587
         *
588
         * @return cmbUnits JUnitsComboBox
589
         */
590
        private JComboBoxUnits getCmbUnits() {
591
                if (cmbUnits == null) {
592
                        cmbUnits = new JComboBoxUnits();
593
                }
594
                return cmbUnits;
595
        }
596
        /**
597
         * Returns the option selected in the reference unit Jcombobox
598
         *
599
         */
600
        public int getUnit() {
601
                return getCmbUnits().getSelectedUnitIndex();
602
        }
603

    
604
        public int getReferenceSystem() {
605
                return getCmbUnitsReferenceSystem().getSelectedIndex();
606
        }
607
        /**
608
         * Returns the Jcombobox used in the panel to select the type of symbol.
609
         *
610
         * @return cmbType JComboBox
611
         */
612
        private JComboBox getCmbType() {
613
                if (cmbType == null) {
614
                        cmbType = new JComboBox(tabs);
615
                        cmbType.addActionListener(cmbTypeActionListener);
616
                }
617
                return cmbType;
618
        }
619
        /**
620
         * Sets a layer to a symbol in order to create a final symbol composed
621
         * by different layers.
622
         *
623
         * @param layer
624
         */
625
        protected void setLayerToSymbol(ISymbol layer) {
626
                int i = getLayerManager().getSelectedLayerIndex();
627
                IMultiLayerSymbol s = (IMultiLayerSymbol) symbol;
628
                if (i >= 0 && i < s.getLayerCount()) {
629
                        s.setLayer(s.getLayerCount() - 1 - i, layer);
630

    
631
                }
632
                refresh();
633
        }
634

    
635
        public void refresh() {
636
                getSymbolPreviewer().setSymbol(symbol);
637
                doLayout();
638
                repaint();
639
        }
640

    
641
        /**
642
         * <p>
643
         * Returns the type of the symbol that this panels is created for.<br>
644
         * </p>
645
         * <p>
646
         * Possible values returned by this method are
647
         * <ol>
648
         * <li> <b> Geometry.TYPES.POINT </b>, for maker symbols </li>
649
         * <li> <b> Geometry.TYPES.SURFACE </b>, for fill symbols </li>
650
         * <li> <b> Geometry.TYPES.CURVE </b>, for line symbols (not yet implemented) </li>
651
         * <li> <b> Geometry.TYPES.TEXT </b>, for text symbols (not yet implemented) </li>
652
         * <li> maybe some other in the future </li>
653
         * </ol>
654
         * </p>
655
         *
656
         * @return
657
         */
658
        public int getShapeType() {
659
                return shapeType.getType();
660
        }
661
        /**
662
         * Obtains a new layer
663
         *
664
         * @return sym ISymbol
665
         */
666
        public ISymbol getNewLayer() {
667
                ISymbol sym = ((AbstractTypeSymbolEditor) getCmbType().getSelectedItem())
668
                                .getLayer();
669

    
670
                return sym;
671
        }
672

    
673
        private void replaceOptions(AbstractTypeSymbolEditor options) {
674
                if (!replacing) {
675
                        replacing = true;
676
                        if (tabbedPane != null) {
677
                                getPnlCenter().remove(tabbedPane);
678
                        }
679
                        JPanel[] tabs = options.getTabs();
680
                        tabbedPane = new JTabbedPane();
681
                        tabbedPane.setPreferredSize(new Dimension(300, 300));
682
                        for (int i = 0; i < tabs.length; i++) {
683
                                tabbedPane.addTab(tabs[i].getName(), tabs[i]);
684
                        }
685
                        getPnlCenter().add(tabbedPane, BorderLayout.CENTER);
686
                        getPnlCenter().doLayout();
687
                        replacing = false;
688
                }
689
        }
690

    
691

    
692
        public void setOptionsPageFor(ISymbol symbol) {
693
                AbstractTypeSymbolEditor options = getOptionsForSymbol(symbol);
694

    
695
                options.refreshControls(symbol);
696
                getCmbType().setSelectedItem(options);
697
        }
698
        /**
699
         * Obtains the units to be used for the reference system.
700
         *
701
         */
702
        public int getUnitsReferenceSystem() {
703
                return cmbUnitsReferenceSystem.getSelectedIndex();
704
        }
705

    
706
        public static void addSymbolEditorPanel(Class abstractTypeSymbolEditorPanelClass, int shapeType) {
707
                if (editorsByType == null) {
708
                        editorsByType = new Hashtable();
709
                }
710

    
711
                Integer key = new Integer(shapeType);
712
                ArrayList l = (ArrayList) editorsByType.get(key);
713
                if (l == null) {
714
                        l = new ArrayList();
715
                }
716
                l.add(abstractTypeSymbolEditorPanelClass);
717

    
718
                editorsByType.put(key, l);
719
        }
720
        
721
        private static List getSymbolsByType(GeometryType geometryType){
722
            Iterator it = editorsByType.keySet().iterator();
723
            while (it.hasNext()){
724
                int currentType = (Integer)it.next();
725
                if (geometryType.isTypeOf(currentType)){
726
                    return (List)editorsByType.get(currentType);
727
                }
728
            }
729
            return new ArrayList();
730
        }
731

    
732
        public Object getWindowProfile() {
733
                return WindowInfo.DIALOG_PROFILE;
734
        }
735

    
736
}