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