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 @ 43510
History | View | Annotate | Download (37.7 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 | 40688 | jldominguez | import javax.swing.ListModel; |
54 | 40435 | jjdelcerro | import javax.swing.event.ListSelectionEvent; |
55 | import javax.swing.event.ListSelectionListener; |
||
56 | import javax.swing.event.TreeSelectionListener; |
||
57 | import javax.swing.tree.DefaultMutableTreeNode; |
||
58 | 41416 | jjdelcerro | import org.apache.commons.lang3.StringUtils; |
59 | 40435 | jjdelcerro | |
60 | import org.slf4j.Logger; |
||
61 | import org.slf4j.LoggerFactory; |
||
62 | import org.gvsig.andami.PluginServices; |
||
63 | import org.gvsig.andami.messages.NotificationManager; |
||
64 | import org.gvsig.andami.ui.mdiManager.WindowInfo; |
||
65 | import org.gvsig.app.gui.JComboBoxUnits; |
||
66 | import org.gvsig.app.gui.panels.ColorChooserPanel; |
||
67 | import org.gvsig.app.project.documents.view.legend.gui.ISymbolSelector; |
||
68 | import org.gvsig.fmap.geom.Geometry; |
||
69 | import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
||
70 | import org.gvsig.fmap.geom.Geometry.TYPES; |
||
71 | import org.gvsig.fmap.geom.GeometryLocator; |
||
72 | import org.gvsig.fmap.geom.GeometryManager; |
||
73 | import org.gvsig.fmap.geom.exception.CreateGeometryException; |
||
74 | import org.gvsig.fmap.geom.type.GeometryType; |
||
75 | import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException; |
||
76 | import org.gvsig.fmap.geom.type.GeometryTypeNotValidException; |
||
77 | import org.gvsig.fmap.mapcontext.MapContextLocator; |
||
78 | import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
||
79 | import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
||
80 | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
||
81 | 41398 | jjdelcerro | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol_v2; |
82 | 40435 | jjdelcerro | import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol; |
83 | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
||
84 | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolPreferences; |
||
85 | import org.gvsig.gui.beans.AcceptCancelPanel; |
||
86 | import org.gvsig.gui.beans.swing.GridBagLayoutPanel; |
||
87 | import org.gvsig.gui.beans.swing.JButton; |
||
88 | import org.gvsig.gui.beans.swing.JComboBoxFontSizes; |
||
89 | import org.gvsig.gui.beans.swing.JComboBoxFonts; |
||
90 | import org.gvsig.gui.beans.swing.JFileChooser; |
||
91 | 42026 | jjdelcerro | import org.gvsig.gui.beans.swing.JNumberSpinner; |
92 | 40435 | jjdelcerro | import org.gvsig.i18n.Messages; |
93 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
||
94 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IMultiLayerFillSymbol; |
||
95 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol; |
||
96 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.IMultiLayerLineSymbol; |
||
97 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
||
98 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMultiLayerMarkerSymbol; |
||
99 | 41053 | jjdelcerro | import org.gvsig.tools.dispose.Disposable; |
100 | 40435 | jjdelcerro | |
101 | |||
102 | /**
|
||
103 | * Creates the panel where the user has the options to select a symbol.
|
||
104 | * Apart from the option to select one, the user will have a previsualization
|
||
105 | * of all the symbols stored and posibilities to modify an existing one, to create
|
||
106 | * a new symbol and so on.
|
||
107 | *
|
||
108 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
109 | */
|
||
110 | public class SymbolSelector extends JPanel implements ISymbolSelector, ActionListener { |
||
111 | private static final long serialVersionUID = -6405660392303659551L; |
||
112 | private static final GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
||
113 | private static final Logger logger = LoggerFactory.getLogger(SymbolSelector.class); |
||
114 | private JPanel jPanel = null; |
||
115 | protected JScrollPane jScrollPane = null; |
||
116 | private JScrollPane jScrollPane1 = null; |
||
117 | private WindowInfo wi;
|
||
118 | private JSplitPane jSplitPane = null; |
||
119 | protected AcceptCancelPanel okCancelPanel;
|
||
120 | private JPanel northPanel; |
||
121 | private ColorChooserPanel jcc1;
|
||
122 | private ColorChooserPanel jcc2;
|
||
123 | 42026 | jjdelcerro | private JNumberSpinner txtSize;
|
124 | private JNumberSpinner txtAngle;
|
||
125 | 40435 | jjdelcerro | private JPanel jPanelButtons; |
126 | private JButton btnProperties; |
||
127 | private GeometryType shapeType;
|
||
128 | private JButton btnSaveSymbol; |
||
129 | private JButton btnResetSymbol; |
||
130 | private JButton btnNewSymbol; |
||
131 | private JComboBoxFonts cmbFonts;
|
||
132 | private JToggleButton btnBold; |
||
133 | private JToggleButton btnItalic; |
||
134 | private JToggleButton btnUnderlined; |
||
135 | protected JLabel lblTitle; |
||
136 | protected File dir; |
||
137 | protected File rootDir; |
||
138 | protected JComponent jPanelPreview = null; |
||
139 | protected GridBagLayoutPanel jPanelOptions = null; |
||
140 | protected JList jListSymbols = null; |
||
141 | protected String treeRootName; |
||
142 | protected ILibraryModel library;
|
||
143 | 42026 | jjdelcerro | private JNumberSpinner txtWidth;
|
144 | 40435 | jjdelcerro | protected boolean act = true; |
145 | boolean accepted = true; |
||
146 | private SymbolManager manager;
|
||
147 | |||
148 | |||
149 | protected SelectorFilter sFilter = new SelectorFilter() { |
||
150 | private Geometry dummyPointGeom = null; |
||
151 | private Geometry dummyLineGeom = null; |
||
152 | private Geometry dummyPolygonGeom = null; |
||
153 | private boolean isInitialized = false; |
||
154 | |||
155 | 43510 | jjdelcerro | @Override
|
156 | 40435 | jjdelcerro | public boolean accepts(Object obj) { |
157 | if (!isInitialized){
|
||
158 | try {
|
||
159 | dummyPointGeom = geomManager.createPoint(0, 0, SUBTYPES.GEOM2D); |
||
160 | 43510 | jjdelcerro | dummyLineGeom = geomManager.createLine(SUBTYPES.GEOM2D); |
161 | dummyPolygonGeom = geomManager.createPolygon(SUBTYPES.GEOM2D); |
||
162 | 40435 | jjdelcerro | } catch (CreateGeometryException e) {
|
163 | logger.error("Error creating a geometry", e);
|
||
164 | } |
||
165 | isInitialized = true;
|
||
166 | } |
||
167 | |||
168 | if (obj instanceof ISymbol) { |
||
169 | ISymbol sym = (ISymbol) obj; |
||
170 | |||
171 | Geometry compareGeometry = null;
|
||
172 | if (SymbolSelector.this.shapeType.isTypeOf(Geometry.TYPES.POINT)
|
||
173 | 41858 | fdiaz | || SymbolSelector.this.shapeType.isTypeOf(Geometry.TYPES.MULTIPOINT)){ |
174 | 40435 | jjdelcerro | compareGeometry = dummyPointGeom; |
175 | }else if (SymbolSelector.this.shapeType.isTypeOf(Geometry.TYPES.CURVE) |
||
176 | 41858 | fdiaz | || SymbolSelector.this.shapeType.isTypeOf(Geometry.TYPES.MULTICURVE)){ |
177 | 40435 | jjdelcerro | compareGeometry = dummyLineGeom; |
178 | }else if (SymbolSelector.this.shapeType.isTypeOf(Geometry.TYPES.SURFACE) |
||
179 | 41858 | fdiaz | || SymbolSelector.this.shapeType.isTypeOf(Geometry.TYPES.MULTISURFACE)){ |
180 | compareGeometry = dummyPolygonGeom; |
||
181 | 40435 | jjdelcerro | } |
182 | if (compareGeometry != null){ |
||
183 | return sym.isSuitableFor(compareGeometry);
|
||
184 | } |
||
185 | } |
||
186 | return false; |
||
187 | } |
||
188 | }; |
||
189 | protected JComboBoxUnits cmbUnits;
|
||
190 | protected JComboBoxUnitsReferenceSystem cmbReferenceSystem;
|
||
191 | private JComboBoxFontSizes cmbFontSize;
|
||
192 | protected LibraryBrowser libraryBrowser;
|
||
193 | 42455 | jbadia | private SymbolSelectorListModel listModel;
|
194 | 41858 | fdiaz | |
195 | 40435 | jjdelcerro | /**
|
196 | * Constructor method
|
||
197 | *
|
||
198 | * @param currentElement
|
||
199 | * @param shapeType
|
||
200 | */
|
||
201 | 40716 | jldominguez | private void initialize( |
202 | Object currentElement,
|
||
203 | GeometryType shapeType, |
||
204 | boolean initialize) throws IllegalArgumentException { |
||
205 | 41858 | fdiaz | |
206 | 40435 | jjdelcerro | manager = MapContextLocator.getSymbolManager(); |
207 | |||
208 | // TODO 09/08/07 check the currentElement type is suitable for the shapeType specified
|
||
209 | if (currentElement != null && currentElement instanceof ISymbol) { |
||
210 | ISymbol sym = (ISymbol) currentElement; |
||
211 | try {
|
||
212 | 41858 | fdiaz | currentElement = sym.clone(); |
213 | 40435 | jjdelcerro | } catch (CloneNotSupportedException e) { |
214 | NotificationManager.addWarning("Symbol layer", e);
|
||
215 | } |
||
216 | String desc = sym.getDescription();
|
||
217 | // desc += " ("+PluginServices.getText(this, "current")+")";
|
||
218 | // ((ISymbol)currentElement).setDescription(desc);
|
||
219 | } |
||
220 | 41858 | fdiaz | |
221 | 40435 | jjdelcerro | this.shapeType = shapeType;
|
222 | 41858 | fdiaz | |
223 | 40435 | jjdelcerro | // Preferences prefs = Preferences.userRoot().node( "gvsig.foldering" );
|
224 | rootDir = |
||
225 | new File(manager.getSymbolPreferences().getSymbolLibraryPath()); |
||
226 | |||
227 | if (!rootDir.exists()) {
|
||
228 | rootDir.mkdir(); |
||
229 | } |
||
230 | treeRootName = Messages.getText("symbol_library");
|
||
231 | 40716 | jldominguez | if (initialize) {
|
232 | initialize(currentElement); |
||
233 | 40435 | jjdelcerro | } |
234 | |||
235 | } |
||
236 | 41858 | fdiaz | |
237 | 40716 | jldominguez | protected SymbolSelector(
|
238 | Object symbol,
|
||
239 | GeometryType shapeType, SelectorFilter filter, boolean initialize)
|
||
240 | throws IllegalArgumentException { |
||
241 | 40435 | jjdelcerro | super();
|
242 | initialize(symbol, shapeType, initialize); |
||
243 | sFilter = filter; |
||
244 | } |
||
245 | 41858 | fdiaz | |
246 | 40716 | jldominguez | protected SymbolSelector(Object symbol, GeometryType shapeType, boolean initialize) |
247 | throws IllegalArgumentException { |
||
248 | 40435 | jjdelcerro | super();
|
249 | initialize(symbol, shapeType, initialize); |
||
250 | } |
||
251 | 41858 | fdiaz | |
252 | 40435 | jjdelcerro | /**
|
253 | * Constructor method, it is <b>protected</b> by convenience to let StyleSelector
|
||
254 | * to invoke it, but rigorously it should be <b>private</b>.
|
||
255 | *
|
||
256 | * @param symbol
|
||
257 | * @param shapeType
|
||
258 | * @param filter
|
||
259 | */
|
||
260 | 40716 | jldominguez | protected SymbolSelector(
|
261 | Object symbol,
|
||
262 | int shapeType,
|
||
263 | SelectorFilter filter, |
||
264 | boolean initialize) throws IllegalArgumentException { |
||
265 | 40435 | jjdelcerro | super();
|
266 | try {
|
||
267 | GeometryType geometryType = geomManager.getGeometryType(shapeType, SUBTYPES.GEOM2D); |
||
268 | initialize(symbol,geometryType, initialize); |
||
269 | } catch (GeometryTypeNotSupportedException e1) {
|
||
270 | logger.error("Impossible to get the geometry type", e1);
|
||
271 | } catch (GeometryTypeNotValidException e1) {
|
||
272 | logger.error("Impossible to get the geometry type", e1);
|
||
273 | } |
||
274 | sFilter = filter; |
||
275 | } |
||
276 | |||
277 | /**
|
||
278 | * This method initializes this
|
||
279 | * @param currentElement
|
||
280 | * @throws ClassNotFoundException
|
||
281 | *
|
||
282 | */
|
||
283 | 40716 | jldominguez | protected void initialize(Object currentElement) throws IllegalArgumentException { |
284 | 40435 | jjdelcerro | library = new SymbolLibrary(rootDir);
|
285 | |||
286 | this.setLayout(new BorderLayout()); |
||
287 | this.setSize(400, 221); |
||
288 | |||
289 | this.add(getJNorthPanel(), BorderLayout.NORTH); |
||
290 | this.add(getJSplitPane(), BorderLayout.CENTER); |
||
291 | this.add(getJEastPanel(), BorderLayout.EAST); |
||
292 | ActionListener okAction = new ActionListener() { |
||
293 | public void actionPerformed(ActionEvent e) { |
||
294 | 42455 | jbadia | if(SymbolSelector.this.listModel != null){ |
295 | SymbolSelector.this.listModel.dispose(); |
||
296 | } |
||
297 | 40435 | jjdelcerro | PluginServices.getMDIManager().closeWindow(SymbolSelector.this); |
298 | 42455 | jbadia | |
299 | 40435 | jjdelcerro | } |
300 | }, cancelAction = new ActionListener() { |
||
301 | public void actionPerformed(ActionEvent e) { |
||
302 | accepted = false;
|
||
303 | setSymbol(null);
|
||
304 | 42455 | jbadia | if(SymbolSelector.this.listModel != null){ |
305 | SymbolSelector.this.listModel.dispose(); |
||
306 | } |
||
307 | 40435 | jjdelcerro | PluginServices.getMDIManager().closeWindow(SymbolSelector.this); |
308 | } |
||
309 | }; |
||
310 | |||
311 | okCancelPanel = new AcceptCancelPanel();
|
||
312 | okCancelPanel.setOkButtonActionListener(okAction); |
||
313 | okCancelPanel.setCancelButtonActionListener(cancelAction); |
||
314 | |||
315 | this.add(okCancelPanel, BorderLayout.SOUTH); |
||
316 | libraryBrowser.setSelectionRow(0);
|
||
317 | |||
318 | SillyDragNDropAction dndAction = new SillyDragNDropAction();
|
||
319 | libraryBrowser.addMouseListener(dndAction); |
||
320 | libraryBrowser.addMouseMotionListener(dndAction); |
||
321 | getJListSymbols().addMouseListener(dndAction); |
||
322 | getJListSymbols().addMouseMotionListener(dndAction); |
||
323 | setSymbol(currentElement); |
||
324 | } |
||
325 | |||
326 | /**
|
||
327 | * Creates a new symbol selector list model in order to allow the user
|
||
328 | * to select an existing symbol previously created.
|
||
329 | *
|
||
330 | * @return listModel SymbolSelectorListModel
|
||
331 | */
|
||
332 | 40688 | jldominguez | protected ListModel newListModel() { |
333 | 42455 | jbadia | listModel = new SymbolSelectorListModel(
|
334 | 40435 | jjdelcerro | dir, |
335 | sFilter, |
||
336 | manager.getSymbolPreferences().getSymbolFileExtension()); |
||
337 | return listModel;
|
||
338 | } |
||
339 | /**
|
||
340 | * Initializes tha JNorthPanel.
|
||
341 | *
|
||
342 | * @return northPanel JPanel
|
||
343 | * @throws IllegalArgumentException
|
||
344 | */
|
||
345 | protected JPanel getJNorthPanel() throws IllegalArgumentException { |
||
346 | if (northPanel == null) { |
||
347 | String text = ""; |
||
348 | 41858 | fdiaz | if (shapeType.isTypeOf(Geometry.TYPES.POINT) || shapeType.isTypeOf(Geometry.TYPES.MULTIPOINT)){
|
349 | 40435 | jjdelcerro | text = Messages.getText("point_symbols");
|
350 | 41858 | fdiaz | }else if (shapeType.isTypeOf(Geometry.TYPES.CURVE) || shapeType.isTypeOf(Geometry.TYPES.MULTICURVE)){ |
351 | 40435 | jjdelcerro | text = Messages.getText("line_symbols");
|
352 | 41858 | fdiaz | }else if (shapeType.isTypeOf(Geometry.TYPES.SURFACE) || shapeType.isTypeOf(Geometry.TYPES.MULTISURFACE)){ |
353 | 40435 | jjdelcerro | text = Messages.getText("polygon_symbols");
|
354 | } |
||
355 | else{
|
||
356 | 40716 | jldominguez | throw new IllegalArgumentException( |
357 | Messages.getText("shape_type_not_yet_supported"));
|
||
358 | 40435 | jjdelcerro | } |
359 | northPanel = new JPanel(new FlowLayout(FlowLayout.LEADING)); |
||
360 | lblTitle = new JLabel(text); |
||
361 | lblTitle.setFont(lblTitle.getFont().deriveFont(Font.BOLD));
|
||
362 | northPanel.add(lblTitle); |
||
363 | } |
||
364 | return northPanel;
|
||
365 | } |
||
366 | |||
367 | /**
|
||
368 | * This method initializes jList
|
||
369 | *
|
||
370 | * @return javax.swing.JList
|
||
371 | */
|
||
372 | protected JList getJListSymbols() { |
||
373 | if (jListSymbols == null) { |
||
374 | jListSymbols = new JList() ; |
||
375 | jListSymbols.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
||
376 | jListSymbols.setLayoutOrientation(JList.HORIZONTAL_WRAP);
|
||
377 | jListSymbols.setVisibleRowCount(-1);
|
||
378 | jListSymbols.addListSelectionListener(new ListSelectionListener() { |
||
379 | public void valueChanged(ListSelectionEvent e) { |
||
380 | if (jListSymbols.getSelectedValue()!=null) { |
||
381 | ISymbol selSym=null;
|
||
382 | try {
|
||
383 | selSym = (ISymbol) ((ISymbol) jListSymbols |
||
384 | .getSelectedValue()).clone(); |
||
385 | } catch (CloneNotSupportedException ex) { |
||
386 | NotificationManager.addWarning("Symbol layer", ex);
|
||
387 | } |
||
388 | setSymbol(selSym); |
||
389 | updateOptionsPanel(); |
||
390 | } |
||
391 | } |
||
392 | }); |
||
393 | ListCellRenderer renderer = new ListCellRenderer() { |
||
394 | private Color mySelectedBGColor = new Color(255,145,100,255); |
||
395 | public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { |
||
396 | ISymbol sym = (ISymbol) value; |
||
397 | JPanel pnl = new JPanel(); |
||
398 | BoxLayout layout = new BoxLayout(pnl, BoxLayout.Y_AXIS); |
||
399 | pnl.setLayout(layout); |
||
400 | Color bgColor = (isSelected) ? mySelectedBGColor
|
||
401 | : getJListSymbols().getBackground(); |
||
402 | |||
403 | pnl.setBackground(bgColor); |
||
404 | 41147 | jldominguez | SymbolPreviewer sp = new SymbolPreviewer(true); |
405 | 40435 | jjdelcerro | sp.setAlignmentX(Component.CENTER_ALIGNMENT);
|
406 | sp.setPreferredSize(new Dimension(50, 50)); |
||
407 | sp.setSymbol(sym); |
||
408 | sp.setBackground(bgColor); |
||
409 | pnl.add(sp); |
||
410 | String desc = sym.getDescription();
|
||
411 | if (desc == null) { |
||
412 | desc = "["+Messages.getText("no_desc")+"]"; |
||
413 | } |
||
414 | JLabel lbl = new JLabel(desc); |
||
415 | lbl.setBackground(bgColor); |
||
416 | lbl.setAlignmentX(Component.CENTER_ALIGNMENT);
|
||
417 | pnl.add(lbl); |
||
418 | |||
419 | return pnl;
|
||
420 | } |
||
421 | |||
422 | }; |
||
423 | jListSymbols.setCellRenderer(renderer); |
||
424 | } |
||
425 | return jListSymbols;
|
||
426 | } |
||
427 | /**
|
||
428 | * Updates the options panel depending on the type of symbol that the user
|
||
429 | * is controlling or using to show specific options for each one.
|
||
430 | *
|
||
431 | */
|
||
432 | protected void updateOptionsPanel() throws IllegalArgumentException { |
||
433 | Object mySelectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();
|
||
434 | |||
435 | // if (mySelectedElement == null) {
|
||
436 | // return;
|
||
437 | // }
|
||
438 | act = false; // disable events |
||
439 | |||
440 | if (mySelectedElement instanceof CartographicSupport) { |
||
441 | CartographicSupport cs = (CartographicSupport) mySelectedElement; |
||
442 | cmbUnits.setSelectedUnitIndex(cs.getUnit()); |
||
443 | cmbReferenceSystem.setSelectedIndex(cs.getReferenceSystem()); |
||
444 | } |
||
445 | |||
446 | if (mySelectedElement instanceof IMultiLayerSymbol){ |
||
447 | if (((IMultiLayerSymbol)mySelectedElement).getLayerCount() == 1) { |
||
448 | mySelectedElement = ((IMultiLayerSymbol)mySelectedElement).getLayer(0);
|
||
449 | } |
||
450 | } |
||
451 | |||
452 | try {
|
||
453 | |||
454 | jcc1.setEnabled(mySelectedElement!=null);
|
||
455 | jcc2.setEnabled(mySelectedElement!=null);
|
||
456 | |||
457 | if(mySelectedElement instanceof IMultiLayerSymbol){ |
||
458 | jcc1.setColor(Color.WHITE);
|
||
459 | jcc2.setColor(Color.WHITE);
|
||
460 | jcc1.setEnabled(false);
|
||
461 | jcc2.setEnabled(false);
|
||
462 | } |
||
463 | |||
464 | if (shapeType.isTypeOf(Geometry.TYPES.POINT) || shapeType.isTypeOf(Geometry.TYPES.MULTIPOINT)) {
|
||
465 | IMarkerSymbol m = (IMarkerSymbol) mySelectedElement; |
||
466 | txtSize.setEnabled(m!=null);
|
||
467 | txtAngle.setEnabled(m!=null);
|
||
468 | if(m!=null){ |
||
469 | jcc1.setColor(m.getColor()); |
||
470 | txtSize.setDouble(m.getSize()); |
||
471 | txtAngle.setDouble(Math.toDegrees(m.getRotation()));
|
||
472 | } |
||
473 | } |
||
474 | |||
475 | if (shapeType.isTypeOf(Geometry.TYPES.CURVE) || shapeType.isTypeOf(Geometry.TYPES.MULTICURVE)) {
|
||
476 | ILineSymbol l = (ILineSymbol) mySelectedElement; |
||
477 | txtSize.setEnabled(l!=null);
|
||
478 | if(l!=null){ |
||
479 | jcc1.setColor(l.getColor()); |
||
480 | jcc1.setAlpha(l.getAlpha()); |
||
481 | txtSize.setDouble(l.getLineWidth()); |
||
482 | } |
||
483 | } |
||
484 | |||
485 | if (shapeType.isTypeOf(Geometry.TYPES.SURFACE) || shapeType.isTypeOf(Geometry.TYPES.MULTISURFACE)) {
|
||
486 | IFillSymbol f = (IFillSymbol) mySelectedElement; |
||
487 | |||
488 | txtWidth.setEnabled(f!=null);
|
||
489 | cmbReferenceSystem.setEnabled(f!=null);
|
||
490 | cmbUnits.setEnabled(f!=null);
|
||
491 | |||
492 | if (f!=null){ |
||
493 | jcc1.setUseColorIsSelected(f.hasFill()); |
||
494 | jcc1.setColor(f.getFillColor()); |
||
495 | jcc1.setAlpha(f.getFillAlpha()); |
||
496 | jcc2.setUseColorIsSelected(f.hasOutline()); |
||
497 | ILineSymbol outline = f.getOutline(); |
||
498 | if (outline != null) { |
||
499 | jcc2.setColor(outline.getColor()); |
||
500 | txtWidth.setDouble(outline.getLineWidth()); |
||
501 | } |
||
502 | |||
503 | if(f instanceof IMultiLayerFillSymbol){ |
||
504 | txtWidth.setEnabled(false);
|
||
505 | cmbReferenceSystem.setEnabled(false);
|
||
506 | cmbUnits.setEnabled(false);
|
||
507 | } |
||
508 | } |
||
509 | } |
||
510 | |||
511 | } catch (NullPointerException npEx) { |
||
512 | throw new IllegalArgumentException(npEx); |
||
513 | } catch (ClassCastException ccEx) { |
||
514 | throw new IllegalArgumentException(ccEx); |
||
515 | } |
||
516 | |||
517 | act = true; // enable events |
||
518 | } |
||
519 | |||
520 | /**
|
||
521 | * This method initializes jPanel
|
||
522 | *
|
||
523 | * @return javax.swing.JPanel
|
||
524 | */
|
||
525 | protected JPanel getJEastPanel() { |
||
526 | if (jPanel == null) { |
||
527 | jPanel = new JPanel(); |
||
528 | jPanel.setLayout(new BorderLayout()); |
||
529 | jPanel.add(getJPanelOptions(), BorderLayout.CENTER);
|
||
530 | JPanel aux = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5)); |
||
531 | aux.setBorder(BorderFactory.createTitledBorder(null, Messages.getText("preview"))); |
||
532 | aux.add(getJPanelPreview()); |
||
533 | jPanel.add(aux, BorderLayout.NORTH);
|
||
534 | |||
535 | jPanel.add(getJPanelOptions()); |
||
536 | aux = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5)); |
||
537 | aux.add(getJPanelButtons()); |
||
538 | jPanel.add(aux, BorderLayout.SOUTH);
|
||
539 | } |
||
540 | return jPanel;
|
||
541 | } |
||
542 | |||
543 | private JPanel getJPanelButtons() { |
||
544 | if (jPanelButtons == null) { |
||
545 | jPanelButtons = new JPanel(); |
||
546 | GridLayout layout = new GridLayout(); |
||
547 | layout.setColumns(1);
|
||
548 | layout.setVgap(5);
|
||
549 | jPanelButtons.add(getBtnNewSymbol()); |
||
550 | jPanelButtons.add(getBtnSaveSymbol()); |
||
551 | jPanelButtons.add(getBtnResetSymbol()); |
||
552 | jPanelButtons.add(getBtnProperties()); |
||
553 | |||
554 | // do not add components bellow this line!
|
||
555 | layout.setRows(jPanelButtons.getComponentCount()); |
||
556 | jPanelButtons.setLayout(layout); |
||
557 | } |
||
558 | return jPanelButtons;
|
||
559 | } |
||
560 | |||
561 | private JButton getBtnNewSymbol() { |
||
562 | if (btnNewSymbol == null) { |
||
563 | btnNewSymbol = new JButton(); |
||
564 | btnNewSymbol.setName("btnNewSymbol");
|
||
565 | btnNewSymbol.setText(Messages.getText("new"));
|
||
566 | btnNewSymbol.addActionListener(this);
|
||
567 | } |
||
568 | return btnNewSymbol;
|
||
569 | } |
||
570 | |||
571 | private JButton getBtnResetSymbol() { |
||
572 | if (btnResetSymbol == null) { |
||
573 | btnResetSymbol = new JButton(); |
||
574 | btnResetSymbol.setName("btnResetSymbol");
|
||
575 | btnResetSymbol.setText(Messages.getText("reset"));
|
||
576 | btnResetSymbol.addActionListener(this);
|
||
577 | } |
||
578 | return btnResetSymbol;
|
||
579 | } |
||
580 | |||
581 | private JButton getBtnSaveSymbol() { |
||
582 | if (btnSaveSymbol == null) { |
||
583 | btnSaveSymbol = new JButton(); |
||
584 | btnSaveSymbol.setName("btnSaveSymbol");
|
||
585 | btnSaveSymbol.setText(Messages.getText("save"));
|
||
586 | btnSaveSymbol.addActionListener(this);
|
||
587 | } |
||
588 | return btnSaveSymbol;
|
||
589 | } |
||
590 | |||
591 | private JButton getBtnProperties() { |
||
592 | if (btnProperties == null) { |
||
593 | btnProperties = new JButton(); |
||
594 | btnProperties.setName("btnProperties");
|
||
595 | btnProperties.setText(Messages.getText("properties"));
|
||
596 | btnProperties.addActionListener(this);
|
||
597 | } |
||
598 | return btnProperties;
|
||
599 | } |
||
600 | |||
601 | /**
|
||
602 | * This method initializes jScrollPane
|
||
603 | *
|
||
604 | * @return javax.swing.JScrollPane
|
||
605 | * @throws ClassNotFoundException
|
||
606 | */
|
||
607 | 40716 | jldominguez | protected JScrollPane getLeftJScrollPane() { |
608 | 40435 | jjdelcerro | if (jScrollPane == null) { |
609 | jScrollPane = new JScrollPane(); |
||
610 | jScrollPane.setPreferredSize(new java.awt.Dimension(80,130)); |
||
611 | jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); |
||
612 | libraryBrowser = new LibraryBrowser(library);
|
||
613 | libraryBrowser.addTreeSelectionListener(new TreeSelectionListener() { |
||
614 | public void valueChanged(javax.swing.event.TreeSelectionEvent e) { |
||
615 | 41858 | fdiaz | |
616 | 40721 | jldominguez | if (libraryBrowser.getLastSelectedPathComponent() == null) { |
617 | /*
|
||
618 | * This happens when clicking on [+] to expand
|
||
619 | 41858 | fdiaz | * or [-] to collapse a tree node.
|
620 | 40721 | jldominguez | */
|
621 | return;
|
||
622 | } |
||
623 | 41858 | fdiaz | |
624 | 40435 | jjdelcerro | dir = (File) ((DefaultMutableTreeNode) |
625 | libraryBrowser.getLastSelectedPathComponent()).getUserObject(); |
||
626 | |||
627 | if (dir == null) { |
||
628 | return;
|
||
629 | } |
||
630 | 41053 | jjdelcerro | ListModel model = jListSymbols.getModel();
|
631 | if( model != null && model instanceof Disposable ) { |
||
632 | ((Disposable)model).dispose(); |
||
633 | } |
||
634 | 40435 | jjdelcerro | jListSymbols.setModel(newListModel()); |
635 | } |
||
636 | }); |
||
637 | jScrollPane.setViewportView(libraryBrowser); |
||
638 | } |
||
639 | return jScrollPane;
|
||
640 | } |
||
641 | |||
642 | /**
|
||
643 | * This method initializes jScrollPane1
|
||
644 | *
|
||
645 | * @return javax.swing.JScrollPane
|
||
646 | */
|
||
647 | private JScrollPane getJScrollPane1() { |
||
648 | if (jScrollPane1 == null) { |
||
649 | jScrollPane1 = new JScrollPane(); |
||
650 | jScrollPane1.setViewportView(getJListSymbols()); |
||
651 | } |
||
652 | return jScrollPane1;
|
||
653 | } |
||
654 | |||
655 | /**
|
||
656 | * This method initializes jPanelPreview
|
||
657 | *
|
||
658 | * @return javax.swing.JComponent
|
||
659 | */
|
||
660 | protected JComponent getJPanelPreview() { |
||
661 | if (jPanelPreview == null) { |
||
662 | jPanelPreview = new SymbolPreviewer();
|
||
663 | jPanelPreview.setPreferredSize(new java.awt.Dimension(100,100)); |
||
664 | jPanelPreview.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.LOWERED)); |
||
665 | } |
||
666 | return jPanelPreview;
|
||
667 | } |
||
668 | /**
|
||
669 | * This method initializes jPanelOptions
|
||
670 | *
|
||
671 | * @return javax.swing.JPanel
|
||
672 | */
|
||
673 | protected JPanel getJPanelOptions() { |
||
674 | if (jPanelOptions == null) { |
||
675 | jPanelOptions = new GridBagLayoutPanel();
|
||
676 | jPanelOptions.setBorder(BorderFactory.createTitledBorder(null, Messages.getText("options"))); |
||
677 | jcc2 = new ColorChooserPanel(true,true); |
||
678 | jcc2.setAlpha(255);
|
||
679 | if (shapeType.isTypeOf(Geometry.TYPES.POINT) || shapeType.isTypeOf(Geometry.TYPES.MULTIPOINT)) {
|
||
680 | jcc1 = new ColorChooserPanel(true); |
||
681 | |||
682 | jPanelOptions.addComponent( |
||
683 | Messages.getText("color")+":", jcc1); |
||
684 | jPanelOptions.addComponent( |
||
685 | Messages.getText("size")+":", |
||
686 | 42079 | fdiaz | txtSize = new JNumberSpinner(3.0, 3, 0, Double.MAX_VALUE, 1, 2)); |
687 | 40435 | jjdelcerro | jPanelOptions.addComponent(Messages.getText("units")+":", |
688 | cmbUnits = new JComboBoxUnits());
|
||
689 | jPanelOptions.addComponent("",
|
||
690 | cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
|
||
691 | jPanelOptions.addComponent( |
||
692 | Messages.getText("angle")+ " (" +Messages.getText("degree")+"):", |
||
693 | 42079 | fdiaz | txtAngle = new JNumberSpinner(0.0, 3, -180.0, 180.0, 1.0, 2)); |
694 | 40435 | jjdelcerro | |
695 | |||
696 | } else if (shapeType.isTypeOf(Geometry.TYPES.CURVE) || shapeType.isTypeOf(Geometry.TYPES.MULTICURVE)) { |
||
697 | jcc1 = new ColorChooserPanel(true); |
||
698 | jPanelOptions.addComponent( |
||
699 | Messages.getText("color")+":", jcc1); |
||
700 | jPanelOptions.addComponent( |
||
701 | Messages.getText("width")+":", |
||
702 | 42079 | fdiaz | txtSize = new JNumberSpinner(3.0, 3, 0, Double.MAX_VALUE, 1, 2)); |
703 | 40435 | jjdelcerro | jPanelOptions.addComponent(Messages.getText("units")+":", |
704 | cmbUnits = new JComboBoxUnits());
|
||
705 | jPanelOptions.addComponent("",
|
||
706 | cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
|
||
707 | |||
708 | } else if (shapeType.isTypeOf(Geometry.TYPES.SURFACE) || shapeType.isTypeOf(Geometry.TYPES.MULTISURFACE)) { |
||
709 | jcc1 = new ColorChooserPanel(true, true); |
||
710 | jPanelOptions.addComponent( |
||
711 | Messages.getText("fill_color")+":", jcc1); |
||
712 | jPanelOptions.addComponent( |
||
713 | Messages.getText("outline_color")+":", jcc2); |
||
714 | jPanelOptions.addComponent( |
||
715 | Messages.getText("outline_width"),
|
||
716 | 42079 | fdiaz | txtWidth = new JNumberSpinner(3.0, 3, 0, Double.MAX_VALUE, 1, 2)); |
717 | 40435 | jjdelcerro | jPanelOptions.addComponent(Messages.getText("units")+":", |
718 | cmbUnits = new JComboBoxUnits());
|
||
719 | jPanelOptions.addComponent("",
|
||
720 | cmbReferenceSystem = new JComboBoxUnitsReferenceSystem());
|
||
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(Messages.getText("symbol_selector"));
|
||
792 | } |
||
793 | return wi;
|
||
794 | } |
||
795 | |||
796 | 40716 | jldominguez | protected JSplitPane getJSplitPane() { |
797 | 40435 | jjdelcerro | 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 | 41858 | fdiaz | clonedSymbol = (ISymbol) mySelectedElement.clone(); |
846 | 40435 | jjdelcerro | } catch (CloneNotSupportedException e) { |
847 | NotificationManager.addWarning("Symbol layer", e);
|
||
848 | } |
||
849 | SymbolEditor se = new SymbolEditor(clonedSymbol, shapeType);
|
||
850 | PluginServices.getMDIManager().addWindow(se); |
||
851 | |||
852 | ISymbol symbol = se.getSymbol(); |
||
853 | if (symbol instanceof IMultiLayerSymbol) { |
||
854 | IMultiLayerSymbol mSym = (IMultiLayerSymbol) symbol; |
||
855 | if (mSym.getLayerCount() == 1) { |
||
856 | symbol = mSym.getLayer(0);
|
||
857 | } |
||
858 | } |
||
859 | setSymbol(symbol); |
||
860 | |||
861 | } |
||
862 | |||
863 | /**
|
||
864 | * Invoked when the NEW button is pressed
|
||
865 | */
|
||
866 | 41424 | jjdelcerro | protected void newPressed() { |
867 | ISymbol curr_sym = ((SymbolPreviewer) jPanelPreview).getSymbol(); |
||
868 | 40435 | jjdelcerro | |
869 | 41424 | jjdelcerro | if (curr_sym != null) { |
870 | try {
|
||
871 | curr_sym = (ISymbol) curr_sym.clone(); |
||
872 | } catch (Exception cnse) { |
||
873 | logger.info("Unable to clone symbol. "
|
||
874 | + "This can cause an empty symbol if user cancels dialog.",
|
||
875 | cnse); |
||
876 | } |
||
877 | } |
||
878 | SymbolEditor se = new SymbolEditor(curr_sym, shapeType);
|
||
879 | PluginServices.getMDIManager().addWindow(se); |
||
880 | setSymbol(se.getSymbol()); |
||
881 | } |
||
882 | 40435 | jjdelcerro | |
883 | /**
|
||
884 | * Invoked when the RESET button is pressed
|
||
885 | */
|
||
886 | protected void resetPressed() { |
||
887 | setSymbol(null);
|
||
888 | } |
||
889 | |||
890 | /**
|
||
891 | * Invoked when the SAVE button is pressed
|
||
892 | */
|
||
893 | protected void savePressed() { |
||
894 | 41398 | jjdelcerro | Object selected = getSelectedObject();
|
895 | 40435 | jjdelcerro | if (getSelectedObject() ==null) { |
896 | return;
|
||
897 | } |
||
898 | |||
899 | final SymbolPreferences preferences = manager.getSymbolPreferences();
|
||
900 | |||
901 | |||
902 | JFileChooser jfc = new JFileChooser("SYMBOL_SELECTOR_FILECHOOSER", rootDir); |
||
903 | javax.swing.filechooser.FileFilter ff = new javax.swing.filechooser.FileFilter() {
|
||
904 | public boolean accept(File f) { |
||
905 | return f.getAbsolutePath().toLowerCase().endsWith(
|
||
906 | preferences.getSymbolFileExtension()) |
||
907 | || f.isDirectory(); |
||
908 | } |
||
909 | |||
910 | public String getDescription() { |
||
911 | return Messages.getText(
|
||
912 | "gvSIG_symbol_definition_file")
|
||
913 | .concat(" (*")
|
||
914 | .concat(preferences.getSymbolFileExtension()) |
||
915 | .concat(")");
|
||
916 | } |
||
917 | }; |
||
918 | jfc.setFileFilter(ff); |
||
919 | JPanel accessory = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); |
||
920 | accessory.add(new JLabel(Messages.getText("enter_description"))); |
||
921 | JTextField txtDesc = new JTextField(25); |
||
922 | 41398 | jjdelcerro | if( selected instanceof ISymbol ) { |
923 | txtDesc.setText(((ISymbol)selected).getDescription()); |
||
924 | } |
||
925 | 41416 | jjdelcerro | if( selected instanceof ISymbol_v2 && !StringUtils.isEmpty(((ISymbol_v2)selected).getID())) { |
926 | 41398 | jjdelcerro | jfc.setSelectedFile(new File(((ISymbol_v2)selected).getID())); |
927 | } |
||
928 | 41858 | fdiaz | |
929 | 40435 | jjdelcerro | 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 = |
||
940 | s.substring(s.lastIndexOf(File.separator) + 1) |
||
941 | .replaceAll( |
||
942 | preferences.getSymbolFileExtension(), |
||
943 | "");
|
||
944 | } else {
|
||
945 | desc = txtDesc.getText().trim(); |
||
946 | } |
||
947 | ISymbol s = (ISymbol) getSelectedObject(); |
||
948 | s.setDescription(desc); |
||
949 | |||
950 | |||
951 | String symbolFileName = targetFile.getAbsolutePath().substring(
|
||
952 | targetFile.getAbsolutePath().lastIndexOf(File.separator)+1, |
||
953 | targetFile.getAbsolutePath().length()); |
||
954 | File targetDir = new File(targetFile.getAbsolutePath().substring( |
||
955 | 0,
|
||
956 | targetFile.getAbsolutePath().lastIndexOf(File.separator)));
|
||
957 | library.addElement(s, symbolFileName , targetDir); |
||
958 | getJListSymbols().setModel(newListModel()); |
||
959 | } |
||
960 | } |
||
961 | |||
962 | |||
963 | public void actionPerformed(ActionEvent e) { |
||
964 | if (!act) {
|
||
965 | return;
|
||
966 | } |
||
967 | Object selectedElement = ((SymbolPreviewer) jPanelPreview).getSymbol();//getSelectedObject(); |
||
968 | performActionOn(selectedElement, e); |
||
969 | SymbolSelector.this.repaint(); |
||
970 | } |
||
971 | |||
972 | protected void performActionOn(Object selectedElement, ActionEvent e) { |
||
973 | JComponent comp = (JComponent) e.getSource(); |
||
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 | |||
992 | Color c = jcc1.getColor();
|
||
993 | |||
994 | if (selectedElement instanceof IMarkerSymbol) { |
||
995 | IMarkerSymbol m = (IMarkerSymbol) selectedElement; |
||
996 | if (m instanceof IMultiLayerMarkerSymbol) { |
||
997 | IMultiLayerMarkerSymbol mm = (IMultiLayerMarkerSymbol) 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 IMultiLayerLineSymbol) { |
||
1007 | IMultiLayerLineSymbol ml = (IMultiLayerLineSymbol) 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 | } |
||
1030 | Color c = jcc2.getColor();
|
||
1031 | |||
1032 | |||
1033 | if (selectedElement instanceof IFillSymbol) { |
||
1034 | IFillSymbol f = (IFillSymbol) selectedElement; |
||
1035 | ILineSymbol outline = f.getOutline(); |
||
1036 | f.setHasOutline(jcc2.getUseColorisSelected()); |
||
1037 | |||
1038 | if (outline!=null) { |
||
1039 | ILineSymbol l = outline; |
||
1040 | if (l instanceof IMultiLayerLineSymbol && c != null) { |
||
1041 | IMultiLayerLineSymbol ml = (IMultiLayerLineSymbol) l; |
||
1042 | ml.setAlpha(c.getAlpha()); |
||
1043 | } else {
|
||
1044 | l.setLineColor(c); |
||
1045 | } |
||
1046 | } |
||
1047 | |||
1048 | } |
||
1049 | } else if (comp.equals(txtSize)) { |
||
1050 | double s = txtSize.getDouble();
|
||
1051 | |||
1052 | if (selectedElement instanceof IMarkerSymbol) { |
||
1053 | IMarkerSymbol m = (IMarkerSymbol) selectedElement; |
||
1054 | m.setSize(s); |
||
1055 | 41858 | fdiaz | ISymbol sm = m.getSymbolForSelection(); |
1056 | if (sm != null && sm instanceof IMarkerSymbol){ |
||
1057 | ((IMarkerSymbol)sm).setSize(s); |
||
1058 | } |
||
1059 | 40435 | jjdelcerro | } |
1060 | |||
1061 | if (selectedElement instanceof ILineSymbol) { |
||
1062 | ILineSymbol l = (ILineSymbol) selectedElement; |
||
1063 | l.setLineWidth(s); |
||
1064 | 41858 | fdiaz | ISymbol sl = l.getSymbolForSelection(); |
1065 | if (sl != null && sl instanceof ILineSymbol){ |
||
1066 | ((ILineSymbol)sl).setLineWidth(s); |
||
1067 | } |
||
1068 | 40435 | jjdelcerro | } |
1069 | } else if (comp.equals(cmbUnits)) { |
||
1070 | if (selectedElement instanceof CartographicSupport) { |
||
1071 | CartographicSupport cs = (CartographicSupport) selectedElement; |
||
1072 | cs.setUnit(cmbUnits.getSelectedUnitIndex()); |
||
1073 | } |
||
1074 | } else if (comp.equals(cmbReferenceSystem)) { |
||
1075 | if (selectedElement instanceof CartographicSupport) { |
||
1076 | CartographicSupport cs = (CartographicSupport) selectedElement; |
||
1077 | 41188 | jldominguez | cs.setReferenceSystem(cmbReferenceSystem.getSelectedIndex()); |
1078 | 40435 | jjdelcerro | } |
1079 | } else if (comp.equals(txtWidth)) { |
||
1080 | double w = txtWidth.getDouble();
|
||
1081 | if (selectedElement instanceof IFillSymbol) { |
||
1082 | IFillSymbol f = (IFillSymbol) selectedElement; |
||
1083 | ILineSymbol outline = f.getOutline(); |
||
1084 | if (outline!=null) { |
||
1085 | outline.setLineWidth(w); |
||
1086 | } |
||
1087 | } |
||
1088 | } else if (comp.equals(cmbFontSize)) { |
||
1089 | double s = ((Integer) cmbFontSize.getSelectedItem()).doubleValue(); |
||
1090 | if (selectedElement instanceof ITextSymbol) { |
||
1091 | ITextSymbol t = (ITextSymbol) selectedElement; |
||
1092 | t.setFontSize(s); |
||
1093 | } |
||
1094 | } else if (comp.equals(txtAngle)) { |
||
1095 | double a = Math.toRadians(txtAngle.getDouble()); |
||
1096 | if (selectedElement instanceof IMarkerSymbol) { |
||
1097 | IMarkerSymbol m = (IMarkerSymbol) selectedElement; |
||
1098 | m.setRotation(a); |
||
1099 | } |
||
1100 | } |
||
1101 | } |
||
1102 | |||
1103 | public static ISymbolSelector createSymbolBrowser() { |
||
1104 | return MultiShapeSymbolSelector.createSymbolBrowser();
|
||
1105 | } |
||
1106 | |||
1107 | public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType) { |
||
1108 | return createSymbolSelector(currSymbol, shapeType, null); |
||
1109 | } |
||
1110 | |||
1111 | public static ISymbolSelector createSymbolSelector(Object currSymbol, int shapeType, SelectorFilter filter) { |
||
1112 | ISymbolSelector selector = null;
|
||
1113 | |||
1114 | GeometryType geometryType = null;
|
||
1115 | try {
|
||
1116 | geometryType = geomManager.getGeometryType(shapeType, SUBTYPES.GEOM2D); |
||
1117 | } catch (GeometryTypeNotSupportedException e) {
|
||
1118 | logger.error("Impossible to get the geometry type", e);
|
||
1119 | } catch (GeometryTypeNotValidException e) {
|
||
1120 | logger.error("Impossible to get the geometry type", e);
|
||
1121 | } |
||
1122 | |||
1123 | if (filter==null) { |
||
1124 | selector = (shapeType == Geometry.TYPES.GEOMETRY) ? |
||
1125 | new MultiShapeSymbolSelector(currSymbol) :
|
||
1126 | new SymbolSelector(currSymbol, geometryType, true); |
||
1127 | } else {
|
||
1128 | selector = (shapeType == Geometry.TYPES.GEOMETRY) ? |
||
1129 | new MultiShapeSymbolSelector(currSymbol) :
|
||
1130 | new SymbolSelector(currSymbol, geometryType, filter, true); |
||
1131 | } |
||
1132 | return selector;
|
||
1133 | } |
||
1134 | |||
1135 | class SillyDragNDropAction implements MouseListener, MouseMotionListener { |
||
1136 | private boolean doDrop = false; |
||
1137 | private Object selected; |
||
1138 | private File sourceFolder; |
||
1139 | |||
1140 | public void mouseClicked(MouseEvent e) { } |
||
1141 | public void mouseEntered(MouseEvent e) { } |
||
1142 | public void mouseExited(MouseEvent e) { } |
||
1143 | |||
1144 | public void mousePressed(MouseEvent e) { |
||
1145 | if (e.getSource().equals(getJListSymbols())) {
|
||
1146 | selected = getJListSymbols().getSelectedValue(); |
||
1147 | doDrop = selected!=null;
|
||
1148 | DefaultMutableTreeNode node = (DefaultMutableTreeNode) libraryBrowser.getLastSelectedPathComponent(); |
||
1149 | if (node.getUserObject() instanceof File) { |
||
1150 | sourceFolder = (File) node.getUserObject();
|
||
1151 | } |
||
1152 | } |
||
1153 | e.consume(); |
||
1154 | } |
||
1155 | |||
1156 | public void mouseReleased(MouseEvent e) { |
||
1157 | if (doDrop && e.getSource().equals(getJListSymbols())) {
|
||
1158 | Point p = new Point(getJListSymbols().getLocation().x-e.getPoint().x, getJListSymbols().getLocation().y+e.getPoint().y); |
||
1159 | if (libraryBrowser.getBounds().contains(p)) {
|
||
1160 | File destFolder = libraryBrowser.getElementBellow(p);
|
||
1161 | if (destFolder != null) { |
||
1162 | ISymbol sym = (ISymbol) selected; |
||
1163 | int move = InputEvent.SHIFT_DOWN_MASK | InputEvent.BUTTON1_DOWN_MASK; |
||
1164 | // int copy = MouseEvent.CTRL_DOWN_MASK | MouseEvent.BUTTON1_DOWN_MASK;
|
||
1165 | |||
1166 | library.addElement(sym, sym.getDescription(), destFolder); |
||
1167 | if ((e.getModifiers() & (move)) !=0) { |
||
1168 | library.removeElement(sym, sourceFolder); |
||
1169 | } |
||
1170 | |||
1171 | } |
||
1172 | libraryBrowser.refresh(); |
||
1173 | } |
||
1174 | |||
1175 | } |
||
1176 | doDrop = false;
|
||
1177 | } |
||
1178 | |||
1179 | public void mouseDragged(MouseEvent e) { |
||
1180 | if (e.getSource().equals(getJListSymbols())) {
|
||
1181 | |||
1182 | Point p = new Point(getJListSymbols().getLocation().x-e.getPoint().x, getJListSymbols().getLocation().y+e.getPoint().y); |
||
1183 | if (libraryBrowser.getBounds().contains(p)) {
|
||
1184 | libraryBrowser.setSelectedElementBellow(p); |
||
1185 | } |
||
1186 | } |
||
1187 | } |
||
1188 | |||
1189 | public void mouseMoved(MouseEvent e) { |
||
1190 | |||
1191 | } |
||
1192 | |||
1193 | } |
||
1194 | |||
1195 | public Object getWindowProfile() { |
||
1196 | return WindowInfo.DIALOG_PROFILE;
|
||
1197 | } |
||
1198 | |||
1199 | } |