01: package com.opensymphony.workflow.designer.views;
02:
03: import java.awt.*;
04:
05: import org.jgraph.graph.GraphConstants;
06: import org.jgraph.graph.VertexRenderer;
07:
08: public class StepRenderer extends VertexRenderer {
09: public void paint(Graphics g) {
10: int b = borderWidth;
11: Graphics2D g2 = (Graphics2D) g;
12: Dimension d = getSize();
13: boolean tmp = selected;
14: int roundRectArc = StepRenderer.getArcSize(d.width - b,
15: d.height - b);
16: if (super .isOpaque()) {
17: g.setColor(super .getBackground());
18: if (gradientColor != null && !preview) {
19: setOpaque(false);
20: g2.setPaint(new GradientPaint(0, 0, getBackground(),
21: getWidth(), getHeight(), gradientColor, true));
22: }
23: g.fillRoundRect(b - 1, b - 1, d.width - b, d.height - b,
24: roundRectArc, roundRectArc);
25: }
26: try {
27: setBorder(null);
28: setOpaque(false);
29: selected = false;
30: super .paint(g);
31: } finally {
32: selected = tmp;
33: }
34: if (bordercolor != null) {
35: g.setColor(bordercolor);
36: g2.setStroke(new BasicStroke(b));
37: g.drawRoundRect(b - 1, b - 1, d.width - b, d.height - b,
38: roundRectArc, roundRectArc);
39: }
40: if (selected) {
41: g2.setStroke(GraphConstants.SELECTION_STROKE);
42: g.setColor(graph.getHighlightColor());
43: g.drawRoundRect(b - 1, b - 1, d.width - b, d.height - b,
44: roundRectArc, roundRectArc);
45: }
46: }
47:
48: /**
49: * getArcSize calculates an appropriate arc for the corners of the rectangle for boundary size cases of width and
50: * height
51: */
52: public static int getArcSize(int width, int height) {
53: int arcSize;
54:
55: // The arc width of a activity rectangle is 1/5th of the larger
56: // of the two of the dimensions passed in, but at most 1/2
57: // of the smaller of the two. 1/5 because it looks nice and 1/2
58: // so the arc can complete in the given dimension
59:
60: if (width <= height) {
61: arcSize = height / 5;
62: if (arcSize > (width / 2)) {
63: arcSize = width / 2;
64: }
65: } else {
66: arcSize = width / 5;
67: if (arcSize > (height / 2)) {
68: arcSize = height / 2;
69: }
70: }
71:
72: return arcSize;
73: }
74: }
|