svn-gvsig-desktop / tags / J2ME_compat_v1_2_Build_1209 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / SymbologyFactory.java @ 19509
History | View | Annotate | Download (24.6 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: SymbologyFactory.java 17490 2007-12-14 07:20:13Z jdominguez $
|
45 |
* $Log$
|
46 |
* Revision 1.11 2007-09-20 09:33:15 jaume
|
47 |
* Refactored: fixed name of IPersistAnce to IPersistence
|
48 |
*
|
49 |
* Revision 1.10 2007/09/17 14:16:11 jaume
|
50 |
* multilayer symbols sizing bug fixed
|
51 |
*
|
52 |
* Revision 1.9 2007/09/17 09:32:05 jaume
|
53 |
* view refresh frame rate now configurable
|
54 |
*
|
55 |
* Revision 1.8 2007/07/18 06:54:34 jaume
|
56 |
* continuing with cartographic support
|
57 |
*
|
58 |
* Revision 1.7 2007/04/26 11:41:00 jaume
|
59 |
* attempting to let defining size in world units
|
60 |
*
|
61 |
* Revision 1.6 2007/03/27 09:28:40 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.5 2007/03/21 11:02:51 jaume
|
65 |
* javadoc
|
66 |
*
|
67 |
* Revision 1.4 2007/03/20 15:59:03 jaume
|
68 |
* improved factory toolkit
|
69 |
*
|
70 |
* Revision 1.3 2007/03/13 16:58:36 jaume
|
71 |
* Added QuantityByCategory (Multivariable legend) and some bugfixes in symbols
|
72 |
*
|
73 |
* Revision 1.2 2007/03/09 11:20:57 jaume
|
74 |
* Advanced symbology (start committing)
|
75 |
*
|
76 |
* Revision 1.1.2.2 2007/02/15 16:23:44 jaume
|
77 |
* *** empty log message ***
|
78 |
*
|
79 |
* Revision 1.1.2.1 2007/02/12 15:15:20 jaume
|
80 |
* refactored interval legend and added graduated symbol legend
|
81 |
*
|
82 |
* Revision 1.1.2.3 2007/02/09 07:47:05 jaume
|
83 |
* Isymbol moved
|
84 |
*
|
85 |
* Revision 1.1.2.2 2007/02/01 11:42:47 jaume
|
86 |
* *** empty log message ***
|
87 |
*
|
88 |
* Revision 1.1.2.1 2007/01/26 13:48:05 jaume
|
89 |
* patch for opening old projects
|
90 |
*
|
91 |
* Revision 1.1 2007/01/10 16:39:41 jaume
|
92 |
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
|
93 |
*
|
94 |
* Revision 1.3 2006/11/06 16:06:52 jaume
|
95 |
* *** empty log message ***
|
96 |
*
|
97 |
* Revision 1.2 2006/11/06 07:33:54 jaume
|
98 |
* javadoc, source style
|
99 |
*
|
100 |
* Revision 1.1 2006/10/30 19:30:35 jaume
|
101 |
* *** empty log message ***
|
102 |
*
|
103 |
*
|
104 |
*/
|
105 |
package com.iver.cit.gvsig.fmap.core; |
106 |
|
107 |
import java.awt.Color; |
108 |
import java.awt.Font; |
109 |
import java.io.File; |
110 |
import java.io.IOException; |
111 |
|
112 |
import org.apache.log4j.Logger; |
113 |
|
114 |
import com.iver.cit.gvsig.fmap.Messages; |
115 |
import com.iver.cit.gvsig.fmap.core.styles.IStyle; |
116 |
import com.iver.cit.gvsig.fmap.core.styles.SimpleLineStyle; |
117 |
import com.iver.cit.gvsig.fmap.core.symbols.AbstractSymbol; |
118 |
import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol; |
119 |
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol; |
120 |
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol; |
121 |
import com.iver.cit.gvsig.fmap.core.symbols.IMultiLayerSymbol; |
122 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
123 |
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol; |
124 |
import com.iver.cit.gvsig.fmap.core.symbols.LineFillSymbol; |
125 |
import com.iver.cit.gvsig.fmap.core.symbols.MultiLayerFillSymbol; |
126 |
import com.iver.cit.gvsig.fmap.core.symbols.MultiLayerLineSymbol; |
127 |
import com.iver.cit.gvsig.fmap.core.symbols.MultiLayerMarkerSymbol; |
128 |
import com.iver.cit.gvsig.fmap.core.symbols.MultiShapeSymbol; |
129 |
import com.iver.cit.gvsig.fmap.core.symbols.PictureMarkerSymbol; |
130 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol; |
131 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol; |
132 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleMarkerSymbol; |
133 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleTextSymbol; |
134 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
135 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
136 |
import com.iver.utiles.IPersistence; |
137 |
import com.iver.utiles.NotExistInXMLEntity; |
138 |
import com.iver.utiles.XMLEntity; |
139 |
|
140 |
/**
|
141 |
* Factory for obtaining symbology of any kind from several sources like.
|
142 |
* <ol>
|
143 |
* <li>
|
144 |
* <b>XMLEntity's</b> that, at least, contains a full class name
|
145 |
* string property that defines which class handles such symbol.
|
146 |
* </li>
|
147 |
* </ol>
|
148 |
*
|
149 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
150 |
*/
|
151 |
public class SymbologyFactory { |
152 |
public static int DefaultSymbolUnit = -1; // pixel |
153 |
public static int DefaultSymbolReferenceSystem = CartographicSupport.WORLD; |
154 |
public static Color DefaultSymbolColor = Color.DARK_GRAY; |
155 |
public static Color DefaultFillSymbolColor = new Color(60, 235, 235); |
156 |
public static Font DefaultTextFont = new Font("SansSerif", Font.PLAIN, 9); |
157 |
private static Logger logger = Logger.getLogger(SymbologyFactory.class.getName()); |
158 |
// private static WarningSymbol warningSymbol;
|
159 |
|
160 |
/**
|
161 |
* Factory that allows to create <b>ISymbol</b>'s from an ISymbol xml
|
162 |
* descriptor. A barely specific XMLEntity object. The string passed in the
|
163 |
* second argument is the description text that will be used in case no description
|
164 |
* is supplied by the symbol's xml descriptor.
|
165 |
*
|
166 |
* @param xml, the symbol's xml descriptor
|
167 |
* @param defaultDescription, a human readable description string for the symbol.
|
168 |
* @return ISymbol
|
169 |
*/
|
170 |
public static ISymbol createSymbolFromXML(XMLEntity xml, String defaultDescription) { |
171 |
if (!xml.contains("desc")) { |
172 |
if (defaultDescription == null) defaultDescription = ""; |
173 |
xml.putProperty("desc", defaultDescription);
|
174 |
} |
175 |
return (ISymbol) createFromXML(xml);
|
176 |
} |
177 |
|
178 |
/**
|
179 |
* Factory that allows to create <b>IStyle</b>'s from an <b>IStyle</b> xml descriptor. A barely
|
180 |
* specific <b>XMLEntity</b> object. The string passed in the second argument is the
|
181 |
* description text that will be used in case no description is supplied by the
|
182 |
* style's xml descriptor.
|
183 |
*
|
184 |
* @param xml, the style's xml descriptor
|
185 |
* @param defaultDescription, a human readable description string for the style
|
186 |
* @return IStyle
|
187 |
*/
|
188 |
public static IStyle createStyleFromXML(XMLEntity xml, String defaultDescription) { |
189 |
if (!xml.contains("desc")) |
190 |
if (defaultDescription == null) defaultDescription = ""; |
191 |
xml.putProperty("desc", defaultDescription);
|
192 |
return (IStyle) createFromXML(xml);
|
193 |
} |
194 |
|
195 |
/**
|
196 |
* Creates an <b>Object</b> described by the <b>XMLEntity</b> xml, please reffer to the
|
197 |
* XMLEntity definition contract to know what is the format of the xml argument.
|
198 |
* The result of this method is an <b>Object</b> that you can cast to the type you were
|
199 |
* looking for by means of the xml entity.
|
200 |
*
|
201 |
* @param xml
|
202 |
* @return Object
|
203 |
*/
|
204 |
private static Object createFromXML(XMLEntity xml) { |
205 |
String className = null; |
206 |
try {
|
207 |
className = xml.getStringProperty("className");
|
208 |
} catch (NotExistInXMLEntity e) {
|
209 |
logger.error("Class name not set.\n" +
|
210 |
" Maybe you forgot to add the" +
|
211 |
" putProperty(\"className\", yourClassName)" +
|
212 |
" call in the getXMLEntity method of your class", e);
|
213 |
} |
214 |
|
215 |
|
216 |
Class clazz = null; |
217 |
IPersistence obj = null;
|
218 |
String s = className;
|
219 |
|
220 |
try {
|
221 |
clazz = Class.forName(className);
|
222 |
|
223 |
if (xml.contains("desc")) { |
224 |
s += " \"" + xml.getStringProperty("desc") +"\""; |
225 |
} |
226 |
// TODO remove the patch the day we deprecate FSymbol
|
227 |
// begin patch
|
228 |
if (clazz.equals(FSymbol.class))
|
229 |
obj = FSymbol.createFromXML(xml); |
230 |
else {
|
231 |
// end patch
|
232 |
|
233 |
|
234 |
obj = (IPersistence) clazz.newInstance(); |
235 |
logger.info(Messages.getString("creating")+"....... "+s); |
236 |
try {
|
237 |
obj.setXMLEntity(xml); |
238 |
} catch (NotExistInXMLEntity neiXML) {
|
239 |
logger.error(Messages.getString("failed_creating_object")+": "+s); |
240 |
throw neiXML;
|
241 |
} |
242 |
|
243 |
} |
244 |
|
245 |
} catch (InstantiationException e) { |
246 |
logger.error("Trying to instantiate an interface" +
|
247 |
" or abstract class + "+className, e);
|
248 |
} catch (IllegalAccessException e) { |
249 |
logger.error("IllegalAccessException: does your class have an" +
|
250 |
" anonymous constructor?", e);
|
251 |
} catch (ClassNotFoundException e) { |
252 |
logger.error("No class called " + className +
|
253 |
" was found.\nCheck the following.\n<br>" +
|
254 |
"\t- The fullname of the class you're looking " +
|
255 |
"for matches the value in the className " +
|
256 |
"property of the XMLEntity ("+className+").\n<br>" + |
257 |
"\t- The jar file containing your symbol class is in" +
|
258 |
"the application classpath<br>", e);
|
259 |
} |
260 |
return obj;
|
261 |
} |
262 |
|
263 |
/**
|
264 |
* Returns a new empty instance of a <b>IMultiLayer</b> that can be one of:
|
265 |
* <b>MultiLayerMarkerSymbol</b>, <b>MultiLayerLineSymbol</b>, or
|
266 |
* <b>MultiLayerFillSymbol</b> depending on the shape type passed.
|
267 |
*
|
268 |
* @param shapeType, one of FShape.POINT, FShape.LINE, or FShape.POLYGON
|
269 |
* @return IMultiLayerSymbol
|
270 |
*/
|
271 |
public static IMultiLayerSymbol createEmptyMultiLayerSymbol(int shapeType) { |
272 |
|
273 |
IMultiLayerSymbol sym = null;
|
274 |
|
275 |
switch (shapeType % FShape.Z) {
|
276 |
case FShape.POINT:
|
277 |
|
278 |
sym = new MultiLayerMarkerSymbol();
|
279 |
break;
|
280 |
|
281 |
case FShape.LINE:
|
282 |
|
283 |
sym = new MultiLayerLineSymbol();
|
284 |
break;
|
285 |
|
286 |
case FShape.POLYGON:
|
287 |
|
288 |
sym = new MultiLayerFillSymbol();
|
289 |
break;
|
290 |
|
291 |
default:
|
292 |
throw new Error("Shape type not yet supported for multilayer symbols"); |
293 |
} |
294 |
|
295 |
|
296 |
if (sym instanceof CartographicSupport) { |
297 |
CartographicSupport csSym = (CartographicSupport) sym; |
298 |
csSym.setUnit(DefaultSymbolUnit); |
299 |
csSym.setReferenceSystem(DefaultSymbolReferenceSystem); |
300 |
} |
301 |
|
302 |
return sym;
|
303 |
|
304 |
} |
305 |
|
306 |
/**
|
307 |
* Returns a new instance of an <b>IMarkerSymbol</b>.
|
308 |
* @return IMarkerSymbol, the default symbol for markers
|
309 |
*/
|
310 |
public static IMarkerSymbol createDefaultMarkerSymbol() { |
311 |
SimpleMarkerSymbol sms = new SimpleMarkerSymbol();
|
312 |
sms.setColor(DefaultSymbolColor); |
313 |
sms.setSize(4);
|
314 |
return sms;
|
315 |
} |
316 |
|
317 |
/**
|
318 |
* Returns a new instance of an <b>ILineSymbol</b>.
|
319 |
* @return ILineSymbol, the default symbol for lines.
|
320 |
*/
|
321 |
public static ILineSymbol createDefaultLineSymbol() { |
322 |
SimpleLineSymbol sls = new SimpleLineSymbol();
|
323 |
sls.setLineColor(DefaultSymbolColor); |
324 |
sls.setLineWidth(1);
|
325 |
return sls;
|
326 |
} |
327 |
//
|
328 |
// private static void toDefaultCartographicProperties(CartographicSupport cs) {
|
329 |
// cs.setUnit(CartographicSupportToolkit.DefaultMeasureUnit);
|
330 |
// cs.setReferenceSystem(CartographicSupportToolkit.DefaultReferenceSystem);
|
331 |
// }
|
332 |
|
333 |
/**
|
334 |
* Returns a new instance of an <b>IFillSymbol</b>. Black outline,
|
335 |
* and transparent fill.
|
336 |
* @return IFillSymbol, the default symbol for polygons
|
337 |
*/
|
338 |
public static IFillSymbol createDefaultFillSymbol() { |
339 |
|
340 |
SimpleFillSymbol sfs = new SimpleFillSymbol();
|
341 |
|
342 |
// Default symbol for polygons
|
343 |
sfs.setOutline(createDefaultLineSymbol()); |
344 |
sfs.setFillColor(DefaultFillSymbolColor); // transparent fill
|
345 |
// toDefaultCartographicProperties(sfs);
|
346 |
return sfs;
|
347 |
} |
348 |
|
349 |
/**
|
350 |
* Returns a new instance of an <b>ITextSymbol</b>.
|
351 |
* @return ITextSymbol, the default symbol for texts
|
352 |
*/
|
353 |
public static ITextSymbol createDefaultTextSymbol() { |
354 |
SimpleTextSymbol sts = new SimpleTextSymbol();
|
355 |
|
356 |
sts.setFont(DefaultTextFont); |
357 |
sts.setTextColor(DefaultSymbolColor); |
358 |
// toDefaultCartographicProperties(sts);
|
359 |
|
360 |
return sts;
|
361 |
} |
362 |
|
363 |
/**
|
364 |
* Creates a new instance of the default symbol whose type is defined
|
365 |
* by the parameter <b>shapeType</b>
|
366 |
* @param shapeType, one of FShape.POINT, FShape.LINE, FShape.POLYGON,
|
367 |
* FShape.MULTIPOINT, FShape.TEXT, or FShape.MULTI.
|
368 |
* @return ISymbol, the default symbol for the shape type defined by <b>shapeType</b>
|
369 |
*/
|
370 |
public static ISymbol createDefaultSymbolByShapeType(int shapeType) { |
371 |
switch (shapeType % FShape.Z) {
|
372 |
case FShape.POINT:
|
373 |
return createDefaultMarkerSymbol();
|
374 |
case FShape.LINE:
|
375 |
return createDefaultLineSymbol();
|
376 |
case FShape.POLYGON:
|
377 |
return createDefaultFillSymbol();
|
378 |
case FShape.MULTIPOINT:
|
379 |
return createDefaultMarkerSymbol();
|
380 |
case FShape.TEXT:
|
381 |
return createDefaultTextSymbol();
|
382 |
case FShape.MULTI:
|
383 |
return new MultiShapeSymbol(); |
384 |
case FShape.NULL:
|
385 |
return null; |
386 |
default:
|
387 |
throw new Error("shape type not yet supported"); |
388 |
} |
389 |
} |
390 |
|
391 |
/**
|
392 |
* Creates a new instance of the default symbol whose type is defined
|
393 |
* by the parameter <b>shapeType</b> and uses the color defined by the
|
394 |
* parameter color.
|
395 |
* @param shapeType, one of FShape.POINT, FShape.LINE, FShape.POLYGON,
|
396 |
* @param color, the color to be applied to the new ISymbol.
|
397 |
*
|
398 |
* FShape.MULTIPOINT, FShape.TEXT, or FShape.MULTI.
|
399 |
* @return ISymbol, the default symbol for the shape type defined by <b>shapeType</b>
|
400 |
*/
|
401 |
public static ISymbol createDefaultSymbolByShapeType(int shapeType, Color color) { |
402 |
ISymbol sym = createDefaultSymbolByShapeType(shapeType); |
403 |
if (sym instanceof IMarkerSymbol) { |
404 |
((IMarkerSymbol) sym).setColor(color); |
405 |
} |
406 |
|
407 |
if (sym instanceof ILineSymbol) { |
408 |
((ILineSymbol) sym).setLineColor(color); |
409 |
} |
410 |
|
411 |
if (sym instanceof IFillSymbol) { |
412 |
((IFillSymbol) sym).setFillColor(color); |
413 |
} |
414 |
|
415 |
if (sym instanceof ITextSymbol) { |
416 |
((ITextSymbol) sym).setTextColor(color); |
417 |
} |
418 |
|
419 |
return sym;
|
420 |
} |
421 |
|
422 |
public static ISymbol deriveFSymbol(FSymbol fSymbol) { |
423 |
ISymbol derivedSymbol; |
424 |
|
425 |
int symbolType = fSymbol.getSymbolType();
|
426 |
Color color = fSymbol.getColor();
|
427 |
double size = fSymbol.getSize();
|
428 |
int unit = fSymbol.isSizeInPixels() ? -1 : 1; // only meters or pixels |
429 |
// were supported in
|
430 |
// FSymbol
|
431 |
if (symbolType == FShape.LINE) {
|
432 |
ILineSymbol line = createDefaultLineSymbol(); |
433 |
line.setLineColor(color); |
434 |
|
435 |
SimpleLineStyle lineStyle = new SimpleLineStyle();
|
436 |
lineStyle.setUnit(unit); |
437 |
lineStyle.setStroke(fSymbol.getStroke()); |
438 |
lineStyle.setOffset(0);
|
439 |
lineStyle.setReferenceSystem(CartographicSupport.WORLD); |
440 |
lineStyle.setLineWidth((float) size);
|
441 |
line.setLineStyle(lineStyle); |
442 |
derivedSymbol = line; |
443 |
|
444 |
} else if (symbolType == FShape.POINT) { |
445 |
int style = fSymbol.getStyle();
|
446 |
IMarkerSymbol marker; |
447 |
if (style == FConstant.SYMBOL_STYLE_MARKER_IMAGEN) {
|
448 |
marker = new PictureMarkerSymbol();
|
449 |
PictureMarkerSymbol pic = (PictureMarkerSymbol) marker; |
450 |
try {
|
451 |
pic.setImage(new File(fSymbol.getIconURI().getPath())); |
452 |
} catch (IOException e) { |
453 |
// image could not be restored,
|
454 |
// will use a regular point as symbol
|
455 |
fSymbol.setStyle(FConstant.SYMBOL_STYLE_MARKER_CIRCLE); |
456 |
return deriveFSymbol(fSymbol);
|
457 |
} |
458 |
} else {
|
459 |
marker = new SimpleMarkerSymbol();
|
460 |
SimpleMarkerSymbol sms = (SimpleMarkerSymbol) marker; |
461 |
if (style == FConstant.SYMBOL_STYLE_MARKER_CIRCLE) {
|
462 |
sms.setStyle(SimpleMarkerSymbol.CIRCLE_STYLE); |
463 |
} else if (style == FConstant.SYMBOL_STYLE_MARKER_CROSS) { |
464 |
sms.setStyle(SimpleMarkerSymbol.CROSS_STYLE); |
465 |
} else if (style == FConstant.SYMBOL_STYLE_MARKER_SQUARE) { |
466 |
sms.setStyle(SimpleMarkerSymbol.SQUARE_STYLE); |
467 |
} else if (style == FConstant.SYMBOL_STYLE_MARKER_TRIANGLE) { |
468 |
sms.setStyle(SimpleMarkerSymbol.TRIANGLE_STYLE); |
469 |
} |
470 |
Color outlineColor = fSymbol.getOutlineColor();
|
471 |
if (outlineColor != null) { |
472 |
sms.setOutlined(true);
|
473 |
sms.setOutlineColor(outlineColor); |
474 |
} |
475 |
} |
476 |
marker.setColor(color); |
477 |
marker.setSize(size); |
478 |
marker.setRotation(fSymbol.getRotation()); |
479 |
derivedSymbol = marker; |
480 |
|
481 |
} else if (symbolType == FShape.POLYGON) { |
482 |
IFillSymbol fill; |
483 |
int fSymbolStyle = fSymbol.getStyle();
|
484 |
color = null;
|
485 |
if (fSymbolStyle == FConstant.SYMBOL_STYLE_FILL_SOLID) {
|
486 |
fill = createDefaultFillSymbol(); |
487 |
color = fSymbol.getColor(); |
488 |
} else if (fSymbolStyle == FConstant.SYMBOL_STYLE_FILL_TRANSPARENT || |
489 |
fSymbolStyle == FConstant.SYMBOL_STYLE_DGNSPECIAL) { |
490 |
fill = createDefaultFillSymbol(); |
491 |
} else {
|
492 |
// lets see how to derive FSymbol with fill patterns
|
493 |
if (fSymbolStyle == FConstant.SYMBOL_STYLE_FILL_CROSS) {
|
494 |
// the cross will be substituted by two line fill symbols
|
495 |
// with
|
496 |
// perpendicular line angles mixed into a multilayer symbol
|
497 |
IMultiLayerSymbol mfs = createEmptyMultiLayerSymbol(FShape.POLYGON); |
498 |
fSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_VERTICAL); |
499 |
LineFillSymbol firstLayer = (LineFillSymbol) deriveFSymbol(fSymbol); |
500 |
fSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_HORIZONTAL); |
501 |
LineFillSymbol secondLayer = (LineFillSymbol) deriveFSymbol(fSymbol); |
502 |
mfs.addLayer(firstLayer); |
503 |
mfs.addLayer(secondLayer); |
504 |
fill = (IFillSymbol) mfs; |
505 |
fSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_CROSS); // restore
|
506 |
// old
|
507 |
// style
|
508 |
// (just
|
509 |
// in
|
510 |
// case)
|
511 |
} else if (fSymbolStyle == FConstant.SYMBOL_STYLE_FILL_CROSS_DIAGONAL ) { |
512 |
// the cross will be substituted by two line fill symbols
|
513 |
// with
|
514 |
// perpendicular line angles mixed into a multilayer symbol
|
515 |
IMultiLayerSymbol mfs = createEmptyMultiLayerSymbol(FShape.POLYGON); |
516 |
fSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_UPWARD_DIAGONAL); |
517 |
LineFillSymbol firstLayer = (LineFillSymbol) deriveFSymbol(fSymbol); |
518 |
fSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL); |
519 |
LineFillSymbol secondLayer = (LineFillSymbol) deriveFSymbol(fSymbol); |
520 |
mfs.addLayer(firstLayer); |
521 |
mfs.addLayer(secondLayer); |
522 |
fill = (IFillSymbol) mfs; |
523 |
fSymbol.setStyle(FConstant.SYMBOL_STYLE_FILL_CROSS_DIAGONAL); // restore
|
524 |
// old
|
525 |
// style
|
526 |
// (just
|
527 |
// in
|
528 |
// case)
|
529 |
} else {
|
530 |
LineFillSymbol lfs = new LineFillSymbol();
|
531 |
// Let's create the filling line symbol
|
532 |
fSymbol.setSymbolType(FShape.LINE); |
533 |
ILineSymbol lineSymbol = (ILineSymbol) deriveFSymbol(fSymbol); |
534 |
SimpleLineStyle lineStyle = new SimpleLineStyle();
|
535 |
lineStyle.setLineWidth(1f);
|
536 |
lineSymbol.setLineStyle(lineStyle); |
537 |
|
538 |
// restore the old value for symbol type (should be always
|
539 |
// FShape.POLYGON)
|
540 |
//assert symbolType == FShape.POLYGON;
|
541 |
fSymbol.setSymbolType(symbolType); |
542 |
double angle = 0; |
543 |
switch (fSymbolStyle) {
|
544 |
case FConstant.SYMBOL_STYLE_FILL_UPWARD_DIAGONAL:
|
545 |
angle = 45;
|
546 |
break;
|
547 |
case FConstant.SYMBOL_STYLE_FILL_VERTICAL:
|
548 |
angle = 90;
|
549 |
break;
|
550 |
case FConstant.SYMBOL_STYLE_FILL_HORIZONTAL:
|
551 |
angle = 0;
|
552 |
break;
|
553 |
case FConstant.SYMBOL_STYLE_FILL_DOWNWARD_DIAGONAL:
|
554 |
angle = -45;
|
555 |
break;
|
556 |
} |
557 |
lfs.setSeparation(10);
|
558 |
lfs.setAngle(angle*FConstant.DEGREE_TO_RADIANS); |
559 |
lfs.setLineSymbol(lineSymbol); |
560 |
fill = lfs; |
561 |
} |
562 |
} |
563 |
|
564 |
fill.setFillColor(color); |
565 |
|
566 |
if (fSymbol.isOutlined()) {
|
567 |
// Let's create the outline line symbol
|
568 |
fSymbol.setSymbolType(FShape.LINE); |
569 |
ILineSymbol outline = (ILineSymbol) deriveFSymbol(fSymbol); |
570 |
|
571 |
// restore the old value for symbol type (should be always
|
572 |
// FShape.POLYGON)
|
573 |
//assert symbolType == FShape.POLYGON;
|
574 |
fSymbol.setSymbolType(symbolType); |
575 |
outline.setLineColor(fSymbol.getOutlineColor()); |
576 |
fill.setOutline(outline); |
577 |
} |
578 |
derivedSymbol = fill; |
579 |
} else if (symbolType == FShape.MULTI) { |
580 |
fSymbol.setSymbolType(FShape.LINE); |
581 |
ILineSymbol line = (ILineSymbol) deriveFSymbol(fSymbol); |
582 |
fSymbol.setSymbolType(FShape.POINT); |
583 |
IMarkerSymbol marker = (IMarkerSymbol) deriveFSymbol(fSymbol); |
584 |
fSymbol.setSymbolType(FShape.POLYGON); |
585 |
IFillSymbol fill = (IFillSymbol) deriveFSymbol(fSymbol); |
586 |
//assert symbolType == FShape.MULTI;
|
587 |
fSymbol.setSymbolType(symbolType); |
588 |
MultiShapeSymbol multiShapeSymbol = new MultiShapeSymbol();
|
589 |
multiShapeSymbol.setMarkerSymbol(marker); |
590 |
multiShapeSymbol.setLineSymbol(line); |
591 |
multiShapeSymbol.setFillSymbol(fill); |
592 |
|
593 |
derivedSymbol = multiShapeSymbol; |
594 |
} else if (symbolType == FShape.TEXT) { |
595 |
ITextSymbol textSym = createDefaultTextSymbol(); |
596 |
textSym.setTextColor(color); |
597 |
derivedSymbol = textSym; |
598 |
} else {
|
599 |
throw new Error("FSymbol of type "+symbolType+" cannot be imported yet!"); |
600 |
} |
601 |
|
602 |
// establish the general description;
|
603 |
if (derivedSymbol instanceof AbstractSymbol) { |
604 |
AbstractSymbol symbol = (AbstractSymbol) derivedSymbol; |
605 |
symbol.setIsShapeVisible(true);
|
606 |
symbol.setDescription(fSymbol.getDescription()); |
607 |
} |
608 |
|
609 |
|
610 |
|
611 |
if (derivedSymbol instanceof CartographicSupport) { |
612 |
CartographicSupport cs = (CartographicSupport) derivedSymbol; |
613 |
// the only options allowed by the old FSymbol class
|
614 |
cs.setUnit(unit); |
615 |
cs.setReferenceSystem(CartographicSupport.WORLD); |
616 |
} |
617 |
|
618 |
return derivedSymbol;
|
619 |
} |
620 |
|
621 |
/* public static ISymbol getWarningSymbol(String message, String symbolDesc, int symbolDrawExceptionType) {
|
622 |
if (warningSymbol == null) {
|
623 |
warningSymbol = new WarningSymbol();
|
624 |
}
|
625 |
warningSymbol.setDescription(symbolDesc);
|
626 |
warningSymbol.setMessage(message);
|
627 |
warningSymbol.setDrawExceptionType(symbolDrawExceptionType);
|
628 |
return warningSymbol;
|
629 |
}
|
630 |
|
631 |
private static class WarningSymbol implements ISymbol {
|
632 |
private String desc;
|
633 |
private String message;
|
634 |
private int exceptionType;
|
635 |
|
636 |
public static void main(String[] args) {
|
637 |
JFrame f = new JFrame();
|
638 |
final ISymbol warning = SymbologyFactory.getWarningSymbol(SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS, "a description", SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS);
|
639 |
JPanel preview = new JPanel() {
|
640 |
@Override
|
641 |
protected void paintComponent(Graphics g) {
|
642 |
// TODO Auto-generated method stub
|
643 |
super.paintComponent(g);
|
644 |
Graphics2D g2 = (Graphics2D)g;
|
645 |
try {
|
646 |
warning.drawInsideRectangle(g2, g2.getTransform(), getBounds());
|
647 |
} catch (SymbolDrawingException e) {
|
648 |
// TODO Auto-generated catch block
|
649 |
e.printStackTrace();
|
650 |
}
|
651 |
}
|
652 |
};
|
653 |
f.setContentPane(preview);
|
654 |
f.pack();
|
655 |
f.setVisible(true);
|
656 |
}
|
657 |
|
658 |
public void draw(Graphics2D g, AffineTransform affineTransform,
|
659 |
FShape shp, Cancellable cancel) {
|
660 |
try {
|
661 |
drawInsideRectangle(g, g.getTransform(), shp.getBounds());
|
662 |
} catch (SymbolDrawingException e) {
|
663 |
// IMPOSSIBLE
|
664 |
}
|
665 |
}
|
666 |
|
667 |
public void setDrawExceptionType(int symbolDrawExceptionType) {
|
668 |
this.exceptionType = symbolDrawExceptionType;
|
669 |
}
|
670 |
|
671 |
public void setMessage(String message) {
|
672 |
this.message = message;
|
673 |
}
|
674 |
|
675 |
public void drawInsideRectangle(Graphics2D g,
|
676 |
AffineTransform scaleInstance, Rectangle r)
|
677 |
throws SymbolDrawingException {
|
678 |
if (message == null) {
|
679 |
message = "Symbol undrawable.\nPlease, check errors.";
|
680 |
}
|
681 |
|
682 |
String[] messageLines = message.split("\n");
|
683 |
int strokeWidth = 5;
|
684 |
g.setColor(Color.red);
|
685 |
g.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
|
686 |
int x = r.x+strokeWidth;
|
687 |
int y = r.x+strokeWidth;
|
688 |
int width = r.width-(strokeWidth+strokeWidth);
|
689 |
int height = r.height-(strokeWidth+strokeWidth);
|
690 |
|
691 |
// g.drawOval(x, y, width, height);
|
692 |
// g.drawLine(x, y, width, height);
|
693 |
int fontSize = 20;
|
694 |
int vAlign = (int) (r.getCenterY() - ((fontSize+2)*messageLines.length/2));
|
695 |
g.setFont(new Font("Arial", fontSize, Font.PLAIN));
|
696 |
g.setColor(Color.black);
|
697 |
|
698 |
for (int i = 0; i < messageLines.length; i++) {
|
699 |
g.drawString(messageLines[i], 2, -vAlign);
|
700 |
System.out.println(messageLines[i]);
|
701 |
vAlign += fontSize + 2;
|
702 |
}
|
703 |
}
|
704 |
|
705 |
public XMLEntity getXMLEntity() {
|
706 |
throw new Error("Found symbology problems, please fix them before saving."); }
|
707 |
|
708 |
public String getDescription() { return desc; }
|
709 |
public int getOnePointRgb() { return 0; }
|
710 |
public ISymbol getSymbolForSelection() { return this; }
|
711 |
public void getPixExtentPlus(FShape shp, float[] distances, ViewPort viewPort, int dpi) {}
|
712 |
public int getSymbolType() { return 0; }
|
713 |
public boolean isShapeVisible() { return false; }
|
714 |
public boolean isSuitableFor(IGeometry geom) { return true; }
|
715 |
public void setDescription(String desc) { this.desc = desc; }
|
716 |
public void setXMLEntity(XMLEntity xml) { }
|
717 |
public String getClassName() { return null; }
|
718 |
|
719 |
public void print(Graphics2D g, AffineTransform at,
|
720 |
FShape shape, PrintRequestAttributeSet properties)
|
721 |
throws ReadDriverException {
|
722 |
throw new ReadDriverException("Your symbology contains errors, please check them before printing.",
|
723 |
new SymbolDrawingException(exceptionType));
|
724 |
}
|
725 |
|
726 |
|
727 |
};*/
|
728 |
} |