Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / SymbolSelector.java @ 34291

History | View | Annotate | Download (36.1 KB)

1
/*
2
 * Created on 26-abr-2005
3
 *
4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 *
6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 *
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 *
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
 *
22
 * For more information, contact:
23
 *
24
 *  Generalitat Valenciana
25
 *   Conselleria d'Infraestructures i Transport
26
 *   Av. Blasco Ib??ez, 50
27
 *   46010 VALENCIA
28
 *   SPAIN
29
 *
30
 *      +34 963862235
31
 *   gvsig@gva.es
32
 *      www.gvsig.gva.es
33
 *
34
 *    or
35
 *
36
 *   IVER T.I. S.A
37
 *   Salamanca 50
38
 *   46005 Valencia
39
 *   Spain
40
 *
41
 *   +34 963163400
42
 *   dac@iver.es
43
 */
44
package org.gvsig.app.gui.styling;
45

    
46
import java.awt.BorderLayout;
47
import java.awt.Color;
48
import java.awt.Component;
49
import java.awt.Dimension;
50
import java.awt.FlowLayout;
51
import java.awt.Font;
52
import java.awt.GridLayout;
53
import java.awt.Point;
54
import java.awt.event.ActionEvent;
55
import java.awt.event.ActionListener;
56
import java.awt.event.InputEvent;
57
import java.awt.event.MouseEvent;
58
import java.awt.event.MouseListener;
59
import java.awt.event.MouseMotionListener;
60
import java.io.File;
61

    
62
import javax.swing.BorderFactory;
63
import javax.swing.BoxLayout;
64
import javax.swing.JComponent;
65
import javax.swing.JLabel;
66
import javax.swing.JList;
67
import javax.swing.JPanel;
68
import javax.swing.JScrollPane;
69
import javax.swing.JSplitPane;
70
import javax.swing.JTextField;
71
import javax.swing.JToggleButton;
72
import javax.swing.ListCellRenderer;
73
import javax.swing.event.ListSelectionEvent;
74
import javax.swing.event.ListSelectionListener;
75
import javax.swing.event.TreeSelectionListener;
76
import javax.swing.tree.DefaultMutableTreeNode;
77

    
78
import org.gvsig.andami.PluginServices;
79
import org.gvsig.andami.messages.NotificationManager;
80
import org.gvsig.andami.ui.mdiManager.WindowInfo;
81
import org.gvsig.app.gui.JComboBoxUnits;
82
import org.gvsig.app.gui.panels.ColorChooserPanel;
83
import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector;
84
import org.gvsig.fmap.geom.Geometry;
85
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
86
import org.gvsig.fmap.geom.GeometryLocator;
87
import org.gvsig.fmap.geom.GeometryManager;
88
import org.gvsig.fmap.geom.exception.CreateGeometryException;
89
import org.gvsig.fmap.geom.primitive.GeneralPathX;
90
import org.gvsig.fmap.mapcontext.MapContextLocator;
91
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
92
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol;
93
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
94
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol;
95
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager;
96
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolPreferences;
97
import org.gvsig.gui.beans.AcceptCancelPanel;
98
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
99
import org.gvsig.gui.beans.swing.JButton;
100
import org.gvsig.gui.beans.swing.JComboBoxFontSizes;
101
import org.gvsig.gui.beans.swing.JComboBoxFonts;
102
import org.gvsig.gui.beans.swing.JFileChooser;
103
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
104
import org.gvsig.i18n.Messages;
105
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
106
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IMultiLayerFillSymbol;
107
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
108
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.IMultiLayerLineSymbol;
109
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
110
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMultiLayerMarkerSymbol;
111
import org.slf4j.Logger;
112
import org.slf4j.LoggerFactory;
113

    
114

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

    
161

    
162
        protected SelectorFilter sFilter = new SelectorFilter() {
163
                private Geometry dummyPointGeom = null;
164
                private Geometry dummyLineGeom = null;
165
                private Geometry dummyPolygonGeom = null;
166
                private boolean isInitialized = false;
167

    
168
                public boolean accepts(Object obj) {
169
                        if (!isInitialized){
170
                                try {
171
                                        dummyPointGeom = geomManager.createPoint(0, 0, SUBTYPES.GEOM2D);
172
                                        dummyLineGeom = geomManager.createSurface(new GeneralPathX(), SUBTYPES.GEOM2D);
173
                                        dummyPolygonGeom = geomManager.createSurface(new GeneralPathX(), SUBTYPES.GEOM2D);
174
                                } catch (CreateGeometryException e) {
175
                                        logger.error("Error creating a geometry", e);
176
                                }
177
                                isInitialized = true;
178
                        }
179

    
180
                        if (obj instanceof ISymbol) {
181
                                ISymbol sym = (ISymbol) obj;
182

    
183
                                Geometry compareGeometry = null;
184
                                switch (SymbolSelector.this.shapeType) {
185
                                case Geometry.TYPES.TEXT:
186
                                        return sym instanceof ITextSymbol;
187
                                case Geometry.TYPES.POINT:
188
                                        compareGeometry = dummyPointGeom;
189
                                        break;
190
                                case Geometry.TYPES.CURVE:
191
                                        compareGeometry = dummyLineGeom;
192
                                        break;
193
                                case Geometry.TYPES.SURFACE:
194
                                        compareGeometry = dummyPolygonGeom;
195
                                        break;
196
                                }
197
                                return sym.isSuitableFor(compareGeometry);
198
                        }
199
                        return false;
200
                }
201
        };
202
        protected JComboBoxUnits cmbUnits;
203
        protected JComboBoxUnitsReferenceSystem cmbReferenceSystem;
204
        private JComboBoxFontSizes cmbFontSize;
205
        protected LibraryBrowser libraryBrowser;
206
        /**
207
         * Constructor method
208
         *
209
         * @param currentElement
210
         * @param shapeType
211
         */
212
        private SymbolSelector(Object currentElement, int shapeType, boolean initialize) {
213
                super();
214

    
215
                manager = MapContextLocator.getSymbolManager();
216

    
217
                // TODO  09/08/07 check the currentElement type is suitable for the shapeType specified
218
                if (currentElement != null && currentElement instanceof ISymbol) {
219
                        ISymbol sym = (ISymbol) currentElement;
220
                        try {
221
                                currentElement = sym.clone(); 
222
                        } catch (CloneNotSupportedException e) {
223
                                NotificationManager.addWarning("Symbol layer", e);
224
                        }
225
                        String desc = sym.getDescription();
226
                        //                    desc += " ("+PluginServices.getText(this, "current")+")";
227
                        //                    ((ISymbol)currentElement).setDescription(desc);
228
                }
229

    
230
                //             for symbols MULTIPOINT is the same than POINT
231
                if (shapeType == Geometry.TYPES.MULTIPOINT) {
232
                        shapeType = Geometry.TYPES.POINT;
233
                }
234

    
235
                this.shapeType = shapeType;
236
                //            Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" );
237
                rootDir =
238
                                new File(manager.getSymbolPreferences().getSymbolLibraryPath());
239
                //                                prefs.get("SymbolLibraryFolder", System.getProperty("user.home")+"/gvSIG/Symbols"));
240
                if (!rootDir.exists()) {
241
                        rootDir.mkdir();
242
                }
243
                treeRootName = Messages.getText("symbol_library");
244
                try {
245
                        if (initialize) {
246
                                initialize(currentElement);
247
                        }
248
                } catch (ClassNotFoundException e) {
249
                        throw new Error(e);
250
                }
251

    
252

    
253
        }
254

    
255
        /**
256
         * Constructor method, it is <b>protected</b> by convenience to let StyleSelector
257
         * to invoke it, but rigorously it should be <b>private</b>.
258
         *
259
         * @param symbol
260
         * @param shapeType
261
         * @param filter
262
         */
263
        protected SymbolSelector(Object symbol, int shapeType, SelectorFilter filter, boolean initialize) {
264
                this(symbol, shapeType, initialize);
265
                sFilter = filter;
266
        }
267

    
268
        /**
269
         * This method initializes this
270
         * @param currentElement
271
         * @throws ClassNotFoundException
272
         *
273
         */
274
        protected void initialize(Object currentElement) throws ClassNotFoundException {
275
                library = new SymbolLibrary(rootDir);
276

    
277
                this.setLayout(new BorderLayout());
278
                this.setSize(400, 221);
279

    
280
                this.add(getJNorthPanel(), BorderLayout.NORTH);
281
                this.add(getJSplitPane(), BorderLayout.CENTER);
282
                this.add(getJEastPanel(), BorderLayout.EAST);
283
                ActionListener okAction = new ActionListener() {
284
                        public void actionPerformed(ActionEvent e) {
285
                                PluginServices.getMDIManager().closeWindow(SymbolSelector.this);
286
                        }
287
                }, cancelAction = new ActionListener() {
288
                        public void actionPerformed(ActionEvent e) {
289
                                accepted = false;
290

    
291
                                setSymbol(null);
292
                                PluginServices.getMDIManager().closeWindow(SymbolSelector.this);
293
                        }
294
                };
295

    
296
                okCancelPanel = new AcceptCancelPanel();
297
                okCancelPanel.setOkButtonActionListener(okAction);
298
                okCancelPanel.setCancelButtonActionListener(cancelAction);
299

    
300
                this.add(okCancelPanel, BorderLayout.SOUTH);
301
                libraryBrowser.setSelectionRow(0);
302

    
303
                SillyDragNDropAction dndAction = new SillyDragNDropAction();
304
                libraryBrowser.addMouseListener(dndAction);
305
                libraryBrowser.addMouseMotionListener(dndAction);
306
                getJListSymbols().addMouseListener(dndAction);
307
                getJListSymbols().addMouseMotionListener(dndAction);
308
                setSymbol(currentElement);
309
        }
310

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

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

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

    
412
                                        return pnl;
413
                                }
414

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

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

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

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

    
445
                try {
446

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

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

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

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

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

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

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

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

    
504

    
505
                        if (shapeType == Geometry.TYPES.TEXT) {
506
                                ITextSymbol t = (ITextSymbol) mySelectedElement;
507
                                cmbFontSize.setEnabled(t!=null);
508
                                if(t!=null){
509
                                        jcc1.setColor(t.getTextColor());
510
                                        Double s = new Double(t.getFont().getSize());
511
                                        cmbFontSize.setSelectedItem(s);
512
                                        int i = cmbFontSize.getSelectedIndex();
513
                                        if (i == -1) {
514
                                                cmbFontSize.addItem(s);
515
                                                cmbFontSize.setSelectedItem(s);
516
                                        }
517
                                }
518
                        }
519
                } catch (NullPointerException npEx) {
520
                        throw new IllegalArgumentException(npEx);
521
                } catch (ClassCastException ccEx) {
522
                        throw new IllegalArgumentException(ccEx);
523
                }
524

    
525
                act = true;  // enable events
526
        }
527

    
528
        /**
529
         * This method initializes jPanel
530
         *
531
         * @return javax.swing.JPanel
532
         */
533
        protected JPanel getJEastPanel() {
534
                if (jPanel == null) {
535
                        jPanel = new JPanel();
536
                        jPanel.setLayout(new BorderLayout());
537
                        jPanel.add(getJPanelOptions(), BorderLayout.CENTER);
538
                        JPanel aux = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
539
                        aux.setBorder(BorderFactory.createTitledBorder(null, Messages.getText("preview")));
540
                        aux.add(getJPanelPreview());
541
                        jPanel.add(aux, BorderLayout.NORTH);
542

    
543
                        jPanel.add(getJPanelOptions());
544
                        aux = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5));
545
                        aux.add(getJPanelButtons());
546
                        jPanel.add(aux, BorderLayout.SOUTH);
547
                }
548
                return jPanel;
549
        }
550

    
551
        private JPanel getJPanelButtons() {
552
                if (jPanelButtons == null) {
553
                        jPanelButtons = new JPanel();
554
                        GridLayout layout = new GridLayout();
555
                        layout.setColumns(1);
556
                        layout.setVgap(5);
557
                        jPanelButtons.add(getBtnNewSymbol());
558
                        jPanelButtons.add(getBtnSaveSymbol());
559
                        jPanelButtons.add(getBtnResetSymbol());
560
                        jPanelButtons.add(getBtnProperties());
561

    
562
                        // do not add components bellow this line!
563
                        layout.setRows(jPanelButtons.getComponentCount());
564
                        jPanelButtons.setLayout(layout);
565
                }
566
                return jPanelButtons;
567
        }
568

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

    
579
        private JButton getBtnResetSymbol() {
580
                if (btnResetSymbol == null) {
581
                        btnResetSymbol = new JButton();
582
                        btnResetSymbol.setName("btnResetSymbol");
583
                        btnResetSymbol.setText(Messages.getText("reset"));
584
                        btnResetSymbol.addActionListener(this);
585
                }
586
                return btnResetSymbol;
587
        }
588

    
589
        private JButton getBtnSaveSymbol() {
590
                if (btnSaveSymbol == null) {
591
                        btnSaveSymbol = new JButton();
592
                        btnSaveSymbol.setName("btnSaveSymbol");
593
                        btnSaveSymbol.setText(Messages.getText("save"));
594
                        btnSaveSymbol.addActionListener(this);
595
                }
596
                return btnSaveSymbol;
597
        }
598

    
599
        private JButton getBtnProperties() {
600
                if (btnProperties == null) {
601
                        btnProperties = new JButton();
602
                        btnProperties.setName("btnProperties");
603
                        btnProperties.setText(Messages.getText("properties"));
604
                        btnProperties.addActionListener(this);
605
                }
606
                return btnProperties;
607
        }
608

    
609
        /**
610
         * This method initializes jScrollPane
611
         *
612
         * @return javax.swing.JScrollPane
613
         * @throws ClassNotFoundException
614
         */
615
        protected JScrollPane getLeftJScrollPane() throws ClassNotFoundException {
616
                if (jScrollPane == null) {
617
                        jScrollPane = new JScrollPane();
618
                        jScrollPane.setPreferredSize(new java.awt.Dimension(80,130));
619
                        jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
620
                        libraryBrowser = new LibraryBrowser(library);
621
                        libraryBrowser.addTreeSelectionListener(new TreeSelectionListener() {
622
                                public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
623
                                        dir = (File) ((DefaultMutableTreeNode)
624
                                                        libraryBrowser.getLastSelectedPathComponent()).getUserObject();
625

    
626
                                        if (dir == null) {
627
                                                return;
628
                                        }
629

    
630
                                        jListSymbols.setModel(newListModel());
631
                                        //                                        jListSymbols.setSelectedValue(selectedElement, true);
632
                                }
633
                        });
634
                        jScrollPane.setViewportView(libraryBrowser);
635
                }
636
                return jScrollPane;
637
        }
638

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

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

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

    
692

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

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

    
719
                        } else if (shapeType == Geometry.TYPES.TEXT) {
720
                                jcc1 = new ColorChooserPanel(true);
721
                                jPanelOptions.addComponent(
722
                                                Messages.getText("font")+":", getCmbFonts());
723

    
724
                                jPanelOptions.addComponent(
725
                                                Messages.getText("color")+":", jcc1);
726
                                jPanelOptions.addComponent(Messages.getText("size")+":",
727
                                                cmbFontSize = new JComboBoxFontSizes());
728
                                jPanelOptions.addComponent(Messages.getText("units")+":",
729
                                                cmbUnits = new JComboBoxUnits());
730
                                jPanelOptions.addComponent("",
731
                                                cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
732

    
733
                                JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING,0,1));
734
                                aux.add(getBtnBold());
735
                                aux.add(getBtnItalic());
736
                                aux.add(getBtnUnderlined());
737
                                jPanelOptions.addComponent(
738
                                                Messages.getText("style")+":", aux);
739

    
740
                        }
741

    
742
                        jcc1.setAlpha(255);
743

    
744
                        if (txtSize != null) {
745
                                txtSize.addActionListener(this);
746
                        }
747
                        if (cmbUnits != null) {
748
                                cmbUnits.addActionListener(this);
749
                        }
750
                        if (cmbReferenceSystem != null) {
751
                                cmbReferenceSystem.addActionListener(this);
752
                        }
753
                        if (jcc1 != null) {
754
                                jcc1.addActionListener(this);
755
                        }
756
                        if (jcc2 != null) {
757
                                jcc2.addActionListener(this);
758
                        }
759
                        if (txtWidth != null) {
760
                                txtWidth.addActionListener(this);
761
                        }
762
                        if (cmbFontSize != null) {
763
                                cmbFontSize.addActionListener(this);
764
                        }
765
                        if (txtAngle != null) {
766
                                txtAngle.addActionListener(this);
767
                        }
768
                }
769
                return jPanelOptions;
770
        }
771

    
772
        private JToggleButton getBtnUnderlined() {
773
                if (btnUnderlined == null) {
774
                        btnUnderlined = new JToggleButton(PluginServices.getIconTheme().
775
                                        get("underline-icon"));
776
                }
777
                return btnUnderlined;
778
        }
779

    
780
        private JToggleButton getBtnItalic() {
781
                if (btnItalic == null) {
782
                        btnItalic = new JToggleButton(PluginServices.getIconTheme().
783
                                        get("italic-icon"));
784
                }
785
                return btnItalic;
786
        }
787

    
788
        private JToggleButton getBtnBold() {
789
                if (btnBold == null) {
790
                        btnBold = new JToggleButton(PluginServices.getIconTheme().
791
                                        get("bold-icon"));
792
                }
793
                return btnBold;
794
        }
795

    
796

    
797
        private JComboBoxFonts getCmbFonts() {
798
                if (cmbFonts == null) {
799
                        cmbFonts = new JComboBoxFonts();
800
                }
801
                return cmbFonts;
802
        }
803

    
804
        public WindowInfo getWindowInfo() {
805
                if (wi == null) {
806
                        wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
807
                        wi.setWidth(706);
808
                        wi.setHeight(500);
809
                        wi.setTitle(Messages.getText("symbol_selector"));
810
                }
811
                return wi;
812
        }
813

    
814
        protected JSplitPane getJSplitPane() throws ClassNotFoundException {
815
                if (jSplitPane == null) {
816
                        jSplitPane = new JSplitPane();
817
                        jSplitPane.setDividerLocation(200);
818
                        jSplitPane.setResizeWeight(0.4);
819
                        jSplitPane.setLeftComponent(getLeftJScrollPane());
820
                        jSplitPane.setRightComponent(getJScrollPane1());
821
                }
822
                return jSplitPane;
823
        }
824

    
825
        public Object getSelectedObject() {
826
                if (!accepted) {
827
                        return null;
828
                }
829
                Object mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
830

    
831
                // if this symbol only has one layer, then no multilayer is needed
832
                if (mySelectedElement instanceof IMultiLayerSymbol) {
833
                        if (((IMultiLayerSymbol) mySelectedElement).getLayerCount()==1) {
834
                                return ((IMultiLayerSymbol) mySelectedElement).getLayer(0);
835
                        }
836
                }
837

    
838
                if (mySelectedElement instanceof CartographicSupport) {
839
                        CartographicSupport csSym = (CartographicSupport) mySelectedElement;
840
                        csSym.setUnit(cmbUnits.getSelectedUnitIndex());
841
                        csSym.setReferenceSystem(cmbReferenceSystem.getSelectedIndex());
842
                }
843

    
844
                return mySelectedElement;
845
        }
846

    
847
        public void setSymbol(Object symbol) {
848
                ((SymbolPreviewer) jPanelPreview).setSymbol((ISymbol) symbol);
849
                updateOptionsPanel();
850
        }
851

    
852
        /**
853
         * Invoked when the PROPERTIES button is pressed
854
         */
855
        protected void propertiesPressed() {
856
                ISymbol mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
857
                if (mySelectedElement ==null) {
858
                        return;
859
                }
860

    
861
                ISymbol clonedSymbol=null;
862
                try {
863
                        clonedSymbol = (ISymbol) mySelectedElement.clone(); 
864
                } catch (CloneNotSupportedException e) {
865
                        NotificationManager.addWarning("Symbol layer", e);
866
                }
867
                SymbolEditor se = new SymbolEditor(clonedSymbol, shapeType);
868
                PluginServices.getMDIManager().addWindow(se);
869

    
870
                ISymbol symbol = se.getSymbol();
871
                if (symbol instanceof IMultiLayerSymbol) {
872
                        IMultiLayerSymbol mSym = (IMultiLayerSymbol) symbol;
873
                        if (mSym.getLayerCount() == 1) {
874
                                symbol =  mSym.getLayer(0);
875
                        }
876
                }
877
                setSymbol(symbol);
878

    
879
        }
880

    
881
        /**
882
         * Invoked when the NEW button is pressed
883
         */
884
        protected void newPressed() {
885
                SymbolEditor se = new SymbolEditor(null, shapeType);
886
                PluginServices.getMDIManager().addWindow(se);
887
                setSymbol(se.getSymbol());
888
        }
889

    
890
        /**
891
         * Invoked when the RESET button is pressed
892
         */
893
        protected void resetPressed() {
894
                setSymbol(null);
895
        }
896

    
897
        /**
898
         * Invoked when the SAVE button is pressed
899
         */
900
        protected void savePressed() {
901
                if (getSelectedObject() ==null) {
902
                        return;
903
                }
904

    
905
                final SymbolPreferences preferences = manager.getSymbolPreferences();
906

    
907

    
908
                JFileChooser jfc = new JFileChooser("SYMBOL_SELECTOR_FILECHOOSER", rootDir);
909
                javax.swing.filechooser.FileFilter ff = new javax.swing.filechooser.FileFilter() {
910
                        public boolean accept(File f) {
911
                                                return f.getAbsolutePath().toLowerCase().endsWith(
912
                                                                preferences.getSymbolFileExtension())
913
                                                                || f.isDirectory();
914
                        }
915

    
916
                        public String getDescription() {
917
                                                return Messages.getText(
918
                                                                "gvSIG_symbol_definition_file")
919
                                                                .concat(" (*")
920
                                                                .concat(preferences.getSymbolFileExtension())
921
                                                                .concat(")");
922
                        }
923
                };
924
                jfc.setFileFilter(ff);
925
                JPanel accessory = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
926
                accessory.add(new JLabel(Messages.getText("enter_description")));
927
                JTextField txtDesc = new JTextField(25);
928
                accessory.add(txtDesc);
929
                jfc.setAccessory(accessory);
930
                if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
931
                        File targetFile = jfc.getSelectedFile();
932

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

    
949

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

    
961

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

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

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

    
991
                        Color c = jcc1.getColor();
992

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

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

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

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

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

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

    
1031

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

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

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

    
1051
                        if (selectedElement instanceof IMarkerSymbol) {
1052
                                IMarkerSymbol m = (IMarkerSymbol) selectedElement;
1053
                                m.setSize(s);
1054
                        }
1055

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

    
1094
        public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType) {
1095
                return createSymbolSelector(currSymbol, shapeType, null);
1096
        }
1097

    
1098
        public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType, SelectorFilter filter) {
1099
                ISymbolSelector selector = null;
1100

    
1101
                // patch for backwards compatibility
1102
                //                if (currSymbol instanceof FSymbol) {
1103
                //                        currSymbol = SymbologyFactory.deriveFSymbol((FSymbol) currSymbol);
1104
                //                }
1105

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

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

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

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

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

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

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

    
1158
                        }
1159
                        doDrop = false;
1160
                }
1161

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

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

    
1172
                public void mouseMoved(MouseEvent e) {
1173

    
1174
                }
1175

    
1176
        }
1177

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

    
1182
}