svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / SymbologyFactory.java @ 27025
History | View | Annotate | Download (17.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: SymbologyFactory.java 26050 2009-01-19 08:26:55Z vcaballero $
|
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.BasicStroke; |
108 |
import java.awt.Color; |
109 |
import java.awt.Font; |
110 |
import java.awt.Graphics; |
111 |
import java.awt.Graphics2D; |
112 |
import java.awt.Rectangle; |
113 |
import java.awt.geom.AffineTransform; |
114 |
import java.awt.geom.Ellipse2D; |
115 |
import java.io.File; |
116 |
|
117 |
import javax.swing.JFrame; |
118 |
import javax.swing.JPanel; |
119 |
|
120 |
import org.apache.log4j.Logger; |
121 |
|
122 |
import com.iver.cit.gvsig.fmap.Messages; |
123 |
import com.iver.cit.gvsig.fmap.core.styles.IStyle; |
124 |
import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol; |
125 |
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol; |
126 |
import com.iver.cit.gvsig.fmap.core.symbols.IMarkerSymbol; |
127 |
import com.iver.cit.gvsig.fmap.core.symbols.IMultiLayerSymbol; |
128 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
129 |
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol; |
130 |
import com.iver.cit.gvsig.fmap.core.symbols.MultiLayerFillSymbol; |
131 |
import com.iver.cit.gvsig.fmap.core.symbols.MultiLayerLineSymbol; |
132 |
import com.iver.cit.gvsig.fmap.core.symbols.MultiLayerMarkerSymbol; |
133 |
import com.iver.cit.gvsig.fmap.core.symbols.MultiShapeSymbol; |
134 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleFillSymbol; |
135 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleLineSymbol; |
136 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleMarkerSymbol; |
137 |
import com.iver.cit.gvsig.fmap.core.symbols.SimpleTextSymbol; |
138 |
import com.iver.cit.gvsig.fmap.core.symbols.SymbolDrawingException; |
139 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
140 |
import com.iver.utiles.IPersistence; |
141 |
import com.iver.utiles.NotExistInXMLEntity; |
142 |
import com.iver.utiles.XMLEntity; |
143 |
import com.iver.utiles.swing.threads.Cancellable; |
144 |
|
145 |
/**
|
146 |
* Factory for obtaining symbology of any kind from several sources like.
|
147 |
* <ol>
|
148 |
* <li>
|
149 |
* <b>XMLEntity's</b> that, at least, contains a full class name
|
150 |
* string property that defines which class handles such symbol.
|
151 |
* </li>
|
152 |
* </ol>
|
153 |
*
|
154 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
155 |
*/
|
156 |
public class SymbologyFactory { |
157 |
|
158 |
/**
|
159 |
* This Constants are only used in SymbologyPage (preferences page for symbology),
|
160 |
* do not use in other context.
|
161 |
*/
|
162 |
public static final Color FactoryDefaultSymbolColor = Color.GRAY; |
163 |
public static final Color FactoryDefaultFillSymbolColor = new Color(60, 235, 235); |
164 |
public static final Font FactoryDefaultTextFont = new Font("Serif", Font.PLAIN, 8); |
165 |
public static final String FactorySymbolLibraryPath = |
166 |
System.getProperty("user.home") + |
167 |
File.separator +
|
168 |
"gvSIG" +
|
169 |
File.separator +
|
170 |
"Symbols";
|
171 |
|
172 |
public static final String FactoryStyleLibraryPath = |
173 |
System.getProperty("user.home") + |
174 |
File.separator +
|
175 |
"gvSIG" +
|
176 |
File.separator +
|
177 |
"Styles";
|
178 |
|
179 |
public static final Boolean FactoryDefaultAleatoryFillColor = false; |
180 |
|
181 |
public static Color DefaultSymbolColor = FactoryDefaultSymbolColor; |
182 |
public static Color DefaultFillSymbolColor = FactoryDefaultFillSymbolColor; |
183 |
public static Font DefaultTextFont = FactoryDefaultTextFont; |
184 |
public static String SymbolLibraryPath = FactorySymbolLibraryPath; |
185 |
public static String StyleLibraryPath = FactoryStyleLibraryPath; |
186 |
|
187 |
public static Boolean DefaultAleatoryFillColor = FactoryDefaultAleatoryFillColor; |
188 |
|
189 |
|
190 |
|
191 |
private static Logger logger = Logger.getLogger(SymbologyFactory.class.getName()); |
192 |
private static WarningSymbol warningSymbol; |
193 |
|
194 |
/**
|
195 |
* Factory that allows to create <b>ISymbol</b>'s from an ISymbol xml
|
196 |
* descriptor. A barely specific XMLEntity object. The string passed in the
|
197 |
* second argument is the description text that will be used in case no description
|
198 |
* is supplied by the symbol's xml descriptor.
|
199 |
*
|
200 |
* @param xml, the symbol's xml descriptor
|
201 |
* @param defaultDescription, a human readable description string for the symbol.
|
202 |
* @return ISymbol
|
203 |
*/
|
204 |
public static ISymbol createSymbolFromXML(XMLEntity xml, String defaultDescription) { |
205 |
if (!xml.contains("desc")) { |
206 |
if (defaultDescription == null) defaultDescription = ""; |
207 |
xml.putProperty("desc", defaultDescription);
|
208 |
} |
209 |
return (ISymbol) createFromXML(xml);
|
210 |
} |
211 |
|
212 |
/**
|
213 |
* Factory that allows to create <b>IStyle</b>'s from an <b>IStyle</b> xml descriptor. A barely
|
214 |
* specific <b>XMLEntity</b> object. The string passed in the second argument is the
|
215 |
* description text that will be used in case no description is supplied by the
|
216 |
* style's xml descriptor.
|
217 |
*
|
218 |
* @param xml, the style's xml descriptor
|
219 |
* @param defaultDescription, a human readable description string for the style
|
220 |
* @return IStyle
|
221 |
*/
|
222 |
public static IStyle createStyleFromXML(XMLEntity xml, String defaultDescription) { |
223 |
if (!xml.contains("desc")) { |
224 |
if (defaultDescription == null) |
225 |
defaultDescription = "";
|
226 |
|
227 |
xml.putProperty("desc", defaultDescription);
|
228 |
} |
229 |
return (IStyle) createFromXML(xml);
|
230 |
} |
231 |
|
232 |
/**
|
233 |
* Creates an <b>Object</b> described by the <b>XMLEntity</b> xml, please reffer to the
|
234 |
* XMLEntity definition contract to know what is the format of the xml argument.
|
235 |
* The result of this method is an <b>Object</b> that you can cast to the type you were
|
236 |
* looking for by means of the xml entity.
|
237 |
*
|
238 |
* @param xml
|
239 |
* @return Object
|
240 |
*/
|
241 |
private static Object createFromXML(XMLEntity xml) { |
242 |
String className = null; |
243 |
try {
|
244 |
className = xml.getStringProperty("className");
|
245 |
} catch (NotExistInXMLEntity e) {
|
246 |
logger.error("Class name not set.\n" +
|
247 |
" Maybe you forgot to add the" +
|
248 |
" putProperty(\"className\", yourClassName)" +
|
249 |
" call in the getXMLEntity method of your class", e);
|
250 |
} |
251 |
|
252 |
|
253 |
Class clazz = null; |
254 |
IPersistence obj = null;
|
255 |
String s = className;
|
256 |
|
257 |
try {
|
258 |
clazz = Class.forName(className);
|
259 |
|
260 |
if (xml.contains("desc")) { |
261 |
s += " \"" + xml.getStringProperty("desc") +"\""; |
262 |
} |
263 |
// TODO remove the patch the day we deprecate FSymbol
|
264 |
// begin patch
|
265 |
if (clazz.equals(FSymbol.class))
|
266 |
obj = FSymbol.createFromXML(xml); |
267 |
else {
|
268 |
// end patch
|
269 |
|
270 |
|
271 |
obj = (IPersistence) clazz.newInstance(); |
272 |
logger.info(Messages.getString("creating")+"....... "+s); |
273 |
try {
|
274 |
obj.setXMLEntity(xml); |
275 |
} catch (NotExistInXMLEntity neiXML) {
|
276 |
logger.error(Messages.getString("failed_creating_object")+": "+s); |
277 |
throw neiXML;
|
278 |
} |
279 |
|
280 |
} |
281 |
|
282 |
} catch (InstantiationException e) { |
283 |
logger.error("Trying to instantiate an interface" +
|
284 |
" or abstract class + "+className, e);
|
285 |
} catch (IllegalAccessException e) { |
286 |
logger.error("IllegalAccessException: does your class have an" +
|
287 |
" anonymous constructor?", e);
|
288 |
} catch (ClassNotFoundException e) { |
289 |
logger.error("No class called " + className +
|
290 |
" was found.\nCheck the following.\n<br>" +
|
291 |
"\t- The fullname of the class you're looking " +
|
292 |
"for matches the value in the className " +
|
293 |
"property of the XMLEntity ("+className+").\n<br>" + |
294 |
"\t- The jar file containing your symbol class is in" +
|
295 |
"the application classpath<br>", e);
|
296 |
} |
297 |
return obj;
|
298 |
} |
299 |
|
300 |
/**
|
301 |
* Returns a new empty instance of a <b>IMultiLayer</b> that can be one of:
|
302 |
* <b>MultiLayerMarkerSymbol</b>, <b>MultiLayerLineSymbol</b>, or
|
303 |
* <b>MultiLayerFillSymbol</b> depending on the shape type passed.
|
304 |
*
|
305 |
* @param shapeType, one of FShape.POINT, FShape.LINE, or FShape.POLYGON
|
306 |
* @return IMultiLayerSymbol
|
307 |
*/
|
308 |
public static IMultiLayerSymbol createEmptyMultiLayerSymbol(int shapeType) { |
309 |
IMultiLayerSymbol mSym; |
310 |
switch (shapeType) {
|
311 |
case FShape.POINT:
|
312 |
mSym = new MultiLayerMarkerSymbol();
|
313 |
break;
|
314 |
case FShape.LINE:
|
315 |
mSym = new MultiLayerLineSymbol();
|
316 |
break;
|
317 |
case FShape.POLYGON:
|
318 |
mSym =new MultiLayerFillSymbol();
|
319 |
break;
|
320 |
default:
|
321 |
throw new Error("Shape type not yet supported for multilayer symbols"); |
322 |
} |
323 |
|
324 |
if (mSym instanceof CartographicSupport) { |
325 |
CartographicSupport cs = (CartographicSupport) mSym; |
326 |
cs.setUnit(CartographicSupportToolkit.DefaultMeasureUnit); |
327 |
cs.setReferenceSystem(CartographicSupportToolkit.DefaultReferenceSystem); |
328 |
} |
329 |
return mSym;
|
330 |
} |
331 |
|
332 |
/**
|
333 |
* Returns a new instance of an <b>IMarkerSymbol</b>.
|
334 |
* @return IMarkerSymbol, the default symbol for markers
|
335 |
*/
|
336 |
public static IMarkerSymbol createDefaultMarkerSymbol() { |
337 |
SimpleMarkerSymbol sms = new SimpleMarkerSymbol();
|
338 |
sms.setColor(DefaultSymbolColor); |
339 |
sms.setSize(4);
|
340 |
toDefaultCartographicProperties(sms); |
341 |
return sms;
|
342 |
} |
343 |
|
344 |
/**
|
345 |
* Returns a new instance of an <b>ILineSymbol</b>. A black line.
|
346 |
* @return ILineSymbol, the default symbol for lines.
|
347 |
*/
|
348 |
public static ILineSymbol createDefaultLineSymbol() { |
349 |
SimpleLineSymbol sls = new SimpleLineSymbol();
|
350 |
sls.setLineColor(DefaultSymbolColor); |
351 |
sls.setLineWidth(1);
|
352 |
toDefaultCartographicProperties(sls); |
353 |
return sls;
|
354 |
} |
355 |
|
356 |
private static void toDefaultCartographicProperties(CartographicSupport cs) { |
357 |
cs.setUnit(CartographicSupportToolkit.DefaultMeasureUnit); |
358 |
cs.setReferenceSystem(CartographicSupportToolkit.DefaultReferenceSystem); |
359 |
} |
360 |
|
361 |
/**
|
362 |
* Returns a new instance of an <b>IFillSymbol</b>. Black outline,
|
363 |
* and transparent fill.
|
364 |
* @return IFillSymbol, the default symbol for polygons
|
365 |
*/
|
366 |
public static IFillSymbol createDefaultFillSymbol() { |
367 |
|
368 |
SimpleFillSymbol sfs = new SimpleFillSymbol();
|
369 |
|
370 |
// Default symbol for polygons
|
371 |
sfs.setOutline(createDefaultLineSymbol()); |
372 |
sfs.setFillColor(DefaultFillSymbolColor); // transparent fill
|
373 |
toDefaultCartographicProperties(sfs); |
374 |
return sfs;
|
375 |
} |
376 |
|
377 |
/**
|
378 |
* Returns a new instance of an <b>ITextSymbol</b>.
|
379 |
* @return ITextSymbol, the default symbol for texts
|
380 |
*/
|
381 |
public static ITextSymbol createDefaultTextSymbol() { |
382 |
SimpleTextSymbol sts = new SimpleTextSymbol();
|
383 |
|
384 |
sts.setFont(DefaultTextFont); |
385 |
sts.setTextColor(DefaultSymbolColor); |
386 |
toDefaultCartographicProperties(sts); |
387 |
|
388 |
return sts;
|
389 |
} |
390 |
|
391 |
/**
|
392 |
* Creates a new instance of the default symbol whose type is defined
|
393 |
* by the parameter <b>shapeType</b>
|
394 |
* @param shapeType, one of FShape.POINT, FShape.LINE, FShape.POLYGON,
|
395 |
* FShape.MULTIPOINT, FShape.TEXT, or FShape.MULTI.
|
396 |
* @return ISymbol, the default symbol for the shape type defined by <b>shapeType</b>
|
397 |
*/
|
398 |
public static ISymbol createDefaultSymbolByShapeType(int shapeType) { |
399 |
switch (shapeType) {
|
400 |
case FShape.POINT:
|
401 |
case FShape.POINT | FShape.M:
|
402 |
return createDefaultMarkerSymbol();
|
403 |
case FShape.LINE:
|
404 |
case FShape.LINE | FShape.M:
|
405 |
return createDefaultLineSymbol();
|
406 |
case FShape.POLYGON:
|
407 |
case FShape.POLYGON | FShape.M:
|
408 |
return createDefaultFillSymbol();
|
409 |
case FShape.MULTIPOINT:
|
410 |
case FShape.MULTIPOINT | FShape.M:
|
411 |
return createDefaultMarkerSymbol();
|
412 |
case FShape.TEXT:
|
413 |
return createDefaultTextSymbol();
|
414 |
case FShape.MULTI:
|
415 |
return new MultiShapeSymbol(); |
416 |
case FShape.NULL:
|
417 |
return null; |
418 |
default:
|
419 |
throw new Error("shape type not yet supported"); |
420 |
} |
421 |
} |
422 |
|
423 |
/**
|
424 |
* Creates a new instance of the default symbol whose type is defined
|
425 |
* by the parameter <b>shapeType</b> and uses the color defined by the
|
426 |
* parameter color.
|
427 |
* @param shapeType, one of FShape.POINT, FShape.LINE, FShape.POLYGON,
|
428 |
* @param color, the color to be applied to the new ISymbol.
|
429 |
*
|
430 |
* FShape.MULTIPOINT, FShape.TEXT, or FShape.MULTI.
|
431 |
* @return ISymbol, the default symbol for the shape type defined by <b>shapeType</b>
|
432 |
*/
|
433 |
public static ISymbol createDefaultSymbolByShapeType(int shapeType, Color color) { |
434 |
ISymbol sym = createDefaultSymbolByShapeType(shapeType); |
435 |
|
436 |
if (sym instanceof IMarkerSymbol) { |
437 |
((IMarkerSymbol) sym).setColor(color); |
438 |
} |
439 |
|
440 |
if (sym instanceof ILineSymbol) { |
441 |
((ILineSymbol) sym).setLineColor(color); |
442 |
} |
443 |
|
444 |
if (sym instanceof IFillSymbol) { |
445 |
((IFillSymbol) sym).setFillColor(color); |
446 |
} |
447 |
|
448 |
if (sym instanceof ITextSymbol) { |
449 |
((ITextSymbol) sym).setTextColor(color); |
450 |
} |
451 |
|
452 |
return sym;
|
453 |
} |
454 |
|
455 |
|
456 |
public static ISymbol getWarningSymbol(String message, String symbolDesc, int symbolDrawExceptionType) { |
457 |
if (warningSymbol == null) { |
458 |
warningSymbol = new WarningSymbol();
|
459 |
} |
460 |
warningSymbol.setDescription(symbolDesc); |
461 |
warningSymbol.setMessage(message); |
462 |
warningSymbol.setDrawExceptionType(symbolDrawExceptionType); |
463 |
return warningSymbol;
|
464 |
} |
465 |
|
466 |
private static class WarningSymbol extends MultiShapeSymbol { |
467 |
private String desc; |
468 |
private String message; |
469 |
private int exceptionType; |
470 |
private SimpleTextSymbol text;
|
471 |
|
472 |
public static void main(String[] args) { |
473 |
JFrame f = new JFrame(); |
474 |
final ISymbol warning = SymbologyFactory.getWarningSymbol(SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS, "a description", SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS); |
475 |
JPanel preview = new JPanel() { |
476 |
@Override
|
477 |
protected void paintComponent(Graphics g) { |
478 |
// TODO Auto-generated method stub
|
479 |
super.paintComponent(g);
|
480 |
Graphics2D g2 = (Graphics2D)g; |
481 |
try {
|
482 |
warning.drawInsideRectangle(g2, g2.getTransform(), getBounds()); |
483 |
} catch (SymbolDrawingException e) {
|
484 |
// TODO Auto-generated catch block
|
485 |
e.printStackTrace(); |
486 |
} |
487 |
} |
488 |
}; |
489 |
f.setContentPane(preview); |
490 |
f.pack(); |
491 |
f.setVisible(true);
|
492 |
} |
493 |
|
494 |
public void draw(Graphics2D g, AffineTransform affineTransform, |
495 |
FShape shp, Cancellable cancel) { |
496 |
try {
|
497 |
drawInsideRectangle(g, g.getTransform(), shp.getBounds()); |
498 |
} catch (SymbolDrawingException e) {
|
499 |
// IMPOSSIBLE
|
500 |
} |
501 |
} |
502 |
|
503 |
public void setDrawExceptionType(int symbolDrawExceptionType) { |
504 |
this.exceptionType = symbolDrawExceptionType;
|
505 |
} |
506 |
|
507 |
public void setMessage(String message) { |
508 |
this.message = message;
|
509 |
} |
510 |
|
511 |
public void drawInsideRectangle(Graphics2D g, |
512 |
AffineTransform scaleInstance, Rectangle r) |
513 |
throws SymbolDrawingException {
|
514 |
g.setClip(r); |
515 |
if (message == null) { |
516 |
message = "Symbol undrawable.\nPlease, check errors.";
|
517 |
} |
518 |
|
519 |
|
520 |
String[] messageLines = message.split("\n"); |
521 |
int strokeWidth = (int) (Math.min(r.width, r.height)*.1); |
522 |
|
523 |
if (strokeWidth == 0) strokeWidth = 1; |
524 |
|
525 |
g.setColor(Color.red);
|
526 |
g.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND)); |
527 |
int x = r.x+strokeWidth;
|
528 |
int y = r.x+strokeWidth;
|
529 |
int width = r.width-(strokeWidth+strokeWidth);
|
530 |
int height = r.height-(strokeWidth+strokeWidth);
|
531 |
|
532 |
double radius = Math.min(width, height)*.5; |
533 |
double centerX = r.getCenterX();
|
534 |
double centerY = r.getCenterY();
|
535 |
Ellipse2D circle = new Ellipse2D.Double(centerX - radius, centerY - radius, 2*radius, 2*radius); |
536 |
g.draw(circle); |
537 |
g.setClip(circle); |
538 |
double aux = Math.cos(Math.PI*0.25)*radius; |
539 |
g.drawLine((int) (centerX - aux), (int) (centerY - aux), (int) (centerX + aux), (int) (centerY + aux)); |
540 |
int fontSize = 20; |
541 |
g.setFont(new Font("Arial", fontSize, Font.PLAIN)); |
542 |
g.setColor(Color.black);
|
543 |
g.setClip(null);
|
544 |
|
545 |
if (text == null) { |
546 |
text = new SimpleTextSymbol();
|
547 |
text.setAutoresizeEnabled(true);
|
548 |
|
549 |
} |
550 |
|
551 |
double lineHeight = (r.getHeight()-6)/messageLines.length; |
552 |
Rectangle textRect = new Rectangle( |
553 |
(int) r.getMinX(),
|
554 |
(int) r.getMinY()+6, |
555 |
(int) r.getWidth(),
|
556 |
(int) lineHeight);
|
557 |
for (int i =0; i < messageLines.length; i++) { |
558 |
text.setText(messageLines[i]); |
559 |
text.drawInsideRectangle(g, null, textRect);
|
560 |
textRect.setLocation((int) r.getX(), (int) (r.getY()+r.getHeight())); |
561 |
} |
562 |
} |
563 |
|
564 |
@Override
|
565 |
public XMLEntity getXMLEntity() {
|
566 |
XMLEntity xml = new XMLEntity();
|
567 |
xml.putProperty("className", getClass().getName());
|
568 |
xml.putProperty("desc", desc);
|
569 |
xml.putProperty("exceptionType", exceptionType);
|
570 |
xml.putProperty("message", message);
|
571 |
return xml;
|
572 |
} |
573 |
|
574 |
@Override
|
575 |
public void setXMLEntity(XMLEntity xml) { |
576 |
setDescription(xml.getStringProperty("desc"));
|
577 |
exceptionType = xml.getIntProperty("exceptionType");
|
578 |
message = xml.getStringProperty("message");
|
579 |
} |
580 |
|
581 |
} |
582 |
|
583 |
|
584 |
} |