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 / SymbolSelector.java @ 42455

History | View | Annotate | Download (37.7 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
package org.gvsig.app.gui.styling;
25

    
26
import java.awt.BorderLayout;
27
import java.awt.Color;
28
import java.awt.Component;
29
import java.awt.Dimension;
30
import java.awt.FlowLayout;
31
import java.awt.Font;
32
import java.awt.GridLayout;
33
import java.awt.Point;
34
import java.awt.event.ActionEvent;
35
import java.awt.event.ActionListener;
36
import java.awt.event.InputEvent;
37
import java.awt.event.MouseEvent;
38
import java.awt.event.MouseListener;
39
import java.awt.event.MouseMotionListener;
40
import java.io.File;
41

    
42
import javax.swing.BorderFactory;
43
import javax.swing.BoxLayout;
44
import javax.swing.JComponent;
45
import javax.swing.JLabel;
46
import javax.swing.JList;
47
import javax.swing.JPanel;
48
import javax.swing.JScrollPane;
49
import javax.swing.JSplitPane;
50
import javax.swing.JTextField;
51
import javax.swing.JToggleButton;
52
import javax.swing.ListCellRenderer;
53
import javax.swing.ListModel;
54
import javax.swing.event.ListSelectionEvent;
55
import javax.swing.event.ListSelectionListener;
56
import javax.swing.event.TreeSelectionListener;
57
import javax.swing.tree.DefaultMutableTreeNode;
58
import org.apache.commons.lang3.StringUtils;
59

    
60
import org.slf4j.Logger;
61
import org.slf4j.LoggerFactory;
62
import org.gvsig.andami.PluginServices;
63
import org.gvsig.andami.messages.NotificationManager;
64
import org.gvsig.andami.ui.mdiManager.WindowInfo;
65
import org.gvsig.app.gui.JComboBoxUnits;
66
import org.gvsig.app.gui.panels.ColorChooserPanel;
67
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector;
68
import org.gvsig.fmap.geom.Geometry;
69
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
70
import org.gvsig.fmap.geom.Geometry.TYPES;
71
import org.gvsig.fmap.geom.GeometryLocator;
72
import org.gvsig.fmap.geom.GeometryManager;
73
import org.gvsig.fmap.geom.exception.CreateGeometryException;
74
import org.gvsig.fmap.geom.type.GeometryType;
75
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
76
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
77
import org.gvsig.fmap.mapcontext.MapContextLocator;
78
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
79
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol;
80
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
81
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol_v2;
82
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol;
83
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager;
84
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolPreferences;
85
import org.gvsig.gui.beans.AcceptCancelPanel;
86
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
87
import org.gvsig.gui.beans.swing.JButton;
88
import org.gvsig.gui.beans.swing.JComboBoxFontSizes;
89
import org.gvsig.gui.beans.swing.JComboBoxFonts;
90
import org.gvsig.gui.beans.swing.JFileChooser;
91
import org.gvsig.gui.beans.swing.JNumberSpinner;
92
import org.gvsig.i18n.Messages;
93
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
94
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IMultiLayerFillSymbol;
95
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
96
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.IMultiLayerLineSymbol;
97
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
98
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMultiLayerMarkerSymbol;
99
import org.gvsig.tools.dispose.Disposable;
100

    
101

    
102
/**
103
 * Creates the panel where the user has the options to select a symbol.
104
 * Apart from the option to select one, the user will have a previsualization
105
 * of all the symbols stored and posibilities to modify an existing one, to create
106
 * a new symbol and so on.
107
 *
108
 * @author jaume dominguez faus - jaume.dominguez@iver.es
109
 */
110
public class SymbolSelector extends JPanel implements ISymbolSelector, ActionListener {
111
        private static final long serialVersionUID = -6405660392303659551L;
112
        private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
113
        private static final Logger logger = LoggerFactory.getLogger(SymbolSelector.class);
114
        private JPanel jPanel = null;
115
        protected JScrollPane jScrollPane = null;
116
        private JScrollPane jScrollPane1 = null;
117
        private WindowInfo wi;
118
        private JSplitPane jSplitPane = null;
119
        protected AcceptCancelPanel okCancelPanel;
120
        private JPanel northPanel;
121
        private ColorChooserPanel jcc1;
122
        private ColorChooserPanel jcc2;
123
        private JNumberSpinner txtSize;
124
        private JNumberSpinner txtAngle;
125
        private JPanel jPanelButtons;
126
        private JButton btnProperties;
127
        private GeometryType shapeType;
128
        private JButton btnSaveSymbol;
129
        private JButton btnResetSymbol;
130
        private JButton btnNewSymbol;
131
        private JComboBoxFonts cmbFonts;
132
        private JToggleButton btnBold;
133
        private JToggleButton btnItalic;
134
        private JToggleButton btnUnderlined;
135
        protected JLabel lblTitle;
136
        protected File dir;
137
        protected File rootDir;
138
        protected JComponent jPanelPreview = null;
139
        protected GridBagLayoutPanel jPanelOptions = null;
140
        protected JList jListSymbols = null;
141
        protected String treeRootName;
142
        protected ILibraryModel library;
143
        private JNumberSpinner txtWidth;
144
        protected boolean act = true;
145
        boolean accepted = true;
146
        private SymbolManager manager;
147

    
148

    
149
        protected SelectorFilter sFilter = new SelectorFilter() {
150
                private Geometry dummyPointGeom = null;
151
                private Geometry dummyLineGeom = null;
152
                private Geometry dummyPolygonGeom = null;
153
                private boolean isInitialized = false;
154

    
155
                public boolean accepts(Object obj) {
156
                        if (!isInitialized){
157
                                try {
158
                                        dummyPointGeom = geomManager.createPoint(0, 0, SUBTYPES.GEOM2D);
159
                                        dummyLineGeom = geomManager.create(TYPES.CURVE, SUBTYPES.GEOM2D);
160
                                        dummyPolygonGeom = geomManager.create(TYPES.SURFACE, SUBTYPES.GEOM2D);
161
                                } catch (CreateGeometryException e) {
162
                                        logger.error("Error creating a geometry", e);
163
                                }
164
                                isInitialized = true;
165
                        }
166

    
167
                        if (obj instanceof ISymbol) {
168
                                ISymbol sym = (ISymbol) obj;
169

    
170
                                Geometry compareGeometry = null;
171
                                if (SymbolSelector.this.shapeType.isTypeOf(Geometry.TYPES.POINT)
172
                                    || SymbolSelector.this.shapeType.isTypeOf(Geometry.TYPES.MULTIPOINT)){
173
                                        compareGeometry = dummyPointGeom;
174
                                }else if (SymbolSelector.this.shapeType.isTypeOf(Geometry.TYPES.CURVE)
175
                    || SymbolSelector.this.shapeType.isTypeOf(Geometry.TYPES.MULTICURVE)){
176
                                        compareGeometry = dummyLineGeom;
177
                                }else if (SymbolSelector.this.shapeType.isTypeOf(Geometry.TYPES.SURFACE)
178
                    || SymbolSelector.this.shapeType.isTypeOf(Geometry.TYPES.MULTISURFACE)){
179
                                        compareGeometry = dummyPolygonGeom;
180
                                }
181
                                if (compareGeometry != null){
182
                                    return sym.isSuitableFor(compareGeometry);
183
                                }
184
                        }
185
                        return false;
186
                }
187
        };
188
        protected JComboBoxUnits cmbUnits;
189
        protected JComboBoxUnitsReferenceSystem cmbReferenceSystem;
190
        private JComboBoxFontSizes cmbFontSize;
191
        protected LibraryBrowser libraryBrowser;
192
        private SymbolSelectorListModel listModel;
193

    
194
        /**
195
         * Constructor method
196
         *
197
         * @param currentElement
198
         * @param shapeType
199
         */
200
        private void initialize(
201
                        Object currentElement,
202
                        GeometryType shapeType,
203
                        boolean initialize) throws IllegalArgumentException {
204

    
205
                manager = MapContextLocator.getSymbolManager();
206

    
207
                // TODO  09/08/07 check the currentElement type is suitable for the shapeType specified
208
                if (currentElement != null && currentElement instanceof ISymbol) {
209
                        ISymbol sym = (ISymbol) currentElement;
210
                        try {
211
                                currentElement = sym.clone();
212
                        } catch (CloneNotSupportedException e) {
213
                                NotificationManager.addWarning("Symbol layer", e);
214
                        }
215
                        String desc = sym.getDescription();
216
                        //                    desc += " ("+PluginServices.getText(this, "current")+")";
217
                        //                    ((ISymbol)currentElement).setDescription(desc);
218
                }
219

    
220
        this.shapeType = shapeType;
221

    
222
                //            Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" );
223
                rootDir =
224
                                new File(manager.getSymbolPreferences().getSymbolLibraryPath());
225

    
226
                if (!rootDir.exists()) {
227
                        rootDir.mkdir();
228
                }
229
                treeRootName = Messages.getText("symbol_library");
230
                if (initialize) {
231
                        initialize(currentElement);
232
                }
233

    
234
        }
235

    
236
        protected SymbolSelector(
237
                        Object symbol,
238
                        GeometryType shapeType, SelectorFilter filter, boolean initialize)
239
                                        throws IllegalArgumentException {
240
            super();
241
            initialize(symbol, shapeType, initialize);
242
            sFilter = filter;
243
        }
244

    
245
        protected SymbolSelector(Object symbol, GeometryType shapeType, boolean initialize)
246
                        throws IllegalArgumentException {
247
            super();
248
            initialize(symbol, shapeType, initialize);
249
        }
250

    
251
        /**
252
         * Constructor method, it is <b>protected</b> by convenience to let StyleSelector
253
         * to invoke it, but rigorously it should be <b>private</b>.
254
         *
255
         * @param symbol
256
         * @param shapeType
257
         * @param filter
258
         */
259
        protected SymbolSelector(
260
                        Object symbol,
261
                        int shapeType,
262
                        SelectorFilter filter,
263
                        boolean initialize) throws IllegalArgumentException {
264
                super();
265
                try {
266
                    GeometryType geometryType = geomManager.getGeometryType(shapeType, SUBTYPES.GEOM2D);
267
                    initialize(symbol,geometryType, initialize);
268
                } catch (GeometryTypeNotSupportedException e1) {
269
                    logger.error("Impossible to get the geometry type", e1);
270
                } catch (GeometryTypeNotValidException e1) {
271
                    logger.error("Impossible to get the geometry type", e1);
272
                }
273
                sFilter = filter;
274
        }
275

    
276
        /**
277
         * This method initializes this
278
         * @param currentElement
279
         * @throws ClassNotFoundException
280
         *
281
         */
282
        protected void initialize(Object currentElement) throws IllegalArgumentException {
283
                library = new SymbolLibrary(rootDir);
284

    
285
                this.setLayout(new BorderLayout());
286
                this.setSize(400, 221);
287

    
288
                this.add(getJNorthPanel(), BorderLayout.NORTH);
289
                this.add(getJSplitPane(), BorderLayout.CENTER);
290
                this.add(getJEastPanel(), BorderLayout.EAST);
291
                ActionListener okAction = new ActionListener() {
292
                        public void actionPerformed(ActionEvent e) {
293
                                if(SymbolSelector.this.listModel != null){
294
                                        SymbolSelector.this.listModel.dispose();
295
                                }
296
                                PluginServices.getMDIManager().closeWindow(SymbolSelector.this);
297
                                
298
                        }
299
                }, cancelAction = new ActionListener() {
300
                        public void actionPerformed(ActionEvent e) {
301
                                accepted = false;
302
                                setSymbol(null);
303
                                if(SymbolSelector.this.listModel != null){
304
                                        SymbolSelector.this.listModel.dispose();
305
                                }
306
                                PluginServices.getMDIManager().closeWindow(SymbolSelector.this);
307
                        }
308
                };
309

    
310
                okCancelPanel = new AcceptCancelPanel();
311
                okCancelPanel.setOkButtonActionListener(okAction);
312
                okCancelPanel.setCancelButtonActionListener(cancelAction);
313

    
314
                this.add(okCancelPanel, BorderLayout.SOUTH);
315
                libraryBrowser.setSelectionRow(0);
316

    
317
                SillyDragNDropAction dndAction = new SillyDragNDropAction();
318
                libraryBrowser.addMouseListener(dndAction);
319
                libraryBrowser.addMouseMotionListener(dndAction);
320
                getJListSymbols().addMouseListener(dndAction);
321
                getJListSymbols().addMouseMotionListener(dndAction);
322
                setSymbol(currentElement);
323
        }
324

    
325
        /**
326
         * Creates a new symbol selector list model in order to allow the user
327
         * to select an existing symbol previously created.
328
         *
329
         * @return listModel SymbolSelectorListModel
330
         */
331
        protected ListModel newListModel() {
332
                listModel = new SymbolSelectorListModel(
333
                                dir,
334
                                sFilter,
335
                                                manager.getSymbolPreferences().getSymbolFileExtension());
336
                return listModel;
337
        }
338
        /**
339
         * Initializes tha JNorthPanel.
340
         *
341
         * @return northPanel JPanel
342
         * @throws IllegalArgumentException
343
         */
344
        protected JPanel getJNorthPanel() throws IllegalArgumentException {
345
                if (northPanel == null) {
346
                        String text = "";
347
                        if (shapeType.isTypeOf(Geometry.TYPES.POINT) || shapeType.isTypeOf(Geometry.TYPES.MULTIPOINT)){
348
                                text = Messages.getText("point_symbols");
349
                        }else if (shapeType.isTypeOf(Geometry.TYPES.CURVE) || shapeType.isTypeOf(Geometry.TYPES.MULTICURVE)){
350
                                text = Messages.getText("line_symbols");
351
                        }else if (shapeType.isTypeOf(Geometry.TYPES.SURFACE) || shapeType.isTypeOf(Geometry.TYPES.MULTISURFACE)){
352
                                text = Messages.getText("polygon_symbols");
353
                        }
354
                        else{
355
                                throw new IllegalArgumentException(
356
                                                Messages.getText("shape_type_not_yet_supported"));
357
                        }
358
                        northPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
359
                        lblTitle = new JLabel(text);
360
                        lblTitle.setFont(lblTitle.getFont().deriveFont(Font.BOLD));
361
                        northPanel.add(lblTitle);
362
                }
363
                return northPanel;
364
        }
365

    
366
        /**
367
         * This method initializes jList
368
         *
369
         * @return javax.swing.JList
370
         */
371
        protected JList getJListSymbols() {
372
                if (jListSymbols == null) {
373
                        jListSymbols = new JList() ;
374
                        jListSymbols.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
375
                        jListSymbols.setLayoutOrientation(JList.HORIZONTAL_WRAP);
376
                        jListSymbols.setVisibleRowCount(-1);
377
                        jListSymbols.addListSelectionListener(new ListSelectionListener() {
378
                                public void valueChanged(ListSelectionEvent e) {
379
                                        if (jListSymbols.getSelectedValue()!=null) {
380
                                                ISymbol selSym=null;
381
                                                try {
382
                                                        selSym = (ISymbol) ((ISymbol) jListSymbols
383
                                                                        .getSelectedValue()).clone();
384
                                                } catch (CloneNotSupportedException ex) {
385
                                                        NotificationManager.addWarning("Symbol layer", ex);
386
                                                }
387
                                                setSymbol(selSym);
388
                                                updateOptionsPanel();
389
                                        }
390
                                }
391
                        });
392
                        ListCellRenderer renderer = new ListCellRenderer() {
393
                                private Color mySelectedBGColor = new Color(255,145,100,255);
394
                                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
395
                                        ISymbol sym = (ISymbol) value;
396
                                        JPanel pnl = new JPanel();
397
                                        BoxLayout layout = new BoxLayout(pnl, BoxLayout.Y_AXIS);
398
                                        pnl.setLayout(layout);
399
                                        Color bgColor = (isSelected) ? mySelectedBGColor
400
                                                        : getJListSymbols().getBackground();
401

    
402
                                        pnl.setBackground(bgColor);
403
                                        SymbolPreviewer sp = new SymbolPreviewer(true);
404
                                        sp.setAlignmentX(Component.CENTER_ALIGNMENT);
405
                                        sp.setPreferredSize(new Dimension(50, 50));
406
                                        sp.setSymbol(sym);
407
                                        sp.setBackground(bgColor);
408
                                        pnl.add(sp);
409
                                        String desc = sym.getDescription();
410
                                        if (desc == null) {
411
                                                desc = "["+Messages.getText("no_desc")+"]";
412
                                        }
413
                                        JLabel lbl = new JLabel(desc);
414
                                        lbl.setBackground(bgColor);
415
                                        lbl.setAlignmentX(Component.CENTER_ALIGNMENT);
416
                                        pnl.add(lbl);
417

    
418
                                        return pnl;
419
                                }
420

    
421
                        };
422
                        jListSymbols.setCellRenderer(renderer);
423
                }
424
                return jListSymbols;
425
        }
426
        /**
427
         * Updates the options panel depending on the type of symbol that the user
428
         * is controlling or using to show specific options for each one.
429
         *
430
         */
431
        protected void updateOptionsPanel() throws IllegalArgumentException {
432
                Object mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
433

    
434
//                if (mySelectedElement == null) {
435
//                        return;
436
//                }
437
                act = false; // disable events
438

    
439
                if (mySelectedElement instanceof CartographicSupport) {
440
                        CartographicSupport cs = (CartographicSupport) mySelectedElement;
441
                        cmbUnits.setSelectedUnitIndex(cs.getUnit());
442
                        cmbReferenceSystem.setSelectedIndex(cs.getReferenceSystem());
443
                }
444

    
445
                if (mySelectedElement instanceof IMultiLayerSymbol){
446
                        if (((IMultiLayerSymbol)mySelectedElement).getLayerCount() == 1) {
447
                                mySelectedElement = ((IMultiLayerSymbol)mySelectedElement).getLayer(0);
448
                        }
449
                }
450

    
451
                try {
452

    
453
                        jcc1.setEnabled(mySelectedElement!=null);
454
                        jcc2.setEnabled(mySelectedElement!=null);
455

    
456
                        if(mySelectedElement instanceof IMultiLayerSymbol){
457
                                jcc1.setColor(Color.WHITE);
458
                                jcc2.setColor(Color.WHITE);
459
                                jcc1.setEnabled(false);
460
                                jcc2.setEnabled(false);
461
                        }
462

    
463
                        if (shapeType.isTypeOf(Geometry.TYPES.POINT) || shapeType.isTypeOf(Geometry.TYPES.MULTIPOINT)) {
464
                                IMarkerSymbol m = (IMarkerSymbol) mySelectedElement;
465
                                txtSize.setEnabled(m!=null);
466
                                txtAngle.setEnabled(m!=null);
467
                                if(m!=null){
468
                                        jcc1.setColor(m.getColor());
469
                                        txtSize.setDouble(m.getSize());
470
                                        txtAngle.setDouble(Math.toDegrees(m.getRotation()));
471
                                }
472
                        }
473

    
474
                        if (shapeType.isTypeOf(Geometry.TYPES.CURVE) || shapeType.isTypeOf(Geometry.TYPES.MULTICURVE)) {
475
                                ILineSymbol l = (ILineSymbol) mySelectedElement;
476
                                txtSize.setEnabled(l!=null);
477
                                if(l!=null){
478
                                        jcc1.setColor(l.getColor());
479
                                        jcc1.setAlpha(l.getAlpha());
480
                                        txtSize.setDouble(l.getLineWidth());
481
                                }
482
                        }
483

    
484
                        if (shapeType.isTypeOf(Geometry.TYPES.SURFACE) || shapeType.isTypeOf(Geometry.TYPES.MULTISURFACE)) {
485
                                IFillSymbol f = (IFillSymbol) mySelectedElement;
486

    
487
                                txtWidth.setEnabled(f!=null);
488
                                cmbReferenceSystem.setEnabled(f!=null);
489
                                cmbUnits.setEnabled(f!=null);
490

    
491
                                if (f!=null){
492
                                        jcc1.setUseColorIsSelected(f.hasFill());
493
                                        jcc1.setColor(f.getFillColor());
494
                                        jcc1.setAlpha(f.getFillAlpha());
495
                                        jcc2.setUseColorIsSelected(f.hasOutline());
496
                                        ILineSymbol outline = f.getOutline();
497
                                        if (outline != null) {
498
                                                jcc2.setColor(outline.getColor());
499
                                                txtWidth.setDouble(outline.getLineWidth());
500
                                        }
501

    
502
                                        if(f instanceof IMultiLayerFillSymbol){
503
                                                txtWidth.setEnabled(false);
504
                                                cmbReferenceSystem.setEnabled(false);
505
                                                cmbUnits.setEnabled(false);
506
                                        }
507
                                }
508
                        }
509

    
510
                } catch (NullPointerException npEx) {
511
                        throw new IllegalArgumentException(npEx);
512
                } catch (ClassCastException ccEx) {
513
                        throw new IllegalArgumentException(ccEx);
514
                }
515

    
516
                act = true;  // enable events
517
        }
518

    
519
        /**
520
         * This method initializes jPanel
521
         *
522
         * @return javax.swing.JPanel
523
         */
524
        protected JPanel getJEastPanel() {
525
                if (jPanel == null) {
526
                        jPanel = new JPanel();
527
                        jPanel.setLayout(new BorderLayout());
528
                        jPanel.add(getJPanelOptions(), BorderLayout.CENTER);
529
                        JPanel aux = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
530
                        aux.setBorder(BorderFactory.createTitledBorder(null, Messages.getText("preview")));
531
                        aux.add(getJPanelPreview());
532
                        jPanel.add(aux, BorderLayout.NORTH);
533

    
534
                        jPanel.add(getJPanelOptions());
535
                        aux = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5));
536
                        aux.add(getJPanelButtons());
537
                        jPanel.add(aux, BorderLayout.SOUTH);
538
                }
539
                return jPanel;
540
        }
541

    
542
        private JPanel getJPanelButtons() {
543
                if (jPanelButtons == null) {
544
                        jPanelButtons = new JPanel();
545
                        GridLayout layout = new GridLayout();
546
                        layout.setColumns(1);
547
                        layout.setVgap(5);
548
                        jPanelButtons.add(getBtnNewSymbol());
549
                        jPanelButtons.add(getBtnSaveSymbol());
550
                        jPanelButtons.add(getBtnResetSymbol());
551
                        jPanelButtons.add(getBtnProperties());
552

    
553
                        // do not add components bellow this line!
554
                        layout.setRows(jPanelButtons.getComponentCount());
555
                        jPanelButtons.setLayout(layout);
556
                }
557
                return jPanelButtons;
558
        }
559

    
560
        private JButton getBtnNewSymbol() {
561
                if (btnNewSymbol == null) {
562
                        btnNewSymbol = new JButton();
563
                        btnNewSymbol.setName("btnNewSymbol");
564
                        btnNewSymbol.setText(Messages.getText("new"));
565
                        btnNewSymbol.addActionListener(this);
566
                }
567
                return btnNewSymbol;
568
        }
569

    
570
        private JButton getBtnResetSymbol() {
571
                if (btnResetSymbol == null) {
572
                        btnResetSymbol = new JButton();
573
                        btnResetSymbol.setName("btnResetSymbol");
574
                        btnResetSymbol.setText(Messages.getText("reset"));
575
                        btnResetSymbol.addActionListener(this);
576
                }
577
                return btnResetSymbol;
578
        }
579

    
580
        private JButton getBtnSaveSymbol() {
581
                if (btnSaveSymbol == null) {
582
                        btnSaveSymbol = new JButton();
583
                        btnSaveSymbol.setName("btnSaveSymbol");
584
                        btnSaveSymbol.setText(Messages.getText("save"));
585
                        btnSaveSymbol.addActionListener(this);
586
                }
587
                return btnSaveSymbol;
588
        }
589

    
590
        private JButton getBtnProperties() {
591
                if (btnProperties == null) {
592
                        btnProperties = new JButton();
593
                        btnProperties.setName("btnProperties");
594
                        btnProperties.setText(Messages.getText("properties"));
595
                        btnProperties.addActionListener(this);
596
                }
597
                return btnProperties;
598
        }
599

    
600
        /**
601
         * This method initializes jScrollPane
602
         *
603
         * @return javax.swing.JScrollPane
604
         * @throws ClassNotFoundException
605
         */
606
        protected JScrollPane getLeftJScrollPane() {
607
                if (jScrollPane == null) {
608
                        jScrollPane = new JScrollPane();
609
                        jScrollPane.setPreferredSize(new java.awt.Dimension(80,130));
610
                        jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
611
                        libraryBrowser = new LibraryBrowser(library);
612
                        libraryBrowser.addTreeSelectionListener(new TreeSelectionListener() {
613
                                public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
614

    
615
                                        if (libraryBrowser.getLastSelectedPathComponent() == null) {
616
                                                /*
617
                                                 * This happens when clicking on [+] to expand
618
                                                 * or [-] to collapse a tree node.
619
                                                 */
620
                                                return;
621
                                        }
622

    
623
                                        dir = (File) ((DefaultMutableTreeNode)
624
                                                        libraryBrowser.getLastSelectedPathComponent()).getUserObject();
625

    
626
                                        if (dir == null) {
627
                                                return;
628
                                        }
629
                                        ListModel model = jListSymbols.getModel();
630
                                        if( model != null && model instanceof Disposable ) {
631
                                                ((Disposable)model).dispose();
632
                                        }
633
                                        jListSymbols.setModel(newListModel());
634
                                }
635
                        });
636
                        jScrollPane.setViewportView(libraryBrowser);
637
                }
638
                return jScrollPane;
639
        }
640

    
641
        /**
642
         * This method initializes jScrollPane1
643
         *
644
         * @return javax.swing.JScrollPane
645
         */
646
        private JScrollPane getJScrollPane1() {
647
                if (jScrollPane1 == null) {
648
                        jScrollPane1 = new JScrollPane();
649
                        jScrollPane1.setViewportView(getJListSymbols());
650
                }
651
                return jScrollPane1;
652
        }
653

    
654
        /**
655
         * This method initializes jPanelPreview
656
         *
657
         * @return javax.swing.JComponent
658
         */
659
        protected JComponent getJPanelPreview() {
660
                if (jPanelPreview == null) {
661
                        jPanelPreview = new SymbolPreviewer();
662
                        jPanelPreview.setPreferredSize(new java.awt.Dimension(100,100));
663
                        jPanelPreview.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
664
                }
665
                return jPanelPreview;
666
        }
667
        /**
668
         * This method initializes jPanelOptions
669
         *
670
         * @return javax.swing.JPanel
671
         */
672
        protected JPanel getJPanelOptions() {
673
                if (jPanelOptions == null) {
674
                        jPanelOptions = new GridBagLayoutPanel();
675
                        jPanelOptions.setBorder(BorderFactory.createTitledBorder(null, Messages.getText("options")));
676
                        jcc2 = new ColorChooserPanel(true,true);
677
                        jcc2.setAlpha(255);
678
                        if (shapeType.isTypeOf(Geometry.TYPES.POINT) || shapeType.isTypeOf(Geometry.TYPES.MULTIPOINT)) {
679
                                jcc1 = new ColorChooserPanel(true);
680

    
681
                                jPanelOptions.addComponent(
682
                                                Messages.getText("color")+":", jcc1);
683
                                jPanelOptions.addComponent(
684
                                                Messages.getText("size")+":",
685
                                                txtSize = new JNumberSpinner(3.0, 3, 0, Double.MAX_VALUE, 1, 2));
686
                                jPanelOptions.addComponent(Messages.getText("units")+":",
687
                                                cmbUnits = new JComboBoxUnits());
688
                                jPanelOptions.addComponent("",
689
                                                cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
690
                                jPanelOptions.addComponent(
691
                                                Messages.getText("angle")+ " (" +Messages.getText("degree")+"):",
692
                                                txtAngle = new JNumberSpinner(0.0, 3, -180.0, 180.0, 1.0, 2));
693

    
694

    
695
                        } else if (shapeType.isTypeOf(Geometry.TYPES.CURVE) || shapeType.isTypeOf(Geometry.TYPES.MULTICURVE)) {
696
                                jcc1 = new ColorChooserPanel(true);
697
                                jPanelOptions.addComponent(
698
                                                Messages.getText("color")+":", jcc1);
699
                                jPanelOptions.addComponent(
700
                                                Messages.getText("width")+":",
701
                                                txtSize = new JNumberSpinner(3.0, 3, 0, Double.MAX_VALUE, 1, 2));
702
                                jPanelOptions.addComponent(Messages.getText("units")+":",
703
                                                cmbUnits = new JComboBoxUnits());
704
                                jPanelOptions.addComponent("",
705
                                                cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
706

    
707
                        } else if (shapeType.isTypeOf(Geometry.TYPES.SURFACE) || shapeType.isTypeOf(Geometry.TYPES.MULTISURFACE)) {
708
                                jcc1 = new ColorChooserPanel(true, true);
709
                                jPanelOptions.addComponent(
710
                                                Messages.getText("fill_color")+":", jcc1);
711
                                jPanelOptions.addComponent(
712
                                                Messages.getText("outline_color")+":", jcc2);
713
                                jPanelOptions.addComponent(
714
                                                Messages.getText("outline_width"),
715
                                                txtWidth = new JNumberSpinner(3.0, 3, 0, Double.MAX_VALUE, 1, 2));
716
                                jPanelOptions.addComponent(Messages.getText("units")+":",
717
                                                cmbUnits = new JComboBoxUnits());
718
                                jPanelOptions.addComponent("",
719
                                                cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
720

    
721
                        }
722

    
723
                        jcc1.setAlpha(255);
724

    
725
                        if (txtSize != null) {
726
                                txtSize.addActionListener(this);
727
                        }
728
                        if (cmbUnits != null) {
729
                                cmbUnits.addActionListener(this);
730
                        }
731
                        if (cmbReferenceSystem != null) {
732
                                cmbReferenceSystem.addActionListener(this);
733
                        }
734
                        if (jcc1 != null) {
735
                                jcc1.addActionListener(this);
736
                        }
737
                        if (jcc2 != null) {
738
                                jcc2.addActionListener(this);
739
                        }
740
                        if (txtWidth != null) {
741
                                txtWidth.addActionListener(this);
742
                        }
743
                        if (cmbFontSize != null) {
744
                                cmbFontSize.addActionListener(this);
745
                        }
746
                        if (txtAngle != null) {
747
                                txtAngle.addActionListener(this);
748
                        }
749
                }
750
                return jPanelOptions;
751
        }
752

    
753
        private JToggleButton getBtnUnderlined() {
754
                if (btnUnderlined == null) {
755
                        btnUnderlined = new JToggleButton(PluginServices.getIconTheme().
756
                                        get("underline-icon"));
757
                }
758
                return btnUnderlined;
759
        }
760

    
761
        private JToggleButton getBtnItalic() {
762
                if (btnItalic == null) {
763
                        btnItalic = new JToggleButton(PluginServices.getIconTheme().
764
                                        get("italic-icon"));
765
                }
766
                return btnItalic;
767
        }
768

    
769
        private JToggleButton getBtnBold() {
770
                if (btnBold == null) {
771
                        btnBold = new JToggleButton(PluginServices.getIconTheme().
772
                                        get("bold-icon"));
773
                }
774
                return btnBold;
775
        }
776

    
777

    
778
        private JComboBoxFonts getCmbFonts() {
779
                if (cmbFonts == null) {
780
                        cmbFonts = new JComboBoxFonts();
781
                }
782
                return cmbFonts;
783
        }
784

    
785
        public WindowInfo getWindowInfo() {
786
                if (wi == null) {
787
                        wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
788
                        wi.setWidth(706);
789
                        wi.setHeight(500);
790
                        wi.setTitle(Messages.getText("symbol_selector"));
791
                }
792
                return wi;
793
        }
794

    
795
        protected JSplitPane getJSplitPane() {
796
                if (jSplitPane == null) {
797
                        jSplitPane = new JSplitPane();
798
                        jSplitPane.setDividerLocation(200);
799
                        jSplitPane.setResizeWeight(0.4);
800
                        jSplitPane.setLeftComponent(getLeftJScrollPane());
801
                        jSplitPane.setRightComponent(getJScrollPane1());
802
                }
803
                return jSplitPane;
804
        }
805

    
806
        public Object getSelectedObject() {
807
                if (!accepted) {
808
                        return null;
809
                }
810
                Object mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
811

    
812
                // if this symbol only has one layer, then no multilayer is needed
813
                if (mySelectedElement instanceof IMultiLayerSymbol) {
814
                        if (((IMultiLayerSymbol) mySelectedElement).getLayerCount()==1) {
815
                                return ((IMultiLayerSymbol) mySelectedElement).getLayer(0);
816
                        }
817
                }
818

    
819
                if (mySelectedElement instanceof CartographicSupport) {
820
                        CartographicSupport csSym = (CartographicSupport) mySelectedElement;
821
                        csSym.setUnit(cmbUnits.getSelectedUnitIndex());
822
                        csSym.setReferenceSystem(cmbReferenceSystem.getSelectedIndex());
823
                }
824

    
825
                return mySelectedElement;
826
        }
827

    
828
        public void setSymbol(Object symbol) {
829
                ((SymbolPreviewer) jPanelPreview).setSymbol((ISymbol) symbol);
830
                updateOptionsPanel();
831
        }
832

    
833
        /**
834
         * Invoked when the PROPERTIES button is pressed
835
         */
836
        protected void propertiesPressed() {
837
                ISymbol mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
838
                if (mySelectedElement ==null) {
839
                        return;
840
                }
841

    
842
                ISymbol clonedSymbol=null;
843
                try {
844
                        clonedSymbol = (ISymbol) mySelectedElement.clone();
845
                } catch (CloneNotSupportedException e) {
846
                        NotificationManager.addWarning("Symbol layer", e);
847
                }
848
                SymbolEditor se = new SymbolEditor(clonedSymbol, shapeType);
849
                PluginServices.getMDIManager().addWindow(se);
850

    
851
                ISymbol symbol = se.getSymbol();
852
                if (symbol instanceof IMultiLayerSymbol) {
853
                        IMultiLayerSymbol mSym = (IMultiLayerSymbol) symbol;
854
                        if (mSym.getLayerCount() == 1) {
855
                                symbol =  mSym.getLayer(0);
856
                        }
857
                }
858
                setSymbol(symbol);
859

    
860
        }
861

    
862
        /**
863
         * Invoked when the NEW button is pressed
864
         */
865
    protected void newPressed() {
866
        ISymbol curr_sym = ((SymbolPreviewer) jPanelPreview).getSymbol();
867

    
868
        if (curr_sym != null) {
869
            try {
870
                curr_sym = (ISymbol) curr_sym.clone();
871
            } catch (Exception cnse) {
872
                logger.info("Unable to clone symbol. "
873
                        + "This can cause an empty symbol if user cancels dialog.",
874
                        cnse);
875
            }
876
        }
877
        SymbolEditor se = new SymbolEditor(curr_sym, shapeType);
878
        PluginServices.getMDIManager().addWindow(se);
879
        setSymbol(se.getSymbol());
880
    }
881

    
882
        /**
883
         * Invoked when the RESET button is pressed
884
         */
885
        protected void resetPressed() {
886
                setSymbol(null);
887
        }
888

    
889
        /**
890
         * Invoked when the SAVE button is pressed
891
         */
892
        protected void savePressed() {
893
                Object selected = getSelectedObject();
894
                if (getSelectedObject() ==null) {
895
                        return;
896
                }
897

    
898
                final SymbolPreferences preferences = manager.getSymbolPreferences();
899

    
900

    
901
                JFileChooser jfc = new JFileChooser("SYMBOL_SELECTOR_FILECHOOSER", rootDir);
902
                javax.swing.filechooser.FileFilter ff = new javax.swing.filechooser.FileFilter() {
903
                        public boolean accept(File f) {
904
                                                return f.getAbsolutePath().toLowerCase().endsWith(
905
                                                                preferences.getSymbolFileExtension())
906
                                                                || f.isDirectory();
907
                        }
908

    
909
                        public String getDescription() {
910
                                                return Messages.getText(
911
                                                                "gvSIG_symbol_definition_file")
912
                                                                .concat(" (*")
913
                                                                .concat(preferences.getSymbolFileExtension())
914
                                                                .concat(")");
915
                        }
916
                };
917
                jfc.setFileFilter(ff);
918
                JPanel accessory = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
919
                accessory.add(new JLabel(Messages.getText("enter_description")));
920
                JTextField txtDesc = new JTextField(25);
921
                if( selected instanceof ISymbol ) {
922
                    txtDesc.setText(((ISymbol)selected).getDescription());
923
                }
924
                if( selected instanceof ISymbol_v2 && !StringUtils.isEmpty(((ISymbol_v2)selected).getID())) {
925
                    jfc.setSelectedFile(new File(((ISymbol_v2)selected).getID()));
926
                }
927

    
928
                accessory.add(txtDesc);
929
                jfc.setAccessory(accessory);
930
                if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
931
                        File targetFile = jfc.getSelectedFile();
932

    
933
                        // apply description
934
                        String desc;
935
                        if (txtDesc.getText()==null || txtDesc.getText().trim().equals("")) {
936
                                // default to file name
937
                                String s = targetFile.getAbsolutePath();
938
                                desc =
939
                                                s.substring(s.lastIndexOf(File.separator) + 1)
940
                                                                .replaceAll(
941
                                                                                preferences.getSymbolFileExtension(),
942
                                                                                "");
943
                        } else {
944
                                desc = txtDesc.getText().trim();
945
                        }
946
                        ISymbol s = (ISymbol) getSelectedObject();
947
                        s.setDescription(desc);
948

    
949

    
950
                        String symbolFileName = targetFile.getAbsolutePath().substring(
951
                                        targetFile.getAbsolutePath().lastIndexOf(File.separator)+1,
952
                                        targetFile.getAbsolutePath().length());
953
                        File targetDir = new File(targetFile.getAbsolutePath().substring(
954
                                        0,
955
                                        targetFile.getAbsolutePath().lastIndexOf(File.separator)));
956
                        library.addElement(s, symbolFileName , targetDir);
957
                        getJListSymbols().setModel(newListModel());
958
                }
959
        }
960

    
961

    
962
        public void actionPerformed(ActionEvent e) {
963
                if (!act) {
964
                        return;
965
                }
966
                Object selectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();//getSelectedObject();
967
                performActionOn(selectedElement, e);
968
                SymbolSelector.this.repaint();
969
        }
970

    
971
        protected void performActionOn(Object selectedElement, ActionEvent e) {
972
                JComponent comp = (JComponent) e.getSource();
973

    
974
                if ( comp.equals(getBtnProperties()) ) {
975
                        // properties pressed
976
                        propertiesPressed();
977
                } else if ( comp.equals(getBtnNewSymbol()) ) {
978
                        // new pressed
979
                        newPressed();
980
                } else if ( comp.equals(getBtnResetSymbol()) ) {
981
                        // reset pressed
982
                        resetPressed();
983
                } else if ( comp.equals(getBtnSaveSymbol()) ) {
984
                        // save pressed
985
                        savePressed();
986
                } else if (comp.equals(jcc1)) {
987
                        if (selectedElement == null) {
988
                                return;
989
                        }
990

    
991
                        Color c = jcc1.getColor();
992

    
993
                        if (selectedElement instanceof IMarkerSymbol) {
994
                                IMarkerSymbol m = (IMarkerSymbol) selectedElement;
995
                                if (m instanceof IMultiLayerMarkerSymbol) {
996
                                        IMultiLayerMarkerSymbol mm = (IMultiLayerMarkerSymbol) m;
997
                                        mm.setAlpha(jcc1.getAlpha());
998
                                } else {
999
                                        m.setColor(c);
1000
                                }
1001
                        }
1002

    
1003
                        if (selectedElement instanceof ILineSymbol) {
1004
                                ILineSymbol l = (ILineSymbol) selectedElement;
1005
                                if (l instanceof IMultiLayerLineSymbol) {
1006
                                        IMultiLayerLineSymbol ml = (IMultiLayerLineSymbol) l;
1007
                                        ml.setAlpha(jcc1.getAlpha());
1008
                                } else {
1009
                                        l.setLineColor(c);
1010
                                }
1011
                        }
1012

    
1013
                        if (selectedElement instanceof IFillSymbol) {
1014
                                IFillSymbol f = (IFillSymbol) selectedElement;
1015

    
1016
                                f.setHasFill(jcc1.getUseColorisSelected());
1017
                                f.setFillColor(c);
1018
                        }
1019

    
1020
                        if (selectedElement instanceof ITextSymbol) {
1021
                                ITextSymbol t = (ITextSymbol) selectedElement;
1022
                                t.setTextColor(c);
1023
                        }
1024

    
1025
                } else if (comp.equals(jcc2)) {
1026
                        if (selectedElement == null) {
1027
                                return;
1028
                        }
1029
                        Color c = jcc2.getColor();
1030

    
1031

    
1032
                        if (selectedElement instanceof IFillSymbol) {
1033
                                IFillSymbol f = (IFillSymbol) selectedElement;
1034
                                ILineSymbol outline = f.getOutline();
1035
                                f.setHasOutline(jcc2.getUseColorisSelected());
1036

    
1037
                                if (outline!=null) {
1038
                                        ILineSymbol l = outline;
1039
                                        if (l instanceof IMultiLayerLineSymbol && c != null) {
1040
                                                IMultiLayerLineSymbol ml = (IMultiLayerLineSymbol) l;
1041
                                                ml.setAlpha(c.getAlpha());
1042
                                        } else {
1043
                                                l.setLineColor(c);
1044
                                        }
1045
                                }
1046

    
1047
                        }
1048
                } else if (comp.equals(txtSize)) {
1049
                        double s = txtSize.getDouble();
1050

    
1051
                        if (selectedElement instanceof IMarkerSymbol) {
1052
                                IMarkerSymbol m = (IMarkerSymbol) selectedElement;
1053
                                m.setSize(s);
1054
                                ISymbol sm = m.getSymbolForSelection();
1055
                                if (sm != null && sm instanceof IMarkerSymbol){
1056
                                    ((IMarkerSymbol)sm).setSize(s);
1057
                                }
1058
                        }
1059

    
1060
                        if (selectedElement instanceof ILineSymbol) {
1061
                                ILineSymbol l = (ILineSymbol) selectedElement;
1062
                                l.setLineWidth(s);
1063
                ISymbol sl = l.getSymbolForSelection();
1064
                if (sl != null && sl instanceof ILineSymbol){
1065
                    ((ILineSymbol)sl).setLineWidth(s);
1066
                }
1067
                        }
1068
                } else if (comp.equals(cmbUnits)) {
1069
                        if (selectedElement instanceof CartographicSupport) {
1070
                                CartographicSupport cs = (CartographicSupport) selectedElement;
1071
                                cs.setUnit(cmbUnits.getSelectedUnitIndex());
1072
                        }
1073
                } else if (comp.equals(cmbReferenceSystem)) {
1074
                        if (selectedElement instanceof CartographicSupport) {
1075
                                CartographicSupport cs = (CartographicSupport) selectedElement;
1076
                                cs.setReferenceSystem(cmbReferenceSystem.getSelectedIndex());
1077
                        }
1078
                } else if (comp.equals(txtWidth)) {
1079
                        double w = txtWidth.getDouble();
1080
                        if (selectedElement instanceof IFillSymbol) {
1081
                                IFillSymbol f = (IFillSymbol) selectedElement;
1082
                                ILineSymbol outline = f.getOutline();
1083
                                if (outline!=null) {
1084
                                        outline.setLineWidth(w);
1085
                                }
1086
                        }
1087
                } else if (comp.equals(cmbFontSize)) {
1088
                        double s = ((Integer) cmbFontSize.getSelectedItem()).doubleValue();
1089
                        if (selectedElement instanceof ITextSymbol) {
1090
                                ITextSymbol t = (ITextSymbol) selectedElement;
1091
                                t.setFontSize(s);
1092
                        }
1093
                } else if (comp.equals(txtAngle)) {
1094
                        double a = Math.toRadians(txtAngle.getDouble());
1095
                        if (selectedElement instanceof IMarkerSymbol) {
1096
                                IMarkerSymbol m = (IMarkerSymbol) selectedElement;
1097
                                m.setRotation(a);
1098
                        }
1099
                }
1100
        }
1101

    
1102
        public static ISymbolSelector createSymbolBrowser() {
1103
                return MultiShapeSymbolSelector.createSymbolBrowser();
1104
        }
1105

    
1106
        public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType) {
1107
                return createSymbolSelector(currSymbol, shapeType, null);
1108
        }
1109

    
1110
        public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType, SelectorFilter filter) {
1111
                ISymbolSelector selector = null;
1112

    
1113
                GeometryType geometryType = null;
1114
        try {
1115
            geometryType = geomManager.getGeometryType(shapeType, SUBTYPES.GEOM2D);
1116
        } catch (GeometryTypeNotSupportedException e) {
1117
            logger.error("Impossible to get the geometry type", e);
1118
        } catch (GeometryTypeNotValidException e) {
1119
            logger.error("Impossible to get the geometry type", e);
1120
        }
1121

    
1122
                if (filter==null) {
1123
                        selector = (shapeType == Geometry.TYPES.GEOMETRY) ?
1124
                                        new MultiShapeSymbolSelector(currSymbol) :
1125
                                                new SymbolSelector(currSymbol, geometryType, true);
1126
                } else {
1127
                        selector = (shapeType == Geometry.TYPES.GEOMETRY) ?
1128
                                        new MultiShapeSymbolSelector(currSymbol) :
1129
                                                new SymbolSelector(currSymbol, geometryType, filter, true);
1130
                }
1131
                return selector;
1132
        }
1133

    
1134
        class SillyDragNDropAction implements MouseListener, MouseMotionListener {
1135
                private boolean doDrop = false;
1136
                private Object selected;
1137
                private File sourceFolder;
1138

    
1139
                public void mouseClicked(MouseEvent e) { }
1140
                public void mouseEntered(MouseEvent e) { }
1141
                public void mouseExited(MouseEvent e) { }
1142

    
1143
                public void mousePressed(MouseEvent e) {
1144
                        if (e.getSource().equals(getJListSymbols())) {
1145
                                selected = getJListSymbols().getSelectedValue();
1146
                                doDrop = selected!=null;
1147
                                DefaultMutableTreeNode node = (DefaultMutableTreeNode) libraryBrowser.getLastSelectedPathComponent();
1148
                                if (node.getUserObject() instanceof File) {
1149
                                        sourceFolder = (File) node.getUserObject();
1150
                                }
1151
                        }
1152
                        e.consume();
1153
                }
1154

    
1155
                public void mouseReleased(MouseEvent e) {
1156
                        if (doDrop && e.getSource().equals(getJListSymbols())) {
1157
                                Point p = new Point(getJListSymbols().getLocation().x-e.getPoint().x, getJListSymbols().getLocation().y+e.getPoint().y);
1158
                                if (libraryBrowser.getBounds().contains(p)) {
1159
                                        File destFolder = libraryBrowser.getElementBellow(p);
1160
                                        if (destFolder != null) {
1161
                                                ISymbol sym = (ISymbol) selected;
1162
                                                int move = InputEvent.SHIFT_DOWN_MASK | InputEvent.BUTTON1_DOWN_MASK;
1163
                                                //                                            int copy = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
1164

    
1165
                                                library.addElement(sym, sym.getDescription(), destFolder);
1166
                                                if ((e.getModifiers() & (move)) !=0) {
1167
                                                        library.removeElement(sym, sourceFolder);
1168
                                                }
1169

    
1170
                                        }
1171
                                        libraryBrowser.refresh();
1172
                                }
1173

    
1174
                        }
1175
                        doDrop = false;
1176
                }
1177

    
1178
                public void mouseDragged(MouseEvent e) {
1179
                        if (e.getSource().equals(getJListSymbols())) {
1180

    
1181
                                Point p = new Point(getJListSymbols().getLocation().x-e.getPoint().x, getJListSymbols().getLocation().y+e.getPoint().y);
1182
                                if (libraryBrowser.getBounds().contains(p)) {
1183
                                        libraryBrowser.setSelectedElementBellow(p);
1184
                                }
1185
                        }
1186
                }
1187

    
1188
                public void mouseMoved(MouseEvent e) {
1189

    
1190
                }
1191

    
1192
        }
1193

    
1194
        public Object getWindowProfile() {
1195
                return WindowInfo.DIALOG_PROFILE;
1196
        }
1197

    
1198
}