Revision 22639 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/SymbologyFactory.java
SymbologyFactory.java | ||
---|---|---|
111 | 111 |
import java.awt.Graphics2D; |
112 | 112 |
import java.awt.Rectangle; |
113 | 113 |
import java.awt.geom.AffineTransform; |
114 |
import java.awt.geom.Ellipse2D; |
|
114 | 115 |
import java.io.File; |
115 | 116 |
|
116 |
import javax.print.attribute.PrintRequestAttributeSet; |
|
117 | 117 |
import javax.swing.JFrame; |
118 | 118 |
import javax.swing.JPanel; |
119 | 119 |
|
120 | 120 |
import org.apache.log4j.Logger; |
121 | 121 |
|
122 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
|
123 | 122 |
import com.iver.cit.gvsig.fmap.Messages; |
124 |
import com.iver.cit.gvsig.fmap.ViewPort; |
|
125 | 123 |
import com.iver.cit.gvsig.fmap.core.styles.IStyle; |
126 | 124 |
import com.iver.cit.gvsig.fmap.core.symbols.IFillSymbol; |
127 | 125 |
import com.iver.cit.gvsig.fmap.core.symbols.ILineSymbol; |
... | ... | |
448 | 446 |
return warningSymbol; |
449 | 447 |
} |
450 | 448 |
|
451 |
private static class WarningSymbol implements ISymbol {
|
|
449 |
private static class WarningSymbol extends MultiShapeSymbol {
|
|
452 | 450 |
private String desc; |
453 | 451 |
private String message; |
454 | 452 |
private int exceptionType; |
453 |
private SimpleTextSymbol text; |
|
455 | 454 |
|
456 | 455 |
public static void main(String[] args) { |
457 | 456 |
JFrame f = new JFrame(); |
... | ... | |
477 | 476 |
|
478 | 477 |
public void draw(Graphics2D g, AffineTransform affineTransform, |
479 | 478 |
FShape shp, Cancellable cancel) { |
480 |
try { |
|
481 |
drawInsideRectangle(g, g.getTransform(), shp.getBounds()); |
|
482 |
} catch (SymbolDrawingException e) { |
|
483 |
// IMPOSSIBLE |
|
479 |
try { |
|
480 |
drawInsideRectangle(g, g.getTransform(), shp.getBounds()); |
|
481 |
} catch (SymbolDrawingException e) { |
|
482 |
// IMPOSSIBLE |
|
483 |
} |
|
484 | 484 |
} |
485 |
} |
|
486 | 485 |
|
487 | 486 |
public void setDrawExceptionType(int symbolDrawExceptionType) { |
488 | 487 |
this.exceptionType = symbolDrawExceptionType; |
... | ... | |
495 | 494 |
public void drawInsideRectangle(Graphics2D g, |
496 | 495 |
AffineTransform scaleInstance, Rectangle r) |
497 | 496 |
throws SymbolDrawingException { |
497 |
g.setClip(r); |
|
498 | 498 |
if (message == null) { |
499 | 499 |
message = "Symbol undrawable.\nPlease, check errors."; |
500 | 500 |
} |
501 | 501 |
|
502 |
|
|
502 | 503 |
String[] messageLines = message.split("\n"); |
503 |
int strokeWidth = 5; |
|
504 |
int strokeWidth = (int) (Math.min(r.width, r.height)*.1); |
|
505 |
|
|
506 |
if (strokeWidth == 0) strokeWidth = 1; |
|
507 |
|
|
504 | 508 |
g.setColor(Color.red); |
505 | 509 |
g.setStroke(new BasicStroke(strokeWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND)); |
506 | 510 |
int x = r.x+strokeWidth; |
... | ... | |
508 | 512 |
int width = r.width-(strokeWidth+strokeWidth); |
509 | 513 |
int height = r.height-(strokeWidth+strokeWidth); |
510 | 514 |
|
511 |
// g.drawOval(x, y, width, height); |
|
512 |
// g.drawLine(x, y, width, height); |
|
515 |
double radius = Math.min(width, height)*.5; |
|
516 |
double centerX = r.getCenterX(); |
|
517 |
double centerY = r.getCenterY(); |
|
518 |
Ellipse2D circle = new Ellipse2D.Double(centerX - radius, centerY - radius, 2*radius, 2*radius); |
|
519 |
g.draw(circle); |
|
520 |
g.setClip(circle); |
|
521 |
double aux = Math.cos(Math.PI*0.25)*radius; |
|
522 |
g.drawLine((int) (centerX - aux), (int) (centerY - aux), (int) (centerX + aux), (int) (centerY + aux)); |
|
513 | 523 |
int fontSize = 20; |
514 |
int vAlign = (int) (r.getCenterY() - ((fontSize+2)*messageLines.length/2)); |
|
515 | 524 |
g.setFont(new Font("Arial", fontSize, Font.PLAIN)); |
516 | 525 |
g.setColor(Color.black); |
526 |
g.setClip(null); |
|
517 | 527 |
|
518 |
for (int i = 0; i < messageLines.length; i++) {
|
|
519 |
g.drawString(messageLines[i], 2, -vAlign);
|
|
520 |
System.out.println(messageLines[i]);
|
|
521 |
vAlign += fontSize + 2; |
|
528 |
if (text == null) {
|
|
529 |
text = new SimpleTextSymbol();
|
|
530 |
text.setAutoresizeEnabled(true);
|
|
531 |
|
|
522 | 532 |
} |
533 |
|
|
534 |
double lineHeight = (r.getHeight()-6)/messageLines.length; |
|
535 |
Rectangle textRect = new Rectangle( |
|
536 |
(int) r.getMinX(), |
|
537 |
(int) r.getMinY()+6, |
|
538 |
(int) r.getWidth(), |
|
539 |
(int) lineHeight); |
|
540 |
for (int i =0; i < messageLines.length; i++) { |
|
541 |
text.setText(messageLines[i]); |
|
542 |
text.drawInsideRectangle(g, null, textRect); |
|
543 |
textRect.setLocation((int) r.getX(), (int) (r.getY()+r.getHeight())); |
|
544 |
} |
|
523 | 545 |
} |
524 | 546 |
|
547 |
@Override |
|
525 | 548 |
public XMLEntity getXMLEntity() { |
526 |
throw new Error("Found symbology problems, please fix them before saving."); } |
|
527 |
|
|
528 |
public String getDescription() { return desc; } |
|
529 |
public int getOnePointRgb() { return 0; } |
|
530 |
public ISymbol getSymbolForSelection() { return this; } |
|
531 |
public void getPixExtentPlus(FShape shp, float[] distances, ViewPort viewPort, int dpi) {} |
|
532 |
public int getSymbolType() { return 0; } |
|
533 |
public boolean isShapeVisible() { return false; } |
|
534 |
public boolean isSuitableFor(IGeometry geom) { return true; } |
|
535 |
public void setDescription(String desc) { this.desc = desc; } |
|
536 |
public void setXMLEntity(XMLEntity xml) { } |
|
537 |
public String getClassName() { return null; } |
|
538 |
|
|
539 |
public void print(Graphics2D g, AffineTransform at, |
|
540 |
FShape shape, PrintRequestAttributeSet properties) |
|
541 |
throws ReadDriverException { |
|
542 |
throw new ReadDriverException("Your symbology contains errors, please check them before printing.", |
|
543 |
new SymbolDrawingException(exceptionType)); |
|
549 |
XMLEntity xml = new XMLEntity(); |
|
550 |
xml.putProperty("className", getClass().getName()); |
|
551 |
xml.putProperty("desc", desc); |
|
552 |
xml.putProperty("exceptionType", exceptionType); |
|
553 |
xml.putProperty("message", message); |
|
554 |
return xml; |
|
544 | 555 |
} |
556 |
|
|
557 |
@Override |
|
558 |
public void setXMLEntity(XMLEntity xml) { |
|
559 |
setDescription(xml.getStringProperty("desc")); |
|
560 |
exceptionType = xml.getIntProperty("exceptionType"); |
|
561 |
message = xml.getStringProperty("message"); |
|
562 |
} |
|
545 | 563 |
|
546 |
|
|
547 | 564 |
}; |
548 | 565 |
} |
Also available in: Unified diff