Revision 24039 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/styling/SymbolSelector.java

View differences:

SymbolSelector.java
84 84
import org.gvsig.gui.beans.swing.JIncrementalNumberField;
85 85

  
86 86
import com.iver.andami.PluginServices;
87
import com.iver.andami.ui.mdiManager.IWindowListener;
87 88
import com.iver.andami.ui.mdiManager.WindowInfo;
88 89
import com.iver.cit.gvsig.fmap.core.CartographicSupport;
89 90
import com.iver.cit.gvsig.fmap.core.FPoint2D;
......
115 116
 */
116 117
public class SymbolSelector extends JPanel implements ISymbolSelector, ActionListener {
117 118

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

  
152 153

  
153
	protected SelectorFilter sFilter = new SelectorFilter() {
154
		private final IGeometry dummyPointGeom = ShapeFactory.createPoint2D(new FPoint2D());
155
		private final IGeometry dummyLineGeom = ShapeFactory.createPolyline2D(new GeneralPathX());
156
		private final IGeometry dummyPolygonGeom = ShapeFactory.createPolygon2D(new GeneralPathX());
154
    protected SelectorFilter sFilter = new SelectorFilter() {
155
        private final IGeometry dummyPointGeom = ShapeFactory.createPoint2D(new FPoint2D());
156
        private final IGeometry dummyLineGeom = ShapeFactory.createPolyline2D(new GeneralPathX());
157
        private final IGeometry dummyPolygonGeom = ShapeFactory.createPolygon2D(new GeneralPathX());
157 158

  
158
		public boolean accepts(Object obj) {
159
			if (obj instanceof ISymbol) {
160
				ISymbol sym = (ISymbol) obj;
159
        public boolean accepts(Object obj) {
160
            if (obj instanceof ISymbol) {
161
                ISymbol sym = (ISymbol) obj;
161 162

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

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

  
204
		// for symbols MULTIPOINT is the same than POINT
205
		if (shapeType == FShape.MULTIPOINT) shapeType = FShape.POINT;
205
        // for symbols MULTIPOINT is the same than POINT
206
        if (shapeType == FShape.MULTIPOINT) shapeType = FShape.POINT;
206 207

  
207
		this.shapeType = shapeType;
208
        this.shapeType = shapeType;
208 209

  
209 210
//		Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" );
210
		rootDir = new File(SymbologyFactory.SymbolLibraryPath);
211
        rootDir = new File(SymbologyFactory.SymbolLibraryPath);
211 212
//		prefs.get("SymbolLibraryFolder", System.getProperty("user.home")+"/gvSIG/Symbols"));
212
		if (!rootDir.exists())
213
			rootDir.mkdir();
214
		treeRootName = PluginServices.getText(this, "symbol_library");
215
		try {
216
			if (initialize)
217
				initialize(currentElement);
218
		} catch (ClassNotFoundException e) {
219
			throw new Error(e);
220
		}
213
        if (!rootDir.exists())
214
            rootDir.mkdir();
215
        treeRootName = PluginServices.getText(this, "symbol_library");
216
        try {
217
            if (initialize)
218
                initialize(currentElement);
219
        } catch (ClassNotFoundException e) {
220
            throw new Error(e);
221
        }
221 222

  
222 223

  
223
	}
224
    }
224 225

  
225
	/**
226
	 * Constructor method, it is <b>protected</b> by convenience to let StyleSelector
227
	 * to invoke it, but rigorously it should be <b>private</b>.
228
	 *
229
	 * @param symbol
230
	 * @param shapeType
231
	 * @param filter
232
	 */
233
	protected SymbolSelector(Object symbol, int shapeType, SelectorFilter filter, boolean initialize) {
234
		this(symbol, shapeType, initialize);
235
		sFilter = filter;
236
	}
226
    /**
227
     * Constructor method, it is <b>protected</b> by convenience to let StyleSelector
228
     * to invoke it, but rigorously it should be <b>private</b>.
229
     *
230
     * @param symbol
231
     * @param shapeType
232
     * @param filter
233
     */
234
    protected SymbolSelector(Object symbol, int shapeType, SelectorFilter filter, boolean initialize) {
235
        this(symbol, shapeType, initialize);
236
        sFilter = filter;
237
    }
237 238

  
238
	/**
239
	 * This method initializes this
240
	 * @param currentElement
241
	 * @throws ClassNotFoundException
242
	 *
243
	 */
244
	protected void initialize(Object currentElement) throws ClassNotFoundException {
245
		library = new SymbolLibrary(rootDir);
239
    /**
240
     * This method initializes this
241
     * @param currentElement
242
     * @throws ClassNotFoundException
243
     *
244
     */
245
    protected void initialize(Object currentElement) throws ClassNotFoundException {
246
        library = new SymbolLibrary(rootDir);
246 247

  
247
		this.setLayout(new BorderLayout());
248
		this.setSize(400, 221);
248
        this.setLayout(new BorderLayout());
249
        this.setSize(400, 221);
249 250

  
250
		this.add(getJNorthPanel(), BorderLayout.NORTH);
251
		this.add(getJSplitPane(), BorderLayout.CENTER);
252
		this.add(getJEastPanel(), BorderLayout.EAST);
253
		ActionListener okAction = new ActionListener() {
254
			public void actionPerformed(ActionEvent e) {
255
				PluginServices.getMDIManager().closeWindow(SymbolSelector.this);
256
			}
257
		}, cancelAction = new ActionListener() {
258
			public void actionPerformed(ActionEvent e) {
259
				accepted = false;
251
        this.add(getJNorthPanel(), BorderLayout.NORTH);
252
        this.add(getJSplitPane(), BorderLayout.CENTER);
253
        this.add(getJEastPanel(), BorderLayout.EAST);
254
        ActionListener okAction = new ActionListener() {
255
            public void actionPerformed(ActionEvent e) {
256
            	accepted = true;
257
                PluginServices.getMDIManager().closeWindow(SymbolSelector.this);
258
            }
259
        }, cancelAction = new ActionListener() {
260
            public void actionPerformed(ActionEvent e) {
261
            	 PluginServices.getMDIManager().closeWindow(SymbolSelector.this);
262
            }
263
        };
260 264

  
261
				setSymbol(null);
262
				PluginServices.getMDIManager().closeWindow(SymbolSelector.this);
263
			}
264
		};
265
        okCancelPanel = new AcceptCancelPanel();
266
        okCancelPanel.setOkButtonActionListener(okAction);
267
        okCancelPanel.setCancelButtonActionListener(cancelAction);
265 268

  
266
		okCancelPanel = new AcceptCancelPanel();
267
		okCancelPanel.setOkButtonActionListener(okAction);
268
		okCancelPanel.setCancelButtonActionListener(cancelAction);
269
        this.add(okCancelPanel, BorderLayout.SOUTH);
270
        libraryBrowser.setSelectionRow(0);
269 271

  
270
		this.add(okCancelPanel, BorderLayout.SOUTH);
271
		libraryBrowser.setSelectionRow(0);
272
        SillyDragNDropAction dndAction = new SillyDragNDropAction();
273
        libraryBrowser.addMouseListener(dndAction);
274
        libraryBrowser.addMouseMotionListener(dndAction);
275
        getJListSymbols().addMouseListener(dndAction);
276
        getJListSymbols().addMouseMotionListener(dndAction);
277
        setSymbol(currentElement);
278
    }
272 279

  
273
		SillyDragNDropAction dndAction = new SillyDragNDropAction();
274
		libraryBrowser.addMouseListener(dndAction);
275
		libraryBrowser.addMouseMotionListener(dndAction);
276
		getJListSymbols().addMouseListener(dndAction);
277
		getJListSymbols().addMouseMotionListener(dndAction);
278
		setSymbol(currentElement);
279
	}
280
    /**
281
     * Creates a new symbol selector list model in order to allow the user
282
     * to select an existing symbol previously created.
283
     *
284
     * @return listModel SymbolSelectorListModel
285
     */
286
    protected SymbolSelectorListModel newListModel() {
287
        SymbolSelectorListModel listModel = new SymbolSelectorListModel(
288
                dir,
289
                sFilter,
290
                SymbolLibrary.SYMBOL_FILE_EXTENSION);
291
        return listModel;
292
    }
293
    /**
294
     * Initializes tha JNorthPanel.
295
     *
296
     * @return northPanel JPanel
297
     * @throws IllegalArgumentException
298
     */
299
    protected JPanel getJNorthPanel() throws IllegalArgumentException {
300
        if (northPanel == null) {
301
            String text = "";
302
            switch (shapeType) {
303
            case FShape.POINT:
304
                text = PluginServices.getText(this, "point_symbols");
305
                break;
306
            case FShape.LINE:
307
                text = PluginServices.getText(this, "line_symbols");
308
                break;
309
            case FShape.POLYGON:
310
                text = PluginServices.getText(this, "polygon_symbols");
311
                break;
312
            case FShape.TEXT:
313
                text = PluginServices.getText(this, "text_symbols");
314
                break;
315
            default:
316
                throw new IllegalArgumentException(PluginServices.getText(this, "shape_type_not_yet_supported"));
317
            }
318
            northPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
319
            lblTitle = new JLabel(text);
320
            lblTitle.setFont(lblTitle.getFont().deriveFont(Font.BOLD));
321
            northPanel.add(lblTitle);
322
        }
323
        return northPanel;
324
    }
280 325

  
281
	/**
282
	 * Creates a new symbol selector list model in order to allow the user
283
	 * to select an existing symbol previously created.
284
	 *
285
	 * @return listModel SymbolSelectorListModel
286
	 */
287
	protected SymbolSelectorListModel newListModel() {
288
		SymbolSelectorListModel listModel = new SymbolSelectorListModel(
289
				dir,
290
				sFilter,
291
				SymbolLibrary.SYMBOL_FILE_EXTENSION);
292
		return listModel;
293
	}
294
	/**
295
	 * Initializes tha JNorthPanel.
296
	 *
297
	 * @return northPanel JPanel
298
	 * @throws IllegalArgumentException
299
	 */
300
	protected JPanel getJNorthPanel() throws IllegalArgumentException {
301
		if (northPanel == null) {
302
			String text = "";
303
			switch (shapeType) {
304
			case FShape.POINT:
305
				text = PluginServices.getText(this, "point_symbols");
306
				break;
307
			case FShape.LINE:
308
				text = PluginServices.getText(this, "line_symbols");
309
				break;
310
			case FShape.POLYGON:
311
				text = PluginServices.getText(this, "polygon_symbols");
312
				break;
313
			case FShape.TEXT:
314
				text = PluginServices.getText(this, "text_symbols");
315
				break;
316
			default:
317
				throw new IllegalArgumentException(PluginServices.getText(this, "shape_type_not_yet_supported"));
318
			}
319
			northPanel = new JPanel(new FlowLayout(FlowLayout.LEADING));
320
			lblTitle = new JLabel(text);
321
			lblTitle.setFont(lblTitle.getFont().deriveFont(Font.BOLD));
322
			northPanel.add(lblTitle);
323
		}
324
		return northPanel;
325
	}
326
    /**
327
     * This method initializes jList
328
     *
329
     * @return javax.swing.JList
330
     */
331
    protected JList getJListSymbols() {
332
        if (jListSymbols == null) {
333
            jListSymbols = new JList() ;
334
            jListSymbols.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
335
            jListSymbols.setLayoutOrientation(JList.HORIZONTAL_WRAP);
336
            jListSymbols.setVisibleRowCount(-1);
337
            jListSymbols.addListSelectionListener(new ListSelectionListener() {
338
                public void valueChanged(ListSelectionEvent e) {
339
                    if (jListSymbols.getSelectedValue()!=null) {
340
                        ISymbol selSym = SymbologyFactory.createSymbolFromXML(
341
                                ((ISymbol) jListSymbols.getSelectedValue()).getXMLEntity(), null);
342
                        setSymbol(selSym);
343
                        updateOptionsPanel();
344
                    }
345
                }
346
            });
347
            ListCellRenderer renderer = new ListCellRenderer() {
348
                private Color mySelectedBGColor = new Color(255,145,100,255);
349
                public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
350
                    ISymbol sym = (ISymbol) value;
351
                    JPanel pnl = new JPanel();
352
                    BoxLayout layout = new BoxLayout(pnl, BoxLayout.Y_AXIS);
353
                    pnl.setLayout(layout);
354
                    Color bgColor = (isSelected) ? mySelectedBGColor
355
                            : getJListSymbols().getBackground();
326 356

  
327
	/**
328
	 * This method initializes jList
329
	 *
330
	 * @return javax.swing.JList
331
	 */
332
	protected JList getJListSymbols() {
333
		if (jListSymbols == null) {
334
			jListSymbols = new JList() ;
335
			jListSymbols.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
336
			jListSymbols.setLayoutOrientation(JList.HORIZONTAL_WRAP);
337
			jListSymbols.setVisibleRowCount(-1);
338
			jListSymbols.addListSelectionListener(new ListSelectionListener() {
339
				public void valueChanged(ListSelectionEvent e) {
340
					if (jListSymbols.getSelectedValue()!=null) {
341
						ISymbol selSym = SymbologyFactory.createSymbolFromXML(
342
								((ISymbol) jListSymbols.getSelectedValue()).getXMLEntity(), null);
343
						setSymbol(selSym);
344
						updateOptionsPanel();
345
					}
346
				}
347
			});
348
			ListCellRenderer renderer = new ListCellRenderer() {
349
				private Color mySelectedBGColor = new Color(255,145,100,255);
350
				public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
351
					ISymbol sym = (ISymbol) value;
352
					JPanel pnl = new JPanel();
353
					BoxLayout layout = new BoxLayout(pnl, BoxLayout.Y_AXIS);
354
					pnl.setLayout(layout);
355
					Color bgColor = (isSelected) ? mySelectedBGColor
356
							: getJListSymbols().getBackground();
357
                    pnl.setBackground(bgColor);
358
                    SymbolPreviewer sp = new SymbolPreviewer();
359
                    sp.setAlignmentX(Component.CENTER_ALIGNMENT);
360
                    sp.setPreferredSize(new Dimension(50, 50));
361
                    sp.setSymbol(sym);
362
                    sp.setBackground(bgColor);
363
                    pnl.add(sp);
364
                    String desc = sym.getDescription();
365
                    if (desc == null) {
366
                        desc = "["+PluginServices.getText(this, "no_desc")+"]";
367
                    }
368
                    JLabel lbl = new JLabel(desc);
369
                    lbl.setBackground(bgColor);
370
                    lbl.setAlignmentX(Component.CENTER_ALIGNMENT);
371
                    pnl.add(lbl);
357 372

  
358
					pnl.setBackground(bgColor);
359
					SymbolPreviewer sp = new SymbolPreviewer();
360
					sp.setAlignmentX(Component.CENTER_ALIGNMENT);
361
					sp.setPreferredSize(new Dimension(50, 50));
362
					sp.setSymbol(sym);
363
					sp.setBackground(bgColor);
364
					pnl.add(sp);
365
					String desc = sym.getDescription();
366
					if (desc == null) {
367
						desc = "["+PluginServices.getText(this, "no_desc")+"]";
368
					}
369
					JLabel lbl = new JLabel(desc);
370
					lbl.setBackground(bgColor);
371
					lbl.setAlignmentX(Component.CENTER_ALIGNMENT);
372
					pnl.add(lbl);
373
                    return pnl;
374
                }
373 375

  
374
					return pnl;
375
				}
376
            };
377
            jListSymbols.setCellRenderer(renderer);
378
        }
379
        return jListSymbols;
380
    }
381
    /**
382
     * Updates the options panel depending on the type of symbol that the user
383
     * is controlling or using to show specific options for each one.
384
     *
385
     */
386
    protected void updateOptionsPanel() throws IllegalArgumentException {
387
        Object mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
376 388

  
377
			};
378
			jListSymbols.setCellRenderer(renderer);
379
		}
380
		return jListSymbols;
381
	}
382
	/**
383
	 * Updates the options panel depending on the type of symbol that the user
384
	 * is controlling or using to show specific options for each one.
385
	 *
386
	 */
387
	protected void updateOptionsPanel() throws IllegalArgumentException {
388
		Object mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
389
        if (mySelectedElement == null) return;
390
        act = false; // disable events
389 391

  
390
		if (mySelectedElement == null) return;
391
		act = false; // disable events
392
        if (mySelectedElement instanceof CartographicSupport) {
393
            CartographicSupport cs = (CartographicSupport) mySelectedElement;
394
            cmbUnits.setSelectedUnitIndex(cs.getUnit());
395
            cmbReferenceSystem.setSelectedIndex(cs.getReferenceSystem());
396
        }
392 397

  
393
		if (mySelectedElement instanceof CartographicSupport) {
394
			CartographicSupport cs = (CartographicSupport) mySelectedElement;
395
			cmbUnits.setSelectedUnitIndex(cs.getUnit());
396
			cmbReferenceSystem.setSelectedIndex(cs.getReferenceSystem());
397
		}
398
        if (mySelectedElement instanceof IMultiLayerSymbol){
399
            if (((IMultiLayerSymbol)mySelectedElement).getLayerCount() == 1)
400
                mySelectedElement = ((IMultiLayerSymbol)mySelectedElement).getLayer(0);
401
        }
398 402

  
399
		if (mySelectedElement instanceof IMultiLayerSymbol){
400
			if (((IMultiLayerSymbol)mySelectedElement).getLayerCount() == 1)
401
				mySelectedElement = ((IMultiLayerSymbol)mySelectedElement).getLayer(0);
402
		}
403 403

  
404
        try {
404 405

  
405
		try {
406
            jcc1.setEnabled(true);
407
            jcc2.setEnabled(true);
406 408

  
407
			jcc1.setEnabled(true);
408
			jcc2.setEnabled(true);
409
            if(mySelectedElement instanceof IMultiLayerSymbol){
410
                jcc1.setColor(Color.WHITE);
411
                jcc2.setColor(Color.WHITE);
412
                jcc1.setEnabled(false);
413
                jcc2.setEnabled(false);
414
            }
409 415

  
410
			if(mySelectedElement instanceof IMultiLayerSymbol){
411
				jcc1.setColor(Color.WHITE);
412
				jcc2.setColor(Color.WHITE);
413
				jcc1.setEnabled(false);
414
				jcc2.setEnabled(false);
415
			}
416 416

  
417
            if (shapeType == FShape.POINT) {
418
                IMarkerSymbol m = (IMarkerSymbol) mySelectedElement;
419
                jcc1.setColor(m.getColor());
420
                txtSize.setDouble(m.getSize());
421
                txtAngle.setDouble(m.getRotation());
422
            }
417 423

  
418
			if (shapeType == FShape.POINT) {
419
				IMarkerSymbol m = (IMarkerSymbol) mySelectedElement;
420
				jcc1.setColor(m.getColor());
421
				txtSize.setDouble(m.getSize());
422
				txtAngle.setDouble(m.getRotation());
423
			}
424
            if (shapeType == FShape.LINE) {
425
                ILineSymbol l = (ILineSymbol) mySelectedElement;
426
                jcc1.setColor(l.getColor());
427
                jcc1.setAlpha(l.getAlpha());
428
                txtSize.setDouble(l.getLineWidth());
429
            }
424 430

  
425
			if (shapeType == FShape.LINE) {
426
				ILineSymbol l = (ILineSymbol) mySelectedElement;
427
				jcc1.setColor(l.getColor());
428
				jcc1.setAlpha(l.getAlpha());
429
				txtSize.setDouble(l.getLineWidth());
430
			}
431
            if (shapeType == FShape.POLYGON) {
432
                IFillSymbol f = (IFillSymbol) mySelectedElement;
431 433

  
432
			if (shapeType == FShape.POLYGON) {
433
				IFillSymbol f = (IFillSymbol) mySelectedElement;
434
                txtWidth.setEnabled(true);
435
                cmbReferenceSystem.setEnabled(true);
436
                cmbUnits.setEnabled(true);
434 437

  
435
				txtWidth.setEnabled(true);
436
				cmbReferenceSystem.setEnabled(true);
437
				cmbUnits.setEnabled(true);
438
                jcc1.setUseColorIsSelected(f.hasFill());
439
                jcc1.setColor(f.getFillColor());
440
                jcc1.setAlpha(f.getFillAlpha());
441
                jcc2.setUseColorIsSelected(f.hasOutline());
442
                ILineSymbol outline = f.getOutline();
443
                if (outline != null) {
444
                    jcc2.setColor(outline.getColor());
445
                    txtWidth.setDouble(outline.getLineWidth());
446
                }
438 447

  
439
				jcc1.setUseColorIsSelected(f.hasFill());
440
				jcc1.setColor(f.getFillColor());
441
				jcc1.setAlpha(f.getFillAlpha());
442
				jcc2.setUseColorIsSelected(f.hasOutline());
443
				ILineSymbol outline = f.getOutline();
444
				if (outline != null) {
445
					jcc2.setColor(outline.getColor());
446
					txtWidth.setDouble(outline.getLineWidth());
447
				}
448
                if(f instanceof MultiLayerFillSymbol){
449
                    txtWidth.setEnabled(false);
450
                    cmbReferenceSystem.setEnabled(false);
451
                    cmbUnits.setEnabled(false);
452
                }
453
            }
448 454

  
449
				if(f instanceof MultiLayerFillSymbol){
450
					txtWidth.setEnabled(false);
451
					cmbReferenceSystem.setEnabled(false);
452
					cmbUnits.setEnabled(false);
453
				}
454
			}
455 455

  
456
            if (shapeType == FShape.TEXT) {
457
                ITextSymbol t = (ITextSymbol) mySelectedElement;
458
                jcc1.setColor(t.getTextColor());
459
                Double s = new Double(t.getFont().getSize());
460
                cmbFontSize.setSelectedItem(s);
461
                int i = cmbFontSize.getSelectedIndex();
462
                if (i == -1) {
463
                    cmbFontSize.addItem(s);
464
                    cmbFontSize.setSelectedItem(s);
465
                }
466
            }
467
        } catch (NullPointerException npEx) {
468
            throw new IllegalArgumentException(npEx);
469
        } catch (ClassCastException ccEx) {
470
            throw new IllegalArgumentException(ccEx);
471
        }
456 472

  
457
			if (shapeType == FShape.TEXT) {
458
				ITextSymbol t = (ITextSymbol) mySelectedElement;
459
				jcc1.setColor(t.getTextColor());
460
				Double s = new Double(t.getFont().getSize());
461
				cmbFontSize.setSelectedItem(s);
462
				int i = cmbFontSize.getSelectedIndex();
463
				if (i == -1) {
464
					cmbFontSize.addItem(s);
465
					cmbFontSize.setSelectedItem(s);
466
				}
467
			}
468
		} catch (NullPointerException npEx) {
469
			throw new IllegalArgumentException(npEx);
470
		} catch (ClassCastException ccEx) {
471
			throw new IllegalArgumentException(ccEx);
472
		}
473
        act = true;  // enable events
474
    }
473 475

  
474
		act = true;  // enable events
475
	}
476
    /**
477
     * This method initializes jPanel
478
     *
479
     * @return javax.swing.JPanel
480
     */
481
    protected JPanel getJEastPanel() {
482
        if (jPanel == null) {
483
            jPanel = new JPanel();
484
            jPanel.setLayout(new BorderLayout());
485
            jPanel.add(getJPanelOptions(), BorderLayout.CENTER);
486
            JPanel aux = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
487
            aux.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "preview")));
488
            aux.add(getJPanelPreview());
489
            jPanel.add(aux, BorderLayout.NORTH);
476 490

  
477
	/**
478
	 * This method initializes jPanel
479
	 *
480
	 * @return javax.swing.JPanel
481
	 */
482
	protected JPanel getJEastPanel() {
483
		if (jPanel == null) {
484
			jPanel = new JPanel();
485
			jPanel.setLayout(new BorderLayout());
486
			jPanel.add(getJPanelOptions(), BorderLayout.CENTER);
487
			JPanel aux = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
488
			aux.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "preview")));
489
			aux.add(getJPanelPreview());
490
			jPanel.add(aux, BorderLayout.NORTH);
491
            jPanel.add(getJPanelOptions());
492
            aux = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5));
493
            aux.add(getJPanelButtons());
494
            jPanel.add(aux, BorderLayout.SOUTH);
495
        }
496
        return jPanel;
497
    }
491 498

  
492
			jPanel.add(getJPanelOptions());
493
			aux = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5));
494
			aux.add(getJPanelButtons());
495
			jPanel.add(aux, BorderLayout.SOUTH);
496
		}
497
		return jPanel;
498
	}
499
    private JPanel getJPanelButtons() {
500
        if (jPanelButtons == null) {
501
            jPanelButtons = new JPanel();
502
            GridLayout layout = new GridLayout();
503
            layout.setColumns(1);
504
            layout.setVgap(5);
505
            jPanelButtons.add(getBtnNewSymbol());
506
            jPanelButtons.add(getBtnSaveSymbol());
507
            jPanelButtons.add(getBtnResetSymbol());
508
            jPanelButtons.add(getBtnProperties());
499 509

  
500
	private JPanel getJPanelButtons() {
501
		if (jPanelButtons == null) {
502
			jPanelButtons = new JPanel();
503
			GridLayout layout = new GridLayout();
504
			layout.setColumns(1);
505
			layout.setVgap(5);
506
			jPanelButtons.add(getBtnNewSymbol());
507
			jPanelButtons.add(getBtnSaveSymbol());
508
			jPanelButtons.add(getBtnResetSymbol());
509
			jPanelButtons.add(getBtnProperties());
510
            // do not add components bellow this line!
511
            layout.setRows(jPanelButtons.getComponentCount());
512
            jPanelButtons.setLayout(layout);
513
        }
514
        return jPanelButtons;
515
    }
510 516

  
511
			// do not add components bellow this line!
512
			layout.setRows(jPanelButtons.getComponentCount());
513
			jPanelButtons.setLayout(layout);
514
		}
515
		return jPanelButtons;
516
	}
517
    private JButton getBtnNewSymbol() {
518
        if (btnNewSymbol == null) {
519
            btnNewSymbol = new JButton();
520
            btnNewSymbol.setName("btnNewSymbol");
521
            btnNewSymbol.setText(PluginServices.getText(this, "new"));
522
            btnNewSymbol.addActionListener(this);
523
        }
524
        return btnNewSymbol;
525
    }
517 526

  
518
	private JButton getBtnNewSymbol() {
519
		if (btnNewSymbol == null) {
520
			btnNewSymbol = new JButton();
521
			btnNewSymbol.setName("btnNewSymbol");
522
			btnNewSymbol.setText(PluginServices.getText(this, "new"));
523
			btnNewSymbol.addActionListener(this);
524
		}
525
		return btnNewSymbol;
526
	}
527
    private JButton getBtnResetSymbol() {
528
        if (btnResetSymbol == null) {
529
            btnResetSymbol = new JButton();
530
            btnResetSymbol.setName("btnResetSymbol");
531
            btnResetSymbol.setText(PluginServices.getText(this, "reset"));
532
            btnResetSymbol.addActionListener(this);
533
        }
534
        return btnResetSymbol;
535
    }
527 536

  
528
	private JButton getBtnResetSymbol() {
529
		if (btnResetSymbol == null) {
530
			btnResetSymbol = new JButton();
531
			btnResetSymbol.setName("btnResetSymbol");
532
			btnResetSymbol.setText(PluginServices.getText(this, "reset"));
533
			btnResetSymbol.addActionListener(this);
534
		}
535
		return btnResetSymbol;
536
	}
537
    private JButton getBtnSaveSymbol() {
538
        if (btnSaveSymbol == null) {
539
            btnSaveSymbol = new JButton();
540
            btnSaveSymbol.setName("btnSaveSymbol");
541
            btnSaveSymbol.setText(PluginServices.getText(this, "save"));
542
            btnSaveSymbol.addActionListener(this);
543
        }
544
        return btnSaveSymbol;
545
    }
537 546

  
538
	private JButton getBtnSaveSymbol() {
539
		if (btnSaveSymbol == null) {
540
			btnSaveSymbol = new JButton();
541
			btnSaveSymbol.setName("btnSaveSymbol");
542
			btnSaveSymbol.setText(PluginServices.getText(this, "save"));
543
			btnSaveSymbol.addActionListener(this);
544
		}
545
		return btnSaveSymbol;
546
	}
547
    private JButton getBtnProperties() {
548
        if (btnProperties == null) {
549
            btnProperties = new JButton();
550
            btnProperties.setName("btnProperties");
551
            btnProperties.setText(PluginServices.getText(this, "properties"));
552
            btnProperties.addActionListener(this);
553
        }
554
        return btnProperties;
555
    }
547 556

  
548
	private JButton getBtnProperties() {
549
		if (btnProperties == null) {
550
			btnProperties = new JButton();
551
			btnProperties.setName("btnProperties");
552
			btnProperties.setText(PluginServices.getText(this, "properties"));
553
			btnProperties.addActionListener(this);
554
		}
555
		return btnProperties;
556
	}
557
    /**
558
     * This method initializes jScrollPane
559
     *
560
     * @return javax.swing.JScrollPane
561
     * @throws ClassNotFoundException
562
     */
563
    protected JScrollPane getLeftJScrollPane() throws ClassNotFoundException {
564
        if (jScrollPane == null) {
565
            jScrollPane = new JScrollPane();
566
            jScrollPane.setPreferredSize(new java.awt.Dimension(80,130));
567
            jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
568
            libraryBrowser = new LibraryBrowser(library);
569
            libraryBrowser.addTreeSelectionListener(new TreeSelectionListener() {
570
                public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
571
                    dir = (File) ((DefaultMutableTreeNode)
572
                            libraryBrowser.getLastSelectedPathComponent()).getUserObject();
557 573

  
558
	/**
559
	 * This method initializes jScrollPane
560
	 *
561
	 * @return javax.swing.JScrollPane
562
	 * @throws ClassNotFoundException
563
	 */
564
	protected JScrollPane getLeftJScrollPane() throws ClassNotFoundException {
565
		if (jScrollPane == null) {
566
			jScrollPane = new JScrollPane();
567
			jScrollPane.setPreferredSize(new java.awt.Dimension(80,130));
568
			jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
569
			libraryBrowser = new LibraryBrowser(library);
570
			libraryBrowser.addTreeSelectionListener(new TreeSelectionListener() {
571
				public void valueChanged(javax.swing.event.TreeSelectionEvent e) {
572
					dir = (File) ((DefaultMutableTreeNode)
573
							libraryBrowser.getLastSelectedPathComponent()).getUserObject();
574
                    if (dir == null) return;
574 575

  
575
					if (dir == null) return;
576

  
577
					jListSymbols.setModel(newListModel());
576
                    jListSymbols.setModel(newListModel());
578 577
//					jListSymbols.setSelectedValue(selectedElement, true);
579
				}
580
			});
581
			jScrollPane.setViewportView(libraryBrowser);
582
		}
583
		return jScrollPane;
584
	}
578
                }
579
            });
580
            jScrollPane.setViewportView(libraryBrowser);
581
        }
582
        return jScrollPane;
583
    }
585 584

  
586
	/**
587
	 * This method initializes jScrollPane1
588
	 *
589
	 * @return javax.swing.JScrollPane
590
	 */
591
	private JScrollPane getJScrollPane1() {
592
		if (jScrollPane1 == null) {
593
			jScrollPane1 = new JScrollPane();
594
			jScrollPane1.setViewportView(getJListSymbols());
595
		}
596
		return jScrollPane1;
597
	}
585
    /**
586
     * This method initializes jScrollPane1
587
     *
588
     * @return javax.swing.JScrollPane
589
     */
590
    private JScrollPane getJScrollPane1() {
591
        if (jScrollPane1 == null) {
592
            jScrollPane1 = new JScrollPane();
593
            jScrollPane1.setViewportView(getJListSymbols());
594
        }
595
        return jScrollPane1;
596
    }
598 597

  
599
	/**
600
	 * This method initializes jPanelPreview
601
	 *
602
	 * @return javax.swing.JComponent
603
	 */
604
	protected JComponent getJPanelPreview() {
605
		if (jPanelPreview == null) {
606
			jPanelPreview = new SymbolPreviewer();
607
			jPanelPreview.setPreferredSize(new java.awt.Dimension(100,100));
608
			jPanelPreview.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
609
		}
610
		return jPanelPreview;
611
	}
612
	/**
613
	 * This method initializes jPanelOptions
614
	 *
615
	 * @return javax.swing.JPanel
616
	 */
617
	protected JPanel getJPanelOptions() {
618
		if (jPanelOptions == null) {
619
			jPanelOptions = new GridBagLayoutPanel();
620
			jPanelOptions.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "options")));
621
			jcc2 = new ColorChooserPanel(true,true);
622
			jcc2.setAlpha(255);
623
			if (shapeType == FShape.POINT) {
624
				jcc1 = new ColorChooserPanel(true);
598
    /**
599
     * This method initializes jPanelPreview
600
     *
601
     * @return javax.swing.JComponent
602
     */
603
    protected JComponent getJPanelPreview() {
604
        if (jPanelPreview == null) {
605
            jPanelPreview = new SymbolPreviewer();
606
            jPanelPreview.setPreferredSize(new java.awt.Dimension(100,100));
607
            jPanelPreview.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED));
608
        }
609
        return jPanelPreview;
610
    }
611
    /**
612
     * This method initializes jPanelOptions
613
     *
614
     * @return javax.swing.JPanel
615
     */
616
    protected JPanel getJPanelOptions() {
617
        if (jPanelOptions == null) {
618
            jPanelOptions = new GridBagLayoutPanel();
619
            jPanelOptions.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "options")));
620
            jcc2 = new ColorChooserPanel(true,true);
621
            jcc2.setAlpha(255);
622
            if (shapeType == FShape.POINT) {
623
                jcc1 = new ColorChooserPanel(true);
625 624

  
626
				jPanelOptions.addComponent(
627
						PluginServices.getText(this, "color")+":", jcc1);
628
				jPanelOptions.addComponent(
629
						PluginServices.getText(this, "size")+":",
630
						txtSize = new JIncrementalNumberField(String.valueOf(3), 3, 0, Double.MAX_VALUE, 1));
631
				jPanelOptions.addComponent(PluginServices.getText(this, "units")+":",
632
						cmbUnits = new JComboBoxUnits());
633
				jPanelOptions.addComponent("",
634
						cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
635
				jPanelOptions.addComponent(
636
						PluginServices.getText(this, "angle")+":",
637
						txtAngle = new JIncrementalNumberField());
625
                jPanelOptions.addComponent(
626
                        PluginServices.getText(this, "color")+":", jcc1);
627
                jPanelOptions.addComponent(
628
                        PluginServices.getText(this, "size")+":",
629
                        txtSize = new JIncrementalNumberField(String.valueOf(3), 3, 0, Double.MAX_VALUE, 1));
630
                jPanelOptions.addComponent(PluginServices.getText(this, "units")+":",
631
                        cmbUnits = new JComboBoxUnits());
632
                jPanelOptions.addComponent("",
633
                        cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
634
                jPanelOptions.addComponent(
635
                        PluginServices.getText(this, "angle")+":",
636
                        txtAngle = new JIncrementalNumberField());
638 637

  
639 638

  
640
			} else if (shapeType == FShape.LINE) {
641
				jcc1 = new ColorChooserPanel(true);
642
				jPanelOptions.addComponent(
643
						PluginServices.getText(this, "color")+":", jcc1);
644
				jPanelOptions.addComponent(
645
						PluginServices.getText(this, "width")+":",
646
						txtSize = new JIncrementalNumberField(String.valueOf(3), 3, 0, Double.MAX_VALUE, 1));
647
				jPanelOptions.addComponent(PluginServices.getText(this, "units")+":",
648
						cmbUnits = new JComboBoxUnits());
649
				jPanelOptions.addComponent("",
650
						cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
639
            } else if (shapeType == FShape.LINE) {
640
                jcc1 = new ColorChooserPanel(true);
641
                jPanelOptions.addComponent(
642
                        PluginServices.getText(this, "color")+":", jcc1);
643
                jPanelOptions.addComponent(
644
                        PluginServices.getText(this, "width")+":",
645
                        txtSize = new JIncrementalNumberField(String.valueOf(3), 3, 0, Double.MAX_VALUE, 1));
646
                jPanelOptions.addComponent(PluginServices.getText(this, "units")+":",
647
                        cmbUnits = new JComboBoxUnits());
648
                jPanelOptions.addComponent("",
649
                        cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
651 650

  
652
			} else if (shapeType == FShape.POLYGON) {
653
				jcc1 = new ColorChooserPanel(true, true);
654
				jPanelOptions.addComponent(
655
						PluginServices.getText(this, "fill_color")+":", jcc1);
656
				jPanelOptions.addComponent(
657
						PluginServices.getText(this, "outline_color")+":", jcc2);
658
				jPanelOptions.addComponent(
659
						PluginServices.getText(this, "outline_width"),
660
						txtWidth = new JIncrementalNumberField(String.valueOf(3), 3, 0, Double.MAX_VALUE, 1));
661
				jPanelOptions.addComponent(PluginServices.getText(this, "units")+":",
662
						cmbUnits = new JComboBoxUnits());
663
				jPanelOptions.addComponent("",
664
						cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
651
            } else if (shapeType == FShape.POLYGON) {
652
                jcc1 = new ColorChooserPanel(true, true);
653
                jPanelOptions.addComponent(
654
                        PluginServices.getText(this, "fill_color")+":", jcc1);
655
                jPanelOptions.addComponent(
656
                        PluginServices.getText(this, "outline_color")+":", jcc2);
657
                jPanelOptions.addComponent(
658
                        PluginServices.getText(this, "outline_width"),
659
                        txtWidth = new JIncrementalNumberField(String.valueOf(3), 3, 0, Double.MAX_VALUE, 1));
660
                jPanelOptions.addComponent(PluginServices.getText(this, "units")+":",
661
                        cmbUnits = new JComboBoxUnits());
662
                jPanelOptions.addComponent("",
663
                        cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
665 664

  
666
			} else if (shapeType == FShape.TEXT) {
667
				jcc1 = new ColorChooserPanel(true);
668
				jPanelOptions.addComponent(
669
						PluginServices.getText(this, "font")+":", getCmbFonts());
665
            } else if (shapeType == FShape.TEXT) {
666
                jcc1 = new ColorChooserPanel(true);
667
                jPanelOptions.addComponent(
668
                        PluginServices.getText(this, "font")+":", getCmbFonts());
670 669

  
671
				jPanelOptions.addComponent(
672
						PluginServices.getText(this, "color")+":", jcc1);
673
				jPanelOptions.addComponent(PluginServices.getText(this, "size")+":",
674
						cmbFontSize = new JComboBoxFontSizes());
675
				jPanelOptions.addComponent(PluginServices.getText(this, "units")+":",
676
						cmbUnits = new JComboBoxUnits());
677
				jPanelOptions.addComponent("",
678
						cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
670
                jPanelOptions.addComponent(
671
                        PluginServices.getText(this, "color")+":", jcc1);
672
                jPanelOptions.addComponent(PluginServices.getText(this, "size")+":",
673
                        cmbFontSize = new JComboBoxFontSizes());
674
                jPanelOptions.addComponent(PluginServices.getText(this, "units")+":",
675
                        cmbUnits = new JComboBoxUnits());
676
                jPanelOptions.addComponent("",
677
                        cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
679 678

  
680
				JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING,0,1));
681
				aux.add(getBtnBold());
682
				aux.add(getBtnItalic());
683
				aux.add(getBtnUnderlined());
684
				jPanelOptions.addComponent(
685
						PluginServices.getText(this, "style")+":", aux);
679
                JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING,0,1));
680
                aux.add(getBtnBold());
681
                aux.add(getBtnItalic());
682
                aux.add(getBtnUnderlined());
683
                jPanelOptions.addComponent(
684
                        PluginServices.getText(this, "style")+":", aux);
686 685

  
687
			}
686
            }
688 687

  
689
			jcc1.setAlpha(255);
688
            jcc1.setAlpha(255);
690 689

  
691
			if (txtSize != null)			txtSize.addActionListener(this);
692
			if (cmbUnits != null)			cmbUnits.addActionListener(this);
693
			if (cmbReferenceSystem != null)	cmbReferenceSystem.addActionListener(this);
694
			if (jcc1 != null)				jcc1.addActionListener(this);
695
			if (jcc2 != null)				jcc2.addActionListener(this);
696
			if (txtWidth != null)			txtWidth.addActionListener(this);
697
			if (cmbFontSize != null)		cmbFontSize.addActionListener(this);
698
			if (txtAngle != null)			txtAngle.addActionListener(this);
699
		}
700
		return jPanelOptions;
701
	}
690
            if (txtSize != null)			txtSize.addActionListener(this);
691
            if (cmbUnits != null)			cmbUnits.addActionListener(this);
692
            if (cmbReferenceSystem != null)	cmbReferenceSystem.addActionListener(this);
693
            if (jcc1 != null)				jcc1.addActionListener(this);
694
            if (jcc2 != null)				jcc2.addActionListener(this);
695
            if (txtWidth != null)			txtWidth.addActionListener(this);
696
            if (cmbFontSize != null)		cmbFontSize.addActionListener(this);
697
            if (txtAngle != null)			txtAngle.addActionListener(this);
698
        }
699
        return jPanelOptions;
700
    }
702 701

  
703
	private JToggleButton getBtnUnderlined() {
704
		if (btnUnderlined == null) {
705
			btnUnderlined = new JToggleButton(PluginServices.getIconTheme().
706
					get("underline-icon"));
707
		}
708
		return btnUnderlined;
709
	}
702
    private JToggleButton getBtnUnderlined() {
703
        if (btnUnderlined == null) {
704
            btnUnderlined = new JToggleButton(PluginServices.getIconTheme().
705
                    get("underline-icon"));
706
        }
707
        return btnUnderlined;
708
    }
710 709

  
711
	private JToggleButton getBtnItalic() {
712
		if (btnItalic == null) {
713
			btnItalic = new JToggleButton(PluginServices.getIconTheme().
714
					get("italic-icon"));
715
		}
716
		return btnItalic;
717
	}
710
    private JToggleButton getBtnItalic() {
711
        if (btnItalic == null) {
712
            btnItalic = new JToggleButton(PluginServices.getIconTheme().
713
                    get("italic-icon"));
714
        }
715
        return btnItalic;
716
    }
718 717

  
719
	private JToggleButton getBtnBold() {
720
		if (btnBold == null) {
721
			btnBold = new JToggleButton(PluginServices.getIconTheme().
722
					get("bold-icon"));
723
		}
724
		return btnBold;
725
	}
718
    private JToggleButton getBtnBold() {
719
        if (btnBold == null) {
720
            btnBold = new JToggleButton(PluginServices.getIconTheme().
721
                    get("bold-icon"));
722
        }
723
        return btnBold;
724
    }
726 725

  
727 726

  
728
	private JComboBoxFonts getCmbFonts() {
729
		if (cmbFonts == null) {
730
			cmbFonts = new JComboBoxFonts();
731
		}
732
		return cmbFonts;
733
	}
727
    private JComboBoxFonts getCmbFonts() {
728
        if (cmbFonts == null) {
729
            cmbFonts = new JComboBoxFonts();
730
        }
731
        return cmbFonts;
732
    }
734 733

  
735
	public WindowInfo getWindowInfo() {
736
		if (wi == null) {
737
			wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
738
			wi.setWidth(706);
739
			wi.setHeight(500);
740
			wi.setTitle(PluginServices.getText(this, "symbol_selector"));
741
		}
742
		return wi;
743
	}
734
    public WindowInfo getWindowInfo() {
735
        if (wi == null) {
736
            wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
737
            wi.setWidth(706);
738
            wi.setHeight(500);
739
            wi.setTitle(PluginServices.getText(this, "symbol_selector"));
740
        }
741
        return wi;
742
    }
744 743

  
745
	protected JSplitPane getJSplitPane() throws ClassNotFoundException {
746
		if (jSplitPane == null) {
747
			jSplitPane = new JSplitPane();
748
			jSplitPane.setDividerLocation(200);
749
			jSplitPane.setResizeWeight(0.4);
750
			jSplitPane.setLeftComponent(getLeftJScrollPane());
751
			jSplitPane.setRightComponent(getJScrollPane1());
752
		}
753
		return jSplitPane;
754
	}
744
    protected JSplitPane getJSplitPane() throws ClassNotFoundException {
745
        if (jSplitPane == null) {
746
            jSplitPane = new JSplitPane();
747
            jSplitPane.setDividerLocation(200);
748
            jSplitPane.setResizeWeight(0.4);
749
            jSplitPane.setLeftComponent(getLeftJScrollPane());
750
            jSplitPane.setRightComponent(getJScrollPane1());
751
        }
752
        return jSplitPane;
753
    }
755 754

  
756
	public Object getSelectedObject() {
757
		if (!accepted) return null;
758
		Object mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
755
    public Object getSelectedObject() {
756
        if (!accepted) return null;
757
        Object mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
759 758

  
760
		// if this symbol only has one layer, then no multilayer is needed
761
		if (mySelectedElement instanceof IMultiLayerSymbol) {
762
			if (((IMultiLayerSymbol) mySelectedElement).getLayerCount()==1)
763
				return ((IMultiLayerSymbol) mySelectedElement).getLayer(0);
764
		}
759
        // if this symbol only has one layer, then no multilayer is needed
760
        if (mySelectedElement instanceof IMultiLayerSymbol) {
761
            if (((IMultiLayerSymbol) mySelectedElement).getLayerCount()==1)
762
                return ((IMultiLayerSymbol) mySelectedElement).getLayer(0);
763
        }
765 764

  
766
		if (mySelectedElement instanceof CartographicSupport) {
767
			CartographicSupport csSym = (CartographicSupport) mySelectedElement;
768
			csSym.setUnit(cmbUnits.getSelectedUnitIndex());
769
			csSym.setReferenceSystem(cmbReferenceSystem.getSelectedIndex());
770
		}
765
        if (mySelectedElement instanceof CartographicSupport) {
766
            CartographicSupport csSym = (CartographicSupport) mySelectedElement;
767
            csSym.setUnit(cmbUnits.getSelectedUnitIndex());
768
            csSym.setReferenceSystem(cmbReferenceSystem.getSelectedIndex());
769
        }
771 770

  
772
		return mySelectedElement;
773
	}
771
        return mySelectedElement;
772
    }
774 773

  
775
	public void setSymbol(Object symbol) {
776
		((SymbolPreviewer) jPanelPreview).setSymbol((ISymbol) symbol);
777
		updateOptionsPanel();
778
	}
774
    public void setSymbol(Object symbol) {
775
        ((SymbolPreviewer) jPanelPreview).setSymbol((ISymbol) symbol);
776
        updateOptionsPanel();
777
    }
779 778

  
780
	/**
781
	 * Invoked when the PROPERTIES button is pressed
782
	 */
783
	protected void propertiesPressed() {
784
		ISymbol mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
785
		if (mySelectedElement ==null)
786
			return;
779
    /**
780
     * Invoked when the PROPERTIES button is pressed
781
     */
782
    protected void propertiesPressed() {
783
        ISymbol mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
784
        if (mySelectedElement ==null)
785
            return;
787 786

  
788
		ISymbol clonedSymbol = SymbologyFactory.createSymbolFromXML(
789
				mySelectedElement.getXMLEntity(), null);
790
		SymbolEditor se = new SymbolEditor(clonedSymbol, shapeType);
791
		PluginServices.getMDIManager().addWindow(se);
787
        ISymbol clonedSymbol = SymbologyFactory.createSymbolFromXML(
788
                mySelectedElement.getXMLEntity(), null);
789
        SymbolEditor se = new SymbolEditor(clonedSymbol, shapeType);
790
        PluginServices.getMDIManager().addWindow(se);
792 791

  
793
		ISymbol symbol = se.getSymbol();
794
		if (symbol instanceof IMultiLayerSymbol) {
795
			IMultiLayerSymbol mSym = (IMultiLayerSymbol) symbol;
796
			if (mSym.getLayerCount() == 1) {
797
				symbol =  mSym.getLayer(0);
798
			}
799
		}
800
		setSymbol(symbol);
792
        ISymbol symbol = se.getSymbol();
793
        if (symbol instanceof IMultiLayerSymbol) {
794
            IMultiLayerSymbol mSym = (IMultiLayerSymbol) symbol;
795
            if (mSym.getLayerCount() == 1) {
796
                symbol =  mSym.getLayer(0);
797
            }
798
        }
799
        setSymbol(symbol);
801 800

  
802
	}
801
    }
803 802

  
804
	/**
805
	 * Invoked when the NEW button is pressed
806
	 */
807
	protected void newPressed() {
808
		SymbolEditor se = new SymbolEditor(null, shapeType);
809
		PluginServices.getMDIManager().addWindow(se);
810
		setSymbol(se.getSymbol());
811
	}
803
    /**
804
     * Invoked when the NEW button is pressed
805
     */
806
    protected void newPressed() {
807
        SymbolEditor se = new SymbolEditor(null, shapeType);
808
        PluginServices.getMDIManager().addWindow(se);
809
        setSymbol(se.getSymbol());
810
    }
812 811

  
813
	/**
814
	 * Invoked when the RESET button is pressed
815
	 */
816
	protected void resetPressed() {
817
		setSymbol(null);
818
	}
812
    /**
813
     * Invoked when the RESET button is pressed
814
     */
815
    protected void resetPressed() {
816
        setSymbol(null);
817
    }
819 818

  
820
	/**
821
	 * Invoked when the SAVE button is pressed
822
	 */
823
	protected void savePressed() {
824
		if (getSelectedObject() ==null)
825
			return;
819
    /**
820
     * Invoked when the SAVE button is pressed
821
     */
822
    protected void savePressed() {
823
        if (getSelectedObject() ==null)
824
            return;
826 825

  
827 826

  
828
		JFileChooser jfc = new JFileChooser("SYMBOL_SELECTOR_FILECHOOSER", rootDir);
829
		javax.swing.filechooser.FileFilter ff = new javax.swing.filechooser.FileFilter() {
830
			public boolean accept(File f) {
831
				return f.getAbsolutePath().
832
				toLowerCase().
833
				endsWith(SymbolLibrary.SYMBOL_FILE_EXTENSION) || f.isDirectory();
834
			}
827
        JFileChooser jfc = new JFileChooser("SYMBOL_SELECTOR_FILECHOOSER", rootDir);
828
        javax.swing.filechooser.FileFilter ff = new javax.swing.filechooser.FileFilter() {
829
            public boolean accept(File f) {
830
                return f.getAbsolutePath().
831
                toLowerCase().
832
                endsWith(SymbolLibrary.SYMBOL_FILE_EXTENSION) || f.isDirectory();
833
            }
835 834

  
836
			public String getDescription() {
837
				return PluginServices.getText(
838
						this, "gvSIG_symbol_definition_file")+ " (*.sym)";
839
			}
840
		};
841
		jfc.setFileFilter(ff);
842
		JPanel accessory = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
843
		accessory.add(new JLabel(PluginServices.getText(this, "enter_description")));
844
		JTextField txtDesc = new JTextField(25);
845
		accessory.add(txtDesc);
846
		jfc.setAccessory(accessory);
847
		if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
848
			File targetFile = jfc.getSelectedFile();
835
            public String getDescription() {
836
                return PluginServices.getText(
837
                        this, "gvSIG_symbol_definition_file")+ " (*.sym)";
838
            }
839
        };
840
        jfc.setFileFilter(ff);
841
        JPanel accessory = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5));
842
        accessory.add(new JLabel(PluginServices.getText(this, "enter_description")));
843
        JTextField txtDesc = new JTextField(25);
844
        accessory.add(txtDesc);
845
        jfc.setAccessory(accessory);
846
        if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) {
847
            File targetFile = jfc.getSelectedFile();
849 848

  
850
			// apply description
851
			String desc;
852
			if (txtDesc.getText()==null || txtDesc.getText().trim().equals("")) {
853
				// default to file name
854
				String s = targetFile.getAbsolutePath();
855
				desc = s.substring(s.lastIndexOf(File.separator)+1).
856
				replaceAll(SymbolLibrary.SYMBOL_FILE_EXTENSION, "");
857
			} else {
858
				desc = txtDesc.getText().trim();
859
			}
860
			ISymbol s = (ISymbol) getSelectedObject();
861
			s.setDescription(desc);
849
            // apply description
850
            String desc;
851
            if (txtDesc.getText()==null || txtDesc.getText().trim().equals("")) {
852
                // default to file name
853
                String s = targetFile.getAbsolutePath();
854
                desc = s.substring(s.lastIndexOf(File.separator)+1).
855
                replaceAll(SymbolLibrary.SYMBOL_FILE_EXTENSION, "");
856
            } else {
857
                desc = txtDesc.getText().trim();
858
            }
859
            ISymbol s = (ISymbol) getSelectedObject();
860
            s.setDescription(desc);
862 861

  
863 862

  
864
			getJListSymbols().setModel(newListModel());
863
            getJListSymbols().setModel(newListModel());
865 864
//			getJListSymbols().setSelectedValue(
866 865
//			selectedElement, true);
867
			String symbolFileName = targetFile.getAbsolutePath().substring(
868
					targetFile.getAbsolutePath().lastIndexOf(File.separator)+1,
869
					targetFile.getAbsolutePath().length());
870
			File targetDir = new File(targetFile.getAbsolutePath().substring(
871
					0,
872
					targetFile.getAbsolutePath().lastIndexOf(File.separator)));
873
			library.addElement(s, symbolFileName , targetDir);
874
		}
875
	}
866
            String symbolFileName = targetFile.getAbsolutePath().substring(
867
                    targetFile.getAbsolutePath().lastIndexOf(File.separator)+1,
868
                    targetFile.getAbsolutePath().length());
869
            File targetDir = new File(targetFile.getAbsolutePath().substring(
870
                    0,
871
                    targetFile.getAbsolutePath().lastIndexOf(File.separator)));
872
            library.addElement(s, symbolFileName , targetDir);
873
        }
874
    }
876 875

  
877 876

  
878
	public void actionPerformed(ActionEvent e) {
879
		if (!act) return;
880
		Object selectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();//getSelectedObject();
881
		performActionOn(selectedElement, e);
882
		SymbolSelector.this.repaint();
883
	}
877
    public void actionPerformed(ActionEvent e) {
878
        if (!act) return;
879
        Object selectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();//getSelectedObject();
880
        performActionOn(selectedElement, e);
881
        SymbolSelector.this.repaint();
882
    }
884 883

  
885
	protected void performActionOn(Object selectedElement, ActionEvent e) {
886
		JComponent comp = (JComponent) e.getSource();
884
    protected void performActionOn(Object selectedElement, ActionEvent e) {
885
        JComponent comp = (JComponent) e.getSource();
887 886

  
888
		if (selectedElement instanceof IMultiLayerSymbol){
889
			if (((IMultiLayerSymbol)selectedElement).getLayerCount() == 1)
890
				selectedElement = ((IMultiLayerSymbol)selectedElement).getLayer(0);
891
		}
887
        if (selectedElement instanceof IMultiLayerSymbol){
888
            if (((IMultiLayerSymbol)selectedElement).getLayerCount() == 1)
889
                selectedElement = ((IMultiLayerSymbol)selectedElement).getLayer(0);
890
        }
892 891

  
893
		if ( comp.equals(getBtnProperties()) ) {
894
			// properties pressed
895
			propertiesPressed();
896
		} else if ( comp.equals(getBtnNewSymbol()) ) {
897
			// new pressed
898
			newPressed();
899
		} else if ( comp.equals(getBtnResetSymbol()) ) {
900
			// reset pressed
901
			resetPressed();
902
		} else if ( comp.equals(getBtnSaveSymbol()) ) {
903
			// save pressed
904
			savePressed();
905
		} else if (comp.equals(jcc1)) {
906
			if (selectedElement == null)
907
				return;
892
        if ( comp.equals(getBtnProperties()) ) {
893
            // properties pressed
894
            propertiesPressed();
895
        } else if ( comp.equals(getBtnNewSymbol()) ) {
896
            // new pressed
897
            newPressed();
898
        } else if ( comp.equals(getBtnResetSymbol()) ) {
899
            // reset pressed
900
            resetPressed();
901
        } else if ( comp.equals(getBtnSaveSymbol()) ) {
902
            // save pressed
903
            savePressed();
904
        } else if (comp.equals(jcc1)) {
905
            if (selectedElement == null)
906
                return;
908 907

  
909
			Color c = jcc1.getColor();
908
            Color c = jcc1.getColor();
910 909

  
911 910

  
912
			if (selectedElement instanceof IMarkerSymbol) {
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff