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