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