1
14 package demo.view.flowchart.painters;
15
16 import y.view.AbstractCustomNodePainter;
17 import y.view.NodeRealizer;
18 import y.view.GenericNodeRealizer;
19 import y.view.YRenderingHints;
20
21 import java.awt.Shape;
22 import java.awt.Graphics2D;
23 import java.awt.Color;
24 import java.awt.GradientPaint;
25
26
29 public abstract class AbstractFlowchartPainter extends AbstractCustomNodePainter implements GenericNodeRealizer.ContainsTest, FlowchartRealizerConstants {
30 protected Shape outline;
31 protected Shape innerShape;
32
33
34
40 protected void paintNode(NodeRealizer context, Graphics2D graphics, boolean sloppy) {
41 updateOutline(context);
42 updateInsideShape(context);
43
44 boolean useSelectionStyle = useSelectionStyle(context, graphics);
45 graphics.setStroke(getLineStroke(context, useSelectionStyle));
46
47 Color fillColor1 = getFillColor(context, useSelectionStyle);
48 Color fillColor2 = getFillColor2(context, useSelectionStyle);
49 Color lineColor = getLineColor(context, useSelectionStyle);
50
51 if (fillColor1 != null) {
52 if (fillColor2 != null && useGradientStyle(graphics)) {
53 double x = context.getX();
54 double y = context.getY();
55 double width = context.getWidth();
56 double heigh = context.getHeight();
57 GradientPaint gp = new GradientPaint((float) x, (float) y, fillColor1, (float) x + (float) width,
58 (float) y + (float) heigh, fillColor2);
59 graphics.setPaint(gp);
60 } else {
61 graphics.setColor(fillColor1);
62 }
63 if (outline != null) {
64 graphics.fill(outline);
65 }
66 }
67 if (lineColor!=null){
68 graphics.setColor(lineColor);
69 if (outline != null){
70 graphics.draw(outline);
71 }
72 if (innerShape!=null){
73 graphics.draw(innerShape);
74 }
75 }
76 }
77
78
82 Shape getOutline() {
83 return outline;
84 }
85
86
90 public Shape getInnerShape() {
91 return innerShape;
92 }
93
94
98 protected abstract void updateOutline(NodeRealizer context);
99
100
104 protected void updateInsideShape(NodeRealizer context) {
105 }
106
107 public boolean contains(NodeRealizer context, double x, double y) {
108 updateOutline(context);
109 return outline != null && outline.contains(x, y);
110 }
111
112
113 static boolean useGradientStyle( final Graphics2D graphics ) {
114 return YRenderingHints.isGradientPaintingEnabled(graphics);
115 }
116
117 static boolean useSelectionStyle(
118 final NodeRealizer context,
119 final Graphics2D gfx
120 ) {
121 return context.isSelected() && YRenderingHints.isSelectionPaintingEnabled(gfx);
122 }
123 }
124