001: package org.enhydra.jawe.components.graph;
002:
003: import java.awt.Rectangle;
004: import java.awt.geom.Rectangle2D;
005: import java.util.HashMap;
006: import java.util.Map;
007:
008: import org.enhydra.shark.xpdl.elements.Participant;
009: import org.jgraph.JGraph;
010: import org.jgraph.graph.CellMapper;
011: import org.jgraph.graph.CellView;
012: import org.jgraph.graph.CellViewRenderer;
013: import org.jgraph.graph.GraphModel;
014: import org.jgraph.graph.VertexView;
015:
016: /**
017: * Represents a view for a model's Participant object.
018: *
019: * @author Sasa Bojanic
020: */
021: public class DefaultGraphParticipantView extends VertexView implements
022: GraphParticipantViewInterface {
023:
024: protected static Map renderers = new HashMap();
025:
026: /**
027: * Constructs a participant view for the specified model object.
028: *
029: * @param cell reference to the model object
030: */
031: public DefaultGraphParticipantView(Object cell) {
032: super (cell);
033: }
034:
035: /**
036: * Returns a renderer for the class.
037: */
038: public CellViewRenderer getRenderer() {
039: String type = ((GraphParticipantInterface) super .getCell())
040: .getType();
041: GraphParticipantRendererInterface gprenderer = (GraphParticipantRendererInterface) renderers
042: .get(type);
043: if (gprenderer == null) {
044: gprenderer = createRenderer((Participant) ((GraphParticipantInterface) super
045: .getCell()).getUserObject());
046: renderers.put(type, gprenderer);
047: }
048: return gprenderer;
049: }
050:
051: /**
052: * Returns true if name portion of ParticipantView intersects the given rectangle.
053: */
054: public boolean intersects(JGraph graph, Rectangle2D rect) {//HM, JGraph3.4.1
055: Rectangle2D lBounds = getBounds();//HM, JGraph3.4.1
056: boolean rotateParticipant = GraphUtilities
057: .getGraphParticipantOrientation(
058: ((Graph) graph).getWorkflowProcess(),
059: ((Graph) graph).getXPDLObject())
060: .equals(
061: GraphEAConstants.EA_JAWE_GRAPH_PARTICIPANT_ORIENTATION_VALUE_VERTICAL);
062:
063: if (lBounds != null) {
064: Rectangle nameBounds;
065: if (rotateParticipant)
066: nameBounds = new Rectangle((int) lBounds.getX(),
067: (int) lBounds.getY(), (int) lBounds.getWidth(),
068: GraphUtilities.getGraphController()
069: .getGraphSettings()
070: .getParticipantNameWidth());
071: else
072: nameBounds = new Rectangle((int) lBounds.getX(),
073: (int) lBounds.getY(), GraphUtilities
074: .getGraphController()
075: .getGraphSettings()
076: .getParticipantNameWidth(),
077: (int) lBounds.getHeight());
078: return nameBounds.intersects(rect);
079: }
080: return false;
081: }
082:
083: /**
084: * Clears childView's and then refreshes it.
085: */
086: public void refreshChildViews(GraphModel model, CellMapper mapper) {
087: childViews.clear();
088: refresh(model, mapper, false);
089: }
090:
091: /**
092: * Returns the bounding rectangle for this view.
093: */
094: public Rectangle2D getBounds() {//HM, JGraph3.4.1
095: return bounds;
096: }
097:
098: /**
099: * Adds participants child view to it.
100: */
101: public void addChildView(CellView childView) {
102: if (childView != null) {
103: childViews.add(childView);
104: }
105: }
106:
107: protected GraphParticipantRendererInterface createRenderer(
108: Participant par) {
109: return GraphUtilities.getGraphController()
110: .getGraphObjectRendererFactory()
111: .createParticipantRenderer(par);
112: }
113:
114: }
|