Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SymbolSelector.java @ 27580

History | View | Annotate | Download (38.5 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 com.iver.cit.gvsig.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.FocusEvent;
57
import java.awt.event.FocusListener;
58
import java.awt.event.InputEvent;
59
import java.awt.event.MouseEvent;
60
import java.awt.event.MouseListener;
61
import java.awt.event.MouseMotionListener;
62
import java.io.File;
63

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

    
80
import org.gvsig.gui.beans.AcceptCancelPanel;
81
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
82
import org.gvsig.gui.beans.swing.JButton;
83
import org.gvsig.gui.beans.swing.JComboBoxFontSizes;
84
import org.gvsig.gui.beans.swing.JComboBoxFonts;
85
import org.gvsig.gui.beans.swing.JFileChooser;
86
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
87

    
88
import com.iver.andami.PluginServices;
89
import com.iver.andami.ui.mdiManager.IWindow;
90
import com.iver.andami.ui.mdiManager.IWindowListener;
91
import com.iver.andami.ui.mdiManager.WindowInfo;
92
import com.iver.cit.gvsig.fmap.core.CartographicSupport;
93
import com.iver.cit.gvsig.fmap.core.FPoint2D;
94
import com.iver.cit.gvsig.fmap.core.FShape;
95
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
96
import com.iver.cit.gvsig.fmap.core.IGeometry;
97
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
98
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
99
import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol;
100
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol;
101
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol;
102
import com.iver.cit.gvsig.fmap.core.symbols.IMultiLayerSymbol;
103
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
104
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol;
105
import com.iver.cit.gvsig.fmap.core.symbols.MultiLayerFillSymbol;
106
import com.iver.cit.gvsig.fmap.core.symbols.MultiLayerLineSymbol;
107
import com.iver.cit.gvsig.fmap.core.symbols.MultiLayerMarkerSymbol;
108
import com.iver.cit.gvsig.gui.JComboBoxUnits;
109
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
110
import com.iver.cit.gvsig.project.documents.view.legend.gui.ISymbolSelector;
111

    
112
/**
113
 * Creates the panel where the user has the options to select a symbol.
114
 * Apart from the option to select one, the user will have a previsualization
115
 * of all the symbols stored and posibilities to modify an existing one, to create
116
 * a new symbol and so on.
117
 *
118
 * @author jaume dominguez faus - jaume.dominguez@iver.es
119
 */
120
public class SymbolSelector extends JPanel implements ISymbolSelector, ActionListener, FocusListener, IWindowListener{
121

    
122
        private static final long serialVersionUID = -6405660392303659551L;
123
        private JPanel jPanel = null;
124
        protected JScrollPane jScrollPane = null;
125
        private JScrollPane jScrollPane1 = null;
126
        private WindowInfo wi;
127
        private JSplitPane jSplitPane = null;
128
        protected AcceptCancelPanel okCancelPanel;
129
        private JPanel northPanel;
130
        private ColorChooserPanel jcc1;
131
        private ColorChooserPanel jcc2;
132
        private JIncrementalNumberField txtSize;
133
        private JIncrementalNumberField txtAngle;
134
        private JPanel jPanelButtons;
135
        private JButton btnProperties;
136
        private int shapeType;
137
        private JButton btnSaveSymbol;
138
        private JButton btnResetSymbol;
139
        private JButton btnNewSymbol;
140
        private JComboBoxFonts cmbFonts;
141
        private JToggleButton btnBold;
142
        private JToggleButton btnItalic;
143
        private JToggleButton btnUnderlined;
144
        protected JLabel lblTitle;
145
        protected File dir;
146
        protected File rootDir;
147
        protected JComponent jPanelPreview = null;
148
        protected GridBagLayoutPanel jPanelOptions = null;
149
        protected JList jListSymbols = null;
150
        protected String treeRootName;
151
        protected ILibraryModel library;
152
        private JIncrementalNumberField txtWidth;
153
        protected boolean act = true;
154
        protected boolean accepted = false;
155
        private String wiTitle = null;
156

    
157
        protected SelectorFilter sFilter = new SelectorFilter() {
158
                private final IGeometry dummyPointGeom = ShapeFactory.createPoint2D(new FPoint2D());
159
                private final IGeometry dummyLineGeom = ShapeFactory.createPolyline2D(new GeneralPathX());
160
                private final IGeometry dummyPolygonGeom = ShapeFactory.createPolygon2D(new GeneralPathX());
161

    
162
                public boolean accepts(Object obj) {
163
                        if (obj instanceof ISymbol) {
164
                                ISymbol sym = (ISymbol) obj;
165

    
166
                                IGeometry compareGeometry = null;
167
                                switch (SymbolSelector.this.shapeType) {
168
                                case FShape.TEXT:
169
                                        return sym instanceof ITextSymbol;
170
                                case FShape.POINT:
171
                                        compareGeometry = dummyPointGeom;
172
                                        break;
173
                                case FShape.LINE:
174
                                        compareGeometry = dummyLineGeom;
175
                                        break;
176
                                case FShape.POLYGON:
177
                                        compareGeometry = dummyPolygonGeom;
178
                                        break;
179
                                }
180
                                return sym.isSuitableFor(compareGeometry);
181
                        }
182
                        return false;
183
                }
184
        };
185
        protected JComboBoxUnits cmbUnits;
186
        protected JComboBoxUnitsReferenceSystem cmbReferenceSystem;
187
        private JComboBoxFontSizes cmbFontSize;
188
        protected LibraryBrowser libraryBrowser;
189
        private boolean showAcceptPanel;
190
        /**
191
         * Constructor method
192
         *
193
         * @param currentElement
194
         * @param shapeType
195
         */
196
        private SymbolSelector(Object currentElement, int shapeType, boolean initialize, boolean showAcceptPanel) {
197
                super();
198

    
199
                // TODO  09/08/07 check the currentElement type is suitable for the shapeType specified
200
                if (currentElement != null && currentElement instanceof ISymbol) {
201
                        ISymbol sym = (ISymbol) currentElement;
202
                        currentElement = SymbologyFactory.createSymbolFromXML(
203
                                        sym.getXMLEntity(), "");
204
                        String desc = sym.getDescription();
205
//                        desc = " ("+PluginServices.getText(this, "current")+")";
206
//                        ((ISymbol)currentElement).setDescription(desc);
207
                }
208

    
209
                // for symbols MULTIPOINT is the same than POINT
210
                if (shapeType == FShape.MULTIPOINT) shapeType = FShape.POINT;
211

    
212
                //Remove the M or the Z coordinate
213
                switch (shapeType) {
214
                case FShape.POINT | FShape.Z:
215
                case FShape.POINT | FShape.M:
216
                        this.shapeType = FShape.POINT;
217
                        break;
218
                case FShape.LINE | FShape.Z:
219
                case FShape.LINE | FShape.M:
220
                        this.shapeType = FShape.LINE;
221
                        break;
222
                case FShape.POLYGON | FShape.Z:
223
                case FShape.POLYGON | FShape.M:
224
                        this.shapeType = FShape.POLYGON;
225
                        break;
226
                default:
227
                        this.shapeType = shapeType;
228
                }
229

    
230
//                Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" );
231
                rootDir = new File(SymbologyFactory.SymbolLibraryPath);
232
//                prefs.get("SymbolLibraryFolder", System.getProperty("user.home")+"/gvSIG/Symbols"));
233
                if (!rootDir.exists())
234
                        rootDir.mkdir();
235
                treeRootName = PluginServices.getText(this, "symbol_library");
236
                this.showAcceptPanel = showAcceptPanel;
237
                try {
238
                        if (initialize)
239
                                initialize(currentElement);
240
                } catch (ClassNotFoundException e) {
241
                        throw new Error(e);
242
                }
243

    
244

    
245
        }
246

    
247
        /**
248
         * Constructor method, it is <b>protected</b> by convenience to let StyleSelector
249
         * to invoke it, but rigorously it should be <b>private</b>.
250
         *
251
         * @param symbol
252
         * @param shapeType
253
         * @param filter
254
         */
255
        protected SymbolSelector(Object symbol, int shapeType, SelectorFilter filter, boolean initialize) {
256
                this(symbol, shapeType, initialize, true);
257
                sFilter = filter;
258
        }
259

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

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

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

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

    
299
                        }
300
                };
301

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

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

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

    
319
        /**
320
         * Creates a new symbol selector list model in order to allow the user
321
         * to select an existing symbol previously created.
322
         *
323
         * @return listModel SymbolSelectorListModel
324
         */
325
        protected SymbolSelectorListModel newListModel() {
326
                SymbolSelectorListModel listModel = new SymbolSelectorListModel(
327
                                dir,
328
                                sFilter,
329
                                SymbolLibrary.SYMBOL_FILE_EXTENSION);
330
                return listModel;
331
        }
332
        /**
333
         * Initializes tha JNorthPanel.
334
         *
335
         * @return northPanel JPanel
336
         * @throws IllegalArgumentException
337
         */
338
        protected JPanel getJNorthPanel() throws IllegalArgumentException {
339
                if (northPanel == null) {
340
                        String text = "";
341
                        switch (shapeType) {
342
                        case FShape.POINT:
343
                        case FShape.POINT | FShape.Z:
344
                        case FShape.POINT | FShape.M:
345
                                text = PluginServices.getText(this, "point_symbols");
346
                                break;
347
                        case FShape.LINE:
348
                        case FShape.LINE | FShape.Z:
349
                        case FShape.LINE | FShape.M:
350
                                text = PluginServices.getText(this, "line_symbols");
351
                                break;
352
                        case FShape.POLYGON:
353
                        case FShape.POLYGON | FShape.Z:
354
                        case FShape.POLYGON | FShape.M:
355
                                text = PluginServices.getText(this, "polygon_symbols");
356
                                break;
357
                        case FShape.TEXT:
358
                                text = PluginServices.getText(this, "text_symbols");
359
                                break;
360
                        default:
361
                                throw new IllegalArgumentException(PluginServices.getText(this, "shape_type_not_yet_supported"));
362
                        }
363
                        northPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
364
                        lblTitle = new JLabel(text);
365
                        lblTitle.setFont(lblTitle.getFont().deriveFont(Font.BOLD));
366
                        northPanel.add(lblTitle);
367
                }
368
                return northPanel;
369
        }
370

    
371
        /**
372
         * This method initializes jList
373
         *
374
         * @return javax.swing.JList
375
         */
376
        protected JList getJListSymbols() {
377
                if (jListSymbols == null) {
378
                        jListSymbols = new JList() ;
379
                        jListSymbols.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
380
                        jListSymbols.setLayoutOrientation(JList.HORIZONTAL_WRAP);
381
                        jListSymbols.setVisibleRowCount(-1);
382
                        jListSymbols.addListSelectionListener(new ListSelectionListener() {
383
                                public void valueChanged(ListSelectionEvent e) {
384
                                        if (jListSymbols.getSelectedValue()!=null) {
385
                                                ISymbol selSym = SymbologyFactory.createSymbolFromXML(
386
                                                                ((ISymbol) jListSymbols.getSelectedValue()).getXMLEntity(), null);
387
                                                setSymbol(selSym);
388
                                                updateOptionsPanel();
389
                                        }
390
                                }
391
                        });
392
                        ListCellRenderer renderer = new ListCellRenderer() {
393
                                private Color mySelectedBGColor = new Color(255,145,100,255);
394
                                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
395
                                        ISymbol sym = (ISymbol) value;
396
                                        JPanel pnl = new JPanel();
397
                                        BoxLayout layout = new BoxLayout(pnl, BoxLayout.Y_AXIS);
398
                                        pnl.setLayout(layout);
399
                                        Color bgColor = (isSelected) ? mySelectedBGColor
400
                                                        : getJListSymbols().getBackground();
401

    
402
                                        pnl.setBackground(bgColor);
403
                                        SymbolPreviewer sp = new SymbolPreviewer();
404
                                        sp.setAlignmentX(Component.CENTER_ALIGNMENT);
405
                                        sp.setPreferredSize(new Dimension(50, 50));
406
                                        sp.setSymbol(sym);
407
                                        sp.setBackground(bgColor);
408
                                        pnl.add(sp);
409
                                        String desc = sym.getDescription();
410
                                        if (desc == null) {
411
                                                desc = "["+PluginServices.getText(this, "no_desc")+"]";
412
                                        }
413
                                        JLabel lbl = new JLabel(desc);
414
                                        lbl.setBackground(bgColor);
415
                                        lbl.setAlignmentX(Component.CENTER_ALIGNMENT);
416
                                        pnl.add(lbl);
417

    
418
                                        return pnl;
419
                                }
420

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

    
434
                if (mySelectedElement == null) return;
435
                act = false; // disable events
436

    
437
                if (mySelectedElement instanceof CartographicSupport) {
438
                        CartographicSupport cs = (CartographicSupport) mySelectedElement;
439
                        cmbUnits.setSelectedUnitIndex(cs.getUnit());
440
                        cmbReferenceSystem.setSelectedIndex(cs.getReferenceSystem());
441
                }
442

    
443
                if (mySelectedElement instanceof IMultiLayerSymbol){
444
                        if (((IMultiLayerSymbol)mySelectedElement).getLayerCount() == 1)
445
                                mySelectedElement = ((IMultiLayerSymbol)mySelectedElement).getLayer(0);
446
                }
447

    
448

    
449
                try {
450

    
451
                        jcc1.setEnabled(true);
452
                        jcc2.setEnabled(true);
453

    
454
                        if(mySelectedElement instanceof IMultiLayerSymbol){
455
                                jcc1.setColor(Color.WHITE);
456
                                jcc2.setColor(Color.WHITE);
457
                                jcc1.setEnabled(false);
458
                                jcc2.setEnabled(false);
459
                        }
460

    
461

    
462
                        if (shapeType == FShape.POINT) {
463
                                IMarkerSymbol m = (IMarkerSymbol) mySelectedElement;
464
                                jcc1.setColor(m.getColor());
465
                                txtSize.setDouble(m.getSize());
466
                                txtAngle.setDouble(Math.toDegrees(m.getRotation()));
467
                        }
468

    
469
                        if (shapeType == FShape.LINE) {
470
                                ILineSymbol l = (ILineSymbol) mySelectedElement;
471
                                jcc1.setColor(l.getColor());
472
                                jcc1.setAlpha(l.getAlpha());
473
                                txtSize.setDouble(l.getLineWidth());
474
                        }
475

    
476
                        if (shapeType == FShape.POLYGON) {
477
                                IFillSymbol f = (IFillSymbol) mySelectedElement;
478

    
479
                                txtWidth.setEnabled(true);
480
                                cmbReferenceSystem.setEnabled(true);
481
                                cmbUnits.setEnabled(true);
482

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

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

    
500

    
501
                        if (shapeType == FShape.TEXT) {
502
                                ITextSymbol t = (ITextSymbol) mySelectedElement;
503
                                jcc1.setColor(t.getTextColor());
504
                                Double s = new Double(t.getFont().getSize());
505
                                cmbFontSize.setSelectedItem(s);
506
                                int i = cmbFontSize.getSelectedIndex();
507
                                if (i == -1) {
508
                                        cmbFontSize.addItem(s);
509
                                        cmbFontSize.setSelectedItem(s);
510
                                }
511
                        }
512
                } catch (NullPointerException npEx) {
513
                        throw new IllegalArgumentException(npEx);
514
                } catch (ClassCastException ccEx) {
515
                        throw new IllegalArgumentException(ccEx);
516
                }
517

    
518
                act = true;  // enable events
519
        }
520

    
521
        /**
522
         * This method initializes jPanel
523
         *
524
         * @return javax.swing.JPanel
525
         */
526
        protected JPanel getJEastPanel() {
527
                if (jPanel == null) {
528
                        jPanel = new JPanel();
529
                        jPanel.setLayout(new BorderLayout());
530
                        jPanel.add(getJPanelOptions(), BorderLayout.CENTER);
531
                        JPanel aux = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
532
                        aux.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "preview")));
533
                        aux.add(getJPanelPreview());
534
                        jPanel.add(aux, BorderLayout.NORTH);
535

    
536
                        jPanel.add(getJPanelOptions());
537
                        aux = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5));
538
                        aux.add(getJPanelButtons());
539
                        jPanel.add(aux, BorderLayout.SOUTH);
540
                }
541
                return jPanel;
542
        }
543

    
544
        private JPanel getJPanelButtons() {
545
                if (jPanelButtons == null) {
546
                        jPanelButtons = new JPanel();
547
                        GridLayout layout = new GridLayout();
548
                        layout.setColumns(1);
549
                        layout.setVgap(5);
550
                        jPanelButtons.add(getBtnNewSymbol());
551
                        jPanelButtons.add(getBtnSaveSymbol());
552
                        jPanelButtons.add(getBtnResetSymbol());
553
                        jPanelButtons.add(getBtnProperties());
554

    
555
                        // do not add components bellow this line!
556
                        layout.setRows(jPanelButtons.getComponentCount());
557
                        jPanelButtons.setLayout(layout);
558
                }
559
                return jPanelButtons;
560
        }
561

    
562
        private JButton getBtnNewSymbol() {
563
                if (btnNewSymbol == null) {
564
                        btnNewSymbol = new JButton();
565
                        btnNewSymbol.setName("btnNewSymbol");
566
                        btnNewSymbol.setText(PluginServices.getText(this, "new"));
567
                        btnNewSymbol.addActionListener(this);
568
                }
569
                return btnNewSymbol;
570
        }
571

    
572
        private JButton getBtnResetSymbol() {
573
                if (btnResetSymbol == null) {
574
                        btnResetSymbol = new JButton();
575
                        btnResetSymbol.setName("btnResetSymbol");
576
                        btnResetSymbol.setText(PluginServices.getText(this, "reset"));
577
                        btnResetSymbol.addActionListener(this);
578
                }
579
                return btnResetSymbol;
580
        }
581

    
582
        private JButton getBtnSaveSymbol() {
583
                if (btnSaveSymbol == null) {
584
                        btnSaveSymbol = new JButton();
585
                        btnSaveSymbol.setName("btnSaveSymbol");
586
                        btnSaveSymbol.setText(PluginServices.getText(this, "save"));
587
                        btnSaveSymbol.addActionListener(this);
588
                }
589
                return btnSaveSymbol;
590
        }
591

    
592
        private JButton getBtnProperties() {
593
                if (btnProperties == null) {
594
                        btnProperties = new JButton();
595
                        btnProperties.setName("btnProperties");
596
                        btnProperties.setText(PluginServices.getText(this, "properties"));
597
                        btnProperties.addActionListener(this);
598
                }
599
                return btnProperties;
600
        }
601

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

    
619
                                        if (dir == null) return;
620

    
621
                                        jListSymbols.setModel(newListModel());
622
//                                        jListSymbols.setSelectedValue(selectedElement, true);
623
                                }
624
                        });
625
                        jScrollPane.setViewportView(libraryBrowser);
626
                }
627
                return jScrollPane;
628
        }
629

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

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

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

    
683

    
684
                        } else if (shapeType == FShape.LINE) {
685
                                jcc1 = new ColorChooserPanel(true);
686
                                jPanelOptions.addComponent(
687
                                                PluginServices.getText(this, "color")+":", jcc1);
688
                                jPanelOptions.addComponent(
689
                                                PluginServices.getText(this, "width")+":",
690
                                                txtSize = new JIncrementalNumberField(String.valueOf(3), 3, 0, Double.MAX_VALUE, 1));
691
                                jPanelOptions.addComponent(PluginServices.getText(this, "units")+":",
692
                                                cmbUnits = new JComboBoxUnits());
693
                                jPanelOptions.addComponent("",
694
                                                cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
695

    
696
                        } else if (shapeType == FShape.POLYGON) {
697
                                jcc1 = new ColorChooserPanel(true, true);
698
                                jPanelOptions.addComponent(
699
                                                PluginServices.getText(this, "fill_color")+":", jcc1);
700
                                jPanelOptions.addComponent(
701
                                                PluginServices.getText(this, "outline_color")+":", jcc2);
702
                                jPanelOptions.addComponent(
703
                                                PluginServices.getText(this, "outline_width"),
704
                                                txtWidth = new JIncrementalNumberField(String.valueOf(3), 3, 0, Double.MAX_VALUE, 1));
705
                                jPanelOptions.addComponent(PluginServices.getText(this, "units")+":",
706
                                                cmbUnits = new JComboBoxUnits());
707
                                jPanelOptions.addComponent("",
708
                                                cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
709

    
710
                        } else if (shapeType == FShape.TEXT) {
711
                                jcc1 = new ColorChooserPanel(true);
712
                                jPanelOptions.addComponent(
713
                                                PluginServices.getText(this, "font")+":", getCmbFonts());
714

    
715
                                jPanelOptions.addComponent(
716
                                                PluginServices.getText(this, "color")+":", jcc1);
717
                                jPanelOptions.addComponent(PluginServices.getText(this, "size")+":",
718
                                                cmbFontSize = new JComboBoxFontSizes());
719
                                jPanelOptions.addComponent(PluginServices.getText(this, "units")+":",
720
                                                cmbUnits = new JComboBoxUnits());
721
                                jPanelOptions.addComponent("",
722
                                                cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
723

    
724
                                JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING,0,1));
725
                                aux.add(getBtnBold());
726
                                aux.add(getBtnItalic());
727
                                aux.add(getBtnUnderlined());
728
                                jPanelOptions.addComponent(
729
                                                PluginServices.getText(this, "style")+":", aux);
730

    
731
                        }
732

    
733
                        jcc1.setAlpha(255);
734

    
735
                        if (txtSize != null){
736
                                txtSize.addActionListener(this);
737
                                txtSize.addFocusListener(this);
738
                        }
739
                        if (cmbUnits != null)                        cmbUnits.addActionListener(this);
740
                        if (cmbReferenceSystem != null)        cmbReferenceSystem.addActionListener(this);
741
                        if (jcc1 != null)                                jcc1.addActionListener(this);
742
                        if (jcc2 != null)                                jcc2.addActionListener(this);
743
                        if (txtWidth != null)                        txtWidth.addActionListener(this);
744
                        if (cmbFontSize != null)                cmbFontSize.addActionListener(this);
745
                        if (txtAngle != null)                        txtAngle.addActionListener(this);
746
                }
747
                return jPanelOptions;
748
        }
749

    
750
        private JToggleButton getBtnUnderlined() {
751
                if (btnUnderlined == null) {
752
                        btnUnderlined = new JToggleButton(PluginServices.getIconTheme().
753
                                        get("underline-icon"));
754
                }
755
                return btnUnderlined;
756
        }
757

    
758
        private JToggleButton getBtnItalic() {
759
                if (btnItalic == null) {
760
                        btnItalic = new JToggleButton(PluginServices.getIconTheme().
761
                                        get("italic-icon"));
762
                }
763
                return btnItalic;
764
        }
765

    
766
        private JToggleButton getBtnBold() {
767
                if (btnBold == null) {
768
                        btnBold = new JToggleButton(PluginServices.getIconTheme().
769
                                        get("bold-icon"));
770
                }
771
                return btnBold;
772
        }
773

    
774

    
775
        private JComboBoxFonts getCmbFonts() {
776
                if (cmbFonts == null) {
777
                        cmbFonts = new JComboBoxFonts();
778
                }
779
                return cmbFonts;
780
        }
781

    
782
        public WindowInfo getWindowInfo() {
783
                if (wi == null) {
784
                        wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
785
                        wi.setWidth(706);
786
                        wi.setHeight(500);
787
                        if (wiTitle == null){
788
                                wi.setTitle(PluginServices.getText(this, "symbol_selector"));
789
                        } else {
790
                                wi.setTitle(wiTitle);
791
                        }
792
                }
793
                return wi;
794
        }
795

    
796
        protected JSplitPane getJSplitPane() throws ClassNotFoundException {
797
                if (jSplitPane == null) {
798
                        jSplitPane = new JSplitPane();
799
                        jSplitPane.setDividerLocation(200);
800
                        jSplitPane.setResizeWeight(0.4);
801
                        jSplitPane.setLeftComponent(getLeftJScrollPane());
802
                        jSplitPane.setRightComponent(getJScrollPane1());
803
                }
804
                return jSplitPane;
805
        }
806

    
807
        public Object getSelectedObject() {
808

    
809
                Object mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
810

    
811
                // if this symbol only has one layer, then no multilayer is needed
812
                if (mySelectedElement instanceof IMultiLayerSymbol) {
813
                        if (((IMultiLayerSymbol) mySelectedElement).getLayerCount()==1)
814
                                return ((IMultiLayerSymbol) mySelectedElement).getLayer(0);
815
                }
816

    
817
                if (mySelectedElement instanceof CartographicSupport) {
818
                        CartographicSupport csSym = (CartographicSupport) mySelectedElement;
819
                        csSym.setUnit(cmbUnits.getSelectedUnitIndex());
820
                        csSym.setReferenceSystem(cmbReferenceSystem.getSelectedIndex());
821
                }
822

    
823
                return mySelectedElement;
824
        }
825

    
826
        public void setSymbol(Object symbol) {
827
                ((SymbolPreviewer) jPanelPreview).setSymbol((ISymbol) symbol);
828
                updateOptionsPanel();
829
        }
830

    
831
        /**
832
         * Invoked when the PROPERTIES button is pressed
833
         */
834
        protected void propertiesPressed() {
835
//                boolean state = accepted;
836
//                accepted = true;
837
                ISymbol mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
838
                if (mySelectedElement ==null)
839
                        return;
840

    
841
                ISymbol clonedSymbol = SymbologyFactory.createSymbolFromXML(
842
                                mySelectedElement.getXMLEntity(), null);
843

    
844
                if(clonedSymbol instanceof IFillSymbol && txtWidth != null){
845
                        IFillSymbol f = (IFillSymbol) clonedSymbol;
846
                        ILineSymbol outline = f.getOutline();
847
                        if (outline!=null)
848
                                outline.setLineWidth(txtWidth.getDouble());
849
                }
850

    
851
                if (txtSize != null) {
852
                        if(clonedSymbol instanceof IMarkerSymbol){
853
                                IMarkerSymbol m = (IMarkerSymbol) clonedSymbol;
854
                                m.setSize(txtSize.getDouble());
855
                        }else if(clonedSymbol instanceof ILineSymbol) {
856
                                ILineSymbol l = (ILineSymbol) clonedSymbol;
857
                                l.setLineWidth(txtSize.getDouble());
858
                        }
859
                }
860

    
861
                SymbolEditor se = new SymbolEditor(clonedSymbol, shapeType);
862
                PluginServices.getMDIManager().addWindow(se);
863

    
864
                ISymbol symbol = se.getSymbol();
865
                if (symbol instanceof IMultiLayerSymbol) {
866
                        IMultiLayerSymbol mSym = (IMultiLayerSymbol) symbol;
867
                        if (mSym.getLayerCount() == 1) {
868
                                symbol =  mSym.getLayer(0);
869
                        }
870
                }
871
                setSymbol(symbol);
872
//                accepted = state;
873
        }
874

    
875
        /**
876
         * Invoked when the NEW button is pressed
877
         */
878
        protected void newPressed() {
879
                SymbolEditor se = new SymbolEditor(null, shapeType);
880
                PluginServices.getMDIManager().addWindow(se);
881
                setSymbol(se.getSymbol());
882
        }
883

    
884
        /**
885
         * Invoked when the RESET button is pressed
886
         */
887
        protected void resetPressed() {
888
                setSymbol(null);
889
        }
890

    
891
        /**
892
         * Invoked when the SAVE button is pressed
893
         */
894
        protected void savePressed() {
895
                if (getSelectedObject() == null)
896
                        return;
897

    
898

    
899
                JFileChooser jfc = new JFileChooser("SYMBOL_SELECTOR_FILECHOOSER", rootDir);
900
                javax.swing.filechooser.FileFilter ff = new javax.swing.filechooser.FileFilter() {
901
                        public boolean accept(File f) {
902
                                return f.getAbsolutePath().
903
                                toLowerCase().
904
                                endsWith(SymbolLibrary.SYMBOL_FILE_EXTENSION) || f.isDirectory();
905
                        }
906

    
907
                        public String getDescription() {
908
                                return PluginServices.getText(
909
                                                this, "gvSIG_symbol_definition_file")+ " (*.sym)";
910
                        }
911
                };
912
                jfc.setFileFilter(ff);
913
                JPanel accessory = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
914
                accessory.add(new JLabel(PluginServices.getText(this, "enter_description")));
915
                JTextField txtDesc = new JTextField(25);
916
                accessory.add(txtDesc);
917
                jfc.setAccessory(accessory);
918
                if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
919
                        File targetFile = jfc.getSelectedFile();
920

    
921
                        // apply description
922
                        String desc;
923
                        if (txtDesc.getText()==null || txtDesc.getText().trim().equals("")) {
924
                                // default to file name
925
                                String s = targetFile.getAbsolutePath();
926
                                desc = s.substring(s.lastIndexOf(File.separator)+1).
927
                                replaceAll(SymbolLibrary.SYMBOL_FILE_EXTENSION, "");
928
                        } else {
929
                                desc = txtDesc.getText().trim();
930
                        }
931
                        ISymbol s = (ISymbol) getSelectedObject();
932
                        s.setDescription(desc);
933

    
934

    
935
                        String symbolFileName = targetFile.getAbsolutePath().substring(
936
                                        targetFile.getAbsolutePath().lastIndexOf(File.separator)+1,
937
                                        targetFile.getAbsolutePath().length());
938
                        File targetDir = new File(targetFile.getAbsolutePath().substring(
939
                                        0,
940
                                        targetFile.getAbsolutePath().lastIndexOf(File.separator)));
941
                        library.addElement(s, symbolFileName , targetDir);
942
                        getJListSymbols().setModel(newListModel());
943

    
944
                }
945
        }
946

    
947

    
948
        public void actionPerformed(ActionEvent e) {
949
                if (!act) return;
950
                Object selectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();//getSelectedObject();
951
                performActionOn(selectedElement, (JComponent) e.getSource());
952
                SymbolSelector.this.repaint();
953
        }
954

    
955
        protected void performActionOn(Object selectedElement, JComponent comp) {
956

    
957
                if (selectedElement instanceof IMultiLayerSymbol){
958
                        if (((IMultiLayerSymbol)selectedElement).getLayerCount() == 1)
959
                                selectedElement = ((IMultiLayerSymbol)selectedElement).getLayer(0);
960
                }
961

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

    
978
                        Color c = jcc1.getColor();
979

    
980

    
981
                        if (selectedElement instanceof IMarkerSymbol) {
982
                                IMarkerSymbol m = (IMarkerSymbol) selectedElement;
983
                                if (m instanceof MultiLayerMarkerSymbol) {
984
                                        MultiLayerMarkerSymbol mm = (MultiLayerMarkerSymbol) m;
985
                                        mm.setAlpha(jcc1.getAlpha());
986
                                } else {
987
                                        m.setColor(c);
988
                                }
989
                        }
990

    
991
                        if (selectedElement instanceof ILineSymbol) {
992
                                ILineSymbol l = (ILineSymbol) selectedElement;
993
                                if (l instanceof MultiLayerLineSymbol) {
994
                                        MultiLayerLineSymbol ml = (MultiLayerLineSymbol) l;
995
                                        ml.setAlpha(jcc1.getAlpha());
996
                                } else {
997
                                        l.setLineColor(c);
998
                                }
999
                        }
1000

    
1001
                        if (selectedElement instanceof IFillSymbol) {
1002
                                IFillSymbol f = (IFillSymbol) selectedElement;
1003

    
1004
                                f.setHasFill(jcc1.getUseColorisSelected());
1005
                                f.setFillColor(c);
1006
                        }
1007

    
1008
                        if (selectedElement instanceof ITextSymbol) {
1009
                                ITextSymbol t = (ITextSymbol) selectedElement;
1010
                                t.setTextColor(c);
1011
                        }
1012

    
1013
                } else if (comp.equals(jcc2)) {
1014
                        if (selectedElement == null)
1015
                                return;
1016
                        Color c = jcc2.getColor();
1017

    
1018

    
1019
                        if (selectedElement instanceof IFillSymbol) {
1020
                                IFillSymbol f = (IFillSymbol) selectedElement;
1021
                                ILineSymbol outline = f.getOutline();
1022
                                f.setHasOutline(jcc2.getUseColorisSelected());
1023

    
1024
                                if (outline!=null) {
1025
                                        ILineSymbol l = (ILineSymbol) outline;
1026
                                        if (l instanceof MultiLayerLineSymbol && c != null) {
1027
                                                MultiLayerLineSymbol ml = (MultiLayerLineSymbol) l;
1028
                                                ml.setAlpha(c.getAlpha());
1029
                                        } else {
1030
                                                l.setLineColor(c);
1031
                                        }
1032
                                }
1033

    
1034
                        }
1035
                } else if (comp.equals(txtSize)) {
1036
                        double s = txtSize.getDouble();
1037

    
1038
                        if (selectedElement instanceof IMarkerSymbol) {
1039
                                IMarkerSymbol m = (IMarkerSymbol) selectedElement;
1040
                                m.setSize(s);
1041
                        }
1042

    
1043
                        if (selectedElement instanceof ILineSymbol) {
1044
                                ILineSymbol l = (ILineSymbol) selectedElement;
1045
                                l.setLineWidth(s);
1046
                        }
1047
                } else if (comp.equals(cmbUnits)) {
1048
                        if (selectedElement instanceof CartographicSupport) {
1049
                                CartographicSupport cs = (CartographicSupport) selectedElement;
1050
                                cs.setUnit(cmbUnits.getSelectedUnitIndex());
1051
                        }
1052
                } else if (comp.equals(cmbReferenceSystem)) {
1053
                        if (selectedElement instanceof CartographicSupport) {
1054
                                CartographicSupport cs = (CartographicSupport) selectedElement;
1055
                                cs.setReferenceSystem(cmbReferenceSystem.getSelectedIndex());
1056
                        }
1057
                } else if (comp.equals(txtWidth)) {
1058
                        double w = txtWidth.getDouble();
1059
                        if (selectedElement instanceof IFillSymbol) {
1060
                                IFillSymbol f = (IFillSymbol) selectedElement;
1061
                                ILineSymbol outline = f.getOutline();
1062
                                if (outline!=null)
1063
                                        outline.setLineWidth(w);
1064
                        }
1065
                } else if (comp.equals(cmbFontSize)) {
1066
                        double s = ((Integer) cmbFontSize.getSelectedItem()).doubleValue();
1067
                        if (selectedElement instanceof ITextSymbol) {
1068
                                ITextSymbol t = (ITextSymbol) selectedElement;
1069
                                t.setFontSize(s);
1070
                        }
1071
                } else if (comp.equals(txtAngle)) {
1072
                        double a = Math.toRadians(txtAngle.getDouble());
1073
                        if (selectedElement instanceof IMarkerSymbol) {
1074
                                IMarkerSymbol m = (IMarkerSymbol) selectedElement;
1075
                                m.setRotation(a);
1076
                        }
1077
                }
1078
        }
1079
        public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType, boolean showAcceptPanel) {
1080
                return createSymbolSelector(currSymbol, shapeType, null, showAcceptPanel);
1081
        }
1082
        public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType) {
1083
                return createSymbolSelector(currSymbol, shapeType, null);
1084
        }
1085
        public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType, SelectorFilter filter) {
1086
                return createSymbolSelector(currSymbol, shapeType, filter, true);
1087
        }
1088

    
1089
        public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType, SelectorFilter filter, boolean showAcceptPanel) {
1090
                ISymbolSelector selector = null;
1091

    
1092
                // patch for backwards compatibility
1093
//                if (currSymbol instanceof FSymbol) {
1094
//                currSymbol = SymbologyFactory.deriveFSymbol((FSymbol) currSymbol);
1095
//                }
1096

    
1097
                if (filter==null)
1098
                        selector = (shapeType == FShape.MULTI) ?
1099
                                        new MultiShapeSymbolSelector(currSymbol) :
1100
                                                new SymbolSelector(currSymbol, shapeType, true, showAcceptPanel);
1101
                                        else
1102
                                                selector = (shapeType == FShape.MULTI) ?
1103
                                                                new MultiShapeSymbolSelector(currSymbol) :
1104
                                                                        new SymbolSelector(currSymbol, shapeType, filter, true);
1105
                                                                return selector;
1106
        }
1107

    
1108
        class SillyDragNDropAction implements MouseListener, MouseMotionListener {
1109
                private boolean doDrop = false;
1110
                private Object selected;
1111
                private File sourceFolder;
1112

    
1113
                public void mouseClicked(MouseEvent e) { }
1114
                public void mouseEntered(MouseEvent e) { }
1115
                public void mouseExited(MouseEvent e) { }
1116

    
1117
                public void mousePressed(MouseEvent e) {
1118
                        if (e.getSource().equals(getJListSymbols())) {
1119
                                selected = getJListSymbols().getSelectedValue();
1120
                                doDrop = selected!=null;
1121
                                DefaultMutableTreeNode node = (DefaultMutableTreeNode) libraryBrowser.getLastSelectedPathComponent();
1122
                                if (node.getUserObject() instanceof File) {
1123
                                        sourceFolder = (File) node.getUserObject();
1124
                                }
1125
                        }
1126
                        e.consume();
1127
                }
1128

    
1129
                public void mouseReleased(MouseEvent e) {
1130
                        if (doDrop && e.getSource().equals(getJListSymbols())) {
1131
                                Point p = new Point(getJListSymbols().getLocation().x-e.getPoint().x, getJListSymbols().getLocation().y+e.getPoint().y);
1132
                                if (libraryBrowser.getBounds().contains(p)) {
1133
                                        File destFolder = libraryBrowser.getElementBellow(p);
1134
                                        if (destFolder != null) {
1135
                                                ISymbol sym = (ISymbol) selected;
1136
                                                int move = InputEvent.SHIFT_DOWN_MASK | InputEvent.BUTTON1_DOWN_MASK;
1137
//                                                int copy = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
1138

    
1139
                                                library.addElement(sym, sym.getDescription(), destFolder);
1140
                                                if ((e.getModifiers() & (move)) !=0) {
1141
                                                        library.removeElement(sym, sourceFolder);
1142
                                                }
1143

    
1144
                                        }
1145
                                        libraryBrowser.refresh();
1146
                                }
1147

    
1148
                        }
1149
                        doDrop = false;
1150
                }
1151

    
1152
                public void mouseDragged(MouseEvent e) {
1153
                        if (e.getSource().equals(getJListSymbols())) {
1154

    
1155
                                Point p = new Point(getJListSymbols().getLocation().x-e.getPoint().x, getJListSymbols().getLocation().y+e.getPoint().y);
1156
                                if (libraryBrowser.getBounds().contains(p)) {
1157
                                        libraryBrowser.setSelectedElementBellow(p);
1158
                                }
1159
                        }
1160
                }
1161

    
1162
                public void mouseMoved(MouseEvent e) {
1163

    
1164
                }
1165

    
1166
        }
1167

    
1168
        public void windowActivated() {
1169
                // TODO Auto-generated method stub
1170
        }
1171

    
1172
        public void windowClosed() {
1173
                if(!accepted){
1174
                        ((SymbolPreviewer) jPanelPreview).setSymbol(null);
1175
                }
1176
        }
1177

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

    
1182
        public void setTitle(String title){
1183
                this.wiTitle = title;
1184
        }
1185

    
1186
        public String getTitle(){
1187
                return this.wiTitle;
1188
        }
1189

    
1190
        public void focusGained(FocusEvent e) {
1191
                // TODO Auto-generated method stub
1192

    
1193
        }
1194

    
1195
        public void focusLost(FocusEvent e) {
1196
                if (!act) return;
1197
                Object selectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();//getSelectedObject();
1198
                performActionOn(selectedElement, (JComponent) e.getSource());
1199
                SymbolSelector.this.repaint();
1200

    
1201
        }
1202

    
1203
}