Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SymbolSelector.java @ 22477

History | View | Annotate | Download (34.3 KB)

1 9745 jaume
/*
2
 * Created on 26-abr-2005
3
 *
4 18623 jdominguez
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5 9745 jaume
 *
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 18623 jdominguez
 *   Av. Blasco Ib??ez, 50
27 9745 jaume
 *   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 18623 jdominguez
import java.awt.Point;
54 9745 jaume
import java.awt.event.ActionEvent;
55
import java.awt.event.ActionListener;
56 18623 jdominguez
import java.awt.event.InputEvent;
57
import java.awt.event.MouseEvent;
58
import java.awt.event.MouseListener;
59
import java.awt.event.MouseMotionListener;
60 9745 jaume
import java.io.File;
61
62
import javax.swing.BorderFactory;
63
import javax.swing.BoxLayout;
64
import javax.swing.JComponent;
65
import javax.swing.JLabel;
66
import javax.swing.JList;
67
import javax.swing.JPanel;
68
import javax.swing.JScrollPane;
69
import javax.swing.JSplitPane;
70 10679 jaume
import javax.swing.JTextField;
71
import javax.swing.JToggleButton;
72 9745 jaume
import javax.swing.ListCellRenderer;
73
import javax.swing.event.ListSelectionEvent;
74
import javax.swing.event.ListSelectionListener;
75 18623 jdominguez
import javax.swing.event.TreeSelectionListener;
76
import javax.swing.tree.DefaultMutableTreeNode;
77 9745 jaume
78 21299 vcaballero
import org.gvsig.fmap.geom.Geometry;
79
import org.gvsig.fmap.geom.GeometryFactory;
80
import org.gvsig.fmap.geom.GeometryManager;
81
import org.gvsig.fmap.geom.primitive.GeneralPathX;
82
import org.gvsig.fmap.geom.primitive.Point2D;
83 20994 jmvivo
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
84
import org.gvsig.fmap.mapcontext.rendering.symbols.IFillSymbol;
85
import org.gvsig.fmap.mapcontext.rendering.symbols.ILineSymbol;
86
import org.gvsig.fmap.mapcontext.rendering.symbols.IMarkerSymbol;
87
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol;
88
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
89
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol;
90
import org.gvsig.fmap.mapcontext.rendering.symbols.MultiLayerLineSymbol;
91
import org.gvsig.fmap.mapcontext.rendering.symbols.MultiLayerMarkerSymbol;
92
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory;
93 9745 jaume
import org.gvsig.gui.beans.AcceptCancelPanel;
94
import org.gvsig.gui.beans.swing.GridBagLayoutPanel;
95 11919 jaume
import org.gvsig.gui.beans.swing.JButton;
96
import org.gvsig.gui.beans.swing.JComboBoxFontSizes;
97
import org.gvsig.gui.beans.swing.JComboBoxFonts;
98 18623 jdominguez
import org.gvsig.gui.beans.swing.JFileChooser;
99 11734 jaume
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
100 9745 jaume
101
import com.iver.andami.PluginServices;
102
import com.iver.andami.ui.mdiManager.WindowInfo;
103 18623 jdominguez
import com.iver.cit.gvsig.gui.JComboBoxUnits;
104 9745 jaume
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel;
105 13729 jaume
import com.iver.cit.gvsig.project.documents.view.legend.gui.ISymbolSelector;
106 9745 jaume
107
/**
108 13189 jvidal
 * Creates the panel where the user has the options to select a symbol.
109
 * Apart from the option to select one, the user will have a previsualization
110
 * of all the symbols stored and posibilities to modify an existing one, to create
111
 * a new symbol and so on.
112
 *
113 9745 jaume
 * @author jaume dominguez faus - jaume.dominguez@iver.es
114
 */
115 18623 jdominguez
public class SymbolSelector extends JPanel implements ISymbolSelector, ActionListener {
116 9745 jaume
117 11919 jaume
          private static final long serialVersionUID = -6405660392303659551L;
118 9745 jaume
    private JPanel jPanel = null;
119 18623 jdominguez
    protected JScrollPane jScrollPane = null;
120 9745 jaume
    private JScrollPane jScrollPane1 = null;
121 10679 jaume
    private WindowInfo wi;
122 9745 jaume
        private JSplitPane jSplitPane = null;
123 11503 jaume
        protected AcceptCancelPanel okCancelPanel;
124 9745 jaume
        private JPanel northPanel;
125
        private ColorChooserPanel jcc1;
126
        private ColorChooserPanel jcc2;
127 11734 jaume
        private JIncrementalNumberField txtSize;
128
        private JIncrementalNumberField txtAngle;
129 9745 jaume
        private JPanel jPanelButtons;
130
        private JButton btnProperties;
131
        private int shapeType;
132
        private JButton btnSaveSymbol;
133
        private JButton btnResetSymbol;
134 10679 jaume
        private JButton btnNewSymbol;
135 11919 jaume
        private JComboBoxFonts cmbFonts;
136 10679 jaume
        private JToggleButton btnBold;
137
        private JToggleButton btnItalic;
138
        private JToggleButton btnUnderlined;
139
        protected JLabel lblTitle;
140
        protected File dir;
141
        protected File rootDir;
142
        protected JComponent jPanelPreview = null;
143
    protected GridBagLayoutPanel jPanelOptions = null;
144
    protected JList jListSymbols = null;
145
    protected String treeRootName;
146 18623 jdominguez
    protected ILibraryModel library;
147 11734 jaume
    private JIncrementalNumberField txtWidth;
148 18623 jdominguez
    protected boolean act = true;
149
    boolean accepted = true;
150 10927 jaume
151 11919 jaume
152 10679 jaume
        protected SelectorFilter sFilter = new SelectorFilter() {
153 21299 vcaballero
                GeometryFactory geomFactory=GeometryManager.getInstance().getGeometryFactory();
154
                private final Geometry dummyPointGeom = geomFactory.createPoint2D(new Point2D());
155
                private final Geometry dummyLineGeom = geomFactory.createPolyline2D(new GeneralPathX());
156
                private final Geometry dummyPolygonGeom = geomFactory.createPolygon2D(new GeneralPathX());
157 10679 jaume
158
                public boolean accepts(Object obj) {
159
                        if (obj instanceof ISymbol) {
160
                                ISymbol sym = (ISymbol) obj;
161
162 21299 vcaballero
                                Geometry compareGeometry = null;
163 10679 jaume
                                switch (SymbolSelector.this.shapeType) {
164 21299 vcaballero
                                case Geometry.TYPES.TEXT:
165 18623 jdominguez
                                        return sym instanceof ITextSymbol;
166 21299 vcaballero
                                case Geometry.TYPES.POINT:
167 10679 jaume
                                        compareGeometry = dummyPointGeom;
168
                                        break;
169 21299 vcaballero
                                case Geometry.TYPES.CURVE:
170 10679 jaume
                                        compareGeometry = dummyLineGeom;
171
                                        break;
172 21299 vcaballero
                                case Geometry.TYPES.SURFACE:
173 10679 jaume
                                        compareGeometry = dummyPolygonGeom;
174
                                        break;
175
                                }
176
                                return sym.isSuitableFor(compareGeometry);
177
                        }
178
                        return false;
179
                }
180
        };
181 18623 jdominguez
        protected JComboBoxUnits cmbUnits;
182
        protected JComboBoxUnitsReferenceSystem cmbReferenceSystem;
183 11919 jaume
        private JComboBoxFontSizes cmbFontSize;
184 18623 jdominguez
        protected LibraryBrowser libraryBrowser;
185 13189 jvidal
        /**
186
         * Constructor method
187
         *
188
         * @param currentElement
189
         * @param shapeType
190
         */
191 18623 jdominguez
        private SymbolSelector(Object currentElement, int shapeType, boolean initialize) {
192 9745 jaume
            super();
193 13189 jvidal
194 12994 jaume
            // TODO  09/08/07 check the currentElement type is suitable for the shapeType specified
195 10679 jaume
            if (currentElement != null && currentElement instanceof ISymbol) {
196
                    ISymbol sym = (ISymbol) currentElement;
197
                    currentElement = SymbologyFactory.createSymbolFromXML(
198
                                    sym.getXMLEntity(), "");
199
                    String desc = sym.getDescription();
200
                    desc += " ("+PluginServices.getText(this, "current")+")";
201
                    ((ISymbol)currentElement).setDescription(desc);
202 14821 jmvivo
            }
203 13729 jaume
204 9745 jaume
            this.shapeType = shapeType;
205 18623 jdominguez
//            Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" );
206
                rootDir = new File(SymbologyFactory.SymbolLibraryPath);
207
//                                prefs.get("SymbolLibraryFolder", System.getProperty("user.home")+"/gvSIG/Symbols"));
208 10679 jaume
                if (!rootDir.exists())
209
                        rootDir.mkdir();
210
                treeRootName = PluginServices.getText(this, "symbol_library");
211 18623 jdominguez
                try {
212
                        if (initialize)
213
                                initialize(currentElement);
214
                } catch (ClassNotFoundException e) {
215
                        throw new Error(e);
216
                }
217 14821 jmvivo
218
219 9745 jaume
    }
220 14821 jmvivo
221 13189 jvidal
        /**
222 14821 jmvivo
         * Constructor method, it is <b>protected</b> by convenience to let StyleSelector
223 18623 jdominguez
         * to invoke it, but rigorously it should be <b>private</b>.
224 13189 jvidal
         *
225
         * @param symbol
226
         * @param shapeType
227
         * @param filter
228
         */
229 18623 jdominguez
    protected SymbolSelector(Object symbol, int shapeType, SelectorFilter filter, boolean initialize) {
230
            this(symbol, shapeType, initialize);
231 10679 jaume
            sFilter = filter;
232
    }
233 9745 jaume
234
    /**
235
     * This method initializes this
236 21299 vcaballero
     * @param currentElement
237
     * @throws ClassNotFoundException
238 9745 jaume
     *
239
     */
240 18623 jdominguez
    protected void initialize(Object currentElement) throws ClassNotFoundException {
241 20709 vcaballero
            library = new SymbolLibrary(rootDir);
242 11919 jaume
243 10995 jaume
            this.setLayout(new BorderLayout());
244
            this.setSize(400, 221);
245
246
            this.add(getJNorthPanel(), BorderLayout.NORTH);
247
            this.add(getJSplitPane(), BorderLayout.CENTER);
248
            this.add(getJEastPanel(), BorderLayout.EAST);
249
            ActionListener okAction = new ActionListener() {
250 9745 jaume
                    public void actionPerformed(ActionEvent e) {
251
                            PluginServices.getMDIManager().closeWindow(SymbolSelector.this);
252
                    }
253
            }, cancelAction = new ActionListener() {
254
                    public void actionPerformed(ActionEvent e) {
255 18623 jdominguez
                            accepted = false;
256 21299 vcaballero
257 9745 jaume
                            setSymbol(null);
258
                            PluginServices.getMDIManager().closeWindow(SymbolSelector.this);
259
                    }
260
            };
261
262 11503 jaume
            okCancelPanel = new AcceptCancelPanel();
263
            okCancelPanel.setOkButtonActionListener(okAction);
264
            okCancelPanel.setCancelButtonActionListener(cancelAction);
265 9745 jaume
266 10995 jaume
            this.add(okCancelPanel, BorderLayout.SOUTH);
267 18623 jdominguez
            libraryBrowser.setSelectionRow(0);
268 21299 vcaballero
269 18623 jdominguez
            SillyDragNDropAction dndAction = new SillyDragNDropAction();
270
            libraryBrowser.addMouseListener(dndAction);
271
            libraryBrowser.addMouseMotionListener(dndAction);
272
            getJListSymbols().addMouseListener(dndAction);
273
            getJListSymbols().addMouseMotionListener(dndAction);
274
            setSymbol(currentElement);
275 9745 jaume
    }
276
277 13189 jvidal
    /**
278
     * Creates a new symbol selector list model in order to allow the user
279
     * to select an existing symbol previously created.
280
     *
281
     * @return listModel SymbolSelectorListModel
282
     */
283 10995 jaume
    protected SymbolSelectorListModel newListModel() {
284
            SymbolSelectorListModel listModel = new SymbolSelectorListModel(
285 10679 jaume
                            dir,
286
                            sFilter,
287 18623 jdominguez
                            SymbolLibrary.SYMBOL_FILE_EXTENSION);
288 10679 jaume
            return listModel;
289
    }
290 13189 jvidal
    /**
291
     * Initializes tha JNorthPanel.
292
     *
293
     * @return northPanel JPanel
294
     * @throws IllegalArgumentException
295
     */
296 18623 jdominguez
    protected JPanel getJNorthPanel() throws IllegalArgumentException {
297 9745 jaume
                if (northPanel == null) {
298
                        String text = "";
299
                        switch (shapeType) {
300 21299 vcaballero
                        case Geometry.TYPES.POINT:
301 9745 jaume
                                text = PluginServices.getText(this, "point_symbols");
302
                                break;
303 21299 vcaballero
                        case Geometry.TYPES.CURVE:
304 9745 jaume
                                text = PluginServices.getText(this, "line_symbols");
305
                                break;
306 21299 vcaballero
                        case Geometry.TYPES.SURFACE:
307 9745 jaume
                                text = PluginServices.getText(this, "polygon_symbols");
308
                                break;
309 21299 vcaballero
                        case Geometry.TYPES.TEXT:
310 10679 jaume
                                text = PluginServices.getText(this, "text_symbols");
311
                                break;
312 9745 jaume
                        default:
313
                                throw new IllegalArgumentException(PluginServices.getText(this, "shape_type_not_yet_supported"));
314
                        }
315
                        northPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
316 10679 jaume
                        lblTitle = new JLabel(text);
317
                        lblTitle.setFont(lblTitle.getFont().deriveFont(Font.BOLD));
318
                        northPanel.add(lblTitle);
319 9745 jaume
                }
320
                return northPanel;
321
        }
322
323 13189 jvidal
    /**
324 9745 jaume
     * This method initializes jList
325
     *
326
     * @return javax.swing.JList
327
     */
328 10679 jaume
    protected JList getJListSymbols() {
329 9745 jaume
            if (jListSymbols == null) {
330 18623 jdominguez
                    jListSymbols = new JList() ;
331 9745 jaume
                    jListSymbols.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
332
            jListSymbols.setLayoutOrientation(JList.HORIZONTAL_WRAP);
333
            jListSymbols.setVisibleRowCount(-1);
334
            jListSymbols.addListSelectionListener(new ListSelectionListener() {
335
                    public void valueChanged(ListSelectionEvent e) {
336 18623 jdominguez
                            if (jListSymbols.getSelectedValue()!=null) {
337
                                    ISymbol selSym = SymbologyFactory.createSymbolFromXML(
338
                                                    ((ISymbol) jListSymbols.getSelectedValue()).getXMLEntity(), null);
339
                                    setSymbol(selSym);
340
                                    updateOptionsPanel();
341
                            }
342 9745 jaume
                    }
343
            });
344
            ListCellRenderer renderer = new ListCellRenderer() {
345
                        private Color mySelectedBGColor = new Color(255,145,100,255);
346
                            public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
347
                                    ISymbol sym = (ISymbol) value;
348
                                    JPanel pnl = new JPanel();
349
                                    BoxLayout layout = new BoxLayout(pnl, BoxLayout.Y_AXIS);
350
                                    pnl.setLayout(layout);
351
                                    Color bgColor = (isSelected) ? mySelectedBGColor
352
                                                             : getJListSymbols().getBackground();
353
354
                                    pnl.setBackground(bgColor);
355 10679 jaume
                                    SymbolPreviewer sp = new SymbolPreviewer();
356 9745 jaume
                                    sp.setAlignmentX(Component.CENTER_ALIGNMENT);
357
                                    sp.setPreferredSize(new Dimension(50, 50));
358
                                    sp.setSymbol(sym);
359
                                    sp.setBackground(bgColor);
360
                                    pnl.add(sp);
361 13758 jaume
                                    String desc = sym.getDescription();
362
                                    if (desc == null) {
363
                                            desc = "["+PluginServices.getText(this, "no_desc")+"]";
364
                                    }
365
                                    JLabel lbl = new JLabel(desc);
366 9745 jaume
                                    lbl.setBackground(bgColor);
367
                                    lbl.setAlignmentX(Component.CENTER_ALIGNMENT);
368
                                    pnl.add(lbl);
369
370
                                    return pnl;
371
                            }
372
373
                };
374
                jListSymbols.setCellRenderer(renderer);
375
            }
376
            return jListSymbols;
377
    }
378 13189 jvidal
    /**
379
     * Updates the options panel depending on the type of symbol that the user
380
     * is controlling or using to show specific options for each one.
381
     *
382
     */
383 14346 jdominguez
    protected void updateOptionsPanel() throws IllegalArgumentException {
384 18623 jdominguez
            Object mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
385 21299 vcaballero
386 18623 jdominguez
            if (mySelectedElement == null) return;
387 11919 jaume
            act = false; // disable events
388 9745 jaume
389 18623 jdominguez
            if (mySelectedElement instanceof CartographicSupport) {
390
                        CartographicSupport cs = (CartographicSupport) mySelectedElement;
391
                        cmbUnits.setSelectedUnitIndex(cs.getUnit());
392
                        cmbReferenceSystem.setSelectedIndex(cs.getReferenceSystem());
393
                }
394 9745 jaume
395 14346 jdominguez
            try {
396 21299 vcaballero
                if (shapeType == Geometry.TYPES.POINT) {
397 11919 jaume
                        IMarkerSymbol m = (IMarkerSymbol) mySelectedElement;
398
                        jcc1.setColor(m.getColor());
399 20779 vcaballero
                        txtSize.setDouble(m.getSize());
400 11919 jaume
                        txtAngle.setDouble(m.getRotation());
401
                }
402 9745 jaume
403 21299 vcaballero
                if (shapeType == Geometry.TYPES.CURVE) {
404 14821 jmvivo
                        ILineSymbol l = (ILineSymbol) mySelectedElement;
405 11919 jaume
                        jcc1.setColor(l.getColor());
406 18623 jdominguez
                        jcc1.setAlpha(l.getAlpha());
407 11919 jaume
                        txtSize.setDouble(l.getLineWidth());
408
                }
409
410 21299 vcaballero
                if (shapeType == Geometry.TYPES.SURFACE) {
411 14821 jmvivo
                        IFillSymbol f = (IFillSymbol) mySelectedElement;
412 18623 jdominguez
413 21299 vcaballero
                        jcc1.setUseColorIsSelected(f.hasFill());
414 11919 jaume
                        jcc1.setColor(f.getFillColor());
415 18623 jdominguez
                        jcc1.setAlpha(f.getFillAlpha());
416
                        jcc2.setUseColorIsSelected(f.hasOutline());
417 12731 jaume
                        ILineSymbol outline = f.getOutline();
418
                        if (outline != null) {
419
                                jcc2.setColor(outline.getColor());
420
                                txtWidth.setDouble(outline.getLineWidth());
421
                        }
422 13189 jvidal
423 11919 jaume
                }
424
425 18623 jdominguez
426 21299 vcaballero
                if (shapeType == Geometry.TYPES.TEXT) {
427 14821 jmvivo
                        ITextSymbol t = (ITextSymbol) mySelectedElement;
428 11919 jaume
                        jcc1.setColor(t.getTextColor());
429
                        Double s = new Double(t.getFont().getSize());
430
                        cmbFontSize.setSelectedItem(s);
431
                        int i = cmbFontSize.getSelectedIndex();
432
                        if (i == -1) {
433
                                cmbFontSize.addItem(s);
434
                                cmbFontSize.setSelectedItem(s);
435
                        }
436
                }
437 14346 jdominguez
            } catch (NullPointerException npEx) {
438
                    throw new IllegalArgumentException(npEx);
439
            } catch (ClassCastException ccEx) {
440
                    throw new IllegalArgumentException(ccEx);
441
            }
442 11919 jaume
443
            act = true;  // enable events
444 9745 jaume
        }
445
446
        /**
447
     * This method initializes jPanel
448
     *
449
     * @return javax.swing.JPanel
450
     */
451 18623 jdominguez
    protected JPanel getJEastPanel() {
452 9745 jaume
            if (jPanel == null) {
453
                    jPanel = new JPanel();
454
                    jPanel.setLayout(new BorderLayout());
455
                    jPanel.add(getJPanelOptions(), BorderLayout.CENTER);
456
                    JPanel aux = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
457
                    aux.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "preview")));
458
                    aux.add(getJPanelPreview());
459
                    jPanel.add(aux, BorderLayout.NORTH);
460 10927 jaume
461 10679 jaume
                    jPanel.add(getJPanelOptions());
462 9745 jaume
                    aux = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5));
463
                    aux.add(getJPanelButtons());
464
                    jPanel.add(aux, BorderLayout.SOUTH);
465
            }
466
            return jPanel;
467
    }
468
469
    private JPanel getJPanelButtons() {
470
                if (jPanelButtons == null) {
471
                        jPanelButtons = new JPanel();
472
                        GridLayout layout = new GridLayout();
473
                        layout.setColumns(1);
474
                        layout.setVgap(5);
475 10679 jaume
                        jPanelButtons.add(getBtnNewSymbol());
476 9745 jaume
                        jPanelButtons.add(getBtnSaveSymbol());
477
                        jPanelButtons.add(getBtnResetSymbol());
478
                        jPanelButtons.add(getBtnProperties());
479
480
                        // do not add components bellow this line!
481
                        layout.setRows(jPanelButtons.getComponentCount());
482
                        jPanelButtons.setLayout(layout);
483
                }
484
                return jPanelButtons;
485
        }
486
487 10679 jaume
        private JButton getBtnNewSymbol() {
488
                if (btnNewSymbol == null) {
489
                        btnNewSymbol = new JButton();
490
                        btnNewSymbol.setName("btnNewSymbol");
491
                        btnNewSymbol.setText(PluginServices.getText(this, "new"));
492 18623 jdominguez
                        btnNewSymbol.addActionListener(this);
493 10679 jaume
                }
494
                return btnNewSymbol;
495
        }
496
497 9745 jaume
        private JButton getBtnResetSymbol() {
498
                if (btnResetSymbol == null) {
499
                        btnResetSymbol = new JButton();
500
                        btnResetSymbol.setName("btnResetSymbol");
501
                        btnResetSymbol.setText(PluginServices.getText(this, "reset"));
502 18623 jdominguez
                        btnResetSymbol.addActionListener(this);
503 9745 jaume
                }
504
                return btnResetSymbol;
505
        }
506
507
        private JButton getBtnSaveSymbol() {
508
                if (btnSaveSymbol == null) {
509
                        btnSaveSymbol = new JButton();
510
                        btnSaveSymbol.setName("btnSaveSymbol");
511
                        btnSaveSymbol.setText(PluginServices.getText(this, "save"));
512 18623 jdominguez
                        btnSaveSymbol.addActionListener(this);
513 9745 jaume
                }
514
                return btnSaveSymbol;
515
        }
516
517
        private JButton getBtnProperties() {
518
                if (btnProperties == null) {
519
                        btnProperties = new JButton();
520
                        btnProperties.setName("btnProperties");
521
                        btnProperties.setText(PluginServices.getText(this, "properties"));
522 18623 jdominguez
                        btnProperties.addActionListener(this);
523 9745 jaume
                }
524
                return btnProperties;
525
        }
526
527
        /**
528
     * This method initializes jScrollPane
529
     *
530
     * @return javax.swing.JScrollPane
531 21299 vcaballero
         * @throws ClassNotFoundException
532 9745 jaume
     */
533 18623 jdominguez
        protected JScrollPane getLeftJScrollPane() throws ClassNotFoundException {
534
                if (jScrollPane == null) {
535
                        jScrollPane = new JScrollPane();
536
                        jScrollPane.setPreferredSize(new java.awt.Dimension(80,130));
537
                        jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
538
                        libraryBrowser = new LibraryBrowser(library);
539
                        libraryBrowser.addTreeSelectionListener(new TreeSelectionListener() {
540
                                public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
541
                                        dir = (File) ((DefaultMutableTreeNode)
542
                                        libraryBrowser.getLastSelectedPathComponent()).getUserObject();
543 9745 jaume
544 18623 jdominguez
                                        if (dir == null) return;
545
546
                                        jListSymbols.setModel(newListModel());
547
//                                        jListSymbols.setSelectedValue(selectedElement, true);
548
                                }
549
                        });
550
                        jScrollPane.setViewportView(libraryBrowser);
551
                }
552
                return jScrollPane;
553
        }
554
555 9745 jaume
    /**
556
     * This method initializes jScrollPane1
557
     *
558
     * @return javax.swing.JScrollPane
559
     */
560
    private JScrollPane getJScrollPane1() {
561
            if (jScrollPane1 == null) {
562
                    jScrollPane1 = new JScrollPane();
563
                    jScrollPane1.setViewportView(getJListSymbols());
564
            }
565
            return jScrollPane1;
566
    }
567
568
    /**
569 13189 jvidal
     * This method initializes jPanelPreview
570 9745 jaume
     *
571 13189 jvidal
     * @return javax.swing.JComponent
572 9745 jaume
     */
573 10679 jaume
    protected JComponent getJPanelPreview() {
574 9745 jaume
            if (jPanelPreview == null) {
575 10679 jaume
                    jPanelPreview = new SymbolPreviewer();
576 9745 jaume
                    jPanelPreview.setPreferredSize(new java.awt.Dimension(100,100));
577
                    jPanelPreview.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
578
            }
579
            return jPanelPreview;
580
    }
581 13189 jvidal
    /**
582
     * This method initializes jPanelOptions
583
     *
584
     * @return javax.swing.JPanel
585
     */
586 10679 jaume
    protected JPanel getJPanelOptions() {
587 9745 jaume
            if (jPanelOptions == null) {
588
                    jPanelOptions = new GridBagLayoutPanel();
589 10679 jaume
                    jPanelOptions.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "options")));
590 18623 jdominguez
                    jcc2 = new ColorChooserPanel(true,true);
591 9745 jaume
                    jcc2.setAlpha(255);
592 21299 vcaballero
                    if (shapeType == Geometry.TYPES.POINT) {
593 18623 jdominguez
                            jcc1 = new ColorChooserPanel(true);
594 21299 vcaballero
595 9745 jaume
                            jPanelOptions.addComponent(
596
                                            PluginServices.getText(this, "color")+":", jcc1);
597
                            jPanelOptions.addComponent(
598
                                            PluginServices.getText(this, "size")+":",
599 11919 jaume
                                            txtSize = new JIncrementalNumberField(String.valueOf(3), 3, 0, Double.MAX_VALUE, 1));
600 11503 jaume
                            jPanelOptions.addComponent(PluginServices.getText(this, "units")+":",
601 18623 jdominguez
                                            cmbUnits = new JComboBoxUnits());
602
                            jPanelOptions.addComponent("",
603
                                            cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
604 9745 jaume
                            jPanelOptions.addComponent(
605
                                            PluginServices.getText(this, "angle")+":",
606 11734 jaume
                                            txtAngle = new JIncrementalNumberField());
607 11919 jaume
608 21299 vcaballero
609
                    } else if (shapeType == Geometry.TYPES.CURVE) {
610 18623 jdominguez
                            jcc1 = new ColorChooserPanel(true);
611
                        jPanelOptions.addComponent(
612 9745 jaume
                                            PluginServices.getText(this, "color")+":", jcc1);
613
                            jPanelOptions.addComponent(
614
                                            PluginServices.getText(this, "width")+":",
615 11919 jaume
                                            txtSize = new JIncrementalNumberField(String.valueOf(3), 3, 0, Double.MAX_VALUE, 1));
616 11503 jaume
                            jPanelOptions.addComponent(PluginServices.getText(this, "units")+":",
617 18623 jdominguez
                                            cmbUnits = new JComboBoxUnits());
618
                            jPanelOptions.addComponent("",
619
                                            cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
620 11503 jaume
621 21299 vcaballero
                    } else if (shapeType == Geometry.TYPES.SURFACE) {
622 18623 jdominguez
                            jcc1 = new ColorChooserPanel(true, true);
623
                        jPanelOptions.addComponent(
624 9745 jaume
                                            PluginServices.getText(this, "fill_color")+":", jcc1);
625
                            jPanelOptions.addComponent(
626
                                            PluginServices.getText(this, "outline_color")+":", jcc2);
627
                            jPanelOptions.addComponent(
628 10927 jaume
                                            PluginServices.getText(this, "outline_width"),
629 11919 jaume
                                            txtWidth = new JIncrementalNumberField(String.valueOf(3), 3, 0, Double.MAX_VALUE, 1));
630 11503 jaume
                            jPanelOptions.addComponent(PluginServices.getText(this, "units")+":",
631 18623 jdominguez
                                            cmbUnits = new JComboBoxUnits());
632
                            jPanelOptions.addComponent("",
633
                                            cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
634 11919 jaume
635 21299 vcaballero
                    } else if (shapeType == Geometry.TYPES.TEXT) {
636 18623 jdominguez
                            jcc1 = new ColorChooserPanel(true);
637
                        jPanelOptions.addComponent(
638 10679 jaume
                                            PluginServices.getText(this, "font")+":", getCmbFonts());
639 10927 jaume
640 10679 jaume
                            jPanelOptions.addComponent(
641
                                            PluginServices.getText(this, "color")+":", jcc1);
642 11503 jaume
                            jPanelOptions.addComponent(PluginServices.getText(this, "size")+":",
643 11919 jaume
                                            cmbFontSize = new JComboBoxFontSizes());
644 11503 jaume
                            jPanelOptions.addComponent(PluginServices.getText(this, "units")+":",
645 18623 jdominguez
                                            cmbUnits = new JComboBoxUnits());
646
                            jPanelOptions.addComponent("",
647
                                            cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
648 11503 jaume
649 10679 jaume
                            JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING,0,1));
650
                            aux.add(getBtnBold());
651
                            aux.add(getBtnItalic());
652
                            aux.add(getBtnUnderlined());
653
                            jPanelOptions.addComponent(
654
                                            PluginServices.getText(this, "style")+":", aux);
655 10927 jaume
656 11919 jaume
                    }
657
658 18623 jdominguez
                    jcc1.setAlpha(255);
659 21299 vcaballero
660 18623 jdominguez
                    if (txtSize != null)                        txtSize.addActionListener(this);
661
                    if (cmbUnits != null)                        cmbUnits.addActionListener(this);
662
                    if (cmbReferenceSystem != null)        cmbReferenceSystem.addActionListener(this);
663
                    if (jcc1 != null)                                jcc1.addActionListener(this);
664
                    if (jcc2 != null)                                jcc2.addActionListener(this);
665
                    if (txtWidth != null)                        txtWidth.addActionListener(this);
666
                    if (cmbFontSize != null)                cmbFontSize.addActionListener(this);
667
                    if (txtAngle != null)                        txtAngle.addActionListener(this);
668 9745 jaume
            }
669
            return jPanelOptions;
670
    }
671 10927 jaume
672 10679 jaume
    private JToggleButton getBtnUnderlined() {
673
            if (btnUnderlined == null) {
674 14821 jmvivo
                        btnUnderlined = new JToggleButton(PluginServices.getIconTheme().
675
                                        get("underline-icon"));
676 10679 jaume
                }
677
                return btnUnderlined;
678
    }
679 9745 jaume
680 10679 jaume
    private JToggleButton getBtnItalic() {
681
            if (btnItalic == null) {
682 14821 jmvivo
                        btnItalic = new JToggleButton(PluginServices.getIconTheme().
683
                                        get("italic-icon"));
684
            }
685 10679 jaume
                return btnItalic;
686
        }
687
688
        private JToggleButton getBtnBold() {
689
            if (btnBold == null) {
690 14821 jmvivo
                        btnBold = new JToggleButton(PluginServices.getIconTheme().
691
                                        get("bold-icon"));
692 10679 jaume
                }
693
                return btnBold;
694
        }
695
696 10927 jaume
697 11919 jaume
        private JComboBoxFonts getCmbFonts() {
698 10679 jaume
                if (cmbFonts == null) {
699 11919 jaume
                        cmbFonts = new JComboBoxFonts();
700 10679 jaume
                }
701
                return cmbFonts;
702
        }
703 10927 jaume
704 9745 jaume
        public WindowInfo getWindowInfo() {
705
                if (wi == null) {
706
                        wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
707
                        wi.setWidth(706);
708
                        wi.setHeight(500);
709
                        wi.setTitle(PluginServices.getText(this, "symbol_selector"));
710
                }
711
                return wi;
712
        }
713
714 18623 jdominguez
        protected JSplitPane getJSplitPane() throws ClassNotFoundException {
715 9745 jaume
                if (jSplitPane == null) {
716
                        jSplitPane = new JSplitPane();
717
                        jSplitPane.setDividerLocation(200);
718
                        jSplitPane.setResizeWeight(0.4);
719 18623 jdominguez
                jSplitPane.setLeftComponent(getLeftJScrollPane());
720 9745 jaume
                jSplitPane.setRightComponent(getJScrollPane1());
721
                }
722
                return jSplitPane;
723
        }
724
725 10679 jaume
        public Object getSelectedObject() {
726 18623 jdominguez
                if (!accepted) return null;
727
                Object mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
728 21299 vcaballero
729 18623 jdominguez
            // if this symbol only has one layer, then no multilayer is needed
730
                if (mySelectedElement instanceof IMultiLayerSymbol) {
731
                        if (((IMultiLayerSymbol) mySelectedElement).getLayerCount()==1)
732
                                return ((IMultiLayerSymbol) mySelectedElement).getLayer(0);
733 10679 jaume
                }
734 21299 vcaballero
735 18623 jdominguez
                if (mySelectedElement instanceof CartographicSupport) {
736
                        CartographicSupport csSym = (CartographicSupport) mySelectedElement;
737
                        csSym.setUnit(cmbUnits.getSelectedUnitIndex());
738
                        csSym.setReferenceSystem(cmbReferenceSystem.getSelectedIndex());
739
                }
740 21299 vcaballero
741 18623 jdominguez
                return mySelectedElement;
742 9745 jaume
        }
743
744 10679 jaume
        public void setSymbol(Object symbol) {
745
                ((SymbolPreviewer) jPanelPreview).setSymbol((ISymbol) symbol);
746 12657 jaume
                updateOptionsPanel();
747 9745 jaume
        }
748
749 10679 jaume
        /**
750
         * Invoked when the PROPERTIES button is pressed
751
         */
752
        protected void propertiesPressed() {
753 18623 jdominguez
                ISymbol mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
754
                if (mySelectedElement ==null)
755 10679 jaume
                        return;
756 9745 jaume
757 18623 jdominguez
                ISymbol clonedSymbol = SymbologyFactory.createSymbolFromXML(
758
                                mySelectedElement.getXMLEntity(), null);
759
                SymbolEditor se = new SymbolEditor(clonedSymbol, shapeType);
760 10679 jaume
                PluginServices.getMDIManager().addWindow(se);
761 21299 vcaballero
762 18623 jdominguez
                ISymbol symbol = se.getSymbol();
763
                if (symbol instanceof IMultiLayerSymbol) {
764
                        IMultiLayerSymbol mSym = (IMultiLayerSymbol) symbol;
765
                        if (mSym.getLayerCount() == 1) {
766
                                symbol =  mSym.getLayer(0);
767
                        }
768
                }
769
                setSymbol(symbol);
770 12657 jaume
771 10679 jaume
        }
772
773
        /**
774
         * Invoked when the NEW button is pressed
775
         */
776
        protected void newPressed() {
777
                SymbolEditor se = new SymbolEditor(null, shapeType);
778
                PluginServices.getMDIManager().addWindow(se);
779
                setSymbol(se.getSymbol());
780
        }
781
782
        /**
783
         * Invoked when the RESET button is pressed
784
         */
785
        protected void resetPressed() {
786
                setSymbol(null);
787
        }
788
789
        /**
790
         * Invoked when the SAVE button is pressed
791
         */
792
        protected void savePressed() {
793
                if (getSelectedObject() ==null)
794
                        return;
795
796
797 18623 jdominguez
                JFileChooser jfc = new JFileChooser("SYMBOL_SELECTOR_FILECHOOSER", rootDir);
798 10679 jaume
                javax.swing.filechooser.FileFilter ff = new javax.swing.filechooser.FileFilter() {
799
                        public boolean accept(File f) {
800
                                return f.getAbsolutePath().
801
                                toLowerCase().
802 18623 jdominguez
                                endsWith(SymbolLibrary.SYMBOL_FILE_EXTENSION) || f.isDirectory();
803 10679 jaume
                        }
804
805
                        public String getDescription() {
806
                                return PluginServices.getText(
807
                                                this, "gvSIG_symbol_definition_file")+ " (*.sym)";
808
                        }
809
                };
810
                jfc.setFileFilter(ff);
811
                JPanel accessory = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
812
                accessory.add(new JLabel(PluginServices.getText(this, "enter_description")));
813
                JTextField txtDesc = new JTextField(25);
814
                accessory.add(txtDesc);
815
                jfc.setAccessory(accessory);
816
                if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
817
                        File targetFile = jfc.getSelectedFile();
818
819
                        // apply description
820
                        String desc;
821
                        if (txtDesc.getText()==null || txtDesc.getText().trim().equals("")) {
822
                                // default to file name
823
                                String s = targetFile.getAbsolutePath();
824 18623 jdominguez
                                desc = s.substring(s.lastIndexOf(File.separator)+1).
825
                                        replaceAll(SymbolLibrary.SYMBOL_FILE_EXTENSION, "");
826 10679 jaume
                        } else {
827
                                desc = txtDesc.getText().trim();
828
                        }
829
                        ISymbol s = (ISymbol) getSelectedObject();
830
                        s.setDescription(desc);
831
832 21299 vcaballero
833 10679 jaume
                        getJListSymbols().setModel(newListModel());
834 18623 jdominguez
//                        getJListSymbols().setSelectedValue(
835
//                                        selectedElement, true);
836
                        String symbolFileName = targetFile.getAbsolutePath().substring(
837 21299 vcaballero
                                        targetFile.getAbsolutePath().lastIndexOf(File.separator)+1,
838 18623 jdominguez
                                        targetFile.getAbsolutePath().length());
839
                        File targetDir = new File(targetFile.getAbsolutePath().substring(
840
                                        0,
841
                                        targetFile.getAbsolutePath().lastIndexOf(File.separator)));
842
                        library.addElement(s, symbolFileName , targetDir);
843 10679 jaume
                }
844
        }
845
846
847 18623 jdominguez
        public void actionPerformed(ActionEvent e) {
848
                if (!act) return;
849
                Object selectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();//getSelectedObject();
850
                performActionOn(selectedElement, e);
851
                SymbolSelector.this.repaint();
852
        }
853 9745 jaume
854 18623 jdominguez
        protected void performActionOn(Object selectedElement, ActionEvent e) {
855
                JComponent comp = (JComponent) e.getSource();
856 9745 jaume
857 18623 jdominguez
                if ( comp.equals(getBtnProperties()) ) {
858
                        // properties pressed
859
                        propertiesPressed();
860
                } else if ( comp.equals(getBtnNewSymbol()) ) {
861
                        // new pressed
862
                        newPressed();
863
                } else if ( comp.equals(getBtnResetSymbol()) ) {
864
                        // reset pressed
865
                        resetPressed();
866
                } else if ( comp.equals(getBtnSaveSymbol()) ) {
867
                        // save pressed
868
                        savePressed();
869
                } else if (comp.equals(jcc1)) {
870
                        if (selectedElement == null)
871
                                return;
872 9745 jaume
873 18623 jdominguez
                        Color c = jcc1.getColor();
874 9745 jaume
875 18623 jdominguez
                        if (selectedElement instanceof IMarkerSymbol) {
876
                                IMarkerSymbol m = (IMarkerSymbol) selectedElement;
877
                                if (m instanceof MultiLayerMarkerSymbol) {
878
                                        MultiLayerMarkerSymbol mm = (MultiLayerMarkerSymbol) m;
879
                                        mm.setAlpha(jcc1.getAlpha());
880
                                } else {
881
                                        m.setColor(c);
882 11919 jaume
                                }
883 18623 jdominguez
                        }
884 11919 jaume
885 18623 jdominguez
                        if (selectedElement instanceof ILineSymbol) {
886
                                ILineSymbol l = (ILineSymbol) selectedElement;
887
                                if (l instanceof MultiLayerLineSymbol) {
888
                                        MultiLayerLineSymbol ml = (MultiLayerLineSymbol) l;
889
                                        ml.setAlpha(jcc1.getAlpha());
890
                                } else {
891
                                        l.setLineColor(c);
892 11919 jaume
                                }
893 18623 jdominguez
                        }
894 11919 jaume
895 18623 jdominguez
                        if (selectedElement instanceof IFillSymbol) {
896
                                IFillSymbol f = (IFillSymbol) selectedElement;
897 11919 jaume
898 18623 jdominguez
                                f.setHasFill(jcc1.getUseColorisSelected());
899
                                f.setFillColor(c);
900
                        }
901 11919 jaume
902 18623 jdominguez
                        if (selectedElement instanceof ITextSymbol) {
903
                                ITextSymbol t = (ITextSymbol) selectedElement;
904
                                t.setTextColor(c);
905
                        }
906 10679 jaume
907 18623 jdominguez
                } else if (comp.equals(jcc2)) {
908
                        if (selectedElement == null)
909
                                return;
910
                        Color c = jcc2.getColor();
911 10679 jaume
912 18623 jdominguez
913
                        if (selectedElement instanceof IFillSymbol) {
914
                                IFillSymbol f = (IFillSymbol) selectedElement;
915
                                ILineSymbol outline = f.getOutline();
916
                                f.setHasOutline(jcc2.getUseColorisSelected());
917
918
                                if (outline!=null) {
919
                                        ILineSymbol l = (ILineSymbol) outline;
920
                                        if (l instanceof MultiLayerLineSymbol && c != null) {
921
                                                MultiLayerLineSymbol ml = (MultiLayerLineSymbol) l;
922
                                                ml.setAlpha(c.getAlpha());
923
                                        } else {
924
                                                l.setLineColor(c);
925 14755 jdominguez
                                        }
926 11919 jaume
                                }
927
928 18623 jdominguez
                        }
929
                } else if (comp.equals(txtSize)) {
930
                        double s = txtSize.getDouble();
931 11919 jaume
932 18623 jdominguez
                        if (selectedElement instanceof IMarkerSymbol) {
933
                                IMarkerSymbol m = (IMarkerSymbol) selectedElement;
934
                                m.setSize(s);
935 9745 jaume
                        }
936
937 18623 jdominguez
                        if (selectedElement instanceof ILineSymbol) {
938
                                ILineSymbol l = (ILineSymbol) selectedElement;
939
                                l.setLineWidth(s);
940
                        }
941
                } else if (comp.equals(cmbUnits)) {
942
                        if (selectedElement instanceof CartographicSupport) {
943
                                CartographicSupport cs = (CartographicSupport) selectedElement;
944
                                cs.setUnit(cmbUnits.getSelectedUnitIndex());
945 21299 vcaballero
                        }
946 18623 jdominguez
                } else if (comp.equals(cmbReferenceSystem)) {
947
                        if (selectedElement instanceof CartographicSupport) {
948
                                CartographicSupport cs = (CartographicSupport) selectedElement;
949
                                cs.setUnit(cmbReferenceSystem.getSelectedIndex());
950
                        }
951
                } else if (comp.equals(txtWidth)) {
952
                        double w = txtWidth.getDouble();
953
                        if (selectedElement instanceof IFillSymbol) {
954
                                IFillSymbol f = (IFillSymbol) selectedElement;
955
                                ILineSymbol outline = f.getOutline();
956
                                if (outline!=null)
957
                                        outline.setLineWidth(w);
958
                        }
959
                } else if (comp.equals(cmbFontSize)) {
960
                        double s = ((Integer) cmbFontSize.getSelectedItem()).doubleValue();
961
                        if (selectedElement instanceof ITextSymbol) {
962
                                ITextSymbol t = (ITextSymbol) selectedElement;
963
                                t.setFontSize(s);
964
                        }
965
                } else if (comp.equals(txtAngle)) {
966
                        double a = Math.toRadians(txtAngle.getDouble());
967
                        if (selectedElement instanceof IMarkerSymbol) {
968
                                IMarkerSymbol m = (IMarkerSymbol) selectedElement;
969
                                m.setRotation(a);
970
                        }
971 9745 jaume
                }
972
        }
973 14821 jmvivo
974 13729 jaume
        public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType) {
975
                return createSymbolSelector(currSymbol, shapeType, null);
976
        }
977 14821 jmvivo
978 13729 jaume
        public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType, SelectorFilter filter) {
979
                ISymbolSelector selector = null;
980 21299 vcaballero
981 15905 jdominguez
                // patch for backwards compatibility
982 18623 jdominguez
//                if (currSymbol instanceof FSymbol) {
983
//                        currSymbol = SymbologyFactory.deriveFSymbol((FSymbol) currSymbol);
984
//                }
985 21299 vcaballero
986 13729 jaume
                if (filter==null)
987 22035 vcaballero
                        selector = (shapeType == Geometry.TYPES.GEOMETRY) ?
988 14821 jmvivo
                                        new MultiShapeSymbolSelector(currSymbol) :
989 18623 jdominguez
                                        new SymbolSelector(currSymbol, shapeType, true);
990 14821 jmvivo
                else
991 22035 vcaballero
                        selector = (shapeType == Geometry.TYPES.GEOMETRY) ?
992 13729 jaume
                                        new MultiShapeSymbolSelector(currSymbol) :
993 18623 jdominguez
                                        new SymbolSelector(currSymbol, shapeType, filter, true);
994 13729 jaume
                return selector;
995
        }
996 21299 vcaballero
997 18623 jdominguez
        class SillyDragNDropAction implements MouseListener, MouseMotionListener {
998
                private boolean doDrop = false;
999
                private Object selected;
1000
                private File sourceFolder;
1001 21299 vcaballero
1002 18623 jdominguez
                public void mouseClicked(MouseEvent e) { }
1003
                public void mouseEntered(MouseEvent e) { }
1004
                public void mouseExited(MouseEvent e) { }
1005 13729 jaume
1006 18623 jdominguez
                public void mousePressed(MouseEvent e) {
1007
                        if (e.getSource().equals(getJListSymbols())) {
1008
                                selected = getJListSymbols().getSelectedValue();
1009
                                doDrop = selected!=null;
1010
                                DefaultMutableTreeNode node = (DefaultMutableTreeNode) libraryBrowser.getLastSelectedPathComponent();
1011
                                if (node.getUserObject() instanceof File) {
1012
                                        sourceFolder = (File) node.getUserObject();
1013
                                }
1014
                        }
1015
                        e.consume();
1016
                }
1017
1018
                public void mouseReleased(MouseEvent e) {
1019
                        if (doDrop && e.getSource().equals(getJListSymbols())) {
1020
                                Point p = new Point(getJListSymbols().getLocation().x-e.getPoint().x, getJListSymbols().getLocation().y+e.getPoint().y);
1021
                                if (libraryBrowser.getBounds().contains(p)) {
1022
                                        File destFolder = libraryBrowser.getElementBellow(p);
1023
                                        if (destFolder != null) {
1024
                                                ISymbol sym = (ISymbol) selected;
1025
                                                int move = InputEvent.SHIFT_DOWN_MASK | InputEvent.BUTTON1_DOWN_MASK;
1026 20779 vcaballero
//                                            int copy = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
1027 21299 vcaballero
1028 18623 jdominguez
                                                library.addElement(sym, sym.getDescription(), destFolder);
1029
                                            if ((e.getModifiers() & (move)) !=0) {
1030
                                                    library.removeElement(sym, sourceFolder);
1031 21299 vcaballero
                                            }
1032 18623 jdominguez
1033
                                        }
1034
                                        libraryBrowser.refresh();
1035
                                }
1036
1037
                        }
1038
                        doDrop = false;
1039
                }
1040
1041
                public void mouseDragged(MouseEvent e) {
1042
                        if (e.getSource().equals(getJListSymbols())) {
1043 21299 vcaballero
1044 18623 jdominguez
                                Point p = new Point(getJListSymbols().getLocation().x-e.getPoint().x, getJListSymbols().getLocation().y+e.getPoint().y);
1045
                                if (libraryBrowser.getBounds().contains(p)) {
1046
                                        libraryBrowser.setSelectedElementBellow(p);
1047
                                }
1048
                        }
1049
                }
1050
1051
                public void mouseMoved(MouseEvent e) {
1052 21299 vcaballero
1053 18623 jdominguez
                }
1054 21299 vcaballero
1055 18623 jdominguez
        }
1056
1057 12731 jaume
}