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