001: package org.enhydra.jawe.components.graph;
002:
003: import java.awt.BasicStroke;
004: import java.awt.Color;
005: import java.awt.Graphics;
006: import java.awt.Graphics2D;
007: import java.awt.Rectangle;
008:
009: import javax.swing.BorderFactory;
010: import javax.swing.ImageIcon;
011:
012: import org.enhydra.jawe.JaWEManager;
013: import org.enhydra.jawe.Utils;
014: import org.enhydra.shark.xpdl.XMLUtil;
015: import org.enhydra.shark.xpdl.XPDLConstants;
016: import org.enhydra.shark.xpdl.elements.Activity;
017:
018: /**
019: * Class used to display activity object.
020: *
021: * @author Sasa Bojanic
022: * @author Miroslav Popov
023: */
024: public class DefaultGraphActivityRenderer extends MultiLinedRenderer
025: implements GraphActivityRendererInterface {
026:
027: protected static int arc = 5;
028:
029: /**
030: * Paints activity. Overrides super class paint to add specific painting. First it
031: * fills inner with color. Then it adds specific drawing for join type. Then it apply
032: * JPanel with name and icon. At the end it draws shadow and border
033: */
034: public void paint(Graphics g) {
035: int actW = GraphUtilities.getGraphController()
036: .getGraphSettings().getActivityWidth();
037: int actH = GraphUtilities.getGraphController()
038: .getGraphSettings().getActivityHeight();
039: int shadowWidth = GraphUtilities.getGraphController()
040: .getGraphSettings().getShadowWidth();
041: boolean showShadow = GraphUtilities.getGraphController()
042: .getGraphSettings().isShadowEnabled();
043:
044: GraphActivityInterface gact = (GraphActivityInterface) view
045: .getCell();
046: Activity act = (Activity) gact.getUserObject();
047: boolean frontJoin = false;
048: if (XMLUtil.isANDTypeSplitOrJoin(act, 1))
049: frontJoin = true;
050: boolean backJoin = false;
051: if (XMLUtil.isANDTypeSplitOrJoin(act, 0))
052: backJoin = true;
053:
054: Color bckgC = getFillColor();
055: if (selected)
056: bckgC = GraphUtilities.getGraphController()
057: .getGraphSettings().getSelectedActivityColor();
058:
059: // fill activity
060: g.setColor(bckgC);
061: g.fillRoundRect(0, 0, actW - shadowWidth, actH - shadowWidth,
062: arc, arc);
063:
064: // drawing panel
065: super .setOpaque(false);
066: Graphics gl = g.create(5, 5, actW - 9 - shadowWidth, actH - 9
067: - shadowWidth);
068: Rectangle panelRect = new Rectangle(0, 0, actW - 9
069: - shadowWidth, actH - 9 - shadowWidth);
070: super .setBounds(panelRect);
071: graph.setHighlightColor(bckgC);
072: setBorder(BorderFactory.createLineBorder(bckgC, 0));
073: super .paint(gl);
074: setBorder(BorderFactory.createLineBorder(bordercolor, 0));
075: setForeground(bordercolor);
076:
077: // shadow
078: if (showShadow) {
079: g.setColor(new Color(192, 192, 192));
080: ((Graphics2D) g).setStroke(new BasicStroke(shadowWidth,
081: BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
082: g.drawLine(shadowWidth, actH - shadowWidth, actW
083: - shadowWidth, actH - shadowWidth);
084: if (!backJoin)
085: g.drawLine(actW - shadowWidth, actH - shadowWidth, actW
086: - shadowWidth, shadowWidth);
087: }
088:
089: // draw border
090: g.setColor(bordercolor);
091: ((Graphics2D) g).setStroke(borderStroke);
092: g.drawRoundRect(0, 0, actW - 1 - shadowWidth, actH - 1
093: - shadowWidth, arc, arc);
094:
095: // add > to front
096: Color gCol = GraphUtilities.getGraphController()
097: .getGraphSettings().getBackgroundColor();
098: if (frontJoin) {
099: g.setColor(gCol);
100: int[] x = { 0, 4, 0 };
101: int[] y = { arc, actH / 2, actH - arc };
102: g.fillPolygon(x, y, 3);
103: g.setColor(bordercolor);
104: ((Graphics2D) g).setStroke(borderStroke);
105: g.drawLine(x[0], y[0], x[1], y[1]);
106: g.drawLine(x[1], y[1], x[2], y[2]);
107: }
108: // add > to back
109: if (backJoin) {
110: g.setColor(gCol);
111: // clean
112: int[] x = { actW - shadowWidth - 4, actW, actW,
113: actW - shadowWidth - 4, actW - shadowWidth };
114: int[] y = { 0, 0, actH, actH, actH / 2 };
115: g.fillPolygon(x, y, 5);
116: g.setColor(new Color(192, 192, 192));
117: ((Graphics2D) g).setStroke(new BasicStroke(shadowWidth,
118: BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
119: g.drawLine(x[0] + 1, y[0], x[4] + 1, y[4]);
120: g.drawLine(x[4] + 1, y[4], x[3] + 1, y[3] - shadowWidth);
121: g.setColor(bordercolor);
122: ((Graphics2D) g).setStroke(borderStroke);
123: g.drawLine(x[0], y[0], x[4], y[4]);
124: g.drawLine(x[4], y[4], x[3], y[3] - shadowWidth);
125: }
126:
127: int type = act.getActivityType();
128: if (type == XPDLConstants.ACTIVITY_TYPE_BLOCK
129: && GraphUtilities.getGraphController()
130: .getGraphSettings().shouldDrawBlockLines()) {
131: g.setColor(bordercolor);
132: g.drawLine(3, 0, 3, actH - 2 - shadowWidth);
133: g.drawLine(actW - 4 - shadowWidth, 0, actW - 4
134: - shadowWidth, actH - 2 - shadowWidth);
135: } else if (type == XPDLConstants.ACTIVITY_TYPE_SUBFLOW
136: && GraphUtilities.getGraphController()
137: .getGraphSettings().shouldDrawSubflowLines()) {
138: g.setColor(bordercolor);
139: ((Graphics2D) g).setStroke(borderStroke);
140: g.drawRect(3, 3, actW - 7 - shadowWidth, actH - 7
141: - shadowWidth);
142: }
143: }
144:
145: protected Color getFillColor() {
146: Activity act = (Activity) ((GraphActivityInterface) view
147: .getCell()).getUserObject();
148: Color c = JaWEManager.getInstance().getJaWEController()
149: .getTypeResolver().getJaWEType(act).getColor();
150: GraphSettings gv = GraphUtilities.getGraphController()
151: .getGraphSettings();
152: if (!gv.shouldUseBubbles()) {
153: boolean isStartingAct = JaWEManager.getInstance()
154: .getXPDLUtils().isStartingActivity(act);
155: boolean isEndingAct = JaWEManager.getInstance()
156: .getXPDLUtils().isEndingActivity(act);
157: if (isStartingAct && isEndingAct) {
158: c = gv.getStartEndActivityColor();
159: } else if (isStartingAct) {
160: c = gv.getStartActivityColor();
161: } else if (isEndingAct) {
162: c = gv.getEndActivityColor();
163: }
164: }
165: return c;
166: }
167:
168: public ImageIcon getIcon() {
169: Activity act = (Activity) ((GraphActivityInterface) view
170: .getCell()).getUserObject();
171:
172: String icon = act.getIcon();
173:
174: ImageIcon ii = null;
175: if (!icon.equals("")) {
176: ii = (ImageIcon) Utils.getOriginalActivityIconsMap().get(
177: icon);
178: }
179:
180: if (ii == null) {
181: ii = JaWEManager.getInstance().getJaWEController()
182: .getTypeResolver().getJaWEType(act).getIcon();
183: }
184:
185: return ii;
186: }
187:
188: }
|