001: package org.enhydra.jawe.components.graph;
002:
003: import java.awt.Color;
004: import java.awt.Dimension;
005: import java.awt.Font;
006: import java.awt.Graphics;
007: import java.awt.Graphics2D;
008: import java.awt.Rectangle;
009:
010: import javax.swing.ImageIcon;
011:
012: import org.enhydra.jawe.JaWEManager;
013: import org.enhydra.shark.xpdl.elements.Participant;
014: import org.jgraph.graph.GraphConstants;
015:
016: /**
017: * Class used to display participant object. It differs from other renderers because the
018: * super class paint method isn't called.
019: *
020: * @author Sasa Bojanic
021: * @author Miroslav Popov
022: */
023: public class DefaultGraphParticipantRenderer extends MultiLinedRenderer
024: implements GraphParticipantRendererInterface {
025:
026: /**
027: * Paints participant. Overrides superclass paint to add specific painting. Basically,
028: * it draws a rectangle and vertical line, it draws it twice for selected participants.
029: * Eventually departmetns name is displayed rotated and in color to indicate selection.
030: *
031: * @param g Graphics to paint to
032: */
033: public void paint(Graphics g) {
034: boolean rotateParticipant = GraphUtilities
035: .getGraphParticipantOrientation(
036: ((Graph) graph).getWorkflowProcess(),
037: ((Graph) graph).getXPDLObject())
038: .equals(
039: GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ORIENTATION_VALUE_VERTICAL);
040:
041: int participantNameWidth = GraphUtilities.getGraphController()
042: .getGraphSettings().getParticipantNameWidth();
043:
044: String label = graph.convertValueToString(view.getCell());
045: Graphics2D g2 = (Graphics2D) g;
046: Dimension d = view.getBounds().getBounds().getSize();// HM, JGraph3.4.1
047:
048: g2.setStroke(GraphSettings.DEPARTMENT_STROKE);
049:
050: Color bordCol = GraphUtilities.getGraphController()
051: .getGraphSettings().getParticipantBorderColor();
052: g.setColor(bordCol);
053:
054: // paint bounds
055: g.drawRect(0, 0, d.width - 1, d.height - 1);
056:
057: // width of name part
058: GraphParticipantInterface p = (GraphParticipantInterface) view
059: .getCell();
060: Color pc;
061: Participant par = (Participant) p.getPropertyObject();
062: if (par instanceof FreeTextExpressionParticipant) {
063: pc = GraphUtilities.getGraphController().getGraphSettings()
064: .getParticipantFreeTextExpressionColor();
065: } else if (par instanceof CommonExpressionParticipant) {
066: pc = GraphUtilities.getGraphController().getGraphSettings()
067: .getParticipantCommonExpressionColor();
068: } else {
069: pc = JaWEManager.getInstance().getJaWEController()
070: .getTypeResolver().getJaWEType(par).getColor();
071: }
072:
073: g.setColor(pc);
074: if (rotateParticipant)
075: g.fillRect(1, 1, d.width - 3, participantNameWidth - 2);
076: else
077: g.fillRect(1, 1, participantNameWidth - 2, d.height - 3);
078: g.setColor(bordCol);
079: // }
080:
081: if (rotateParticipant)
082: g.drawLine(0, participantNameWidth, d.width - 1,
083: participantNameWidth);
084: else
085: g.drawLine(participantNameWidth, 0, participantNameWidth,
086: d.height - 1);
087:
088: // this section paints participant in a case when object is selected
089: // NOTE: hasFocus condition is removed because participant has focus
090: // when any of it's children has
091: if (selected) {// || hasFocus) {
092: g2.setStroke(GraphConstants.SELECTION_STROKE);
093: // if (hasFocus) g.setColor(graph.getGridColor());
094: // else if (selected) g.setColor(graph.getHighlightColor());
095: g.setColor(graph.getHighlightColor());
096: g.drawRect(0, 0, d.width - 1, d.height - 1);
097:
098: if (rotateParticipant)
099: g.drawLine(0, participantNameWidth, d.width - 1,
100: participantNameWidth);
101: else
102: g.drawLine(participantNameWidth, 0,
103: participantNameWidth, d.height - 1);
104:
105: }
106:
107: // Eventually, participants (participants) name comes on. For selected
108: // one label is shown in highlight color (previously set), for others
109: // label color is same as for border. Translate and rotate calls set
110: // the drawing origin and direction, so label is displayed sidewise and
111: // vertically centered.
112: if (label != null) {
113: if (!selected) {
114: g2.setStroke(GraphSettings.DEPARTMENT_STROKE);
115: // g.setColor(GraphUtilities.getGraphController().getGraphSettings().getParticipantTextColor());
116: }
117:
118: Font f = GraphConstants.getFont(view.getAllAttributes());
119: g2.setFont(f);
120: int textL = getFontMetrics(f).stringWidth(label);
121: int textH = getFontMetrics(f).getHeight();
122:
123: Graphics2D pg;
124: if (rotateParticipant) {
125: if (textL > d.width)
126: textL = d.width;
127:
128: textL = (d.width - textL) / 2 - 10;
129: pg = (Graphics2D) g.create(1, 1, d.width - 3,
130: participantNameWidth - 2);
131: pg.translate(textL, (participantNameWidth - textH) / 2);
132: super .setBounds(new Rectangle(1, 1, d.width - 3,
133: participantNameWidth - 2));
134: } else {
135: if (textL > d.height - 20)
136: textL = d.height - 20;
137:
138: textL = d.height / 2 - textL / 2 - 10;
139: pg = (Graphics2D) g.create(1, 1,
140: participantNameWidth - 2, d.height - 3);
141: pg.translate(1, d.height - textL);
142: // pg.translate((participantNameWidth - textH) / 2, d.height - textL);
143: pg.rotate(Math.toRadians(-90));
144: super .setBounds(new Rectangle(1, 1, d.height - 4,
145: participantNameWidth - 5));
146: }
147:
148: super .paint(pg);
149: // super.paint(g2);
150: }
151: }
152:
153: public ImageIcon getIcon() {
154: GraphParticipantInterface p = (GraphParticipantInterface) view
155: .getCell();
156:
157: Participant par = (Participant) p.getPropertyObject();
158: if (par instanceof FreeTextExpressionParticipant) {
159: return GraphUtilities.getGraphController()
160: .getGraphSettings().getFreeTextParticipantIcon();
161: } else if (par instanceof CommonExpressionParticipant) {
162: return GraphUtilities.getGraphController()
163: .getGraphSettings()
164: .getCommonExpresionParticipantIcon();
165: } else {
166: return JaWEManager.getInstance().getJaWEController()
167: .getTypeResolver().getJaWEType(par).getIcon();
168: }
169: }
170:
171: public void setTextPosition(int place) {
172: }
173:
174: }
|