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

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

    
59
import org.slf4j.Logger;
60
import org.slf4j.LoggerFactory;
61
import org.gvsig.andami.PluginServices;
62
import org.gvsig.andami.messages.NotificationManager;
63
import org.gvsig.andami.ui.mdiManager.WindowInfo;
64
import org.gvsig.app.gui.JComboBoxUnits;
65
import org.gvsig.app.gui.panels.ColorChooserPanel;
66
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector;
67
import org.gvsig.fmap.geom.Geometry;
68
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
69
import org.gvsig.fmap.geom.Geometry.TYPES;
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.JIncrementalNumberField;
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

    
100

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

    
147

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

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

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

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

    
205
                // TODO  09/08/07 check the currentElement type is suitable for the shapeType specified
206
                if (currentElement != null && currentElement instanceof ISymbol) {
207
                        ISymbol sym = (ISymbol) currentElement;
208
                        try {
209
                                currentElement = sym.clone(); 
210
                        } catch (CloneNotSupportedException e) {
211
                                NotificationManager.addWarning("Symbol layer", e);
212
                        }
213
                        String desc = sym.getDescription();
214
                        //                    desc += " ("+PluginServices.getText(this, "current")+")";
215
                        //                    ((ISymbol)currentElement).setDescription(desc);
216
                }
217
        
218
        this.shapeType = shapeType;
219
      
220
                //            Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" );
221
                rootDir =
222
                                new File(manager.getSymbolPreferences().getSymbolLibraryPath());
223

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

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

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

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

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

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

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

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

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

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

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

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

    
410
                                        return pnl;
411
                                }
412

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

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

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

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

    
443
                try {
444

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

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

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

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

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

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

    
483
                                if (f!=null){
484
                                        jcc1.setUseColorIsSelected(f.hasFill());
485
                                        jcc1.setColor(f.getFillColor());
486
                                        jcc1.setAlpha(f.getFillAlpha());
487
                                        jcc2.setUseColorIsSelected(f.hasOutline());
488
                                        ILineSymbol outline = f.getOutline();
489
                                        if (outline != null) {
490
                                                jcc2.setColor(outline.getColor());
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 (NullPointerException npEx) {
503
                        throw new IllegalArgumentException(npEx);
504
                } catch (ClassCastException ccEx) {
505
                        throw new IllegalArgumentException(ccEx);
506
                }
507

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

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

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

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

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

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

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

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

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

    
592
        /**
593
         * This method initializes jScrollPane
594
         *
595
         * @return javax.swing.JScrollPane
596
         * @throws ClassNotFoundException
597
         */
598
        protected JScrollPane getLeftJScrollPane() {
599
                if (jScrollPane == null) {
600
                        jScrollPane = new JScrollPane();
601
                        jScrollPane.setPreferredSize(new java.awt.Dimension(80,130));
602
                        jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
603
                        libraryBrowser = new LibraryBrowser(library);
604
                        libraryBrowser.addTreeSelectionListener(new TreeSelectionListener() {
605
                                public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
606
                                        
607
                                        if (libraryBrowser.getLastSelectedPathComponent() == null) {
608
                                                /*
609
                                                 * This happens when clicking on [+] to expand
610
                                                 * or [-] to collapse a tree node. 
611
                                                 */
612
                                                return;
613
                                        }
614
                                        
615
                                        dir = (File) ((DefaultMutableTreeNode)
616
                                                        libraryBrowser.getLastSelectedPathComponent()).getUserObject();
617

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

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

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

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

    
686

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

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

    
713
                        }
714

    
715
                        jcc1.setAlpha(255);
716

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

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

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

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

    
769

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

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

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

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

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

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

    
817
                return mySelectedElement;
818
        }
819

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

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

    
834
                ISymbol clonedSymbol=null;
835
                try {
836
                        clonedSymbol = (ISymbol) mySelectedElement.clone(); 
837
                } catch (CloneNotSupportedException e) {
838
                        NotificationManager.addWarning("Symbol layer", e);
839
                }
840
                SymbolEditor se = new SymbolEditor(clonedSymbol, shapeType);
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
            try {
861
                curr_sym = (ISymbol) curr_sym.clone();
862
            } catch (Exception cnse) {
863
                logger.info("Unable to clone symbol. "
864
                    + "This can cause an empty symbol if user cancels dialog.",
865
                    cnse);
866
            }
867

    
868
                SymbolEditor se = new SymbolEditor(curr_sym, shapeType);
869
                PluginServices.getMDIManager().addWindow(se);
870
                setSymbol(se.getSymbol());
871
        }
872

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

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

    
889
                final SymbolPreferences preferences = manager.getSymbolPreferences();
890

    
891

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

    
900
                        public String getDescription() {
901
                                                return Messages.getText(
902
                                                                "gvSIG_symbol_definition_file")
903
                                                                .concat(" (*")
904
                                                                .concat(preferences.getSymbolFileExtension())
905
                                                                .concat(")");
906
                        }
907
                };
908
                jfc.setFileFilter(ff);
909
                JPanel accessory = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
910
                accessory.add(new JLabel(Messages.getText("enter_description")));
911
                JTextField txtDesc = new JTextField(25);
912
                if( selected instanceof ISymbol ) {
913
                    txtDesc.setText(((ISymbol)selected).getDescription());
914
                }
915
                if( selected instanceof ISymbol_v2 ) {
916
                    jfc.setSelectedFile(new File(((ISymbol_v2)selected).getID()));
917
                }
918
                
919
                accessory.add(txtDesc);
920
                jfc.setAccessory(accessory);
921
                if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
922
                        File targetFile = jfc.getSelectedFile();
923

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

    
940

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

    
952

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

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

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

    
982
                        Color c = jcc1.getColor();
983

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

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

    
1004
                        if (selectedElement instanceof IFillSymbol) {
1005
                                IFillSymbol f = (IFillSymbol) selectedElement;
1006

    
1007
                                f.setHasFill(jcc1.getUseColorisSelected());
1008
                                f.setFillColor(c);
1009
                        }
1010

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

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

    
1022

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

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

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

    
1042
                        if (selectedElement instanceof IMarkerSymbol) {
1043
                                IMarkerSymbol m = (IMarkerSymbol) selectedElement;
1044
                                m.setSize(s);
1045
                        }
1046

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

    
1085
        public static ISymbolSelector createSymbolBrowser() {
1086
                return MultiShapeSymbolSelector.createSymbolBrowser();
1087
        }
1088

    
1089
        public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType) {
1090
                return createSymbolSelector(currSymbol, shapeType, null);
1091
        }
1092

    
1093
        public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType, SelectorFilter filter) {
1094
                ISymbolSelector selector = null;
1095

    
1096
                GeometryType geometryType = null;
1097
        try {
1098
            geometryType = geomManager.getGeometryType(shapeType, SUBTYPES.GEOM2D);
1099
        } catch (GeometryTypeNotSupportedException e) {
1100
            logger.error("Impossible to get the geometry type", e);
1101
        } catch (GeometryTypeNotValidException e) {
1102
            logger.error("Impossible to get the geometry type", e);
1103
        }
1104

    
1105
                if (filter==null) {
1106
                        selector = (shapeType == Geometry.TYPES.GEOMETRY) ?
1107
                                        new MultiShapeSymbolSelector(currSymbol) :
1108
                                                new SymbolSelector(currSymbol, geometryType, true);
1109
                } else {
1110
                        selector = (shapeType == Geometry.TYPES.GEOMETRY) ?
1111
                                        new MultiShapeSymbolSelector(currSymbol) :
1112
                                                new SymbolSelector(currSymbol, geometryType, filter, true);
1113
                }
1114
                return selector;
1115
        }
1116

    
1117
        class SillyDragNDropAction implements MouseListener, MouseMotionListener {
1118
                private boolean doDrop = false;
1119
                private Object selected;
1120
                private File sourceFolder;
1121

    
1122
                public void mouseClicked(MouseEvent e) { }
1123
                public void mouseEntered(MouseEvent e) { }
1124
                public void mouseExited(MouseEvent e) { }
1125

    
1126
                public void mousePressed(MouseEvent e) {
1127
                        if (e.getSource().equals(getJListSymbols())) {
1128
                                selected = getJListSymbols().getSelectedValue();
1129
                                doDrop = selected!=null;
1130
                                DefaultMutableTreeNode node = (DefaultMutableTreeNode) libraryBrowser.getLastSelectedPathComponent();
1131
                                if (node.getUserObject() instanceof File) {
1132
                                        sourceFolder = (File) node.getUserObject();
1133
                                }
1134
                        }
1135
                        e.consume();
1136
                }
1137

    
1138
                public void mouseReleased(MouseEvent e) {
1139
                        if (doDrop && e.getSource().equals(getJListSymbols())) {
1140
                                Point p = new Point(getJListSymbols().getLocation().x-e.getPoint().x, getJListSymbols().getLocation().y+e.getPoint().y);
1141
                                if (libraryBrowser.getBounds().contains(p)) {
1142
                                        File destFolder = libraryBrowser.getElementBellow(p);
1143
                                        if (destFolder != null) {
1144
                                                ISymbol sym = (ISymbol) selected;
1145
                                                int move = InputEvent.SHIFT_DOWN_MASK | InputEvent.BUTTON1_DOWN_MASK;
1146
                                                //                                            int copy = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
1147

    
1148
                                                library.addElement(sym, sym.getDescription(), destFolder);
1149
                                                if ((e.getModifiers() & (move)) !=0) {
1150
                                                        library.removeElement(sym, sourceFolder);
1151
                                                }
1152

    
1153
                                        }
1154
                                        libraryBrowser.refresh();
1155
                                }
1156

    
1157
                        }
1158
                        doDrop = false;
1159
                }
1160

    
1161
                public void mouseDragged(MouseEvent e) {
1162
                        if (e.getSource().equals(getJListSymbols())) {
1163

    
1164
                                Point p = new Point(getJListSymbols().getLocation().x-e.getPoint().x, getJListSymbols().getLocation().y+e.getPoint().y);
1165
                                if (libraryBrowser.getBounds().contains(p)) {
1166
                                        libraryBrowser.setSelectedElementBellow(p);
1167
                                }
1168
                        }
1169
                }
1170

    
1171
                public void mouseMoved(MouseEvent e) {
1172

    
1173
                }
1174

    
1175
        }
1176

    
1177
        public Object getWindowProfile() {
1178
                return WindowInfo.DIALOG_PROFILE;
1179
        }
1180

    
1181
}