1
28 package demo.view.flowchart.painters;
29
30 import y.view.AbstractCustomNodePainter;
31 import y.view.NodeRealizer;
32 import y.view.GenericNodeRealizer;
33
34 import java.awt.Paint;
35 import java.awt.Shape;
36 import java.awt.Graphics2D;
37 import java.awt.Color;
38 import java.awt.GradientPaint;
39
40
43 public abstract class AbstractFlowchartPainter extends AbstractCustomNodePainter implements GenericNodeRealizer.ContainsTest, FlowchartRealizerConstants {
44
50 protected void paintNode(NodeRealizer context, Graphics2D graphics, boolean sloppy) {
51 final Shape outline = newShape(context);
52 if (initializeFill(context, graphics)) {
53 graphics.fill(outline);
54 }
55 if (initializeLine(context, graphics)) {
56 graphics.draw(outline);
57
58 final Shape decoration = newDecoration(context);
59 if (decoration != null) {
60 graphics.draw(decoration);
61 }
62 }
63 }
64
65 protected Paint getFillPaint( final NodeRealizer context, final boolean selected ) {
66 final Color fc1 = getFillColor(context, selected);
67 if (fc1 != null) {
68 final Color fc2 = getFillColor2(context, selected);
69 if (fc2 != null) {
70 final double x = context.getX();
71 final double y = context.getY();
72 return new GradientPaint(
73 (float) x, (float) y, fc1,
74 (float)(x + context.getWidth()), (float) (y + context.getHeight()), fc2,
75 true);
76 } else {
77 return fc1;
78 }
79 } else {
80 return null;
81 }
82 }
83
84
88 protected abstract Shape newShape(NodeRealizer context);
89
90
94 protected Shape newDecoration(NodeRealizer context) {
95 return null;
96 }
97
98 public boolean contains(NodeRealizer context, double x, double y) {
99 return newShape(context).contains(x, y);
100 }
101
102
103 protected double getBorderDistance(NodeRealizer context, double defaultValue) {
104 GenericNodeRealizer gnr = (GenericNodeRealizer) context;
105 Object value = gnr.getStyleProperty(PROPERTY_BORDER_DISTANCE);
106 if (value instanceof Number) {
107 return ((Number) value).doubleValue();
108 } else {
109 return defaultValue;
110 }
111 }
112
113 protected double getRadius(NodeRealizer context, double defaultValue) {
114 GenericNodeRealizer gnr = (GenericNodeRealizer) context;
115 Object value = gnr.getStyleProperty(PROPERTY_RADIUS);
116 if (value instanceof Number) {
117 return ((Number) value).doubleValue();
118 } else {
119 return defaultValue;
120 }
121 }
122 }
123