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

History | View | Annotate | Download (37.6 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.JIncrementalNumberField;
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 JIncrementalNumberField txtSize;
124
        private JIncrementalNumberField 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 JIncrementalNumberField 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

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

    
204
                manager = MapContextLocator.getSymbolManager();
205

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

    
219
        this.shapeType = shapeType;
220

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

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

    
233
        }
234

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

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

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

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

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

    
287
                this.add(getJNorthPanel(), BorderLayout.NORTH);
288
                this.add(getJSplitPane(), BorderLayout.CENTER);
289
                this.add(getJEastPanel(), BorderLayout.EAST);
290
                ActionListener okAction = new ActionListener() {
291
                        public void actionPerformed(ActionEvent e) {
292
                                PluginServices.getMDIManager().closeWindow(SymbolSelector.this);
293
                        }
294
                }, cancelAction = new ActionListener() {
295
                        public void actionPerformed(ActionEvent e) {
296
                                accepted = false;
297

    
298
                                setSymbol(null);
299
                                PluginServices.getMDIManager().closeWindow(SymbolSelector.this);
300
                        }
301
                };
302

    
303
                okCancelPanel = new AcceptCancelPanel();
304
                okCancelPanel.setOkButtonActionListener(okAction);
305
                okCancelPanel.setCancelButtonActionListener(cancelAction);
306

    
307
                this.add(okCancelPanel, BorderLayout.SOUTH);
308
                libraryBrowser.setSelectionRow(0);
309

    
310
                SillyDragNDropAction dndAction = new SillyDragNDropAction();
311
                libraryBrowser.addMouseListener(dndAction);
312
                libraryBrowser.addMouseMotionListener(dndAction);
313
                getJListSymbols().addMouseListener(dndAction);
314
                getJListSymbols().addMouseMotionListener(dndAction);
315
                setSymbol(currentElement);
316
        }
317

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

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

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

    
411
                                        return pnl;
412
                                }
413

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

    
427
//                if (mySelectedElement == null) {
428
//                        return;
429
//                }
430
                act = false; // disable events
431

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

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

    
444
                try {
445

    
446
                        jcc1.setEnabled(mySelectedElement!=null);
447
                        jcc2.setEnabled(mySelectedElement!=null);
448

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

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

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

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

    
480
                                txtWidth.setEnabled(f!=null);
481
                                cmbReferenceSystem.setEnabled(f!=null);
482
                                cmbUnits.setEnabled(f!=null);
483

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

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

    
503
                } catch (NullPointerException npEx) {
504
                        throw new IllegalArgumentException(npEx);
505
                } catch (ClassCastException ccEx) {
506
                        throw new IllegalArgumentException(ccEx);
507
                }
508

    
509
                act = true;  // enable events
510
        }
511

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

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

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

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

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

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

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

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

    
593
        /**
594
         * This method initializes jScrollPane
595
         *
596
         * @return javax.swing.JScrollPane
597
         * @throws ClassNotFoundException
598
         */
599
        protected JScrollPane getLeftJScrollPane() {
600
                if (jScrollPane == null) {
601
                        jScrollPane = new JScrollPane();
602
                        jScrollPane.setPreferredSize(new java.awt.Dimension(80,130));
603
                        jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
604
                        libraryBrowser = new LibraryBrowser(library);
605
                        libraryBrowser.addTreeSelectionListener(new TreeSelectionListener() {
606
                                public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
607

    
608
                                        if (libraryBrowser.getLastSelectedPathComponent() == null) {
609
                                                /*
610
                                                 * This happens when clicking on [+] to expand
611
                                                 * or [-] to collapse a tree node.
612
                                                 */
613
                                                return;
614
                                        }
615

    
616
                                        dir = (File) ((DefaultMutableTreeNode)
617
                                                        libraryBrowser.getLastSelectedPathComponent()).getUserObject();
618

    
619
                                        if (dir == null) {
620
                                                return;
621
                                        }
622
                                        ListModel model = jListSymbols.getModel();
623
                                        if( model != null && model instanceof Disposable ) {
624
                                                ((Disposable)model).dispose();
625
                                        }
626
                                        jListSymbols.setModel(newListModel());
627
                                }
628
                        });
629
                        jScrollPane.setViewportView(libraryBrowser);
630
                }
631
                return jScrollPane;
632
        }
633

    
634
        /**
635
         * This method initializes jScrollPane1
636
         *
637
         * @return javax.swing.JScrollPane
638
         */
639
        private JScrollPane getJScrollPane1() {
640
                if (jScrollPane1 == null) {
641
                        jScrollPane1 = new JScrollPane();
642
                        jScrollPane1.setViewportView(getJListSymbols());
643
                }
644
                return jScrollPane1;
645
        }
646

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

    
674
                                jPanelOptions.addComponent(
675
                                                Messages.getText("color")+":", jcc1);
676
                                jPanelOptions.addComponent(
677
                                                Messages.getText("size")+":",
678
                                                txtSize = new JIncrementalNumberField(String.valueOf(3), 3, 0, Double.MAX_VALUE, 1));
679
                                jPanelOptions.addComponent(Messages.getText("units")+":",
680
                                                cmbUnits = new JComboBoxUnits());
681
                                jPanelOptions.addComponent("",
682
                                                cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
683
                                jPanelOptions.addComponent(
684
                                                Messages.getText("angle")+ " (" +Messages.getText("degree")+"):",
685
                                                txtAngle = new JIncrementalNumberField());
686

    
687

    
688
                        } else if (shapeType.isTypeOf(Geometry.TYPES.CURVE) || shapeType.isTypeOf(Geometry.TYPES.MULTICURVE)) {
689
                                jcc1 = new ColorChooserPanel(true);
690
                                jPanelOptions.addComponent(
691
                                                Messages.getText("color")+":", jcc1);
692
                                jPanelOptions.addComponent(
693
                                                Messages.getText("width")+":",
694
                                                txtSize = new JIncrementalNumberField(String.valueOf(3), 3, 0, Double.MAX_VALUE, 1));
695
                                jPanelOptions.addComponent(Messages.getText("units")+":",
696
                                                cmbUnits = new JComboBoxUnits());
697
                                jPanelOptions.addComponent("",
698
                                                cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
699

    
700
                        } else if (shapeType.isTypeOf(Geometry.TYPES.SURFACE) || shapeType.isTypeOf(Geometry.TYPES.MULTISURFACE)) {
701
                                jcc1 = new ColorChooserPanel(true, true);
702
                                jPanelOptions.addComponent(
703
                                                Messages.getText("fill_color")+":", jcc1);
704
                                jPanelOptions.addComponent(
705
                                                Messages.getText("outline_color")+":", jcc2);
706
                                jPanelOptions.addComponent(
707
                                                Messages.getText("outline_width"),
708
                                                txtWidth = new JIncrementalNumberField(String.valueOf(3), 3, 0, Double.MAX_VALUE, 1));
709
                                jPanelOptions.addComponent(Messages.getText("units")+":",
710
                                                cmbUnits = new JComboBoxUnits());
711
                                jPanelOptions.addComponent("",
712
                                                cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
713

    
714
                        }
715

    
716
                        jcc1.setAlpha(255);
717

    
718
                        if (txtSize != null) {
719
                                txtSize.addActionListener(this);
720
                        }
721
                        if (cmbUnits != null) {
722
                                cmbUnits.addActionListener(this);
723
                        }
724
                        if (cmbReferenceSystem != null) {
725
                                cmbReferenceSystem.addActionListener(this);
726
                        }
727
                        if (jcc1 != null) {
728
                                jcc1.addActionListener(this);
729
                        }
730
                        if (jcc2 != null) {
731
                                jcc2.addActionListener(this);
732
                        }
733
                        if (txtWidth != null) {
734
                                txtWidth.addActionListener(this);
735
                        }
736
                        if (cmbFontSize != null) {
737
                                cmbFontSize.addActionListener(this);
738
                        }
739
                        if (txtAngle != null) {
740
                                txtAngle.addActionListener(this);
741
                        }
742
                }
743
                return jPanelOptions;
744
        }
745

    
746
        private JToggleButton getBtnUnderlined() {
747
                if (btnUnderlined == null) {
748
                        btnUnderlined = new JToggleButton(PluginServices.getIconTheme().
749
                                        get("underline-icon"));
750
                }
751
                return btnUnderlined;
752
        }
753

    
754
        private JToggleButton getBtnItalic() {
755
                if (btnItalic == null) {
756
                        btnItalic = new JToggleButton(PluginServices.getIconTheme().
757
                                        get("italic-icon"));
758
                }
759
                return btnItalic;
760
        }
761

    
762
        private JToggleButton getBtnBold() {
763
                if (btnBold == null) {
764
                        btnBold = new JToggleButton(PluginServices.getIconTheme().
765
                                        get("bold-icon"));
766
                }
767
                return btnBold;
768
        }
769

    
770

    
771
        private JComboBoxFonts getCmbFonts() {
772
                if (cmbFonts == null) {
773
                        cmbFonts = new JComboBoxFonts();
774
                }
775
                return cmbFonts;
776
        }
777

    
778
        public WindowInfo getWindowInfo() {
779
                if (wi == null) {
780
                        wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
781
                        wi.setWidth(706);
782
                        wi.setHeight(500);
783
                        wi.setTitle(Messages.getText("symbol_selector"));
784
                }
785
                return wi;
786
        }
787

    
788
        protected JSplitPane getJSplitPane() {
789
                if (jSplitPane == null) {
790
                        jSplitPane = new JSplitPane();
791
                        jSplitPane.setDividerLocation(200);
792
                        jSplitPane.setResizeWeight(0.4);
793
                        jSplitPane.setLeftComponent(getLeftJScrollPane());
794
                        jSplitPane.setRightComponent(getJScrollPane1());
795
                }
796
                return jSplitPane;
797
        }
798

    
799
        public Object getSelectedObject() {
800
                if (!accepted) {
801
                        return null;
802
                }
803
                Object mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
804

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

    
812
                if (mySelectedElement instanceof CartographicSupport) {
813
                        CartographicSupport csSym = (CartographicSupport) mySelectedElement;
814
                        csSym.setUnit(cmbUnits.getSelectedUnitIndex());
815
                        csSym.setReferenceSystem(cmbReferenceSystem.getSelectedIndex());
816
                }
817

    
818
                return mySelectedElement;
819
        }
820

    
821
        public void setSymbol(Object symbol) {
822
                ((SymbolPreviewer) jPanelPreview).setSymbol((ISymbol) symbol);
823
                updateOptionsPanel();
824
        }
825

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

    
835
                ISymbol clonedSymbol=null;
836
                try {
837
                        clonedSymbol = (ISymbol) mySelectedElement.clone();
838
                } catch (CloneNotSupportedException e) {
839
                        NotificationManager.addWarning("Symbol layer", e);
840
                }
841
                SymbolEditor se = new SymbolEditor(clonedSymbol, shapeType);
842
                PluginServices.getMDIManager().addWindow(se);
843

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

    
853
        }
854

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

    
861
        if (curr_sym != null) {
862
            try {
863
                curr_sym = (ISymbol) curr_sym.clone();
864
            } catch (Exception cnse) {
865
                logger.info("Unable to clone symbol. "
866
                        + "This can cause an empty symbol if user cancels dialog.",
867
                        cnse);
868
            }
869
        }
870
        SymbolEditor se = new SymbolEditor(curr_sym, shapeType);
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
                        public boolean accept(File f) {
897
                                                return f.getAbsolutePath().toLowerCase().endsWith(
898
                                                                preferences.getSymbolFileExtension())
899
                                                                || f.isDirectory();
900
                        }
901

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

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

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

    
942

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

    
954

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

    
964
        protected void performActionOn(Object selectedElement, ActionEvent e) {
965
                JComponent comp = (JComponent) e.getSource();
966

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

    
984
                        Color c = jcc1.getColor();
985

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

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

    
1006
                        if (selectedElement instanceof IFillSymbol) {
1007
                                IFillSymbol f = (IFillSymbol) selectedElement;
1008

    
1009
                                f.setHasFill(jcc1.getUseColorisSelected());
1010
                                f.setFillColor(c);
1011
                        }
1012

    
1013
                        if (selectedElement instanceof ITextSymbol) {
1014
                                ITextSymbol t = (ITextSymbol) selectedElement;
1015
                                t.setTextColor(c);
1016
                        }
1017

    
1018
                } else if (comp.equals(jcc2)) {
1019
                        if (selectedElement == null) {
1020
                                return;
1021
                        }
1022
                        Color c = jcc2.getColor();
1023

    
1024

    
1025
                        if (selectedElement instanceof IFillSymbol) {
1026
                                IFillSymbol f = (IFillSymbol) selectedElement;
1027
                                ILineSymbol outline = f.getOutline();
1028
                                f.setHasOutline(jcc2.getUseColorisSelected());
1029

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

    
1040
                        }
1041
                } else if (comp.equals(txtSize)) {
1042
                        double s = txtSize.getDouble();
1043

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

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

    
1095
        public static ISymbolSelector createSymbolBrowser() {
1096
                return MultiShapeSymbolSelector.createSymbolBrowser();
1097
        }
1098

    
1099
        public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType) {
1100
                return createSymbolSelector(currSymbol, shapeType, null);
1101
        }
1102

    
1103
        public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType, SelectorFilter filter) {
1104
                ISymbolSelector selector = null;
1105

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

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

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

    
1132
                public void mouseClicked(MouseEvent e) { }
1133
                public void mouseEntered(MouseEvent e) { }
1134
                public void mouseExited(MouseEvent e) { }
1135

    
1136
                public void mousePressed(MouseEvent e) {
1137
                        if (e.getSource().equals(getJListSymbols())) {
1138
                                selected = getJListSymbols().getSelectedValue();
1139
                                doDrop = selected!=null;
1140
                                DefaultMutableTreeNode node = (DefaultMutableTreeNode) libraryBrowser.getLastSelectedPathComponent();
1141
                                if (node.getUserObject() instanceof File) {
1142
                                        sourceFolder = (File) node.getUserObject();
1143
                                }
1144
                        }
1145
                        e.consume();
1146
                }
1147

    
1148
                public void mouseReleased(MouseEvent e) {
1149
                        if (doDrop && e.getSource().equals(getJListSymbols())) {
1150
                                Point p = new Point(getJListSymbols().getLocation().x-e.getPoint().x, getJListSymbols().getLocation().y+e.getPoint().y);
1151
                                if (libraryBrowser.getBounds().contains(p)) {
1152
                                        File destFolder = libraryBrowser.getElementBellow(p);
1153
                                        if (destFolder != null) {
1154
                                                ISymbol sym = (ISymbol) selected;
1155
                                                int move = InputEvent.SHIFT_DOWN_MASK | InputEvent.BUTTON1_DOWN_MASK;
1156
                                                //                                            int copy = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
1157

    
1158
                                                library.addElement(sym, sym.getDescription(), destFolder);
1159
                                                if ((e.getModifiers() & (move)) !=0) {
1160
                                                        library.removeElement(sym, sourceFolder);
1161
                                                }
1162

    
1163
                                        }
1164
                                        libraryBrowser.refresh();
1165
                                }
1166

    
1167
                        }
1168
                        doDrop = false;
1169
                }
1170

    
1171
                public void mouseDragged(MouseEvent e) {
1172
                        if (e.getSource().equals(getJListSymbols())) {
1173

    
1174
                                Point p = new Point(getJListSymbols().getLocation().x-e.getPoint().x, getJListSymbols().getLocation().y+e.getPoint().y);
1175
                                if (libraryBrowser.getBounds().contains(p)) {
1176
                                        libraryBrowser.setSelectedElementBellow(p);
1177
                                }
1178
                        }
1179
                }
1180

    
1181
                public void mouseMoved(MouseEvent e) {
1182

    
1183
                }
1184

    
1185
        }
1186

    
1187
        public Object getWindowProfile() {
1188
                return WindowInfo.DIALOG_PROFILE;
1189
        }
1190

    
1191
}