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: import java.awt.Shape;
009: import java.awt.geom.Point2D;
010:
011: import org.enhydra.jawe.JaWEManager;
012: import org.enhydra.shark.xpdl.elements.Transition;
013: import org.jgraph.JGraph;
014: import org.jgraph.graph.CellView;
015: import org.jgraph.graph.EdgeRenderer;
016: import org.jgraph.graph.EdgeView;
017: import org.jgraph.graph.GraphConstants;
018:
019: /**
020: * Represents a view for a model's Transition object.
021: * @author Sasa Bojanic
022: */
023: public class DefaultGraphTransitionRenderer extends EdgeRenderer
024: implements GraphTransitionRendererInterface {
025:
026: public DefaultGraphTransitionRenderer() {
027: super ();
028: }
029:
030: public void paint(Graphics g) {
031: GraphTransitionInterface tr = (GraphTransitionInterface) view
032: .getCell();
033: if (tr.hasCondition()) {
034: lineWidth = 3;
035: } else {
036: lineWidth = 1;
037: }
038:
039: Transition t = (Transition) tr.getUserObject();
040: Color clr = GraphUtilities.getGraphController()
041: .getGraphSettings().getBubbleConectionColor();
042: if (t != null)
043: clr = JaWEManager.getInstance().getJaWEController()
044: .getTypeResolver().getJaWEType(t).getColor();
045:
046: Shape edgeShape = view.getShape();
047: // Sideeffect: beginShape, lineShape, endShape
048: if (edgeShape != null) {
049: Graphics2D g2 = (Graphics2D) g;
050: int c = BasicStroke.CAP_BUTT;
051: int j = BasicStroke.JOIN_MITER;
052: g2.setStroke(new BasicStroke(lineWidth, c, j));
053: translateGraphics(g);
054: //g.setColor(getForeground());
055: g.setColor(clr);
056: if (view.beginShape != null) {
057: if (beginFill)
058: g2.fill(view.beginShape);
059: g2.draw(view.beginShape);
060: }
061: if (view.endShape != null) {
062: if (endFill)
063: g2.fill(view.endShape);
064: g2.draw(view.endShape);
065: }
066: if (lineDash != null) // Dash For Line Only
067: g2.setStroke(new BasicStroke(lineWidth, c, j, 10.0f,
068: lineDash, 0.0f));
069: if (view.lineShape != null)
070: g2.draw(view.lineShape);
071:
072: if (selected) { // Paint Selected
073: g2.setStroke(GraphConstants.SELECTION_STROKE);
074: g2.setColor(graph.getHighlightColor());
075: if (view.beginShape != null)
076: g2.draw(view.beginShape);
077: if (view.lineShape != null)
078: g2.draw(view.lineShape);
079: if (view.endShape != null)
080: g2.draw(view.endShape);
081: }
082: if (graph.getEditingCell() != view.getCell()
083: && GraphUtilities.getGraphController()
084: .getGraphSettings()
085: .shouldShowTransitionCondition()) {
086: Object label = graph.convertValueToString(view);
087: if (label != null) {
088: g2.setStroke(new BasicStroke(1));
089: g.setFont(getFont());
090: paintLabel(g, label.toString(),
091: getLabelPosition(view), true);
092: }
093: }
094: }
095: }
096:
097: public boolean intersects(JGraph pGraph, CellView value,
098: Rectangle rect) {
099: if (value instanceof EdgeView && pGraph != null
100: && value != null) {
101: setView(value);
102:
103: // If we have two control points, we can get rid of hit
104: // detection on do an intersection test on the two diagonals
105: // of rect and the line between the two points
106: EdgeView edgeView = (EdgeView) value;
107: if (edgeView.getPointCount() == 2) {
108: Point2D p0 = edgeView.getPoint(0);
109: Point2D p1 = edgeView.getPoint(1);
110: if (rect.intersectsLine(p0.getX(), p0.getY(),
111: p1.getX(), p1.getY()))
112: return true;
113: } else {
114: Graphics2D g2 = (Graphics2D) pGraph.getGraphics();
115: if (g2.hit(rect, view.getShape(), true))
116: return true;
117: }
118: }
119: return false;
120: }
121:
122: void setView(CellView value) {
123: if (value instanceof EdgeView) {
124: view = (EdgeView) value;
125: installAttributes(view);
126: } else {
127: view = null;
128: }
129: }
130:
131: }
132:
133: /* End of TransitionRenderer.java */
|