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 @ 47476

History | View | Annotate | Download (39.5 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
import javax.swing.BorderFactory;
42
import javax.swing.BoxLayout;
43
import javax.swing.JComponent;
44
import javax.swing.JLabel;
45
import javax.swing.JList;
46
import javax.swing.JPanel;
47
import javax.swing.JScrollPane;
48
import javax.swing.JSplitPane;
49
import javax.swing.JTextField;
50
import javax.swing.JToggleButton;
51
import javax.swing.ListCellRenderer;
52
import javax.swing.ListModel;
53
import javax.swing.SwingUtilities;
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
import org.apache.commons.lang3.mutable.MutableObject;
60
import org.gvsig.andami.PluginServices;
61
import org.gvsig.andami.messages.NotificationManager;
62
import org.gvsig.andami.ui.mdiManager.WindowInfo;
63
import org.gvsig.app.gui.JComboBoxUnits;
64
import org.gvsig.app.gui.panels.ColorChooserPanel;
65
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector;
66
import org.gvsig.fmap.dal.feature.Feature;
67
import org.gvsig.fmap.dal.feature.FeatureStore;
68
import org.gvsig.fmap.geom.Geometry;
69
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
70
import org.gvsig.fmap.geom.GeometryLocator;
71
import org.gvsig.fmap.geom.GeometryManager;
72
import org.gvsig.fmap.geom.exception.CreateGeometryException;
73
import org.gvsig.fmap.geom.type.GeometryType;
74
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException;
75
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException;
76
import org.gvsig.fmap.mapcontext.MapContextLocator;
77
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
78
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol;
79
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
80
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol_v2;
81
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol;
82
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager;
83
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolPreferences;
84
import org.gvsig.gui.beans.AcceptCancelPanel;
85
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
86
import org.gvsig.gui.beans.swing.JButton;
87
import org.gvsig.gui.beans.swing.JComboBoxFontSizes;
88
import org.gvsig.gui.beans.swing.JComboBoxFonts;
89
import org.gvsig.gui.beans.swing.JFileChooser;
90
import org.gvsig.gui.beans.swing.JNumberSpinner;
91
import org.gvsig.i18n.Messages;
92
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
93
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IMultiLayerFillSymbol;
94
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
95
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.IMultiLayerLineSymbol;
96
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
97
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMultiLayerMarkerSymbol;
98
import org.gvsig.tools.dispose.Disposable;
99
import org.slf4j.Logger;
100
import org.slf4j.LoggerFactory;
101

    
102

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

    
150

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

    
157
        @Override
158
                public boolean accepts(Object obj) {
159
                        if (!isInitialized){
160
                                try {
161
                                        dummyPointGeom = geomManager.createPoint(0, 0, SUBTYPES.GEOM2D);
162
                                        dummyLineGeom = geomManager.createLine(SUBTYPES.GEOM2D);
163
                                        dummyPolygonGeom = geomManager.createPolygon(SUBTYPES.GEOM2D);
164
                                } catch (CreateGeometryException e) {
165
                                        logger.error("Error creating a geometry", e);
166
                                }
167
                                isInitialized = true;
168
                        }
169

    
170
                        if (obj instanceof ISymbol) {
171
                                ISymbol sym = (ISymbol) obj;
172

    
173
                                Geometry compareGeometry = null;
174
                                if (SymbolSelector.this.shapeType.isTypeOf(Geometry.TYPES.POINT)
175
                                    || SymbolSelector.this.shapeType.isTypeOf(Geometry.TYPES.MULTIPOINT)){
176
                                        compareGeometry = dummyPointGeom;
177
                                }else if (SymbolSelector.this.shapeType.isTypeOf(Geometry.TYPES.CURVE)
178
                    || SymbolSelector.this.shapeType.isTypeOf(Geometry.TYPES.MULTICURVE)){
179
                                        compareGeometry = dummyLineGeom;
180
                                }else if (SymbolSelector.this.shapeType.isTypeOf(Geometry.TYPES.SURFACE)
181
                    || SymbolSelector.this.shapeType.isTypeOf(Geometry.TYPES.MULTISURFACE)){
182
                                        compareGeometry = dummyPolygonGeom;
183
                                }
184
                                if (compareGeometry != null){
185
                                    return sym.isSuitableFor(compareGeometry);
186
                                }
187
                        }
188
                        return false;
189
                }
190
        };
191
        protected JComboBoxUnits cmbUnits;
192
        protected JComboBoxUnitsReferenceSystem cmbReferenceSystem;
193
        private JComboBoxFontSizes cmbFontSize;
194
        protected LibraryBrowser libraryBrowser;
195
        private SymbolSelectorListModel listModel;
196
        private FeatureStore featureStore;
197
        /**
198
         * Constructor method
199
         *
200
         * @param currentElement
201
         * @param shapeType
202
         */
203
        private void initialize(
204
                        Object currentElement,
205
                        GeometryType shapeType,
206
                        boolean initialize) throws IllegalArgumentException {
207

    
208
                manager = MapContextLocator.getSymbolManager();
209

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

    
223
        this.shapeType = shapeType;
224

    
225
                //            Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" );
226
                rootDir =
227
                                new File(manager.getSymbolPreferences().getSymbolLibraryPath());
228

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

    
237
        }
238

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

    
248
        protected SymbolSelector(Object symbol, GeometryType shapeType, boolean initialize)
249
                        throws IllegalArgumentException {
250
            super();
251
            initialize(symbol, shapeType, initialize);
252
        }
253

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

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

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

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

    
306
                okCancelPanel = new AcceptCancelPanel();
307
                okCancelPanel.setOkButtonActionListener(okAction);
308
                okCancelPanel.setCancelButtonActionListener(cancelAction);
309

    
310
                this.add(okCancelPanel, BorderLayout.SOUTH);
311
                libraryBrowser.setSelectionRow(0);
312

    
313
                SillyDragNDropAction dndAction = new SillyDragNDropAction();
314
                libraryBrowser.addMouseListener(dndAction);
315
                libraryBrowser.addMouseMotionListener(dndAction);
316
                getJListSymbols().addMouseListener(dndAction);
317
                getJListSymbols().addMouseMotionListener(dndAction);
318
                setSymbol(currentElement);
319
        }
320

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

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

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

    
413
                                        return pnl;
414
                                }
415

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

    
430
                if (mySelectedElement instanceof CartographicSupport) {
431
                        CartographicSupport cs = (CartographicSupport) mySelectedElement;
432
                        cmbUnits.setSelectedUnitIndex(cs.getUnit());
433
                        cmbReferenceSystem.setSelectedIndex(cs.getReferenceSystem());
434
                }
435

    
436
                if (mySelectedElement instanceof IMultiLayerSymbol){
437
                        if (((IMultiLayerSymbol)mySelectedElement).getLayerCount() == 1) {
438
                                mySelectedElement = ((IMultiLayerSymbol)mySelectedElement).getLayer(0);
439
                        }
440
                }
441

    
442
                try {
443

    
444
                        jcc1.setEnabled(mySelectedElement!=null);
445
                        jcc2.setEnabled(mySelectedElement!=null);
446

    
447
                        if(mySelectedElement instanceof IMultiLayerSymbol){
448
                                jcc1.setColor(Color.WHITE);
449
                                jcc2.setColor(Color.WHITE);
450
                                jcc1.setEnabled(false);
451
                                jcc2.setEnabled(false);
452
                        }
453

    
454
                        if (shapeType.isTypeOf(Geometry.TYPES.POINT) || shapeType.isTypeOf(Geometry.TYPES.MULTIPOINT)) {
455
                                IMarkerSymbol m = (IMarkerSymbol) mySelectedElement;
456
                                txtSize.setEnabled(m!=null);
457
                                txtAngle.setEnabled(m!=null);
458
                                if(m!=null){
459
                                        jcc1.setColor(m.getColor());
460
                                        txtSize.setDouble(m.getSize());
461
                                        txtAngle.setDouble(Math.toDegrees(m.getRotation()));
462
                                }
463
                        }
464

    
465
                        if (shapeType.isTypeOf(Geometry.TYPES.CURVE) || shapeType.isTypeOf(Geometry.TYPES.MULTICURVE)) {
466
                                ILineSymbol l = (ILineSymbol) mySelectedElement;
467
                                txtSize.setEnabled(l!=null);
468
                                if(l!=null){
469
                                        jcc1.setColor(l.getColor());
470
                                        jcc1.setAlpha(l.getAlpha());
471
                                        txtSize.setDouble(l.getLineWidth());
472
                                }
473
                        }
474

    
475
                        if (shapeType.isTypeOf(Geometry.TYPES.SURFACE) || shapeType.isTypeOf(Geometry.TYPES.MULTISURFACE)) {
476
                                IFillSymbol f = (IFillSymbol) mySelectedElement;
477

    
478
                                txtWidth.setEnabled(f!=null);
479
                                cmbReferenceSystem.setEnabled(f!=null);
480
                                cmbUnits.setEnabled(f!=null);
481

    
482
                                if (f!=null){
483
                                        jcc1.setUseColorIsSelected(f.hasFill());
484
                                        jcc1.setColor(f.getFillColor());
485
                                        jcc1.setAlpha(f.getFillAlpha());
486
                                        jcc2.setUseColorIsSelected(f.hasOutline());
487
                                        ILineSymbol outline = f.getOutline();
488
                                        if (outline != null) {
489
                                                jcc2.setColor(outline.getColor());
490
                                                jcc2.setAlpha(outline.getAlpha());
491
                                                txtWidth.setDouble(outline.getLineWidth());
492
                                        }
493

    
494
                                        if(f instanceof IMultiLayerFillSymbol){
495
                                                txtWidth.setEnabled(false);
496
                                                cmbReferenceSystem.setEnabled(false);
497
                                                cmbUnits.setEnabled(false);
498
                                        }
499
                                }
500
                        }
501

    
502
                } catch (Exception npEx) {
503
                        throw new IllegalArgumentException(npEx);
504
                }
505

    
506
                act = true;  // enable events
507
        }
508

    
509
        /**
510
         * This method initializes jPanel
511
         *
512
         * @return javax.swing.JPanel
513
         */
514
        protected JPanel getJEastPanel() {
515
                if (jPanel == null) {
516
                        jPanel = new JPanel();
517
                        jPanel.setLayout(new BorderLayout());
518
                        jPanel.add(getJPanelOptions(), BorderLayout.CENTER);
519
                        JPanel aux = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
520
                        aux.setBorder(BorderFactory.createTitledBorder(null, Messages.getText("preview")));
521
                        aux.add(getJPanelPreview());
522
                        jPanel.add(aux, BorderLayout.NORTH);
523

    
524
                        jPanel.add(getJPanelOptions());
525
                        aux = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5));
526
                        aux.add(getJPanelButtons());
527
                        jPanel.add(aux, BorderLayout.SOUTH);
528
                }
529
                return jPanel;
530
        }
531

    
532
        private JPanel getJPanelButtons() {
533
                if (jPanelButtons == null) {
534
                        jPanelButtons = new JPanel();
535
                        GridLayout layout = new GridLayout();
536
                        layout.setColumns(1);
537
                        layout.setVgap(5);
538
                        jPanelButtons.add(getBtnNewSymbol());
539
                        jPanelButtons.add(getBtnSaveSymbol());
540
                        jPanelButtons.add(getBtnResetSymbol());
541
                        jPanelButtons.add(getBtnProperties());
542

    
543
                        // do not add components bellow this line!
544
                        layout.setRows(jPanelButtons.getComponentCount());
545
                        jPanelButtons.setLayout(layout);
546
                }
547
                return jPanelButtons;
548
        }
549

    
550
        private JButton getBtnNewSymbol() {
551
                if (btnNewSymbol == null) {
552
                        btnNewSymbol = new JButton();
553
                        btnNewSymbol.setName("btnNewSymbol");
554
                        btnNewSymbol.setText(Messages.getText("new"));
555
                        btnNewSymbol.addActionListener(this);
556
                }
557
                return btnNewSymbol;
558
        }
559

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

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

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

    
590
        /**
591
         * This method initializes jScrollPane
592
         *
593
         * @return javax.swing.JScrollPane
594
         * @throws ClassNotFoundException
595
         */
596
        protected JScrollPane getLeftJScrollPane() {
597
                if (jScrollPane == null) {
598
                        jScrollPane = new JScrollPane();
599
                        jScrollPane.setPreferredSize(new java.awt.Dimension(80,130));
600
                        jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
601
                        libraryBrowser = new LibraryBrowser(library);
602
                        libraryBrowser.addTreeSelectionListener((javax.swing.event.TreeSelectionEvent e) -> {
603
                            if (libraryBrowser.getLastSelectedPathComponent() == null) {
604
                                /*
605
                                * This happens when clicking on [+] to expand
606
                                * or [-] to collapse a tree node.
607
                                */
608
                                return;
609
                            }
610
                            
611
                            dir = (File) ((DefaultMutableTreeNode)
612
                                    libraryBrowser.getLastSelectedPathComponent()).getUserObject();
613
                            
614
                            if (dir == null) {
615
                                return;
616
                            }
617
                            ListModel model = jListSymbols.getModel();
618
                            if( model != null && model instanceof Disposable ) {
619
                                ((Disposable)model).dispose();
620
                            }
621
                            jListSymbols.setModel(newListModel());
622
                        });
623
                        jScrollPane.setViewportView(libraryBrowser);
624
                }
625
                return jScrollPane;
626
        }
627

    
628
        /**
629
         * This method initializes jScrollPane1
630
         *
631
         * @return javax.swing.JScrollPane
632
         */
633
        private JScrollPane getJScrollPane1() {
634
                if (jScrollPane1 == null) {
635
                        jScrollPane1 = new JScrollPane();
636
                        jScrollPane1.setViewportView(getJListSymbols());
637
                }
638
                return jScrollPane1;
639
        }
640

    
641
        /**
642
         * This method initializes jPanelPreview
643
         *
644
         * @return javax.swing.JComponent
645
         */
646
        protected SymbolPreviewer getJPanelPreview() {
647
                if (jPanelPreview == null) {
648
                        jPanelPreview = new SymbolPreviewer(getSampleFeature());
649
                        jPanelPreview.setPreferredSize(new java.awt.Dimension(100,100));
650
                        jPanelPreview.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
651
                }
652
                return jPanelPreview;
653
        }
654
        /**
655
         * This method initializes jPanelOptions
656
         *
657
         * @return javax.swing.JPanel
658
         */
659
        protected JPanel getJPanelOptions() {
660
                if (jPanelOptions == null) {
661
                        jPanelOptions = new GridBagLayoutPanel();
662
                        jPanelOptions.setBorder(BorderFactory.createTitledBorder(null, Messages.getText("options")));
663
                        jcc2 = new ColorChooserPanel(true,true);
664
                        jcc2.setAlpha(255);
665
                        if (shapeType.isTypeOf(Geometry.TYPES.POINT) || shapeType.isTypeOf(Geometry.TYPES.MULTIPOINT)) {
666
                                jcc1 = new ColorChooserPanel(true);
667

    
668
                                jPanelOptions.addComponent(
669
                                                Messages.getText("Color")+":", jcc1);
670
                                jPanelOptions.addComponent(
671
                                                Messages.getText("size")+":",
672
                                                txtSize = new JNumberSpinner(3.0, 3, 0, Double.MAX_VALUE, 1, 2));
673
                                jPanelOptions.addComponent(Messages.getText("units")+":",
674
                                                cmbUnits = new JComboBoxUnits());
675
                                jPanelOptions.addComponent("",
676
                                                cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
677
                                jPanelOptions.addComponent(
678
                                                Messages.getText("angle")+ " (" +Messages.getText("degree")+"):",
679
                                                txtAngle = new JNumberSpinner(0.0, 3, -180.0, 180.0, 1.0, 2));
680

    
681

    
682
                        } else if (shapeType.isTypeOf(Geometry.TYPES.CURVE) || shapeType.isTypeOf(Geometry.TYPES.MULTICURVE)) {
683
                                jcc1 = new ColorChooserPanel(true);
684
                                jPanelOptions.addComponent(
685
                                                Messages.getText("Color")+":", jcc1);
686
                                jPanelOptions.addComponent(
687
                                                Messages.getText("width")+":",
688
                                                txtSize = new JNumberSpinner(3.0, 3, 0, Double.MAX_VALUE, 1, 2));
689
                                jPanelOptions.addComponent(Messages.getText("units")+":",
690
                                                cmbUnits = new JComboBoxUnits());
691
                                jPanelOptions.addComponent("",
692
                                                cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
693

    
694
                        } else if (shapeType.isTypeOf(Geometry.TYPES.SURFACE) || shapeType.isTypeOf(Geometry.TYPES.MULTISURFACE)) {
695
                                jcc1 = new ColorChooserPanel(true, true);
696
                                jPanelOptions.addComponent(
697
                                                Messages.getText("fill_color")+":", jcc1);
698
                                jPanelOptions.addComponent(
699
                                                Messages.getText("outline_color")+":", jcc2);
700
                                jPanelOptions.addComponent(
701
                                                Messages.getText("outline_width"),
702
                                                txtWidth = new JNumberSpinner(3.0, 3, 0, Double.MAX_VALUE, 1, 2));
703
                                jPanelOptions.addComponent(Messages.getText("units")+":",
704
                                                cmbUnits = new JComboBoxUnits());
705
                                jPanelOptions.addComponent("",
706
                                                cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
707

    
708
                        }
709

    
710
                        jcc1.setAlpha(255);
711

    
712
                        if (txtSize != null) {
713
                                txtSize.addActionListener(this);
714
                        }
715
                        if (cmbUnits != null) {
716
                                cmbUnits.addActionListener(this);
717
                        }
718
                        if (cmbReferenceSystem != null) {
719
                                cmbReferenceSystem.addActionListener(this);
720
                        }
721
                        if (jcc1 != null) {
722
                                jcc1.addActionListener(this);
723
                        }
724
                        if (jcc2 != null) {
725
                                jcc2.addActionListener(this);
726
                        }
727
                        if (txtWidth != null) {
728
                                txtWidth.addActionListener(this);
729
                        }
730
                        if (cmbFontSize != null) {
731
                                cmbFontSize.addActionListener(this);
732
                        }
733
                        if (txtAngle != null) {
734
                                txtAngle.addActionListener(this);
735
                        }
736
                }
737
                return jPanelOptions;
738
        }
739

    
740
        private JToggleButton getBtnUnderlined() {
741
                if (btnUnderlined == null) {
742
                        btnUnderlined = new JToggleButton(PluginServices.getIconTheme().
743
                                        get("underline-icon"));
744
                }
745
                return btnUnderlined;
746
        }
747

    
748
        private JToggleButton getBtnItalic() {
749
                if (btnItalic == null) {
750
                        btnItalic = new JToggleButton(PluginServices.getIconTheme().
751
                                        get("italic-icon"));
752
                }
753
                return btnItalic;
754
        }
755

    
756
        private JToggleButton getBtnBold() {
757
                if (btnBold == null) {
758
                        btnBold = new JToggleButton(PluginServices.getIconTheme().
759
                                        get("bold-icon"));
760
                }
761
                return btnBold;
762
        }
763

    
764

    
765
        private JComboBoxFonts getCmbFonts() {
766
                if (cmbFonts == null) {
767
                        cmbFonts = new JComboBoxFonts();
768
                }
769
                return cmbFonts;
770
        }
771

    
772
        @Override
773
        public WindowInfo getWindowInfo() {
774
                if (wi == null) {
775
                        wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
776
                        wi.setWidth(706);
777
                        wi.setHeight(500);
778
                        wi.setTitle(Messages.getText("symbol_selector"));
779
                }
780
                return wi;
781
        }
782

    
783
        protected JSplitPane getJSplitPane() {
784
                if (jSplitPane == null) {
785
                        jSplitPane = new JSplitPane();
786
                        jSplitPane.setDividerLocation(200);
787
                        jSplitPane.setResizeWeight(0.4);
788
                        jSplitPane.setLeftComponent(getLeftJScrollPane());
789
                        jSplitPane.setRightComponent(getJScrollPane1());
790
                }
791
                return jSplitPane;
792
        }
793

    
794
        @Override
795
        public Object getSelectedObject() {
796
                if (!accepted) {
797
                        return null;
798
                }
799
                Object mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
800

    
801
                // if this symbol only has one layer, then no multilayer is needed
802
                if (mySelectedElement instanceof IMultiLayerSymbol) {
803
                        if (((IMultiLayerSymbol) mySelectedElement).getLayerCount()==1) {
804
                                return ((IMultiLayerSymbol) mySelectedElement).getLayer(0);
805
                        }
806
                }
807

    
808
                if (mySelectedElement instanceof CartographicSupport) {
809
                        CartographicSupport csSym = (CartographicSupport) mySelectedElement;
810
                        csSym.setUnit(cmbUnits.getSelectedUnitIndex());
811
                        csSym.setReferenceSystem(cmbReferenceSystem.getSelectedIndex());
812
                }
813

    
814
                return mySelectedElement;
815
        }
816

    
817
        @Override
818
        public void setSymbol(Object symbol) {
819
                ((SymbolPreviewer) jPanelPreview).setSymbol((ISymbol) symbol);
820
                updateOptionsPanel();
821
        }
822

    
823
        /**
824
         * Invoked when the PROPERTIES button is pressed
825
         */
826
        protected void propertiesPressed() {
827
                ISymbol mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
828
                if (mySelectedElement ==null) {
829
                        return;
830
                }
831

    
832
                ISymbol clonedSymbol=null;
833
                try {
834
                        clonedSymbol = (ISymbol) mySelectedElement.clone();
835
                } catch (CloneNotSupportedException e) {
836
                        NotificationManager.addWarning("Symbol layer", e);
837
                }
838
                SymbolEditor se = new SymbolEditor(clonedSymbol, shapeType);
839
                se.setFeatureStore(this.featureStore);
840
                SwingUtilities.invokeLater(() -> { se.refresh();});
841
                PluginServices.getMDIManager().addWindow(se);
842

    
843
                ISymbol symbol = se.getSymbol();
844
                if (symbol instanceof IMultiLayerSymbol) {
845
                        IMultiLayerSymbol mSym = (IMultiLayerSymbol) symbol;
846
                        if (mSym.getLayerCount() == 1) {
847
                                symbol =  mSym.getLayer(0);
848
                        }
849
                }
850
                setSymbol(symbol);
851

    
852
        }
853

    
854
        /**
855
         * Invoked when the NEW button is pressed
856
         */
857
    protected void newPressed() {
858
        ISymbol curr_sym = ((SymbolPreviewer) jPanelPreview).getSymbol();
859

    
860
        if (curr_sym != null) {
861
            try {
862
                curr_sym = (ISymbol) curr_sym.clone();
863
            } catch (Exception cnse) {
864
                logger.info("Unable to clone symbol. "
865
                        + "This can cause an empty symbol if user cancels dialog.",
866
                        cnse);
867
            }
868
        }
869
        SymbolEditor se = new SymbolEditor(curr_sym, shapeType);
870
        se.setFeatureStore(featureStore);
871
        PluginServices.getMDIManager().addWindow(se);
872
        setSymbol(se.getSymbol());
873
    }
874

    
875
        /**
876
         * Invoked when the RESET button is pressed
877
         */
878
        protected void resetPressed() {
879
                setSymbol(null);
880
        }
881

    
882
        /**
883
         * Invoked when the SAVE button is pressed
884
         */
885
        protected void savePressed() {
886
                Object selected = getSelectedObject();
887
                if (getSelectedObject() ==null) {
888
                        return;
889
                }
890

    
891
                final SymbolPreferences preferences = manager.getSymbolPreferences();
892

    
893

    
894
                JFileChooser jfc = new JFileChooser("SYMBOL_SELECTOR_FILECHOOSER", rootDir);
895
                javax.swing.filechooser.FileFilter ff = new javax.swing.filechooser.FileFilter() {
896
                        @Override
897
                        public boolean accept(File f) {
898
                                                return f.getAbsolutePath().toLowerCase().endsWith(
899
                                                                preferences.getSymbolFileExtension())
900
                                                                || f.isDirectory();
901
                        }
902

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

    
923
                accessory.add(txtDesc);
924
                jfc.setAccessory(accessory);
925
                if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
926
                        File targetFile = jfc.getSelectedFile();
927

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

    
944

    
945
                        String symbolFileName = targetFile.getAbsolutePath().substring(
946
                                        targetFile.getAbsolutePath().lastIndexOf(File.separator)+1,
947
                                        targetFile.getAbsolutePath().length());
948
                        File targetDir = new File(targetFile.getAbsolutePath().substring(
949
                                        0,
950
                                        targetFile.getAbsolutePath().lastIndexOf(File.separator)));
951
                        library.addElement(s, symbolFileName , targetDir);
952
                        getJListSymbols().setModel(newListModel());
953
                }
954
        }
955

    
956

    
957
        @Override
958
        public void actionPerformed(ActionEvent e) {
959
                if (!act) {
960
                        return;
961
                }
962
                Object selectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();//getSelectedObject();
963
                performActionOn(selectedElement, e);
964
                SymbolSelector.this.repaint();
965
        }
966

    
967
        protected void performActionOn(Object selectedElement, ActionEvent e) {
968
                JComponent comp = (JComponent) e.getSource();
969

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

    
987
                        Color c = jcc1.getColor();
988

    
989
                        if (selectedElement instanceof IMarkerSymbol) {
990
                                IMarkerSymbol m = (IMarkerSymbol) selectedElement;
991
                                if (m instanceof IMultiLayerMarkerSymbol) {
992
                                        IMultiLayerMarkerSymbol mm = (IMultiLayerMarkerSymbol) m;
993
                                        mm.setAlpha(jcc1.getAlpha());
994
                                } else {
995
                                        m.setColor(c);
996
                                }
997
                        }
998

    
999
                        if (selectedElement instanceof ILineSymbol) {
1000
                                ILineSymbol l = (ILineSymbol) selectedElement;
1001
                                if (l instanceof IMultiLayerLineSymbol) {
1002
                                        IMultiLayerLineSymbol ml = (IMultiLayerLineSymbol) l;
1003
                                        ml.setAlpha(jcc1.getAlpha());
1004
                                } else {
1005
                                        l.setLineColor(c);
1006
                                }
1007
                        }
1008

    
1009
                        if (selectedElement instanceof IFillSymbol) {
1010
                                IFillSymbol f = (IFillSymbol) selectedElement;
1011

    
1012
                                f.setHasFill(jcc1.getUseColorisSelected());
1013
                                f.setFillColor(c);
1014
                        }
1015

    
1016
                        if (selectedElement instanceof ITextSymbol) {
1017
                                ITextSymbol t = (ITextSymbol) selectedElement;
1018
                                t.setTextColor(c);
1019
                        }
1020

    
1021
                } else if (comp.equals(jcc2)) {
1022
                        if (selectedElement == null) {
1023
                                return;
1024
                        }
1025
                        Color c = jcc2.getColor();
1026

    
1027

    
1028
                        if (selectedElement instanceof IFillSymbol) {
1029
                                IFillSymbol f = (IFillSymbol) selectedElement;
1030
                                ILineSymbol outline = f.getOutline();
1031
                                f.setHasOutline(jcc2.getUseColorisSelected());
1032

    
1033
                                if (outline!=null) {
1034
                                        ILineSymbol l = outline;
1035
                                        if (l instanceof IMultiLayerLineSymbol && c != null) {
1036
                                                IMultiLayerLineSymbol ml = (IMultiLayerLineSymbol) l;
1037
                                                ml.setAlpha(c.getAlpha());
1038
                                        } else {
1039
                                                l.setLineColor(c);
1040
                                        }
1041
                                }
1042

    
1043
                        }
1044
                } else if (comp.equals(txtSize)) {
1045
                        double s = txtSize.getDouble();
1046

    
1047
                        if (selectedElement instanceof IMarkerSymbol) {
1048
                                IMarkerSymbol m = (IMarkerSymbol) selectedElement;
1049
                                m.setSize(s);
1050
                                ISymbol sm = m.getSymbolForSelection();
1051
                                if (sm != null && sm instanceof IMarkerSymbol){
1052
                                    ((IMarkerSymbol)sm).setSize(s);
1053
                                }
1054
                        }
1055

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

    
1098
        public static ISymbolSelector createSymbolBrowser() {
1099
                return MultiShapeSymbolSelector.createSymbolBrowser();
1100
        }
1101

    
1102
        public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType) {
1103
                return createSymbolSelector(currSymbol, shapeType, null);
1104
        }
1105

    
1106
        public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType, SelectorFilter filter) {
1107
                ISymbolSelector selector;
1108

    
1109
                GeometryType geometryType = null;
1110
        try {
1111
            geometryType = geomManager.getGeometryType(shapeType, SUBTYPES.GEOM2D);
1112
        } catch (Exception e) {
1113
            logger.error("Impossible to get the geometry type", e);
1114
        }
1115

    
1116
                if (filter==null) {
1117
                        selector = (shapeType == Geometry.TYPES.GEOMETRY) ?
1118
                                        new MultiShapeSymbolSelector(currSymbol) :
1119
                                                new SymbolSelector(currSymbol, geometryType, true);
1120
                } else {
1121
                        selector = (shapeType == Geometry.TYPES.GEOMETRY) ?
1122
                                        new MultiShapeSymbolSelector(currSymbol) :
1123
                                                new SymbolSelector(currSymbol, geometryType, filter, true);
1124
                }
1125
                return selector;
1126
        }
1127

    
1128
        class SillyDragNDropAction implements MouseListener, MouseMotionListener {
1129
                private boolean doDrop = false;
1130
                private Object selected;
1131
                private File sourceFolder;
1132

    
1133
                @Override
1134
                public void mouseClicked(MouseEvent e) { }
1135
                
1136
                @Override
1137
                public void mouseEntered(MouseEvent e) { }
1138
                
1139
                @Override
1140
                public void mouseExited(MouseEvent e) { }
1141
                
1142
                @Override
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
                @Override
1156
                public void mouseReleased(MouseEvent e) {
1157
                        if (doDrop && e.getSource().equals(getJListSymbols())) {
1158
                                Point p = new Point(getJListSymbols().getLocation().x-e.getPoint().x, getJListSymbols().getLocation().y+e.getPoint().y);
1159
                                if (libraryBrowser.getBounds().contains(p)) {
1160
                                        File destFolder = libraryBrowser.getElementBellow(p);
1161
                                        if (destFolder != null) {
1162
                                                ISymbol sym = (ISymbol) selected;
1163
                                                int move = InputEvent.SHIFT_DOWN_MASK | InputEvent.BUTTON1_DOWN_MASK;
1164
                                                //                                            int copy = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
1165

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

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

    
1175
                        }
1176
                        doDrop = false;
1177
                }
1178

    
1179
                @Override
1180
                public void mouseDragged(MouseEvent e) {
1181
                        if (e.getSource().equals(getJListSymbols())) {
1182

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

    
1190
                @Override
1191
                public void mouseMoved(MouseEvent e) {
1192

    
1193
                }
1194

    
1195
        }
1196

    
1197
        @Override
1198
        public Object getWindowProfile() {
1199
                return WindowInfo.DIALOG_PROFILE;
1200
        }
1201

    
1202
        @Override
1203
        public void setFeatureStore(FeatureStore store) {
1204
            this.featureStore = store;
1205
            if( this.featureStore!=null ) {
1206
                this.sampleFeature.setValue(this.featureStore.getSampleFeature());
1207
            }
1208
        }
1209
        
1210
        public MutableObject<Feature> getSampleFeature() {
1211
            if( this.sampleFeature == null ) {
1212
                this.sampleFeature = new MutableObject();
1213
                if( this.featureStore!=null ) {
1214
                    this.sampleFeature.setValue(this.featureStore.getSampleFeature());
1215
                }
1216
            }
1217
            return this.sampleFeature;
1218
        }
1219
        
1220

    
1221
}