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