Revision 22997
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/SymbologyFactory.java | ||
---|---|---|
154 | 154 |
* @author jaume dominguez faus - jaume.dominguez@iver.es |
155 | 155 |
*/ |
156 | 156 |
public class SymbologyFactory { |
157 |
|
|
157 |
|
|
158 | 158 |
/** |
159 |
* This Constants are only used in SymbologyPage (preferences page for symbology),
|
|
159 |
* This Constants are only used in SymbologyPage (preferences page for symbology), |
|
160 | 160 |
* do not use in other context. |
161 | 161 |
*/ |
162 | 162 |
public static final Color FactoryDefaultSymbolColor = Color.GRAY; |
... | ... | |
168 | 168 |
"gvSIG" + |
169 | 169 |
File.separator + |
170 | 170 |
"Symbols"; |
171 |
|
|
172 |
|
|
171 |
|
|
172 |
public static final Boolean FactoryDefaultAleatoryFillColor = false; |
|
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
|
173 | 178 |
public static Color DefaultSymbolColor = FactoryDefaultSymbolColor; |
174 | 179 |
public static Color DefaultFillSymbolColor = FactoryDefaultFillSymbolColor; |
175 | 180 |
public static Font DefaultTextFont = FactoryDefaultTextFont; |
176 | 181 |
public static String SymbolLibraryPath = FactorySymbolLibraryPath; |
177 |
|
|
182 |
|
|
183 |
public static Boolean DefaultAleatoryFillColor = FactoryDefaultAleatoryFillColor; |
|
184 |
|
|
185 |
|
|
186 |
|
|
178 | 187 |
private static Logger logger = Logger.getLogger(SymbologyFactory.class.getName()); |
179 | 188 |
private static WarningSymbol warningSymbol; |
180 | 189 |
|
... | ... | |
208 | 217 |
*/ |
209 | 218 |
public static IStyle createStyleFromXML(XMLEntity xml, String defaultDescription) { |
210 | 219 |
if (!xml.contains("desc")) { |
211 |
if (defaultDescription == null)
|
|
220 |
if (defaultDescription == null) |
|
212 | 221 |
defaultDescription = ""; |
213 | 222 |
|
214 | 223 |
xml.putProperty("desc", defaultDescription); |
... | ... | |
307 | 316 |
default: |
308 | 317 |
throw new Error("Shape type not yet supported for multilayer symbols"); |
309 | 318 |
} |
310 |
|
|
319 |
|
|
311 | 320 |
if (mSym instanceof CartographicSupport) { |
312 | 321 |
CartographicSupport cs = (CartographicSupport) mSym; |
313 | 322 |
cs.setUnit(CartographicSupportToolkit.DefaultMeasureUnit); |
... | ... | |
344 | 353 |
cs.setUnit(CartographicSupportToolkit.DefaultMeasureUnit); |
345 | 354 |
cs.setReferenceSystem(CartographicSupportToolkit.DefaultReferenceSystem); |
346 | 355 |
} |
347 |
|
|
356 |
|
|
348 | 357 |
/** |
349 | 358 |
* Returns a new instance of an <b>IFillSymbol</b>. Black outline, |
350 | 359 |
* and transparent fill. |
... | ... | |
415 | 424 |
*/ |
416 | 425 |
public static ISymbol createDefaultSymbolByShapeType(int shapeType, Color color) { |
417 | 426 |
ISymbol sym = createDefaultSymbolByShapeType(shapeType); |
427 |
|
|
428 |
if(!DefaultAleatoryFillColor) |
|
429 |
color = DefaultFillSymbolColor; |
|
430 |
|
|
418 | 431 |
if (sym instanceof IMarkerSymbol) { |
419 | 432 |
((IMarkerSymbol) sym).setColor(color); |
420 | 433 |
} |
... | ... | |
434 | 447 |
return sym; |
435 | 448 |
} |
436 | 449 |
|
437 |
|
|
438 | 450 |
|
439 | 451 |
public static ISymbol getWarningSymbol(String message, String symbolDesc, int symbolDrawExceptionType) { |
440 | 452 |
if (warningSymbol == null) { |
... | ... | |
445 | 457 |
warningSymbol.setDrawExceptionType(symbolDrawExceptionType); |
446 | 458 |
return warningSymbol; |
447 | 459 |
} |
448 |
|
|
460 |
|
|
449 | 461 |
private static class WarningSymbol extends MultiShapeSymbol { |
450 | 462 |
private String desc; |
451 | 463 |
private String message; |
452 | 464 |
private int exceptionType; |
453 | 465 |
private SimpleTextSymbol text; |
454 |
|
|
466 |
|
|
455 | 467 |
public static void main(String[] args) { |
456 | 468 |
JFrame f = new JFrame(); |
457 | 469 |
final ISymbol warning = SymbologyFactory.getWarningSymbol(SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS, "a description", SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS); |
... | ... | |
498 | 510 |
if (message == null) { |
499 | 511 |
message = "Symbol undrawable.\nPlease, check errors."; |
500 | 512 |
} |
501 |
|
|
502 |
|
|
513 |
|
|
514 |
|
|
503 | 515 |
String[] messageLines = message.split("\n"); |
504 | 516 |
int strokeWidth = (int) (Math.min(r.width, r.height)*.1); |
505 |
|
|
517 |
|
|
506 | 518 |
if (strokeWidth == 0) strokeWidth = 1; |
507 |
|
|
519 |
|
|
508 | 520 |
g.setColor(Color.red); |
509 | 521 |
g.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND)); |
510 | 522 |
int x = r.x+strokeWidth; |
511 | 523 |
int y = r.x+strokeWidth; |
512 | 524 |
int width = r.width-(strokeWidth+strokeWidth); |
513 | 525 |
int height = r.height-(strokeWidth+strokeWidth); |
514 |
|
|
526 |
|
|
515 | 527 |
double radius = Math.min(width, height)*.5; |
516 | 528 |
double centerX = r.getCenterX(); |
517 | 529 |
double centerY = r.getCenterY(); |
... | ... | |
524 | 536 |
g.setFont(new Font("Arial", fontSize, Font.PLAIN)); |
525 | 537 |
g.setColor(Color.black); |
526 | 538 |
g.setClip(null); |
527 |
|
|
539 |
|
|
528 | 540 |
if (text == null) { |
529 | 541 |
text = new SimpleTextSymbol(); |
530 | 542 |
text.setAutoresizeEnabled(true); |
531 |
|
|
543 |
|
|
532 | 544 |
} |
533 |
|
|
545 |
|
|
534 | 546 |
double lineHeight = (r.getHeight()-6)/messageLines.length; |
535 | 547 |
Rectangle textRect = new Rectangle( |
536 |
(int) r.getMinX(),
|
|
548 |
(int) r.getMinX(), |
|
537 | 549 |
(int) r.getMinY()+6, |
538 |
(int) r.getWidth(),
|
|
550 |
(int) r.getWidth(), |
|
539 | 551 |
(int) lineHeight); |
540 | 552 |
for (int i =0; i < messageLines.length; i++) { |
541 | 553 |
text.setText(messageLines[i]); |
... | ... | |
543 | 555 |
textRect.setLocation((int) r.getX(), (int) (r.getY()+r.getHeight())); |
544 | 556 |
} |
545 | 557 |
} |
546 |
|
|
558 |
|
|
547 | 559 |
@Override |
548 | 560 |
public XMLEntity getXMLEntity() { |
549 | 561 |
XMLEntity xml = new XMLEntity(); |
... | ... | |
553 | 565 |
xml.putProperty("message", message); |
554 | 566 |
return xml; |
555 | 567 |
} |
556 |
|
|
568 |
|
|
557 | 569 |
@Override |
558 | 570 |
public void setXMLEntity(XMLEntity xml) { |
559 | 571 |
setDescription(xml.getStringProperty("desc")); |
... | ... | |
561 | 573 |
message = xml.getStringProperty("message"); |
562 | 574 |
} |
563 | 575 |
|
564 |
}; |
|
576 |
} |
|
577 |
|
|
578 |
|
|
565 | 579 |
} |
Also available in: Unified diff