svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SymbolEditor.java @ 23502
History | View | Annotate | Download (19.8 KB)
1 | 9745 | jaume | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | *
|
||
3 | * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | * Av. Blasco Ib??ez, 50
|
||
24 | * 46010 VALENCIA
|
||
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | |||
42 | /* CVS MESSAGES:
|
||
43 | 10679 | jaume | *
|
44 | * $Id$
|
||
45 | * $Log$
|
||
46 | 13855 | jaume | * Revision 1.22 2007-09-19 15:36:36 jaume
|
47 | * removed unnecessary imports
|
||
48 | *
|
||
49 | * Revision 1.21 2007/09/17 09:21:45 jaume
|
||
50 | 13729 | jaume | * refactored SymboSelector (added support for multishapedsymbol)
|
51 | *
|
||
52 | * Revision 1.20 2007/08/21 09:32:41 jvidal
|
||
53 | 13189 | jvidal | * javadoc
|
54 | *
|
||
55 | * Revision 1.19 2007/08/10 06:09:57 jaume
|
||
56 | 13008 | jaume | * imports fixed
|
57 | *
|
||
58 | * Revision 1.18 2007/08/10 06:06:05 jaume
|
||
59 | 13004 | jaume | * translations and error messages
|
60 | *
|
||
61 | * Revision 1.17 2007/08/03 11:29:13 jaume
|
||
62 | 12911 | jaume | * refactored AbstractTypeSymbolEditorPanel class name to AbastractTypeSymbolEditor
|
63 | *
|
||
64 | * Revision 1.16 2007/08/01 13:01:43 jaume
|
||
65 | 12866 | jaume | * refactored to be pluggable
|
66 | *
|
||
67 | * Revision 1.15 2007/07/30 12:56:04 jaume
|
||
68 | 12826 | jaume | * organize imports, java 5 code downgraded to 1.4 and added PictureFillSymbol
|
69 | *
|
||
70 | * Revision 1.14 2007/07/30 06:59:51 jaume
|
||
71 | 12820 | jaume | * finished (maybe) LineFillSymbol
|
72 | *
|
||
73 | * Revision 1.13 2007/07/26 12:28:29 jaume
|
||
74 | 12805 | jaume | * maybe finished ArrowMarkerSymbol and ArrowDecoratorStyle
|
75 | *
|
||
76 | * Revision 1.12 2007/07/18 06:56:03 jaume
|
||
77 | 12657 | jaume | * continuing with cartographic support
|
78 | *
|
||
79 | * Revision 1.11 2007/07/12 10:43:55 jaume
|
||
80 | 12561 | jaume | * *** empty log message ***
|
81 | *
|
||
82 | * Revision 1.10 2007/06/29 13:07:33 jaume
|
||
83 | 12427 | jaume | * +PictureLineSymbol
|
84 | *
|
||
85 | * Revision 1.9 2007/05/31 09:36:22 jaume
|
||
86 | 10927 | jaume | * *** empty log message ***
|
87 | *
|
||
88 | 11919 | jaume | * Revision 1.8 2007/05/29 15:47:06 jaume
|
89 | * *** empty log message ***
|
||
90 | *
|
||
91 | 11877 | jaume | * Revision 1.7 2007/05/09 16:08:14 jaume
|
92 | * *** empty log message ***
|
||
93 | *
|
||
94 | 11548 | jaume | * Revision 1.6 2007/05/08 15:44:07 jaume
|
95 | * *** empty log message ***
|
||
96 | *
|
||
97 | 11503 | jaume | * Revision 1.5 2007/04/20 07:54:38 jaume
|
98 | * *** empty log message ***
|
||
99 | *
|
||
100 | 11297 | jaume | * Revision 1.4 2007/03/28 16:44:08 jaume
|
101 | * *** empty log message ***
|
||
102 | *
|
||
103 | 10959 | jaume | * Revision 1.3 2007/03/27 09:49:03 jaume
|
104 | * *** empty log message ***
|
||
105 | *
|
||
106 | 10927 | jaume | * Revision 1.2 2007/03/09 11:25:00 jaume
|
107 | 10679 | jaume | * Advanced symbology (start committing)
|
108 | *
|
||
109 | * Revision 1.1.2.4 2007/02/21 07:35:14 jaume
|
||
110 | * *** empty log message ***
|
||
111 | *
|
||
112 | * Revision 1.1.2.3 2007/02/09 11:00:03 jaume
|
||
113 | * *** empty log message ***
|
||
114 | *
|
||
115 | * Revision 1.1.2.2 2007/02/08 15:43:05 jaume
|
||
116 | * some bug fixes in the editor and removed unnecessary imports
|
||
117 | *
|
||
118 | * Revision 1.1.2.1 2007/01/26 13:49:03 jaume
|
||
119 | * *** empty log message ***
|
||
120 | *
|
||
121 | * Revision 1.1 2007/01/16 11:52:11 jaume
|
||
122 | * *** empty log message ***
|
||
123 | *
|
||
124 | * Revision 1.11 2007/01/10 17:05:05 jaume
|
||
125 | * moved to FMap and gvSIG
|
||
126 | *
|
||
127 | * Revision 1.10 2006/11/13 09:15:23 jaume
|
||
128 | * javadoc and some clean-up
|
||
129 | *
|
||
130 | * Revision 1.9 2006/11/06 17:08:45 jaume
|
||
131 | * *** empty log message ***
|
||
132 | *
|
||
133 | * Revision 1.8 2006/11/06 16:06:52 jaume
|
||
134 | * *** empty log message ***
|
||
135 | *
|
||
136 | * Revision 1.7 2006/11/06 07:33:54 jaume
|
||
137 | * javadoc, source style
|
||
138 | *
|
||
139 | * Revision 1.6 2006/11/02 17:19:28 jaume
|
||
140 | * *** empty log message ***
|
||
141 | *
|
||
142 | * Revision 1.5 2006/10/31 16:16:34 jaume
|
||
143 | * *** empty log message ***
|
||
144 | *
|
||
145 | * Revision 1.4 2006/10/30 19:30:35 jaume
|
||
146 | * *** empty log message ***
|
||
147 | *
|
||
148 | * Revision 1.3 2006/10/29 23:53:49 jaume
|
||
149 | * *** empty log message ***
|
||
150 | *
|
||
151 | * Revision 1.2 2006/10/27 12:41:09 jaume
|
||
152 | * GUI
|
||
153 | *
|
||
154 | * Revision 1.1 2006/10/26 16:31:21 jaume
|
||
155 | * GUI
|
||
156 | *
|
||
157 | *
|
||
158 | */
|
||
159 | 9745 | jaume | package com.iver.cit.gvsig.gui.styling; |
160 | |||
161 | import java.awt.BorderLayout; |
||
162 | import java.awt.Dimension; |
||
163 | import java.awt.FlowLayout; |
||
164 | import java.awt.event.ActionEvent; |
||
165 | import java.awt.event.ActionListener; |
||
166 | 12866 | jaume | import java.lang.reflect.Constructor; |
167 | import java.util.ArrayList; |
||
168 | 9745 | jaume | import java.util.Comparator; |
169 | 13008 | jaume | import java.util.Hashtable; |
170 | 9745 | jaume | import java.util.TreeSet; |
171 | |||
172 | import javax.swing.BorderFactory; |
||
173 | import javax.swing.JComboBox; |
||
174 | import javax.swing.JLabel; |
||
175 | import javax.swing.JPanel; |
||
176 | import javax.swing.JTabbedPane; |
||
177 | |||
178 | import org.gvsig.gui.beans.AcceptCancelPanel; |
||
179 | |||
180 | import com.iver.andami.PluginServices; |
||
181 | 12866 | jaume | import com.iver.andami.messages.NotificationManager; |
182 | 9745 | jaume | import com.iver.andami.ui.mdiManager.IWindow; |
183 | import com.iver.andami.ui.mdiManager.WindowInfo; |
||
184 | 12657 | jaume | import com.iver.cit.gvsig.fmap.core.CartographicSupport; |
185 | 9745 | jaume | import com.iver.cit.gvsig.fmap.core.FShape; |
186 | 10679 | jaume | import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
187 | import com.iver.cit.gvsig.fmap.core.symbols.IMultiLayerSymbol; |
||
188 | 9745 | jaume | import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
189 | 11919 | jaume | import com.iver.cit.gvsig.fmap.core.symbols.SimpleTextSymbol; |
190 | 10927 | jaume | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
191 | 18623 | jdominguez | import com.iver.cit.gvsig.gui.JComboBoxUnits; |
192 | 9745 | jaume | import com.iver.utiles.XMLEntity; |
193 | |||
194 | 13008 | jaume | |
195 | 9745 | jaume | /**
|
196 | 13189 | jvidal | * Creates the panel that is used to control the properties of a symbol in
|
197 | * order to modify or check them and to create a new one.
|
||
198 | 10927 | jaume | *
|
199 | 9745 | jaume | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
200 | 10927 | jaume | *
|
201 | 9745 | jaume | */
|
202 | public class SymbolEditor extends JPanel implements IWindow { |
||
203 | |||
204 | 12866 | jaume | private static Hashtable editorsByType; |
205 | 10679 | jaume | private WindowInfo wi;
|
206 | private JPanel pnlWest = null; |
||
207 | private JPanel pnlCenter = null; |
||
208 | private JPanel pnlPreview = null; |
||
209 | private JPanel pnlLayers = null; |
||
210 | private AcceptCancelPanel okCancelPanel;
|
||
211 | private ISymbol symbol;
|
||
212 | private SymbolPreviewer symbolPreview = null; |
||
213 | private JPanel pnlTypeAndUnits = null; |
||
214 | private JComboBox cmbType; |
||
215 | 18623 | jdominguez | private JComboBoxUnits cmbUnits;
|
216 | 10679 | jaume | private JTabbedPane tabbedPane = null; |
217 | private int shapeType; |
||
218 | private XMLEntity oldSymbolProperties;
|
||
219 | private ActionListener cmbTypeActionListener; |
||
220 | 9745 | jaume | |
221 | 12911 | jaume | private AbstractTypeSymbolEditor[] tabs; |
222 | 9745 | jaume | private SymbolLayerManager layerManager;
|
223 | 10679 | jaume | private boolean replacing = false; |
224 | 18623 | jdominguez | private JComboBoxUnitsReferenceSystem cmbUnitsReferenceSystem;
|
225 | 13189 | jvidal | /**
|
226 | * Constructor method
|
||
227 | *
|
||
228 | * @param symbol ISymbol
|
||
229 | * @param shapeType int
|
||
230 | */
|
||
231 | 10679 | jaume | public SymbolEditor(ISymbol symbol, int shapeType) { |
232 | 11919 | jaume | ////////// /-------------------------------------
|
233 | if (shapeType == FShape.TEXT) {
|
||
234 | this.symbol = symbol == null ? new SimpleTextSymbol(): symbol; |
||
235 | } else {
|
||
236 | ////////// /-------------------------------------
|
||
237 | 10959 | jaume | |
238 | 11919 | jaume | if (!(symbol instanceof IMultiLayerSymbol)) { |
239 | // this is a simple symbol (or null one); it will be
|
||
240 | // converted to a multilayer one to accept layer addition
|
||
241 | 16233 | jdominguez | IMultiLayerSymbol nSym = SymbologyFactory.createEmptyMultiLayerSymbol(shapeType); |
242 | 9745 | jaume | |
243 | 12805 | jaume | if (!(symbol instanceof FSymbol)) |
244 | nSym.addLayer(symbol); |
||
245 | 13189 | jvidal | |
246 | 12657 | jaume | if (symbol instanceof CartographicSupport) { |
247 | CartographicSupport cs = (CartographicSupport) symbol; |
||
248 | CartographicSupport nCs = (CartographicSupport) nSym; |
||
249 | nCs.setReferenceSystem(cs.getReferenceSystem()); |
||
250 | nCs.setUnit(cs.getUnit()); |
||
251 | } |
||
252 | |||
253 | 11919 | jaume | this.symbol = nSym;
|
254 | } else {
|
||
255 | this.symbol = symbol;
|
||
256 | } |
||
257 | 16233 | jdominguez | |
258 | // apply units and reference system to comboboxes
|
||
259 | if (this.symbol instanceof CartographicSupport) { |
||
260 | CartographicSupport cs = (CartographicSupport) this.symbol;
|
||
261 | getCmbUnits().setSelectedUnitIndex(cs.getUnit()); |
||
262 | getCmbUnitsReferenceSystem(). |
||
263 | setSelectedIndex(cs.getReferenceSystem()); |
||
264 | |||
265 | } |
||
266 | |||
267 | 10679 | jaume | } |
268 | this.oldSymbolProperties = this.symbol.getXMLEntity(); |
||
269 | this.shapeType = shapeType;
|
||
270 | initialize(); |
||
271 | } |
||
272 | 9745 | jaume | |
273 | 10679 | jaume | /**
|
274 | * This method initializes this
|
||
275 | 10927 | jaume | *
|
276 | 10679 | jaume | */
|
277 | private void initialize() { |
||
278 | 9745 | jaume | |
279 | 10679 | jaume | cmbTypeActionListener = new ActionListener() { |
280 | int prevIndex = -2; |
||
281 | 9745 | jaume | |
282 | 10679 | jaume | public void actionPerformed(ActionEvent e) { |
283 | int index = getCmbType().getSelectedIndex();
|
||
284 | if (prevIndex != index) {
|
||
285 | // needs to refresh
|
||
286 | prevIndex = index; |
||
287 | 9745 | jaume | |
288 | 12911 | jaume | AbstractTypeSymbolEditor options = (AbstractTypeSymbolEditor) getCmbType() |
289 | 10679 | jaume | .getSelectedItem(); |
290 | |||
291 | 11919 | jaume | ////////// /-------------------------------------
|
292 | if (layerManager!=null) { |
||
293 | ////////// /-------------------------------------
|
||
294 | ISymbol l = layerManager.getSelectedLayer(); |
||
295 | 10679 | jaume | |
296 | 11919 | jaume | // if the symbol is not null and is it managed by the "options" class
|
297 | // refresh the controls
|
||
298 | if (l != null |
||
299 | 12657 | jaume | && l.getClass().equals(options.getSymbolClass())) { |
300 | if (l instanceof CartographicSupport) { |
||
301 | CartographicSupport cs = (CartographicSupport) l; |
||
302 | getCmbUnits().setSelectedUnitIndex(cs.getUnit()); |
||
303 | getCmbUnitsReferenceSystem().setSelectedIndex(cs.getReferenceSystem()); |
||
304 | } |
||
305 | 11919 | jaume | options.refreshControls(l); |
306 | 12657 | jaume | } |
307 | 11919 | jaume | |
308 | replaceOptions(options); |
||
309 | ////////// /-------------------------------------
|
||
310 | } else {
|
||
311 | replaceOptions(options); |
||
312 | } |
||
313 | ////////// /-------------------------------------
|
||
314 | |||
315 | 10679 | jaume | } |
316 | } |
||
317 | }; |
||
318 | |||
319 | Comparator tabComparator = new Comparator() { |
||
320 | 9745 | jaume | public int compare(Object o1, Object o2) { |
321 | 12911 | jaume | if (!(o1 instanceof AbstractTypeSymbolEditor || o1 instanceof AbstractTypeSymbolEditor)) |
322 | 10679 | jaume | throw new IllegalArgumentException(PluginServices.getText( |
323 | this, "trying_to_add_a_non_TypeSymbolEditor_panel")); |
||
324 | 12911 | jaume | AbstractTypeSymbolEditor pnl1 = ( |
325 | AbstractTypeSymbolEditor) o1, pnl2 = (AbstractTypeSymbolEditor) o2; |
||
326 | 9745 | jaume | int result = pnl1.getName().compareTo(pnl2.getName());
|
327 | if (result == 0) |
||
328 | 10679 | jaume | throw new IllegalArgumentException(PluginServices.getText( |
329 | this, "two_panels_with_the_same_name")); |
||
330 | 9745 | jaume | return result;
|
331 | } |
||
332 | }; |
||
333 | 13189 | jvidal | |
334 | |||
335 | 9745 | jaume | TreeSet set = new TreeSet(tabComparator); |
336 | 12866 | jaume | ArrayList editors = (ArrayList) editorsByType.get(new Integer(shapeType)); |
337 | Class[] constrLocator = new Class[] {SymbolEditor.class}; |
||
338 | Object[] constrInitargs = new Object[] { this }; |
||
339 | for (int i = 0; i < editors.size(); i++) { |
||
340 | Class editorClass = (Class) editors.get(i); |
||
341 | try {
|
||
342 | Constructor c = editorClass.getConstructor(constrLocator);
|
||
343 | set.add(c.newInstance(constrInitargs)); |
||
344 | } catch (Exception e) { |
||
345 | 13004 | jaume | NotificationManager.addError(PluginServices.getText(this, "failed_installing_symbol_editor")+" " |
346 | +editorClass.getName(), e); |
||
347 | 13189 | jvidal | } |
348 | }; |
||
349 | 12911 | jaume | tabs = (AbstractTypeSymbolEditor[]) set
|
350 | .toArray(new AbstractTypeSymbolEditor[0]); |
||
351 | 9745 | jaume | |
352 | 10679 | jaume | this.setLayout(new BorderLayout()); |
353 | this.add(getPnlWest(), BorderLayout.WEST); |
||
354 | this.add(getPnlCenter(), BorderLayout.CENTER); |
||
355 | this.add(getOkCancelPanel(), BorderLayout.SOUTH); |
||
356 | 9745 | jaume | |
357 | 10679 | jaume | cmbTypeActionListener.actionPerformed(null);
|
358 | refresh(); |
||
359 | } |
||
360 | 13189 | jvidal | /**
|
361 | * Returns an array of tabs. The value of this array will depend on the
|
||
362 | * symbol selected. For example, if the symbol is composed by lines this
|
||
363 | * method will return tha tabs that allow the user to modify a simple line
|
||
364 | * symbol(in this case simple line and arrow decorator tabs)
|
||
365 | * @param sym
|
||
366 | * @return tabs[] AbstractTypeSymbolEditor[]
|
||
367 | */
|
||
368 | 12911 | jaume | private AbstractTypeSymbolEditor getOptionsForSymbol(ISymbol sym) {
|
369 | 10679 | jaume | if (sym == null) |
370 | return tabs[0]; |
||
371 | for (int i = 0; i < tabs.length; i++) |
||
372 | if (tabs[i].getSymbolClass().equals(sym.getClass()))
|
||
373 | return tabs[i];
|
||
374 | return tabs[0]; |
||
375 | } |
||
376 | 13189 | jvidal | /**
|
377 | * Initializes the OkCancel panel where the accept and cancel buttons
|
||
378 | * will be placed
|
||
379 | * @return okCancelPanel AcceptCancelPanel
|
||
380 | */
|
||
381 | 10679 | jaume | private AcceptCancelPanel getOkCancelPanel() {
|
382 | if (okCancelPanel == null) { |
||
383 | ActionListener action = new ActionListener() { |
||
384 | public void actionPerformed(ActionEvent e) { |
||
385 | if ("CANCEL".equals(e.getActionCommand())) { |
||
386 | symbol = SymbologyFactory.createSymbolFromXML( |
||
387 | oldSymbolProperties, null);
|
||
388 | } |
||
389 | PluginServices.getMDIManager().closeWindow( |
||
390 | SymbolEditor.this); |
||
391 | } |
||
392 | }; |
||
393 | okCancelPanel = new AcceptCancelPanel(action, action);
|
||
394 | } |
||
395 | return okCancelPanel;
|
||
396 | } |
||
397 | 9745 | jaume | |
398 | 10679 | jaume | public WindowInfo getWindowInfo() {
|
399 | if (wi == null) { |
||
400 | wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
||
401 | 22462 | vcaballero | wi.setWidth(720);
|
402 | 10679 | jaume | wi.setHeight(400);
|
403 | wi.setTitle(PluginServices.getText(this, "symbol_property_editor")); |
||
404 | } |
||
405 | return wi;
|
||
406 | } |
||
407 | 9745 | jaume | |
408 | 13729 | jaume | public ISymbol getSymbol() {
|
409 | if (symbol instanceof CartographicSupport) { |
||
410 | CartographicSupport cs = (CartographicSupport) symbol; |
||
411 | cs.setUnit(getUnit()); |
||
412 | cs.setReferenceSystem(getReferenceSystem()); |
||
413 | } |
||
414 | 18623 | jdominguez | //
|
415 | // if (symbol instanceof MultiLayerLineSymbol) {
|
||
416 | // MultiLayerLineSymbol mLineSym = (MultiLayerLineSymbol) symbol;
|
||
417 | // double lineWidth = 0;
|
||
418 | // for (int i = 0; i < mLineSym.getLayerCount(); i++) {
|
||
419 | // lineWidth = Math.max(lineWidth, ((ILineSymbol) mLineSym.getLayer(i)).getLineWidth());
|
||
420 | // }
|
||
421 | //
|
||
422 | // if (mLineSym.getLineWidth() != lineWidth)
|
||
423 | // mLineSym.setLineWidth(lineWidth);
|
||
424 | // }
|
||
425 | 10679 | jaume | return symbol;
|
426 | } |
||
427 | 13189 | jvidal | /**
|
428 | * Initializes the west panel
|
||
429 | * @return
|
||
430 | */
|
||
431 | 10679 | jaume | private JPanel getPnlWest() { |
432 | if (pnlWest == null) { |
||
433 | pnlWest = new JPanel(); |
||
434 | pnlWest.setLayout(new BorderLayout()); |
||
435 | pnlWest.add(getPnlPreview(), java.awt.BorderLayout.NORTH); |
||
436 | 11919 | jaume | ////////// /-------------------------------------
|
437 | if (symbol instanceof IMultiLayerSymbol) { |
||
438 | ////////// /-------------------------------------
|
||
439 | |||
440 | |||
441 | pnlWest.add(getPnlLayers(), java.awt.BorderLayout.SOUTH); |
||
442 | |||
443 | ////////// /-------------------------------------
|
||
444 | } // otherwise, no layer manager needed
|
||
445 | ////////// /-------------------------------------
|
||
446 | 10679 | jaume | } |
447 | return pnlWest;
|
||
448 | } |
||
449 | 13189 | jvidal | /**
|
450 | * Initializes the center panel that shows the properties of a symbol.
|
||
451 | *
|
||
452 | * @return pnlCenter JPanel
|
||
453 | */
|
||
454 | 10679 | jaume | private JPanel getPnlCenter() { |
455 | if (pnlCenter == null) { |
||
456 | pnlCenter = new JPanel(new BorderLayout()); |
||
457 | pnlCenter.setBorder(BorderFactory.createTitledBorder(null, |
||
458 | PluginServices.getText(this, "properties"))); |
||
459 | pnlCenter.add(getPnlTypeAndUnits(), java.awt.BorderLayout.NORTH); |
||
460 | } |
||
461 | return pnlCenter;
|
||
462 | } |
||
463 | 13189 | jvidal | /**
|
464 | * Initializes the preview panel that allows the user to see a previsualization
|
||
465 | * of the final symbol
|
||
466 | *
|
||
467 | * @return pnlPreview JPanel
|
||
468 | */
|
||
469 | 10679 | jaume | private JPanel getPnlPreview() { |
470 | if (pnlPreview == null) { |
||
471 | pnlPreview = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5)); |
||
472 | pnlPreview.setBorder(BorderFactory.createTitledBorder(null, |
||
473 | PluginServices.getText(this, "preview"))); |
||
474 | pnlPreview.add(getSymbolPreviewer()); |
||
475 | } |
||
476 | return pnlPreview;
|
||
477 | } |
||
478 | 13189 | jvidal | /**
|
479 | * Initializes the Layers panel that shows the different layers created that
|
||
480 | * compose a symbol.
|
||
481 | * @return pnlLayers JPanel
|
||
482 | */
|
||
483 | 10679 | jaume | private JPanel getPnlLayers() { |
484 | if (pnlLayers == null) { |
||
485 | pnlLayers = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5)); |
||
486 | pnlLayers.setBorder(BorderFactory.createTitledBorder(null, |
||
487 | PluginServices.getText(this, "layers"))); |
||
488 | pnlLayers.add(getLayerManager()); |
||
489 | } |
||
490 | return pnlLayers;
|
||
491 | } |
||
492 | 13189 | jvidal | /**
|
493 | * Obtains the layer manager used in the panel that shows the different layers
|
||
494 | * that compose the symbol.
|
||
495 | *
|
||
496 | * @return layerManager SymbolLayerManager
|
||
497 | */
|
||
498 | 10679 | jaume | private SymbolLayerManager getLayerManager() {
|
499 | if (layerManager == null) { |
||
500 | layerManager = new SymbolLayerManager(this); |
||
501 | } |
||
502 | return layerManager;
|
||
503 | } |
||
504 | 13189 | jvidal | /**
|
505 | * Obtains the symbol previewer used in the panel that shows the previsualization
|
||
506 | * of the final symbol.
|
||
507 | *
|
||
508 | * @return symbolPreview getSymbolPreviewer
|
||
509 | */
|
||
510 | 10679 | jaume | private SymbolPreviewer getSymbolPreviewer() {
|
511 | if (symbolPreview == null) { |
||
512 | symbolPreview = new SymbolPreviewer();
|
||
513 | 11297 | jaume | symbolPreview.setPreferredSize(new Dimension(150, 100)); |
514 | 9745 | jaume | |
515 | 10679 | jaume | } |
516 | return symbolPreview;
|
||
517 | } |
||
518 | 13189 | jvidal | /**
|
519 | * Initializes the type and units panel where two Jcomboboxes will be placed
|
||
520 | * in order to change the type and the units used in the map.
|
||
521 | *
|
||
522 | * @return pnlTypeAndUnits JPanel
|
||
523 | */
|
||
524 | 10679 | jaume | private JPanel getPnlTypeAndUnits() { |
525 | if (pnlTypeAndUnits == null) { |
||
526 | pnlTypeAndUnits = new JPanel(); |
||
527 | pnlTypeAndUnits.setLayout(new BorderLayout()); |
||
528 | JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING)); |
||
529 | aux.add(new JLabel(PluginServices.getText(this, "type"))); |
||
530 | aux.add(getCmbType()); |
||
531 | pnlTypeAndUnits.add(aux, BorderLayout.WEST);
|
||
532 | 9745 | jaume | |
533 | 10679 | jaume | aux = new JPanel(new FlowLayout(FlowLayout.LEADING)); |
534 | aux.add(new JLabel(PluginServices.getText(this, "units"))); |
||
535 | aux.add(getCmbUnits()); |
||
536 | 11548 | jaume | aux.add(getCmbUnitsReferenceSystem()); |
537 | 10679 | jaume | pnlTypeAndUnits.add(aux, BorderLayout.EAST);
|
538 | 9745 | jaume | |
539 | 10679 | jaume | } |
540 | return pnlTypeAndUnits;
|
||
541 | } |
||
542 | 13189 | jvidal | /**
|
543 | * Obtains the JCombobox to select the reference unit to be used in the
|
||
544 | * final representation of the map in this case there are two options (in
|
||
545 | * the paper and in the map).
|
||
546 | * @return
|
||
547 | */
|
||
548 | 18623 | jdominguez | private JComboBoxUnitsReferenceSystem getCmbUnitsReferenceSystem() {
|
549 | 11548 | jaume | if (cmbUnitsReferenceSystem == null) { |
550 | 18623 | jdominguez | cmbUnitsReferenceSystem = new JComboBoxUnitsReferenceSystem();
|
551 | 11548 | jaume | |
552 | } |
||
553 | |||
554 | return cmbUnitsReferenceSystem;
|
||
555 | } |
||
556 | 13189 | jvidal | /**
|
557 | * Returns the Jcombobox used to select the reference unit (centimeters,
|
||
558 | * milimeters and so on) to be used in the final representation of the map.
|
||
559 | *
|
||
560 | * @return cmbUnits JUnitsComboBox
|
||
561 | */
|
||
562 | 18623 | jdominguez | private JComboBoxUnits getCmbUnits() {
|
563 | 10679 | jaume | if (cmbUnits == null) { |
564 | 18623 | jdominguez | cmbUnits = new JComboBoxUnits();
|
565 | 10679 | jaume | } |
566 | return cmbUnits;
|
||
567 | } |
||
568 | 13189 | jvidal | /**
|
569 | * Returns the option selected in the reference unit Jcombobox
|
||
570 | *
|
||
571 | */
|
||
572 | 12561 | jaume | public int getUnit() { |
573 | return getCmbUnits().getSelectedUnitIndex();
|
||
574 | 11297 | jaume | } |
575 | 13729 | jaume | |
576 | public int getReferenceSystem() { |
||
577 | return getCmbUnitsReferenceSystem().getSelectedIndex();
|
||
578 | } |
||
579 | 13189 | jvidal | /**
|
580 | * Returns the Jcombobox used in the panel to select the type of symbol.
|
||
581 | *
|
||
582 | * @return cmbType JComboBox
|
||
583 | */
|
||
584 | 10679 | jaume | private JComboBox getCmbType() { |
585 | if (cmbType == null) { |
||
586 | cmbType = new JComboBox(tabs); |
||
587 | cmbType.addActionListener(cmbTypeActionListener); |
||
588 | 9745 | jaume | } |
589 | 10679 | jaume | return cmbType;
|
590 | 9745 | jaume | } |
591 | 13189 | jvidal | /**
|
592 | * Sets a layer to a symbol in order to create a final symbol composed
|
||
593 | * by different layers.
|
||
594 | *
|
||
595 | * @param layer
|
||
596 | */
|
||
597 | 10679 | jaume | protected void setLayerToSymbol(ISymbol layer) { |
598 | 14759 | jdominguez | int i = getLayerManager().getSelectedLayerIndex();
|
599 | 10679 | jaume | IMultiLayerSymbol s = (IMultiLayerSymbol) symbol; |
600 | if (i >= 0 && i < s.getLayerCount()) { |
||
601 | s.setLayer(s.getLayerCount() - 1 - i, layer);
|
||
602 | 12657 | jaume | |
603 | 9745 | jaume | } |
604 | 10679 | jaume | refresh(); |
605 | 9745 | jaume | } |
606 | |||
607 | 10679 | jaume | public void refresh() { |
608 | getSymbolPreviewer().setSymbol(symbol); |
||
609 | doLayout(); |
||
610 | repaint(); |
||
611 | 9745 | jaume | } |
612 | |||
613 | /**
|
||
614 | * <p>
|
||
615 | * Returns the type of the symbol that this panels is created for.<br>
|
||
616 | * </p>
|
||
617 | * <p>
|
||
618 | * Possible values returned by this method are
|
||
619 | 10679 | jaume | * <ol>
|
620 | * <li> <b> FShape.POINT </b>, for maker symbols </li>
|
||
621 | * <li> <b> FShape.POLYGON </b>, for fill symbols </li>
|
||
622 | * <li> <b> FShape.LINE </b>, for line symbols (not yet implemented) </li>
|
||
623 | * <li> <b> FShape.TEXT </b>, for text symbols (not yet implemented) </li>
|
||
624 | * <li> maybe some other in the future </li>
|
||
625 | * </ol>
|
||
626 | 9745 | jaume | * </p>
|
627 | 10927 | jaume | *
|
628 | 9745 | jaume | * @return
|
629 | */
|
||
630 | public int getShapeType() { |
||
631 | return shapeType;
|
||
632 | } |
||
633 | 13189 | jvidal | /**
|
634 | * Obtains a new layer
|
||
635 | *
|
||
636 | * @return sym ISymbol
|
||
637 | */
|
||
638 | 10679 | jaume | public ISymbol getNewLayer() {
|
639 | 12911 | jaume | ISymbol sym = ((AbstractTypeSymbolEditor) getCmbType().getSelectedItem()) |
640 | 10679 | jaume | .getLayer(); |
641 | 12657 | jaume | |
642 | return sym;
|
||
643 | 9745 | jaume | } |
644 | 10679 | jaume | |
645 | 12911 | jaume | private void replaceOptions(AbstractTypeSymbolEditor options) { |
646 | 10679 | jaume | if (!replacing) {
|
647 | replacing = true;
|
||
648 | if (tabbedPane != null) |
||
649 | getPnlCenter().remove(tabbedPane); |
||
650 | JPanel[] tabs = options.getTabs(); |
||
651 | tabbedPane = new JTabbedPane(); |
||
652 | tabbedPane.setPreferredSize(new Dimension(300, 300)); |
||
653 | for (int i = 0; i < tabs.length; i++) { |
||
654 | tabbedPane.addTab(tabs[i].getName(), tabs[i]); |
||
655 | } |
||
656 | getPnlCenter().add(tabbedPane, BorderLayout.CENTER);
|
||
657 | getPnlCenter().doLayout(); |
||
658 | replacing = false;
|
||
659 | } |
||
660 | } |
||
661 | |||
662 | 13189 | jvidal | |
663 | 10679 | jaume | public void setOptionsPageFor(ISymbol symbol) { |
664 | 12911 | jaume | AbstractTypeSymbolEditor options = getOptionsForSymbol(symbol); |
665 | 12657 | jaume | |
666 | 10679 | jaume | options.refreshControls(symbol); |
667 | 14736 | jdominguez | getCmbType().setSelectedItem(options); |
668 | 10679 | jaume | } |
669 | 13189 | jvidal | /**
|
670 | * Obtains the units to be used for the reference system.
|
||
671 | *
|
||
672 | */
|
||
673 | 12561 | jaume | public int getUnitsReferenceSystem() { |
674 | return cmbUnitsReferenceSystem.getSelectedIndex();
|
||
675 | } |
||
676 | 12657 | jaume | |
677 | 12866 | jaume | public static void addSymbolEditorPanel(Class abstractTypeSymbolEditorPanelClass, int shapeType) { |
678 | if (editorsByType == null) { |
||
679 | editorsByType = new Hashtable(); |
||
680 | } |
||
681 | 13189 | jvidal | |
682 | 12866 | jaume | Integer key = new Integer(shapeType); |
683 | ArrayList l = (ArrayList) editorsByType.get(key); |
||
684 | if (l == null) { |
||
685 | l = new ArrayList(); |
||
686 | } |
||
687 | l.add(abstractTypeSymbolEditorPanelClass); |
||
688 | 13189 | jvidal | |
689 | 12866 | jaume | editorsByType.put(key, l); |
690 | } |
||
691 | 12657 | jaume | |
692 | 12866 | jaume | |
693 | 9745 | jaume | } |