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

History | View | Annotate | Download (37.2 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.app.gui.styling;
25

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

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

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

    
101

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

    
148

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
411
                                        return pnl;
412
                                }
413

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

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

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

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

    
444
                try {
445

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
687

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

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

    
714
                        }
715

    
716
                        jcc1.setAlpha(255);
717

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

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

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

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

    
770

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

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

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

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

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

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

    
818
                return mySelectedElement;
819
        }
820

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

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

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

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

    
853
        }
854

    
855
        /**
856
         * Invoked when the NEW button is pressed
857
         */
858
        protected void newPressed() {
859
            ISymbol curr_sym = ((SymbolPreviewer) jPanelPreview).getSymbol();
860
            
861
            try {
862
                curr_sym = (ISymbol) curr_sym.clone();
863
            } catch (Exception cnse) {
864
                logger.info("Unable to clone symbol. "
865
                    + "This can cause an empty symbol if user cancels dialog.",
866
                    cnse);
867
            }
868

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

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

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

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

    
892

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

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

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

    
941

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

    
953

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

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

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

    
983
                        Color c = jcc1.getColor();
984

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

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

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

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

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

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

    
1023

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

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

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

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

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

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

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

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

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

    
1106
                if (filter==null) {
1107
                        selector = (shapeType == Geometry.TYPES.GEOMETRY) ?
1108
                                        new MultiShapeSymbolSelector(currSymbol) :
1109
                                                new SymbolSelector(currSymbol, geometryType, true);
1110
                } else {
1111
                        selector = (shapeType == Geometry.TYPES.GEOMETRY) ?
1112
                                        new MultiShapeSymbolSelector(currSymbol) :
1113
                                                new SymbolSelector(currSymbol, geometryType, 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
}