root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SymbolSelector.java @ 27419
History | View | Annotate | Download (35.6 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.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.gvsig.fmap.geom.Geometry; |
79 |
import org.gvsig.fmap.geom.GeometryLocator; |
80 |
import org.gvsig.fmap.geom.GeometryManager; |
81 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
82 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
83 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
84 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
85 |
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
86 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IFillSymbol; |
87 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ILineSymbol; |
88 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMarkerSymbol; |
89 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
90 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
91 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol; |
92 |
import org.gvsig.fmap.mapcontext.rendering.symbols.MultiLayerFillSymbol; |
93 |
import org.gvsig.fmap.mapcontext.rendering.symbols.MultiLayerLineSymbol; |
94 |
import org.gvsig.fmap.mapcontext.rendering.symbols.MultiLayerMarkerSymbol; |
95 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory; |
96 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
97 |
import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
98 |
import org.gvsig.gui.beans.swing.JButton; |
99 |
import org.gvsig.gui.beans.swing.JComboBoxFontSizes; |
100 |
import org.gvsig.gui.beans.swing.JComboBoxFonts; |
101 |
import org.gvsig.gui.beans.swing.JFileChooser; |
102 |
import org.gvsig.gui.beans.swing.JIncrementalNumberField; |
103 |
import org.slf4j.Logger; |
104 |
import org.slf4j.LoggerFactory; |
105 |
|
106 |
import com.iver.andami.PluginServices; |
107 |
import com.iver.andami.messages.NotificationManager; |
108 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
109 |
import com.iver.cit.gvsig.gui.JComboBoxUnits; |
110 |
import com.iver.cit.gvsig.gui.panels.ColorChooserPanel; |
111 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.ISymbolSelector; |
112 |
import com.iver.utiles.XMLException; |
113 |
|
114 |
/**
|
115 |
* Creates the panel where the user has the options to select a symbol.
|
116 |
* Apart from the option to select one, the user will have a previsualization
|
117 |
* of all the symbols stored and posibilities to modify an existing one, to create
|
118 |
* a new symbol and so on.
|
119 |
*
|
120 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
121 |
*/
|
122 |
public class SymbolSelector extends JPanel implements ISymbolSelector, ActionListener { |
123 |
private static final long serialVersionUID = -6405660392303659551L; |
124 |
private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
125 |
private static final Logger logger = LoggerFactory.getLogger(SymbolSelector.class); |
126 |
private JPanel jPanel = null; |
127 |
protected JScrollPane jScrollPane = null; |
128 |
private JScrollPane jScrollPane1 = null; |
129 |
private WindowInfo wi;
|
130 |
private JSplitPane jSplitPane = null; |
131 |
protected AcceptCancelPanel okCancelPanel;
|
132 |
private JPanel northPanel; |
133 |
private ColorChooserPanel jcc1;
|
134 |
private ColorChooserPanel jcc2;
|
135 |
private JIncrementalNumberField txtSize;
|
136 |
private JIncrementalNumberField txtAngle;
|
137 |
private JPanel jPanelButtons; |
138 |
private JButton btnProperties; |
139 |
private int shapeType; |
140 |
private JButton btnSaveSymbol; |
141 |
private JButton btnResetSymbol; |
142 |
private JButton btnNewSymbol; |
143 |
private JComboBoxFonts cmbFonts;
|
144 |
private JToggleButton btnBold; |
145 |
private JToggleButton btnItalic; |
146 |
private JToggleButton btnUnderlined; |
147 |
protected JLabel lblTitle; |
148 |
protected File dir; |
149 |
protected File rootDir; |
150 |
protected JComponent jPanelPreview = null; |
151 |
protected GridBagLayoutPanel jPanelOptions = null; |
152 |
protected JList jListSymbols = null; |
153 |
protected String treeRootName; |
154 |
protected ILibraryModel library;
|
155 |
private JIncrementalNumberField txtWidth;
|
156 |
protected boolean act = true; |
157 |
boolean accepted = true; |
158 |
|
159 |
|
160 |
protected SelectorFilter sFilter = new SelectorFilter() { |
161 |
private Geometry dummyPointGeom = null; |
162 |
private Geometry dummyLineGeom = null; |
163 |
private Geometry dummyPolygonGeom = null; |
164 |
private boolean isInitialized = false; |
165 |
|
166 |
public boolean accepts(Object obj) { |
167 |
if (!isInitialized){
|
168 |
try {
|
169 |
dummyPointGeom = geomManager.createPoint(0, 0, SUBTYPES.GEOM2D); |
170 |
dummyLineGeom = geomManager.createSurface(new GeneralPathX(), SUBTYPES.GEOM2D);
|
171 |
dummyPolygonGeom = geomManager.createSurface(new GeneralPathX(), SUBTYPES.GEOM2D);
|
172 |
} catch (CreateGeometryException e) {
|
173 |
logger.error("Error creating a geometry", e);
|
174 |
} |
175 |
isInitialized = true;
|
176 |
} |
177 |
|
178 |
if (obj instanceof ISymbol) { |
179 |
ISymbol sym = (ISymbol) obj; |
180 |
|
181 |
Geometry compareGeometry = null;
|
182 |
switch (SymbolSelector.this.shapeType) {
|
183 |
case Geometry.TYPES.TEXT:
|
184 |
return sym instanceof ITextSymbol; |
185 |
case Geometry.TYPES.POINT:
|
186 |
compareGeometry = dummyPointGeom; |
187 |
break;
|
188 |
case Geometry.TYPES.CURVE:
|
189 |
compareGeometry = dummyLineGeom; |
190 |
break;
|
191 |
case Geometry.TYPES.SURFACE:
|
192 |
compareGeometry = dummyPolygonGeom; |
193 |
break;
|
194 |
} |
195 |
return sym.isSuitableFor(compareGeometry);
|
196 |
} |
197 |
return false; |
198 |
} |
199 |
}; |
200 |
protected JComboBoxUnits cmbUnits;
|
201 |
protected JComboBoxUnitsReferenceSystem cmbReferenceSystem;
|
202 |
private JComboBoxFontSizes cmbFontSize;
|
203 |
protected LibraryBrowser libraryBrowser;
|
204 |
/**
|
205 |
* Constructor method
|
206 |
*
|
207 |
* @param currentElement
|
208 |
* @param shapeType
|
209 |
*/
|
210 |
private SymbolSelector(Object currentElement, int shapeType, boolean initialize) { |
211 |
super();
|
212 |
|
213 |
// TODO 09/08/07 check the currentElement type is suitable for the shapeType specified
|
214 |
if (currentElement != null && currentElement instanceof ISymbol) { |
215 |
ISymbol sym = (ISymbol) currentElement; |
216 |
try {
|
217 |
currentElement = SymbologyFactory.createSymbolFromXML( |
218 |
sym.getXMLEntity(), "");
|
219 |
} catch (XMLException e) {
|
220 |
NotificationManager.addWarning("Symbol layer", e);
|
221 |
} |
222 |
String desc = sym.getDescription();
|
223 |
// desc += " ("+PluginServices.getText(this, "current")+")";
|
224 |
// ((ISymbol)currentElement).setDescription(desc);
|
225 |
} |
226 |
|
227 |
// for symbols MULTIPOINT is the same than POINT
|
228 |
if (shapeType == Geometry.TYPES.MULTIPOINT) {
|
229 |
shapeType = Geometry.TYPES.POINT; |
230 |
} |
231 |
|
232 |
this.shapeType = shapeType;
|
233 |
// Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" );
|
234 |
rootDir = new File(SymbologyFactory.SymbolLibraryPath); |
235 |
// prefs.get("SymbolLibraryFolder", System.getProperty("user.home")+"/gvSIG/Symbols"));
|
236 |
if (!rootDir.exists()) {
|
237 |
rootDir.mkdir(); |
238 |
} |
239 |
treeRootName = PluginServices.getText(this, "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 |
/**
|
252 |
* Constructor method, it is <b>protected</b> by convenience to let StyleSelector
|
253 |
* to invoke it, but rigorously it should be <b>private</b>.
|
254 |
*
|
255 |
* @param symbol
|
256 |
* @param shapeType
|
257 |
* @param filter
|
258 |
*/
|
259 |
protected SymbolSelector(Object symbol, int shapeType, SelectorFilter filter, boolean initialize) { |
260 |
this(symbol, shapeType, initialize);
|
261 |
sFilter = filter; |
262 |
} |
263 |
|
264 |
/**
|
265 |
* This method initializes this
|
266 |
* @param currentElement
|
267 |
* @throws ClassNotFoundException
|
268 |
*
|
269 |
*/
|
270 |
protected void initialize(Object currentElement) throws ClassNotFoundException { |
271 |
library = new SymbolLibrary(rootDir);
|
272 |
|
273 |
this.setLayout(new BorderLayout()); |
274 |
this.setSize(400, 221); |
275 |
|
276 |
this.add(getJNorthPanel(), BorderLayout.NORTH); |
277 |
this.add(getJSplitPane(), BorderLayout.CENTER); |
278 |
this.add(getJEastPanel(), BorderLayout.EAST); |
279 |
ActionListener okAction = new ActionListener() { |
280 |
public void actionPerformed(ActionEvent e) { |
281 |
PluginServices.getMDIManager().closeWindow(SymbolSelector.this); |
282 |
} |
283 |
}, cancelAction = new ActionListener() { |
284 |
public void actionPerformed(ActionEvent e) { |
285 |
accepted = false;
|
286 |
|
287 |
setSymbol(null);
|
288 |
PluginServices.getMDIManager().closeWindow(SymbolSelector.this); |
289 |
} |
290 |
}; |
291 |
|
292 |
okCancelPanel = new AcceptCancelPanel();
|
293 |
okCancelPanel.setOkButtonActionListener(okAction); |
294 |
okCancelPanel.setCancelButtonActionListener(cancelAction); |
295 |
|
296 |
this.add(okCancelPanel, BorderLayout.SOUTH); |
297 |
libraryBrowser.setSelectionRow(0);
|
298 |
|
299 |
SillyDragNDropAction dndAction = new SillyDragNDropAction();
|
300 |
libraryBrowser.addMouseListener(dndAction); |
301 |
libraryBrowser.addMouseMotionListener(dndAction); |
302 |
getJListSymbols().addMouseListener(dndAction); |
303 |
getJListSymbols().addMouseMotionListener(dndAction); |
304 |
setSymbol(currentElement); |
305 |
} |
306 |
|
307 |
/**
|
308 |
* Creates a new symbol selector list model in order to allow the user
|
309 |
* to select an existing symbol previously created.
|
310 |
*
|
311 |
* @return listModel SymbolSelectorListModel
|
312 |
*/
|
313 |
protected SymbolSelectorListModel newListModel() {
|
314 |
SymbolSelectorListModel listModel = new SymbolSelectorListModel(
|
315 |
dir, |
316 |
sFilter, |
317 |
SymbolLibrary.SYMBOL_FILE_EXTENSION); |
318 |
return listModel;
|
319 |
} |
320 |
/**
|
321 |
* Initializes tha JNorthPanel.
|
322 |
*
|
323 |
* @return northPanel JPanel
|
324 |
* @throws IllegalArgumentException
|
325 |
*/
|
326 |
protected JPanel getJNorthPanel() throws IllegalArgumentException { |
327 |
if (northPanel == null) { |
328 |
String text = ""; |
329 |
switch (shapeType) {
|
330 |
case Geometry.TYPES.POINT:
|
331 |
text = PluginServices.getText(this, "point_symbols"); |
332 |
break;
|
333 |
case Geometry.TYPES.CURVE:
|
334 |
text = PluginServices.getText(this, "line_symbols"); |
335 |
break;
|
336 |
case Geometry.TYPES.SURFACE:
|
337 |
text = PluginServices.getText(this, "polygon_symbols"); |
338 |
break;
|
339 |
case Geometry.TYPES.TEXT:
|
340 |
text = PluginServices.getText(this, "text_symbols"); |
341 |
break;
|
342 |
default:
|
343 |
throw new IllegalArgumentException(PluginServices.getText(this, "shape_type_not_yet_supported")); |
344 |
} |
345 |
northPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); |
346 |
lblTitle = new JLabel(text); |
347 |
lblTitle.setFont(lblTitle.getFont().deriveFont(Font.BOLD));
|
348 |
northPanel.add(lblTitle); |
349 |
} |
350 |
return northPanel;
|
351 |
} |
352 |
|
353 |
/**
|
354 |
* This method initializes jList
|
355 |
*
|
356 |
* @return javax.swing.JList
|
357 |
*/
|
358 |
protected JList getJListSymbols() { |
359 |
if (jListSymbols == null) { |
360 |
jListSymbols = new JList() ; |
361 |
jListSymbols.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
362 |
jListSymbols.setLayoutOrientation(JList.HORIZONTAL_WRAP);
|
363 |
jListSymbols.setVisibleRowCount(-1);
|
364 |
jListSymbols.addListSelectionListener(new ListSelectionListener() { |
365 |
public void valueChanged(ListSelectionEvent e) { |
366 |
if (jListSymbols.getSelectedValue()!=null) { |
367 |
ISymbol selSym=null;
|
368 |
try {
|
369 |
selSym = SymbologyFactory.createSymbolFromXML( |
370 |
((ISymbol) jListSymbols.getSelectedValue()).getXMLEntity(), null);
|
371 |
} catch (XMLException e1) {
|
372 |
NotificationManager.addWarning("Symbol layer", e1);
|
373 |
} |
374 |
setSymbol(selSym); |
375 |
updateOptionsPanel(); |
376 |
} |
377 |
} |
378 |
}); |
379 |
ListCellRenderer renderer = new ListCellRenderer() { |
380 |
private Color mySelectedBGColor = new Color(255,145,100,255); |
381 |
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
382 |
ISymbol sym = (ISymbol) value; |
383 |
JPanel pnl = new JPanel(); |
384 |
BoxLayout layout = new BoxLayout(pnl, BoxLayout.Y_AXIS); |
385 |
pnl.setLayout(layout); |
386 |
Color bgColor = (isSelected) ? mySelectedBGColor
|
387 |
: getJListSymbols().getBackground(); |
388 |
|
389 |
pnl.setBackground(bgColor); |
390 |
SymbolPreviewer sp = new SymbolPreviewer();
|
391 |
sp.setAlignmentX(Component.CENTER_ALIGNMENT);
|
392 |
sp.setPreferredSize(new Dimension(50, 50)); |
393 |
sp.setSymbol(sym); |
394 |
sp.setBackground(bgColor); |
395 |
pnl.add(sp); |
396 |
String desc = sym.getDescription();
|
397 |
if (desc == null) { |
398 |
desc = "["+PluginServices.getText(this, "no_desc")+"]"; |
399 |
} |
400 |
JLabel lbl = new JLabel(desc); |
401 |
lbl.setBackground(bgColor); |
402 |
lbl.setAlignmentX(Component.CENTER_ALIGNMENT);
|
403 |
pnl.add(lbl); |
404 |
|
405 |
return pnl;
|
406 |
} |
407 |
|
408 |
}; |
409 |
jListSymbols.setCellRenderer(renderer); |
410 |
} |
411 |
return jListSymbols;
|
412 |
} |
413 |
/**
|
414 |
* Updates the options panel depending on the type of symbol that the user
|
415 |
* is controlling or using to show specific options for each one.
|
416 |
*
|
417 |
*/
|
418 |
protected void updateOptionsPanel() throws IllegalArgumentException { |
419 |
Object mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
|
420 |
|
421 |
if (mySelectedElement == null) { |
422 |
return;
|
423 |
} |
424 |
act = false; // disable events |
425 |
|
426 |
if (mySelectedElement instanceof CartographicSupport) { |
427 |
CartographicSupport cs = (CartographicSupport) mySelectedElement; |
428 |
cmbUnits.setSelectedUnitIndex(cs.getUnit()); |
429 |
cmbReferenceSystem.setSelectedIndex(cs.getReferenceSystem()); |
430 |
} |
431 |
|
432 |
if (mySelectedElement instanceof IMultiLayerSymbol){ |
433 |
if (((IMultiLayerSymbol)mySelectedElement).getLayerCount() == 1) { |
434 |
mySelectedElement = ((IMultiLayerSymbol)mySelectedElement).getLayer(0);
|
435 |
} |
436 |
} |
437 |
|
438 |
try {
|
439 |
|
440 |
jcc1.setEnabled(true);
|
441 |
jcc2.setEnabled(true);
|
442 |
|
443 |
if(mySelectedElement instanceof IMultiLayerSymbol){ |
444 |
jcc1.setColor(Color.WHITE);
|
445 |
jcc2.setColor(Color.WHITE);
|
446 |
jcc1.setEnabled(false);
|
447 |
jcc2.setEnabled(false);
|
448 |
} |
449 |
|
450 |
if (shapeType == Geometry.TYPES.POINT) {
|
451 |
IMarkerSymbol m = (IMarkerSymbol) mySelectedElement; |
452 |
jcc1.setColor(m.getColor()); |
453 |
txtSize.setDouble(m.getSize()); |
454 |
txtAngle.setDouble(Math.toDegrees(m.getRotation()));
|
455 |
} |
456 |
|
457 |
if (shapeType == Geometry.TYPES.CURVE) {
|
458 |
ILineSymbol l = (ILineSymbol) mySelectedElement; |
459 |
jcc1.setColor(l.getColor()); |
460 |
jcc1.setAlpha(l.getAlpha()); |
461 |
txtSize.setDouble(l.getLineWidth()); |
462 |
} |
463 |
|
464 |
if (shapeType == Geometry.TYPES.SURFACE) {
|
465 |
IFillSymbol f = (IFillSymbol) mySelectedElement; |
466 |
|
467 |
txtWidth.setEnabled(true);
|
468 |
cmbReferenceSystem.setEnabled(true);
|
469 |
cmbUnits.setEnabled(true);
|
470 |
|
471 |
jcc1.setUseColorIsSelected(f.hasFill()); |
472 |
jcc1.setColor(f.getFillColor()); |
473 |
jcc1.setAlpha(f.getFillAlpha()); |
474 |
jcc2.setUseColorIsSelected(f.hasOutline()); |
475 |
ILineSymbol outline = f.getOutline(); |
476 |
if (outline != null) { |
477 |
jcc2.setColor(outline.getColor()); |
478 |
txtWidth.setDouble(outline.getLineWidth()); |
479 |
} |
480 |
|
481 |
if(f instanceof MultiLayerFillSymbol){ |
482 |
txtWidth.setEnabled(false);
|
483 |
cmbReferenceSystem.setEnabled(false);
|
484 |
cmbUnits.setEnabled(false);
|
485 |
} |
486 |
|
487 |
} |
488 |
|
489 |
|
490 |
if (shapeType == Geometry.TYPES.TEXT) {
|
491 |
ITextSymbol t = (ITextSymbol) mySelectedElement; |
492 |
jcc1.setColor(t.getTextColor()); |
493 |
Double s = new Double(t.getFont().getSize()); |
494 |
cmbFontSize.setSelectedItem(s); |
495 |
int i = cmbFontSize.getSelectedIndex();
|
496 |
if (i == -1) { |
497 |
cmbFontSize.addItem(s); |
498 |
cmbFontSize.setSelectedItem(s); |
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, PluginServices.getText(this, "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(PluginServices.getText(this, "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(PluginServices.getText(this, "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(PluginServices.getText(this, "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(PluginServices.getText(this, "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() throws ClassNotFoundException { |
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 |
dir = (File) ((DefaultMutableTreeNode) |
606 |
libraryBrowser.getLastSelectedPathComponent()).getUserObject(); |
607 |
|
608 |
if (dir == null) { |
609 |
return;
|
610 |
} |
611 |
|
612 |
jListSymbols.setModel(newListModel()); |
613 |
// jListSymbols.setSelectedValue(selectedElement, true);
|
614 |
} |
615 |
}); |
616 |
jScrollPane.setViewportView(libraryBrowser); |
617 |
} |
618 |
return jScrollPane;
|
619 |
} |
620 |
|
621 |
/**
|
622 |
* This method initializes jScrollPane1
|
623 |
*
|
624 |
* @return javax.swing.JScrollPane
|
625 |
*/
|
626 |
private JScrollPane getJScrollPane1() { |
627 |
if (jScrollPane1 == null) { |
628 |
jScrollPane1 = new JScrollPane(); |
629 |
jScrollPane1.setViewportView(getJListSymbols()); |
630 |
} |
631 |
return jScrollPane1;
|
632 |
} |
633 |
|
634 |
/**
|
635 |
* This method initializes jPanelPreview
|
636 |
*
|
637 |
* @return javax.swing.JComponent
|
638 |
*/
|
639 |
protected JComponent getJPanelPreview() { |
640 |
if (jPanelPreview == null) { |
641 |
jPanelPreview = new SymbolPreviewer();
|
642 |
jPanelPreview.setPreferredSize(new java.awt.Dimension(100,100)); |
643 |
jPanelPreview.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)); |
644 |
} |
645 |
return jPanelPreview;
|
646 |
} |
647 |
/**
|
648 |
* This method initializes jPanelOptions
|
649 |
*
|
650 |
* @return javax.swing.JPanel
|
651 |
*/
|
652 |
protected JPanel getJPanelOptions() { |
653 |
if (jPanelOptions == null) { |
654 |
jPanelOptions = new GridBagLayoutPanel();
|
655 |
jPanelOptions.setBorder(BorderFactory.createTitledBorder(null, PluginServices.getText(this, "options"))); |
656 |
jcc2 = new ColorChooserPanel(true,true); |
657 |
jcc2.setAlpha(255);
|
658 |
if (shapeType == Geometry.TYPES.POINT) {
|
659 |
jcc1 = new ColorChooserPanel(true); |
660 |
|
661 |
jPanelOptions.addComponent( |
662 |
PluginServices.getText(this, "color")+":", jcc1); |
663 |
jPanelOptions.addComponent( |
664 |
PluginServices.getText(this, "size")+":", |
665 |
txtSize = new JIncrementalNumberField(String.valueOf(3), 3, 0, Double.MAX_VALUE, 1)); |
666 |
jPanelOptions.addComponent(PluginServices.getText(this, "units")+":", |
667 |
cmbUnits = new JComboBoxUnits());
|
668 |
jPanelOptions.addComponent("",
|
669 |
cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
|
670 |
jPanelOptions.addComponent( |
671 |
PluginServices.getText(this, "angle")+ " (" +PluginServices.getText(this, "degree")+"):", |
672 |
txtAngle = new JIncrementalNumberField());
|
673 |
|
674 |
|
675 |
} else if (shapeType == Geometry.TYPES.CURVE) { |
676 |
jcc1 = new ColorChooserPanel(true); |
677 |
jPanelOptions.addComponent( |
678 |
PluginServices.getText(this, "color")+":", jcc1); |
679 |
jPanelOptions.addComponent( |
680 |
PluginServices.getText(this, "width")+":", |
681 |
txtSize = new JIncrementalNumberField(String.valueOf(3), 3, 0, Double.MAX_VALUE, 1)); |
682 |
jPanelOptions.addComponent(PluginServices.getText(this, "units")+":", |
683 |
cmbUnits = new JComboBoxUnits());
|
684 |
jPanelOptions.addComponent("",
|
685 |
cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
|
686 |
|
687 |
} else if (shapeType == Geometry.TYPES.SURFACE) { |
688 |
jcc1 = new ColorChooserPanel(true, true); |
689 |
jPanelOptions.addComponent( |
690 |
PluginServices.getText(this, "fill_color")+":", jcc1); |
691 |
jPanelOptions.addComponent( |
692 |
PluginServices.getText(this, "outline_color")+":", jcc2); |
693 |
jPanelOptions.addComponent( |
694 |
PluginServices.getText(this, "outline_width"), |
695 |
txtWidth = new JIncrementalNumberField(String.valueOf(3), 3, 0, Double.MAX_VALUE, 1)); |
696 |
jPanelOptions.addComponent(PluginServices.getText(this, "units")+":", |
697 |
cmbUnits = new JComboBoxUnits());
|
698 |
jPanelOptions.addComponent("",
|
699 |
cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
|
700 |
|
701 |
} else if (shapeType == Geometry.TYPES.TEXT) { |
702 |
jcc1 = new ColorChooserPanel(true); |
703 |
jPanelOptions.addComponent( |
704 |
PluginServices.getText(this, "font")+":", getCmbFonts()); |
705 |
|
706 |
jPanelOptions.addComponent( |
707 |
PluginServices.getText(this, "color")+":", jcc1); |
708 |
jPanelOptions.addComponent(PluginServices.getText(this, "size")+":", |
709 |
cmbFontSize = new JComboBoxFontSizes());
|
710 |
jPanelOptions.addComponent(PluginServices.getText(this, "units")+":", |
711 |
cmbUnits = new JComboBoxUnits());
|
712 |
jPanelOptions.addComponent("",
|
713 |
cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
|
714 |
|
715 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING,0,1)); |
716 |
aux.add(getBtnBold()); |
717 |
aux.add(getBtnItalic()); |
718 |
aux.add(getBtnUnderlined()); |
719 |
jPanelOptions.addComponent( |
720 |
PluginServices.getText(this, "style")+":", aux); |
721 |
|
722 |
} |
723 |
|
724 |
jcc1.setAlpha(255);
|
725 |
|
726 |
if (txtSize != null) { |
727 |
txtSize.addActionListener(this);
|
728 |
} |
729 |
if (cmbUnits != null) { |
730 |
cmbUnits.addActionListener(this);
|
731 |
} |
732 |
if (cmbReferenceSystem != null) { |
733 |
cmbReferenceSystem.addActionListener(this);
|
734 |
} |
735 |
if (jcc1 != null) { |
736 |
jcc1.addActionListener(this);
|
737 |
} |
738 |
if (jcc2 != null) { |
739 |
jcc2.addActionListener(this);
|
740 |
} |
741 |
if (txtWidth != null) { |
742 |
txtWidth.addActionListener(this);
|
743 |
} |
744 |
if (cmbFontSize != null) { |
745 |
cmbFontSize.addActionListener(this);
|
746 |
} |
747 |
if (txtAngle != null) { |
748 |
txtAngle.addActionListener(this);
|
749 |
} |
750 |
} |
751 |
return jPanelOptions;
|
752 |
} |
753 |
|
754 |
private JToggleButton getBtnUnderlined() { |
755 |
if (btnUnderlined == null) { |
756 |
btnUnderlined = new JToggleButton(PluginServices.getIconTheme(). |
757 |
get("underline-icon"));
|
758 |
} |
759 |
return btnUnderlined;
|
760 |
} |
761 |
|
762 |
private JToggleButton getBtnItalic() { |
763 |
if (btnItalic == null) { |
764 |
btnItalic = new JToggleButton(PluginServices.getIconTheme(). |
765 |
get("italic-icon"));
|
766 |
} |
767 |
return btnItalic;
|
768 |
} |
769 |
|
770 |
private JToggleButton getBtnBold() { |
771 |
if (btnBold == null) { |
772 |
btnBold = new JToggleButton(PluginServices.getIconTheme(). |
773 |
get("bold-icon"));
|
774 |
} |
775 |
return btnBold;
|
776 |
} |
777 |
|
778 |
|
779 |
private JComboBoxFonts getCmbFonts() {
|
780 |
if (cmbFonts == null) { |
781 |
cmbFonts = new JComboBoxFonts();
|
782 |
} |
783 |
return cmbFonts;
|
784 |
} |
785 |
|
786 |
public WindowInfo getWindowInfo() {
|
787 |
if (wi == null) { |
788 |
wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
789 |
wi.setWidth(706);
|
790 |
wi.setHeight(500);
|
791 |
wi.setTitle(PluginServices.getText(this, "symbol_selector")); |
792 |
} |
793 |
return wi;
|
794 |
} |
795 |
|
796 |
protected JSplitPane getJSplitPane() throws ClassNotFoundException { |
797 |
if (jSplitPane == null) { |
798 |
jSplitPane = new JSplitPane(); |
799 |
jSplitPane.setDividerLocation(200);
|
800 |
jSplitPane.setResizeWeight(0.4);
|
801 |
jSplitPane.setLeftComponent(getLeftJScrollPane()); |
802 |
jSplitPane.setRightComponent(getJScrollPane1()); |
803 |
} |
804 |
return jSplitPane;
|
805 |
} |
806 |
|
807 |
public Object getSelectedObject() { |
808 |
if (!accepted) {
|
809 |
return null; |
810 |
} |
811 |
Object mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
|
812 |
|
813 |
// if this symbol only has one layer, then no multilayer is needed
|
814 |
if (mySelectedElement instanceof IMultiLayerSymbol) { |
815 |
if (((IMultiLayerSymbol) mySelectedElement).getLayerCount()==1) { |
816 |
return ((IMultiLayerSymbol) mySelectedElement).getLayer(0); |
817 |
} |
818 |
} |
819 |
|
820 |
if (mySelectedElement instanceof CartographicSupport) { |
821 |
CartographicSupport csSym = (CartographicSupport) mySelectedElement; |
822 |
csSym.setUnit(cmbUnits.getSelectedUnitIndex()); |
823 |
csSym.setReferenceSystem(cmbReferenceSystem.getSelectedIndex()); |
824 |
} |
825 |
|
826 |
return mySelectedElement;
|
827 |
} |
828 |
|
829 |
public void setSymbol(Object symbol) { |
830 |
((SymbolPreviewer) jPanelPreview).setSymbol((ISymbol) symbol); |
831 |
updateOptionsPanel(); |
832 |
} |
833 |
|
834 |
/**
|
835 |
* Invoked when the PROPERTIES button is pressed
|
836 |
*/
|
837 |
protected void propertiesPressed() { |
838 |
ISymbol mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol(); |
839 |
if (mySelectedElement ==null) { |
840 |
return;
|
841 |
} |
842 |
|
843 |
ISymbol clonedSymbol=null;
|
844 |
try {
|
845 |
clonedSymbol = SymbologyFactory.createSymbolFromXML( |
846 |
mySelectedElement.getXMLEntity(), null);
|
847 |
} catch (XMLException e) {
|
848 |
NotificationManager.addWarning("Symbol layer", e);
|
849 |
} |
850 |
SymbolEditor se = new SymbolEditor(clonedSymbol, shapeType);
|
851 |
PluginServices.getMDIManager().addWindow(se); |
852 |
|
853 |
ISymbol symbol = se.getSymbol(); |
854 |
if (symbol instanceof IMultiLayerSymbol) { |
855 |
IMultiLayerSymbol mSym = (IMultiLayerSymbol) symbol; |
856 |
if (mSym.getLayerCount() == 1) { |
857 |
symbol = mSym.getLayer(0);
|
858 |
} |
859 |
} |
860 |
setSymbol(symbol); |
861 |
|
862 |
} |
863 |
|
864 |
/**
|
865 |
* Invoked when the NEW button is pressed
|
866 |
*/
|
867 |
protected void newPressed() { |
868 |
SymbolEditor se = new SymbolEditor(null, shapeType); |
869 |
PluginServices.getMDIManager().addWindow(se); |
870 |
setSymbol(se.getSymbol()); |
871 |
} |
872 |
|
873 |
/**
|
874 |
* Invoked when the RESET button is pressed
|
875 |
*/
|
876 |
protected void resetPressed() { |
877 |
setSymbol(null);
|
878 |
} |
879 |
|
880 |
/**
|
881 |
* Invoked when the SAVE button is pressed
|
882 |
*/
|
883 |
protected void savePressed() { |
884 |
if (getSelectedObject() ==null) { |
885 |
return;
|
886 |
} |
887 |
|
888 |
|
889 |
JFileChooser jfc = new JFileChooser("SYMBOL_SELECTOR_FILECHOOSER", rootDir); |
890 |
javax.swing.filechooser.FileFilter ff = new javax.swing.filechooser.FileFilter() {
|
891 |
public boolean accept(File f) { |
892 |
return f.getAbsolutePath().
|
893 |
toLowerCase(). |
894 |
endsWith(SymbolLibrary.SYMBOL_FILE_EXTENSION) || f.isDirectory(); |
895 |
} |
896 |
|
897 |
public String getDescription() { |
898 |
return PluginServices.getText(
|
899 |
this, "gvSIG_symbol_definition_file")+ " (*.sym)"; |
900 |
} |
901 |
}; |
902 |
jfc.setFileFilter(ff); |
903 |
JPanel accessory = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
904 |
accessory.add(new JLabel(PluginServices.getText(this, "enter_description"))); |
905 |
JTextField txtDesc = new JTextField(25); |
906 |
accessory.add(txtDesc); |
907 |
jfc.setAccessory(accessory); |
908 |
if (jfc.showSaveDialog(this) == JFileChooser.APPROVE_OPTION) { |
909 |
File targetFile = jfc.getSelectedFile();
|
910 |
|
911 |
// apply description
|
912 |
String desc;
|
913 |
if (txtDesc.getText()==null || txtDesc.getText().trim().equals("")) { |
914 |
// default to file name
|
915 |
String s = targetFile.getAbsolutePath();
|
916 |
desc = s.substring(s.lastIndexOf(File.separator)+1). |
917 |
replaceAll(SymbolLibrary.SYMBOL_FILE_EXTENSION, "");
|
918 |
} else {
|
919 |
desc = txtDesc.getText().trim(); |
920 |
} |
921 |
ISymbol s = (ISymbol) getSelectedObject(); |
922 |
s.setDescription(desc); |
923 |
|
924 |
|
925 |
getJListSymbols().setModel(newListModel()); |
926 |
// getJListSymbols().setSelectedValue(
|
927 |
// selectedElement, true);
|
928 |
String symbolFileName = targetFile.getAbsolutePath().substring(
|
929 |
targetFile.getAbsolutePath().lastIndexOf(File.separator)+1, |
930 |
targetFile.getAbsolutePath().length()); |
931 |
File targetDir = new File(targetFile.getAbsolutePath().substring( |
932 |
0,
|
933 |
targetFile.getAbsolutePath().lastIndexOf(File.separator)));
|
934 |
library.addElement(s, symbolFileName , targetDir); |
935 |
} |
936 |
} |
937 |
|
938 |
|
939 |
public void actionPerformed(ActionEvent e) { |
940 |
if (!act) {
|
941 |
return;
|
942 |
} |
943 |
Object selectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();//getSelectedObject(); |
944 |
performActionOn(selectedElement, e); |
945 |
SymbolSelector.this.repaint(); |
946 |
} |
947 |
|
948 |
protected void performActionOn(Object selectedElement, ActionEvent e) { |
949 |
JComponent comp = (JComponent) e.getSource(); |
950 |
|
951 |
if ( comp.equals(getBtnProperties()) ) {
|
952 |
// properties pressed
|
953 |
propertiesPressed(); |
954 |
} else if ( comp.equals(getBtnNewSymbol()) ) { |
955 |
// new pressed
|
956 |
newPressed(); |
957 |
} else if ( comp.equals(getBtnResetSymbol()) ) { |
958 |
// reset pressed
|
959 |
resetPressed(); |
960 |
} else if ( comp.equals(getBtnSaveSymbol()) ) { |
961 |
// save pressed
|
962 |
savePressed(); |
963 |
} else if (comp.equals(jcc1)) { |
964 |
if (selectedElement == null) { |
965 |
return;
|
966 |
} |
967 |
|
968 |
Color c = jcc1.getColor();
|
969 |
|
970 |
if (selectedElement instanceof IMarkerSymbol) { |
971 |
IMarkerSymbol m = (IMarkerSymbol) selectedElement; |
972 |
if (m instanceof MultiLayerMarkerSymbol) { |
973 |
MultiLayerMarkerSymbol mm = (MultiLayerMarkerSymbol) m; |
974 |
mm.setAlpha(jcc1.getAlpha()); |
975 |
} else {
|
976 |
m.setColor(c); |
977 |
} |
978 |
} |
979 |
|
980 |
if (selectedElement instanceof ILineSymbol) { |
981 |
ILineSymbol l = (ILineSymbol) selectedElement; |
982 |
if (l instanceof MultiLayerLineSymbol) { |
983 |
MultiLayerLineSymbol ml = (MultiLayerLineSymbol) l; |
984 |
ml.setAlpha(jcc1.getAlpha()); |
985 |
} else {
|
986 |
l.setLineColor(c); |
987 |
} |
988 |
} |
989 |
|
990 |
if (selectedElement instanceof IFillSymbol) { |
991 |
IFillSymbol f = (IFillSymbol) selectedElement; |
992 |
|
993 |
f.setHasFill(jcc1.getUseColorisSelected()); |
994 |
f.setFillColor(c); |
995 |
} |
996 |
|
997 |
if (selectedElement instanceof ITextSymbol) { |
998 |
ITextSymbol t = (ITextSymbol) selectedElement; |
999 |
t.setTextColor(c); |
1000 |
} |
1001 |
|
1002 |
} else if (comp.equals(jcc2)) { |
1003 |
if (selectedElement == null) { |
1004 |
return;
|
1005 |
} |
1006 |
Color c = jcc2.getColor();
|
1007 |
|
1008 |
|
1009 |
if (selectedElement instanceof IFillSymbol) { |
1010 |
IFillSymbol f = (IFillSymbol) selectedElement; |
1011 |
ILineSymbol outline = f.getOutline(); |
1012 |
f.setHasOutline(jcc2.getUseColorisSelected()); |
1013 |
|
1014 |
if (outline!=null) { |
1015 |
ILineSymbol l = outline; |
1016 |
if (l instanceof MultiLayerLineSymbol && c != null) { |
1017 |
MultiLayerLineSymbol ml = (MultiLayerLineSymbol) l; |
1018 |
ml.setAlpha(c.getAlpha()); |
1019 |
} else {
|
1020 |
l.setLineColor(c); |
1021 |
} |
1022 |
} |
1023 |
|
1024 |
} |
1025 |
} else if (comp.equals(txtSize)) { |
1026 |
double s = txtSize.getDouble();
|
1027 |
|
1028 |
if (selectedElement instanceof IMarkerSymbol) { |
1029 |
IMarkerSymbol m = (IMarkerSymbol) selectedElement; |
1030 |
m.setSize(s); |
1031 |
} |
1032 |
|
1033 |
if (selectedElement instanceof ILineSymbol) { |
1034 |
ILineSymbol l = (ILineSymbol) selectedElement; |
1035 |
l.setLineWidth(s); |
1036 |
} |
1037 |
} else if (comp.equals(cmbUnits)) { |
1038 |
if (selectedElement instanceof CartographicSupport) { |
1039 |
CartographicSupport cs = (CartographicSupport) selectedElement; |
1040 |
cs.setUnit(cmbUnits.getSelectedUnitIndex()); |
1041 |
} |
1042 |
} else if (comp.equals(cmbReferenceSystem)) { |
1043 |
if (selectedElement instanceof CartographicSupport) { |
1044 |
CartographicSupport cs = (CartographicSupport) selectedElement; |
1045 |
cs.setUnit(cmbReferenceSystem.getSelectedIndex()); |
1046 |
} |
1047 |
} else if (comp.equals(txtWidth)) { |
1048 |
double w = txtWidth.getDouble();
|
1049 |
if (selectedElement instanceof IFillSymbol) { |
1050 |
IFillSymbol f = (IFillSymbol) selectedElement; |
1051 |
ILineSymbol outline = f.getOutline(); |
1052 |
if (outline!=null) { |
1053 |
outline.setLineWidth(w); |
1054 |
} |
1055 |
} |
1056 |
} else if (comp.equals(cmbFontSize)) { |
1057 |
double s = ((Integer) cmbFontSize.getSelectedItem()).doubleValue(); |
1058 |
if (selectedElement instanceof ITextSymbol) { |
1059 |
ITextSymbol t = (ITextSymbol) selectedElement; |
1060 |
t.setFontSize(s); |
1061 |
} |
1062 |
} else if (comp.equals(txtAngle)) { |
1063 |
double a = Math.toRadians(txtAngle.getDouble()); |
1064 |
if (selectedElement instanceof IMarkerSymbol) { |
1065 |
IMarkerSymbol m = (IMarkerSymbol) selectedElement; |
1066 |
m.setRotation(a); |
1067 |
} |
1068 |
} |
1069 |
} |
1070 |
|
1071 |
public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType) { |
1072 |
return createSymbolSelector(currSymbol, shapeType, null); |
1073 |
} |
1074 |
|
1075 |
public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType, SelectorFilter filter) { |
1076 |
ISymbolSelector selector = null;
|
1077 |
|
1078 |
// patch for backwards compatibility
|
1079 |
// if (currSymbol instanceof FSymbol) {
|
1080 |
// currSymbol = SymbologyFactory.deriveFSymbol((FSymbol) currSymbol);
|
1081 |
// }
|
1082 |
|
1083 |
if (filter==null) { |
1084 |
selector = (shapeType == Geometry.TYPES.GEOMETRY) ? |
1085 |
new MultiShapeSymbolSelector(currSymbol) :
|
1086 |
new SymbolSelector(currSymbol, shapeType, true); |
1087 |
} else {
|
1088 |
selector = (shapeType == Geometry.TYPES.GEOMETRY) ? |
1089 |
new MultiShapeSymbolSelector(currSymbol) :
|
1090 |
new SymbolSelector(currSymbol, shapeType, filter, true); |
1091 |
} |
1092 |
return selector;
|
1093 |
} |
1094 |
|
1095 |
class SillyDragNDropAction implements MouseListener, MouseMotionListener { |
1096 |
private boolean doDrop = false; |
1097 |
private Object selected; |
1098 |
private File sourceFolder; |
1099 |
|
1100 |
public void mouseClicked(MouseEvent e) { } |
1101 |
public void mouseEntered(MouseEvent e) { } |
1102 |
public void mouseExited(MouseEvent e) { } |
1103 |
|
1104 |
public void mousePressed(MouseEvent e) { |
1105 |
if (e.getSource().equals(getJListSymbols())) {
|
1106 |
selected = getJListSymbols().getSelectedValue(); |
1107 |
doDrop = selected!=null;
|
1108 |
DefaultMutableTreeNode node = (DefaultMutableTreeNode) libraryBrowser.getLastSelectedPathComponent(); |
1109 |
if (node.getUserObject() instanceof File) { |
1110 |
sourceFolder = (File) node.getUserObject();
|
1111 |
} |
1112 |
} |
1113 |
e.consume(); |
1114 |
} |
1115 |
|
1116 |
public void mouseReleased(MouseEvent e) { |
1117 |
if (doDrop && e.getSource().equals(getJListSymbols())) {
|
1118 |
Point p = new Point(getJListSymbols().getLocation().x-e.getPoint().x, getJListSymbols().getLocation().y+e.getPoint().y); |
1119 |
if (libraryBrowser.getBounds().contains(p)) {
|
1120 |
File destFolder = libraryBrowser.getElementBellow(p);
|
1121 |
if (destFolder != null) { |
1122 |
ISymbol sym = (ISymbol) selected; |
1123 |
int move = InputEvent.SHIFT_DOWN_MASK | InputEvent.BUTTON1_DOWN_MASK; |
1124 |
// int copy = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
|
1125 |
|
1126 |
library.addElement(sym, sym.getDescription(), destFolder); |
1127 |
if ((e.getModifiers() & (move)) !=0) { |
1128 |
library.removeElement(sym, sourceFolder); |
1129 |
} |
1130 |
|
1131 |
} |
1132 |
libraryBrowser.refresh(); |
1133 |
} |
1134 |
|
1135 |
} |
1136 |
doDrop = false;
|
1137 |
} |
1138 |
|
1139 |
public void mouseDragged(MouseEvent e) { |
1140 |
if (e.getSource().equals(getJListSymbols())) {
|
1141 |
|
1142 |
Point p = new Point(getJListSymbols().getLocation().x-e.getPoint().x, getJListSymbols().getLocation().y+e.getPoint().y); |
1143 |
if (libraryBrowser.getBounds().contains(p)) {
|
1144 |
libraryBrowser.setSelectedElementBellow(p); |
1145 |
} |
1146 |
} |
1147 |
} |
1148 |
|
1149 |
public void mouseMoved(MouseEvent e) { |
1150 |
|
1151 |
} |
1152 |
|
1153 |
} |
1154 |
|
1155 |
public Object getWindowProfile() { |
1156 |
return WindowInfo.DIALOG_PROFILE;
|
1157 |
} |
1158 |
|
1159 |
} |