root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / gui / styling / SymbolEditor.java @ 21299
History | View | Annotate | Download (19.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 21299 2008-06-06 10:23:57Z vcaballero $
|
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 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 |
import java.lang.reflect.Constructor; |
167 |
import java.util.ArrayList; |
168 |
import java.util.Comparator; |
169 |
import java.util.Hashtable; |
170 |
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.fmap.geom.Geometry; |
179 |
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport; |
180 |
import org.gvsig.fmap.mapcontext.rendering.symbols.FSymbol; |
181 |
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol; |
182 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
183 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SimpleTextSymbol; |
184 |
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory; |
185 |
import org.gvsig.gui.beans.AcceptCancelPanel; |
186 |
|
187 |
import com.iver.andami.PluginServices; |
188 |
import com.iver.andami.messages.NotificationManager; |
189 |
import com.iver.andami.ui.mdiManager.IWindow; |
190 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
191 |
import com.iver.cit.gvsig.gui.JComboBoxUnits; |
192 |
import com.iver.utiles.XMLEntity; |
193 |
|
194 |
|
195 |
/**
|
196 |
* 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 |
*
|
199 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
200 |
*
|
201 |
*/
|
202 |
public class SymbolEditor extends JPanel implements IWindow { |
203 |
|
204 |
private static Hashtable editorsByType; |
205 |
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 |
private JComboBoxUnits cmbUnits;
|
216 |
private JTabbedPane tabbedPane = null; |
217 |
private int shapeType; |
218 |
private XMLEntity oldSymbolProperties;
|
219 |
private ActionListener cmbTypeActionListener; |
220 |
|
221 |
private AbstractTypeSymbolEditor[] tabs; |
222 |
private SymbolLayerManager layerManager;
|
223 |
private boolean replacing = false; |
224 |
private JComboBoxUnitsReferenceSystem cmbUnitsReferenceSystem;
|
225 |
/**
|
226 |
* Constructor method
|
227 |
*
|
228 |
* @param symbol ISymbol
|
229 |
* @param shapeType int
|
230 |
*/
|
231 |
public SymbolEditor(ISymbol symbol, int shapeType) { |
232 |
////////// /-------------------------------------
|
233 |
if (shapeType == Geometry.TYPES.TEXT) {
|
234 |
this.symbol = symbol == null ? new SimpleTextSymbol(): symbol; |
235 |
} else {
|
236 |
////////// /-------------------------------------
|
237 |
|
238 |
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 |
IMultiLayerSymbol nSym = SymbologyFactory.createEmptyMultiLayerSymbol(shapeType); |
242 |
|
243 |
if (!(symbol instanceof FSymbol)) |
244 |
nSym.addLayer(symbol); |
245 |
|
246 |
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 |
this.symbol = nSym;
|
254 |
} else {
|
255 |
this.symbol = symbol;
|
256 |
} |
257 |
|
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 |
} |
268 |
this.oldSymbolProperties = this.symbol.getXMLEntity(); |
269 |
this.shapeType = shapeType;
|
270 |
initialize(); |
271 |
} |
272 |
|
273 |
/**
|
274 |
* This method initializes this
|
275 |
*
|
276 |
*/
|
277 |
private void initialize() { |
278 |
|
279 |
cmbTypeActionListener = new ActionListener() { |
280 |
int prevIndex = -2; |
281 |
|
282 |
public void actionPerformed(ActionEvent e) { |
283 |
int index = getCmbType().getSelectedIndex();
|
284 |
if (prevIndex != index) {
|
285 |
// needs to refresh
|
286 |
prevIndex = index; |
287 |
|
288 |
AbstractTypeSymbolEditor options = (AbstractTypeSymbolEditor) getCmbType() |
289 |
.getSelectedItem(); |
290 |
|
291 |
////////// /-------------------------------------
|
292 |
if (layerManager!=null) { |
293 |
////////// /-------------------------------------
|
294 |
ISymbol l = layerManager.getSelectedLayer(); |
295 |
|
296 |
// if the symbol is not null and is it managed by the "options" class
|
297 |
// refresh the controls
|
298 |
if (l != null |
299 |
&& 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 |
options.refreshControls(l); |
306 |
} |
307 |
|
308 |
replaceOptions(options); |
309 |
////////// /-------------------------------------
|
310 |
} else {
|
311 |
replaceOptions(options); |
312 |
} |
313 |
////////// /-------------------------------------
|
314 |
|
315 |
} |
316 |
} |
317 |
}; |
318 |
|
319 |
Comparator tabComparator = new Comparator() { |
320 |
public int compare(Object o1, Object o2) { |
321 |
if (!(o1 instanceof AbstractTypeSymbolEditor || o1 instanceof AbstractTypeSymbolEditor)) |
322 |
throw new IllegalArgumentException(PluginServices.getText( |
323 |
this, "trying_to_add_a_non_TypeSymbolEditor_panel")); |
324 |
AbstractTypeSymbolEditor pnl1 = ( |
325 |
AbstractTypeSymbolEditor) o1, pnl2 = (AbstractTypeSymbolEditor) o2; |
326 |
int result = pnl1.getName().compareTo(pnl2.getName());
|
327 |
if (result == 0) |
328 |
throw new IllegalArgumentException(PluginServices.getText( |
329 |
this, "two_panels_with_the_same_name")); |
330 |
return result;
|
331 |
} |
332 |
}; |
333 |
|
334 |
|
335 |
TreeSet set = new TreeSet(tabComparator); |
336 |
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 |
NotificationManager.addError(PluginServices.getText(this, "failed_installing_symbol_editor")+" " |
346 |
+editorClass.getName(), e); |
347 |
} |
348 |
}; |
349 |
tabs = (AbstractTypeSymbolEditor[]) set
|
350 |
.toArray(new AbstractTypeSymbolEditor[0]); |
351 |
|
352 |
this.setLayout(new BorderLayout()); |
353 |
this.add(getPnlWest(), BorderLayout.WEST); |
354 |
this.add(getPnlCenter(), BorderLayout.CENTER); |
355 |
this.add(getOkCancelPanel(), BorderLayout.SOUTH); |
356 |
|
357 |
cmbTypeActionListener.actionPerformed(null);
|
358 |
refresh(); |
359 |
} |
360 |
/**
|
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 |
private AbstractTypeSymbolEditor getOptionsForSymbol(ISymbol sym) {
|
369 |
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 |
/**
|
377 |
* Initializes the OkCancel panel where the accept and cancel buttons
|
378 |
* will be placed
|
379 |
* @return okCancelPanel AcceptCancelPanel
|
380 |
*/
|
381 |
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 |
|
398 |
public WindowInfo getWindowInfo() {
|
399 |
if (wi == null) { |
400 |
wi = new WindowInfo(WindowInfo.MODALDIALOG | WindowInfo.RESIZABLE);
|
401 |
wi.setWidth(650);
|
402 |
wi.setHeight(400);
|
403 |
wi.setTitle(PluginServices.getText(this, "symbol_property_editor")); |
404 |
} |
405 |
return wi;
|
406 |
} |
407 |
|
408 |
public ISymbol getSymbol() {
|
409 |
if (symbol instanceof CartographicSupport) { |
410 |
CartographicSupport cs = (CartographicSupport) symbol; |
411 |
cs.setUnit(getUnit()); |
412 |
cs.setReferenceSystem(getReferenceSystem()); |
413 |
} |
414 |
//
|
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 |
return symbol;
|
426 |
} |
427 |
/**
|
428 |
* Initializes the west panel
|
429 |
* @return
|
430 |
*/
|
431 |
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 |
////////// /-------------------------------------
|
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 |
} |
447 |
return pnlWest;
|
448 |
} |
449 |
/**
|
450 |
* Initializes the center panel that shows the properties of a symbol.
|
451 |
*
|
452 |
* @return pnlCenter JPanel
|
453 |
*/
|
454 |
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 |
/**
|
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 |
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 |
/**
|
479 |
* Initializes the Layers panel that shows the different layers created that
|
480 |
* compose a symbol.
|
481 |
* @return pnlLayers JPanel
|
482 |
*/
|
483 |
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 |
/**
|
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 |
private SymbolLayerManager getLayerManager() {
|
499 |
if (layerManager == null) { |
500 |
layerManager = new SymbolLayerManager(this); |
501 |
} |
502 |
return layerManager;
|
503 |
} |
504 |
/**
|
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 |
private SymbolPreviewer getSymbolPreviewer() {
|
511 |
if (symbolPreview == null) { |
512 |
symbolPreview = new SymbolPreviewer();
|
513 |
symbolPreview.setPreferredSize(new Dimension(150, 100)); |
514 |
|
515 |
} |
516 |
return symbolPreview;
|
517 |
} |
518 |
/**
|
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 |
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 |
|
533 |
aux = new JPanel(new FlowLayout(FlowLayout.LEADING)); |
534 |
aux.add(new JLabel(PluginServices.getText(this, "units"))); |
535 |
aux.add(getCmbUnits()); |
536 |
aux.add(getCmbUnitsReferenceSystem()); |
537 |
pnlTypeAndUnits.add(aux, BorderLayout.EAST);
|
538 |
|
539 |
} |
540 |
return pnlTypeAndUnits;
|
541 |
} |
542 |
/**
|
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 |
private JComboBoxUnitsReferenceSystem getCmbUnitsReferenceSystem() {
|
549 |
if (cmbUnitsReferenceSystem == null) { |
550 |
cmbUnitsReferenceSystem = new JComboBoxUnitsReferenceSystem();
|
551 |
|
552 |
} |
553 |
|
554 |
return cmbUnitsReferenceSystem;
|
555 |
} |
556 |
/**
|
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 |
private JComboBoxUnits getCmbUnits() {
|
563 |
if (cmbUnits == null) { |
564 |
cmbUnits = new JComboBoxUnits();
|
565 |
} |
566 |
return cmbUnits;
|
567 |
} |
568 |
/**
|
569 |
* Returns the option selected in the reference unit Jcombobox
|
570 |
*
|
571 |
*/
|
572 |
public int getUnit() { |
573 |
return getCmbUnits().getSelectedUnitIndex();
|
574 |
} |
575 |
|
576 |
public int getReferenceSystem() { |
577 |
return getCmbUnitsReferenceSystem().getSelectedIndex();
|
578 |
} |
579 |
/**
|
580 |
* Returns the Jcombobox used in the panel to select the type of symbol.
|
581 |
*
|
582 |
* @return cmbType JComboBox
|
583 |
*/
|
584 |
private JComboBox getCmbType() { |
585 |
if (cmbType == null) { |
586 |
cmbType = new JComboBox(tabs); |
587 |
cmbType.addActionListener(cmbTypeActionListener); |
588 |
} |
589 |
return cmbType;
|
590 |
} |
591 |
/**
|
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 |
protected void setLayerToSymbol(ISymbol layer) { |
598 |
int i = getLayerManager().getSelectedLayerIndex();
|
599 |
IMultiLayerSymbol s = (IMultiLayerSymbol) symbol; |
600 |
if (i >= 0 && i < s.getLayerCount()) { |
601 |
s.setLayer(s.getLayerCount() - 1 - i, layer);
|
602 |
|
603 |
} |
604 |
refresh(); |
605 |
} |
606 |
|
607 |
public void refresh() { |
608 |
getSymbolPreviewer().setSymbol(symbol); |
609 |
doLayout(); |
610 |
repaint(); |
611 |
} |
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 |
* <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 |
* </p>
|
627 |
*
|
628 |
* @return
|
629 |
*/
|
630 |
public int getShapeType() { |
631 |
return shapeType;
|
632 |
} |
633 |
/**
|
634 |
* Obtains a new layer
|
635 |
*
|
636 |
* @return sym ISymbol
|
637 |
*/
|
638 |
public ISymbol getNewLayer() {
|
639 |
ISymbol sym = ((AbstractTypeSymbolEditor) getCmbType().getSelectedItem()) |
640 |
.getLayer(); |
641 |
|
642 |
return sym;
|
643 |
} |
644 |
|
645 |
private void replaceOptions(AbstractTypeSymbolEditor options) { |
646 |
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 |
|
663 |
public void setOptionsPageFor(ISymbol symbol) { |
664 |
AbstractTypeSymbolEditor options = getOptionsForSymbol(symbol); |
665 |
|
666 |
options.refreshControls(symbol); |
667 |
getCmbType().setSelectedItem(options); |
668 |
} |
669 |
/**
|
670 |
* Obtains the units to be used for the reference system.
|
671 |
*
|
672 |
*/
|
673 |
public int getUnitsReferenceSystem() { |
674 |
return cmbUnitsReferenceSystem.getSelectedIndex();
|
675 |
} |
676 |
|
677 |
public static void addSymbolEditorPanel(Class abstractTypeSymbolEditorPanelClass, int shapeType) { |
678 |
if (editorsByType == null) { |
679 |
editorsByType = new Hashtable(); |
680 |
} |
681 |
|
682 |
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 |
|
689 |
editorsByType.put(key, l); |
690 |
} |
691 |
|
692 |
|
693 |
} |