svn-gvsig-desktop / tags / v2_0_0_Build_2040 / libraries / org.gvsig.symbology / org.gvsig.symbology.swing / org.gvsig.symbology.swing.api / src / main / java / org / gvsig / app / gui / styling / SymbolEditor.java @ 37287
History | View | Annotate | Download (21.9 KB)
1 |
/* 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 |
*
|
44 |
* $Id: SymbolEditor.java 30892 2009-09-21 12:02:19Z cordinyana $
|
45 |
* $Log$
|
46 |
* 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 |
* refactored SymboSelector (added support for multishapedsymbol)
|
51 |
*
|
52 |
* Revision 1.20 2007/08/21 09:32:41 jvidal
|
53 |
* javadoc
|
54 |
*
|
55 |
* Revision 1.19 2007/08/10 06:09:57 jaume
|
56 |
* imports fixed
|
57 |
*
|
58 |
* Revision 1.18 2007/08/10 06:06:05 jaume
|
59 |
* translations and error messages
|
60 |
*
|
61 |
* Revision 1.17 2007/08/03 11:29:13 jaume
|
62 |
* refactored AbstractTypeSymbolEditorPanel class name to AbastractTypeSymbolEditor
|
63 |
*
|
64 |
* Revision 1.16 2007/08/01 13:01:43 jaume
|
65 |
* refactored to be pluggable
|
66 |
*
|
67 |
* Revision 1.15 2007/07/30 12:56:04 jaume
|
68 |
* 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 |
* finished (maybe) LineFillSymbol
|
72 |
*
|
73 |
* Revision 1.13 2007/07/26 12:28:29 jaume
|
74 |
* maybe finished ArrowMarkerSymbol and ArrowDecoratorStyle
|
75 |
*
|
76 |
* Revision 1.12 2007/07/18 06:56:03 jaume
|
77 |
* continuing with cartographic support
|
78 |
*
|
79 |
* Revision 1.11 2007/07/12 10:43:55 jaume
|
80 |
* *** empty log message ***
|
81 |
*
|
82 |
* Revision 1.10 2007/06/29 13:07:33 jaume
|
83 |
* +PictureLineSymbol
|
84 |
*
|
85 |
* Revision 1.9 2007/05/31 09:36:22 jaume
|
86 |
* *** empty log message ***
|
87 |
*
|
88 |
* Revision 1.8 2007/05/29 15:47:06 jaume
|
89 |
* *** empty log message ***
|
90 |
*
|
91 |
* Revision 1.7 2007/05/09 16:08:14 jaume
|
92 |
* *** empty log message ***
|
93 |
*
|
94 |
* Revision 1.6 2007/05/08 15:44:07 jaume
|
95 |
* *** empty log message ***
|
96 |
*
|
97 |
* Revision 1.5 2007/04/20 07:54:38 jaume
|
98 |
* *** empty log message ***
|
99 |
*
|
100 |
* Revision 1.4 2007/03/28 16:44:08 jaume
|
101 |
* *** empty log message ***
|
102 |
*
|
103 |
* Revision 1.3 2007/03/27 09:49:03 jaume
|
104 |
* *** empty log message ***
|
105 |
*
|
106 |
* Revision 1.2 2007/03/09 11:25:00 jaume
|
107 |
* 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 |
package org.gvsig.app.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 |
import java.lang.reflect.Constructor; |
167 |
import java.util.ArrayList; |
168 |
import java.util.Comparator; |
169 |
import java.util.Hashtable; |
170 |
import java.util.Iterator; |
171 |
import java.util.List; |
172 |
import java.util.TreeSet; |
173 |
|
174 |
import javax.swing.BorderFactory; |
175 |
import javax.swing.JComboBox; |
176 |
import javax.swing.JLabel; |
177 |
import javax.swing.JPanel; |
178 |
import javax.swing.JTabbedPane; |
179 |
|
180 |
import org.slf4j.Logger; |
181 |
import org.slf4j.LoggerFactory; |
182 |
|
183 |
import org.gvsig.andami.PluginServices; |
184 |
import org.gvsig.andami.messages.NotificationManager; |
185 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
186 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
187 |
import org.gvsig.app.gui.JComboBoxUnits; |
188 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
189 |
import org.gvsig.fmap.geom.GeometryLocator; |
190 |
import org.gvsig.fmap.geom.GeometryManager; |
191 |
import org.gvsig.fmap.geom.type.GeometryType; |
192 |
import org.gvsig.fmap.geom.type.GeometryTypeNotSupportedException; |
193 |
import org.gvsig.fmap.geom.type.GeometryTypeNotValidException; |
194 |
import org.gvsig.fmap.mapcontext.MapContextLocator; |
195 |
import org.gvsig.fmap.mapcontext.MapContextManager; |
196 |
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
197 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
198 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
199 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
200 |
import org.gvsig.i18n.Messages; |
201 |
|
202 |
/**
|
203 |
* Creates the panel that is used to control the properties of a symbol in
|
204 |
* order to modify or check them and to create a new one.
|
205 |
*
|
206 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
207 |
*
|
208 |
*/
|
209 |
public class SymbolEditor extends JPanel implements IWindow { |
210 |
private static final long serialVersionUID = 9209260593958625497L; |
211 |
|
212 |
private static final GeometryManager GEOMETRY_MANAGER = |
213 |
GeometryLocator.getGeometryManager(); |
214 |
|
215 |
private static final Logger LOG = |
216 |
LoggerFactory.getLogger(SymbolEditor.class); |
217 |
|
218 |
private static Hashtable editorsByType; |
219 |
private WindowInfo wi;
|
220 |
private JPanel pnlWest = null; |
221 |
private JPanel pnlCenter = null; |
222 |
private JPanel pnlPreview = null; |
223 |
private JPanel pnlLayers = null; |
224 |
private AcceptCancelPanel okCancelPanel;
|
225 |
private ISymbol symbol;
|
226 |
private SymbolPreviewer symbolPreview = null; |
227 |
private JPanel pnlTypeAndUnits = null; |
228 |
private JComboBox cmbType; |
229 |
private JComboBoxUnits cmbUnits;
|
230 |
private JTabbedPane tabbedPane = null; |
231 |
private GeometryType shapeType;
|
232 |
private ActionListener cmbTypeActionListener; |
233 |
|
234 |
private AbstractTypeSymbolEditor[] tabs; |
235 |
private SymbolLayerManager layerManager;
|
236 |
private boolean replacing = false; |
237 |
private JComboBoxUnitsReferenceSystem cmbUnitsReferenceSystem;
|
238 |
|
239 |
private ISymbol oldSymbol;
|
240 |
|
241 |
private MapContextManager mapContextManager = MapContextLocator
|
242 |
.getMapContextManager(); |
243 |
|
244 |
|
245 |
public SymbolEditor(ISymbol symbol, GeometryType geometryType) {
|
246 |
super();
|
247 |
initialize(symbol, geometryType); |
248 |
} |
249 |
|
250 |
public SymbolEditor(ISymbol symbol, int shapeType) { |
251 |
super();
|
252 |
try {
|
253 |
GeometryType geometryType = GEOMETRY_MANAGER.getGeometryType(shapeType, SUBTYPES.GEOM2D); |
254 |
initialize(symbol, geometryType); |
255 |
} catch (GeometryTypeNotSupportedException e1) {
|
256 |
LOG.error("Impossible to get the geometry type", e1);
|
257 |
} catch (GeometryTypeNotValidException e1) {
|
258 |
LOG.error("Impossible to get the geometry type", e1);
|
259 |
} |
260 |
} |
261 |
|
262 |
|
263 |
/**
|
264 |
* Constructor method
|
265 |
*
|
266 |
* @param symbol ISymbol
|
267 |
* @param shapeType int
|
268 |
*/
|
269 |
private void initialize(ISymbol symbol, GeometryType shapeType) { |
270 |
////////// /-------------------------------------
|
271 |
// removing the Geometry.TYPES.TEXT: this code can not be executed
|
272 |
// if (shapeType == Geometry.TYPES.TEXT) {
|
273 |
//// this.symbol = symbol == null ? new SimpleTextSymbol(): symbol;
|
274 |
// this.symbol = symbol == null ? SymbologyLocator.getSymbologyManager().createSimpleTextSymbol(): symbol;
|
275 |
// } else {
|
276 |
////////// /-------------------------------------
|
277 |
|
278 |
if (!(symbol instanceof IMultiLayerSymbol)) { |
279 |
// this is a simple symbol (or null one); it will be
|
280 |
// converted to a multilayer one to accept layer addition
|
281 |
IMultiLayerSymbol nSym = |
282 |
mapContextManager.getSymbolManager() |
283 |
.createMultiLayerSymbol(shapeType.getType()); |
284 |
|
285 |
// if (!(symbol instanceof FSymbol)) {
|
286 |
nSym.addLayer(symbol); |
287 |
// }
|
288 |
|
289 |
if (symbol instanceof CartographicSupport) { |
290 |
CartographicSupport cs = (CartographicSupport) symbol; |
291 |
CartographicSupport nCs = (CartographicSupport) nSym; |
292 |
nCs.setReferenceSystem(cs.getReferenceSystem()); |
293 |
nCs.setUnit(cs.getUnit()); |
294 |
} |
295 |
|
296 |
this.symbol = nSym;
|
297 |
} else {
|
298 |
this.symbol = symbol;
|
299 |
} |
300 |
|
301 |
// apply units and reference system to comboboxes
|
302 |
if (this.symbol instanceof CartographicSupport) { |
303 |
CartographicSupport cs = (CartographicSupport) this.symbol;
|
304 |
getCmbUnits().setSelectedUnitIndex(cs.getUnit()); |
305 |
getCmbUnitsReferenceSystem(). |
306 |
setSelectedIndex(cs.getReferenceSystem()); |
307 |
|
308 |
} |
309 |
|
310 |
// }
|
311 |
try {
|
312 |
this.oldSymbol = (ISymbol) this.symbol.clone(); |
313 |
} catch (CloneNotSupportedException e) { |
314 |
NotificationManager.addWarning("Symbol layer", e);
|
315 |
} |
316 |
this.shapeType = shapeType;
|
317 |
initialize(); |
318 |
} |
319 |
|
320 |
/**
|
321 |
* This method initializes this
|
322 |
*
|
323 |
*/
|
324 |
private void initialize() { |
325 |
|
326 |
cmbTypeActionListener = new ActionListener() { |
327 |
int prevIndex = -2; |
328 |
|
329 |
public void actionPerformed(ActionEvent e) { |
330 |
int index = getCmbType().getSelectedIndex();
|
331 |
if (prevIndex != index) {
|
332 |
// needs to refresh
|
333 |
prevIndex = index; |
334 |
|
335 |
AbstractTypeSymbolEditor options = (AbstractTypeSymbolEditor) getCmbType() |
336 |
.getSelectedItem(); |
337 |
|
338 |
////////// /-------------------------------------
|
339 |
if (layerManager!=null) { |
340 |
////////// /-------------------------------------
|
341 |
ISymbol l = layerManager.getSelectedLayer(); |
342 |
|
343 |
// if the symbol is not null and is it managed by the "options" class
|
344 |
// refresh the controls
|
345 |
if (l != null |
346 |
// && l.getClass().equals(options.getSymbolClass())) {
|
347 |
&& options.canManageSymbol(l)) { |
348 |
if (l instanceof CartographicSupport) { |
349 |
CartographicSupport cs = (CartographicSupport) l; |
350 |
getCmbUnits().setSelectedUnitIndex(cs.getUnit()); |
351 |
getCmbUnitsReferenceSystem().setSelectedIndex(cs.getReferenceSystem()); |
352 |
} |
353 |
options.refreshControls(l); |
354 |
} |
355 |
|
356 |
replaceOptions(options); |
357 |
////////// /-------------------------------------
|
358 |
} else {
|
359 |
replaceOptions(options); |
360 |
} |
361 |
////////// /-------------------------------------
|
362 |
|
363 |
} |
364 |
} |
365 |
}; |
366 |
|
367 |
Comparator tabComparator = new Comparator() { |
368 |
public int compare(Object o1, Object o2) { |
369 |
if (!(o1 instanceof AbstractTypeSymbolEditor || o1 instanceof AbstractTypeSymbolEditor)) { |
370 |
throw new IllegalArgumentException(Messages.getText("trying_to_add_a_non_TypeSymbolEditor_panel")); |
371 |
} |
372 |
AbstractTypeSymbolEditor pnl1 = ( |
373 |
AbstractTypeSymbolEditor) o1, pnl2 = (AbstractTypeSymbolEditor) o2; |
374 |
int result = pnl1.getName().compareTo(pnl2.getName());
|
375 |
if (result == 0) { |
376 |
throw new IllegalArgumentException(Messages.getText("two_panels_with_the_same_name")); |
377 |
} |
378 |
return result;
|
379 |
} |
380 |
}; |
381 |
|
382 |
|
383 |
TreeSet set = new TreeSet(tabComparator); |
384 |
List editors = getSymbolsByType(shapeType);
|
385 |
Class[] constrLocator = new Class[] {SymbolEditor.class}; |
386 |
Object[] constrInitargs = new Object[] { this }; |
387 |
for (int i = 0; i < editors.size(); i++) { |
388 |
Class editorClass = (Class) editors.get(i); |
389 |
try {
|
390 |
Constructor c = editorClass.getConstructor(constrLocator);
|
391 |
set.add(c.newInstance(constrInitargs)); |
392 |
} catch (Exception e) { |
393 |
NotificationManager.addError(Messages.getText("failed_installing_symbol_editor")+" " |
394 |
+editorClass.getName(), e); |
395 |
} |
396 |
}; |
397 |
tabs = (AbstractTypeSymbolEditor[]) set
|
398 |
.toArray(new AbstractTypeSymbolEditor[0]); |
399 |
|
400 |
this.setLayout(new BorderLayout()); |
401 |
this.add(getPnlWest(), BorderLayout.WEST); |
402 |
this.add(getPnlCenter(), BorderLayout.CENTER); |
403 |
this.add(getOkCancelPanel(), BorderLayout.SOUTH); |
404 |
|
405 |
cmbTypeActionListener.actionPerformed(null);
|
406 |
refresh(); |
407 |
} |
408 |
/**
|
409 |
* Returns an array of tabs. The value of this array will depend on the
|
410 |
* symbol selected. For example, if the symbol is composed by lines this
|
411 |
* method will return tha tabs that allow the user to modify a simple line
|
412 |
* symbol(in this case simple line and arrow decorator tabs)
|
413 |
* @param sym
|
414 |
* @return tabs[] AbstractTypeSymbolEditor[]
|
415 |
*/
|
416 |
private AbstractTypeSymbolEditor getOptionsForSymbol(ISymbol sym) {
|
417 |
if (sym == null) { |
418 |
return tabs[0]; |
419 |
} |
420 |
for (int i = 0; i < tabs.length; i++) { |
421 |
// if (tabs[i].getSymbolClass().equals(sym.getClass())) {
|
422 |
if (tabs[i].canManageSymbol(sym)) {
|
423 |
return tabs[i];
|
424 |
} |
425 |
} |
426 |
return tabs[0]; |
427 |
} |
428 |
/**
|
429 |
* Initializes the OkCancel panel where the accept and cancel buttons
|
430 |
* will be placed
|
431 |
* @return okCancelPanel AcceptCancelPanel
|
432 |
*/
|
433 |
private AcceptCancelPanel getOkCancelPanel() {
|
434 |
if (okCancelPanel == null) { |
435 |
ActionListener action = new ActionListener() { |
436 |
public void actionPerformed(ActionEvent e) { |
437 |
if ("CANCEL".equals(e.getActionCommand())) { |
438 |
symbol = oldSymbol; |
439 |
} |
440 |
PluginServices.getMDIManager().closeWindow( |
441 |
SymbolEditor.this); |
442 |
} |
443 |
}; |
444 |
okCancelPanel = new AcceptCancelPanel(action, action);
|
445 |
} |
446 |
return okCancelPanel;
|
447 |
} |
448 |
|
449 |
public WindowInfo getWindowInfo() {
|
450 |
if (wi == null) { |
451 |
wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
452 |
wi.setWidth(650);
|
453 |
wi.setHeight(400);
|
454 |
wi.setTitle(Messages.getText("symbol_property_editor"));
|
455 |
} |
456 |
return wi;
|
457 |
} |
458 |
|
459 |
public ISymbol getSymbol() {
|
460 |
if (symbol instanceof CartographicSupport) { |
461 |
CartographicSupport cs = (CartographicSupport) symbol; |
462 |
cs.setUnit(getUnit()); |
463 |
cs.setReferenceSystem(getReferenceSystem()); |
464 |
} |
465 |
//
|
466 |
// if (symbol instanceof MultiLayerLineSymbol) {
|
467 |
// MultiLayerLineSymbol mLineSym = (MultiLayerLineSymbol) symbol;
|
468 |
// double lineWidth = 0;
|
469 |
// for (int i = 0; i < mLineSym.getLayerCount(); i++) {
|
470 |
// lineWidth = Math.max(lineWidth, ((ILineSymbol) mLineSym.getLayer(i)).getLineWidth());
|
471 |
// }
|
472 |
//
|
473 |
// if (mLineSym.getLineWidth() != lineWidth)
|
474 |
// mLineSym.setLineWidth(lineWidth);
|
475 |
// }
|
476 |
return symbol;
|
477 |
} |
478 |
/**
|
479 |
* Initializes the west panel
|
480 |
* @return
|
481 |
*/
|
482 |
private JPanel getPnlWest() { |
483 |
if (pnlWest == null) { |
484 |
pnlWest = new JPanel(); |
485 |
pnlWest.setLayout(new BorderLayout()); |
486 |
pnlWest.add(getPnlPreview(), java.awt.BorderLayout.NORTH); |
487 |
////////// /-------------------------------------
|
488 |
if (symbol instanceof IMultiLayerSymbol) { |
489 |
////////// /-------------------------------------
|
490 |
|
491 |
|
492 |
pnlWest.add(getPnlLayers(), java.awt.BorderLayout.SOUTH); |
493 |
|
494 |
////////// /-------------------------------------
|
495 |
} // otherwise, no layer manager needed
|
496 |
////////// /-------------------------------------
|
497 |
} |
498 |
return pnlWest;
|
499 |
} |
500 |
/**
|
501 |
* Initializes the center panel that shows the properties of a symbol.
|
502 |
*
|
503 |
* @return pnlCenter JPanel
|
504 |
*/
|
505 |
private JPanel getPnlCenter() { |
506 |
if (pnlCenter == null) { |
507 |
pnlCenter = new JPanel(new BorderLayout()); |
508 |
pnlCenter.setBorder(BorderFactory.createTitledBorder(null, |
509 |
Messages.getText("properties")));
|
510 |
pnlCenter.add(getPnlTypeAndUnits(), java.awt.BorderLayout.NORTH); |
511 |
} |
512 |
return pnlCenter;
|
513 |
} |
514 |
/**
|
515 |
* Initializes the preview panel that allows the user to see a previsualization
|
516 |
* of the final symbol
|
517 |
*
|
518 |
* @return pnlPreview JPanel
|
519 |
*/
|
520 |
private JPanel getPnlPreview() { |
521 |
if (pnlPreview == null) { |
522 |
pnlPreview = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5)); |
523 |
pnlPreview.setBorder(BorderFactory.createTitledBorder(null, |
524 |
Messages.getText("preview")));
|
525 |
pnlPreview.add(getSymbolPreviewer()); |
526 |
} |
527 |
return pnlPreview;
|
528 |
} |
529 |
/**
|
530 |
* Initializes the Layers panel that shows the different layers created that
|
531 |
* compose a symbol.
|
532 |
* @return pnlLayers JPanel
|
533 |
*/
|
534 |
private JPanel getPnlLayers() { |
535 |
if (pnlLayers == null) { |
536 |
pnlLayers = new JPanel(new FlowLayout(FlowLayout.CENTER, 5, 5)); |
537 |
pnlLayers.setBorder(BorderFactory.createTitledBorder(null, |
538 |
Messages.getText("layers")));
|
539 |
pnlLayers.add(getLayerManager()); |
540 |
} |
541 |
return pnlLayers;
|
542 |
} |
543 |
/**
|
544 |
* Obtains the layer manager used in the panel that shows the different layers
|
545 |
* that compose the symbol.
|
546 |
*
|
547 |
* @return layerManager SymbolLayerManager
|
548 |
*/
|
549 |
private SymbolLayerManager getLayerManager() {
|
550 |
if (layerManager == null) { |
551 |
layerManager = new SymbolLayerManager(this); |
552 |
} |
553 |
return layerManager;
|
554 |
} |
555 |
/**
|
556 |
* Obtains the symbol previewer used in the panel that shows the previsualization
|
557 |
* of the final symbol.
|
558 |
*
|
559 |
* @return symbolPreview getSymbolPreviewer
|
560 |
*/
|
561 |
private SymbolPreviewer getSymbolPreviewer() {
|
562 |
if (symbolPreview == null) { |
563 |
symbolPreview = new SymbolPreviewer();
|
564 |
symbolPreview.setPreferredSize(new Dimension(150, 100)); |
565 |
|
566 |
} |
567 |
return symbolPreview;
|
568 |
} |
569 |
/**
|
570 |
* Initializes the type and units panel where two Jcomboboxes will be placed
|
571 |
* in order to change the type and the units used in the map.
|
572 |
*
|
573 |
* @return pnlTypeAndUnits JPanel
|
574 |
*/
|
575 |
private JPanel getPnlTypeAndUnits() { |
576 |
if (pnlTypeAndUnits == null) { |
577 |
pnlTypeAndUnits = new JPanel(); |
578 |
pnlTypeAndUnits.setLayout(new BorderLayout()); |
579 |
JPanel aux = new JPanel(new FlowLayout(FlowLayout.LEADING)); |
580 |
aux.add(new JLabel(Messages.getText("type"))); |
581 |
aux.add(getCmbType()); |
582 |
pnlTypeAndUnits.add(aux, BorderLayout.WEST);
|
583 |
|
584 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING)); |
585 |
aux.add(new JLabel(Messages.getText("units"))); |
586 |
aux.add(getCmbUnits()); |
587 |
aux.add(getCmbUnitsReferenceSystem()); |
588 |
pnlTypeAndUnits.add(aux, BorderLayout.EAST);
|
589 |
|
590 |
} |
591 |
return pnlTypeAndUnits;
|
592 |
} |
593 |
/**
|
594 |
* Obtains the JCombobox to select the reference unit to be used in the
|
595 |
* final representation of the map in this case there are two options (in
|
596 |
* the paper and in the map).
|
597 |
* @return
|
598 |
*/
|
599 |
private JComboBoxUnitsReferenceSystem getCmbUnitsReferenceSystem() {
|
600 |
if (cmbUnitsReferenceSystem == null) { |
601 |
cmbUnitsReferenceSystem = new JComboBoxUnitsReferenceSystem();
|
602 |
|
603 |
} |
604 |
|
605 |
return cmbUnitsReferenceSystem;
|
606 |
} |
607 |
/**
|
608 |
* Returns the Jcombobox used to select the reference unit (centimeters,
|
609 |
* milimeters and so on) to be used in the final representation of the map.
|
610 |
*
|
611 |
* @return cmbUnits JUnitsComboBox
|
612 |
*/
|
613 |
private JComboBoxUnits getCmbUnits() {
|
614 |
if (cmbUnits == null) { |
615 |
cmbUnits = new JComboBoxUnits();
|
616 |
} |
617 |
return cmbUnits;
|
618 |
} |
619 |
/**
|
620 |
* Returns the option selected in the reference unit Jcombobox
|
621 |
*
|
622 |
*/
|
623 |
public int getUnit() { |
624 |
return getCmbUnits().getSelectedUnitIndex();
|
625 |
} |
626 |
|
627 |
public int getReferenceSystem() { |
628 |
return getCmbUnitsReferenceSystem().getSelectedIndex();
|
629 |
} |
630 |
/**
|
631 |
* Returns the Jcombobox used in the panel to select the type of symbol.
|
632 |
*
|
633 |
* @return cmbType JComboBox
|
634 |
*/
|
635 |
private JComboBox getCmbType() { |
636 |
if (cmbType == null) { |
637 |
cmbType = new JComboBox(tabs); |
638 |
cmbType.addActionListener(cmbTypeActionListener); |
639 |
} |
640 |
return cmbType;
|
641 |
} |
642 |
/**
|
643 |
* Sets a layer to a symbol in order to create a final symbol composed
|
644 |
* by different layers.
|
645 |
*
|
646 |
* @param layer
|
647 |
*/
|
648 |
protected void setLayerToSymbol(ISymbol layer) { |
649 |
int i = getLayerManager().getSelectedLayerIndex();
|
650 |
IMultiLayerSymbol s = (IMultiLayerSymbol) symbol; |
651 |
if (i >= 0 && i < s.getLayerCount()) { |
652 |
s.setLayer(s.getLayerCount() - 1 - i, layer);
|
653 |
|
654 |
} |
655 |
refresh(); |
656 |
} |
657 |
|
658 |
public void refresh() { |
659 |
getSymbolPreviewer().setSymbol(symbol); |
660 |
doLayout(); |
661 |
repaint(); |
662 |
} |
663 |
|
664 |
/**
|
665 |
* <p>
|
666 |
* Returns the type of the symbol that this panels is created for.<br>
|
667 |
* </p>
|
668 |
* <p>
|
669 |
* Possible values returned by this method are
|
670 |
* <ol>
|
671 |
* <li> <b> Geometry.TYPES.POINT </b>, for maker symbols </li>
|
672 |
* <li> <b> Geometry.TYPES.SURFACE </b>, for fill symbols </li>
|
673 |
* <li> <b> Geometry.TYPES.CURVE </b>, for line symbols (not yet implemented) </li>
|
674 |
* <li> <b> Geometry.TYPES.TEXT </b>, for text symbols (not yet implemented) </li>
|
675 |
* <li> maybe some other in the future </li>
|
676 |
* </ol>
|
677 |
* </p>
|
678 |
*
|
679 |
* @return
|
680 |
*/
|
681 |
public int getShapeType() { |
682 |
return shapeType.getType();
|
683 |
} |
684 |
/**
|
685 |
* Obtains a new layer
|
686 |
*
|
687 |
* @return sym ISymbol
|
688 |
*/
|
689 |
public ISymbol getNewLayer() {
|
690 |
ISymbol sym = ((AbstractTypeSymbolEditor) getCmbType().getSelectedItem()) |
691 |
.getLayer(); |
692 |
|
693 |
return sym;
|
694 |
} |
695 |
|
696 |
private void replaceOptions(AbstractTypeSymbolEditor options) { |
697 |
if (!replacing) {
|
698 |
replacing = true;
|
699 |
if (tabbedPane != null) { |
700 |
getPnlCenter().remove(tabbedPane); |
701 |
} |
702 |
JPanel[] tabs = options.getTabs(); |
703 |
tabbedPane = new JTabbedPane(); |
704 |
tabbedPane.setPreferredSize(new Dimension(300, 300)); |
705 |
for (int i = 0; i < tabs.length; i++) { |
706 |
tabbedPane.addTab(tabs[i].getName(), tabs[i]); |
707 |
} |
708 |
getPnlCenter().add(tabbedPane, BorderLayout.CENTER);
|
709 |
getPnlCenter().doLayout(); |
710 |
replacing = false;
|
711 |
} |
712 |
} |
713 |
|
714 |
|
715 |
public void setOptionsPageFor(ISymbol symbol) { |
716 |
AbstractTypeSymbolEditor options = getOptionsForSymbol(symbol); |
717 |
|
718 |
options.refreshControls(symbol); |
719 |
getCmbType().setSelectedItem(options); |
720 |
} |
721 |
/**
|
722 |
* Obtains the units to be used for the reference system.
|
723 |
*
|
724 |
*/
|
725 |
public int getUnitsReferenceSystem() { |
726 |
return cmbUnitsReferenceSystem.getSelectedIndex();
|
727 |
} |
728 |
|
729 |
public static void addSymbolEditorPanel(Class abstractTypeSymbolEditorPanelClass, int shapeType) { |
730 |
if (editorsByType == null) { |
731 |
editorsByType = new Hashtable(); |
732 |
} |
733 |
|
734 |
Integer key = new Integer(shapeType); |
735 |
ArrayList l = (ArrayList) editorsByType.get(key); |
736 |
if (l == null) { |
737 |
l = new ArrayList(); |
738 |
} |
739 |
l.add(abstractTypeSymbolEditorPanelClass); |
740 |
|
741 |
editorsByType.put(key, l); |
742 |
} |
743 |
|
744 |
private static List getSymbolsByType(GeometryType geometryType){ |
745 |
Iterator it = editorsByType.keySet().iterator();
|
746 |
while (it.hasNext()){
|
747 |
int currentType = (Integer)it.next(); |
748 |
if (geometryType.isTypeOf(currentType)){
|
749 |
return (List)editorsByType.get(currentType); |
750 |
} |
751 |
} |
752 |
return new ArrayList(); |
753 |
} |
754 |
|
755 |
public Object getWindowProfile() { |
756 |
return WindowInfo.DIALOG_PROFILE;
|
757 |
} |
758 |
|
759 |
} |