KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > jawe > graph > TransitionRenderer


1 /* TransitionRenderer.java
2  *
3  * Authors:
4  * Stefanovic Nenad chupo@iis.ns.ac.yu
5  * Bojanic Sasa sasaboy@neobee.net
6  * Puskas Vladimir vpuskas@eunet.yu
7  * Pilipovic Goran zboniek@uns.ac.yu
8  *
9  */

10
11 package org.enhydra.jawe.graph;
12
13 import org.enhydra.jawe.*;
14 import org.enhydra.jawe.xml.elements.Condition;
15
16 import org.jgraph.graph.*;
17 import org.jgraph.JGraph;
18
19 import java.util.*;
20 import java.awt.*;
21 import java.awt.geom.*;
22 import java.awt.event.*;
23 import javax.swing.undo.UndoableEdit JavaDoc;
24
25 /**
26  * Represents a view for a model's Transition object.
27  */

28 public class TransitionRenderer extends EdgeRenderer {
29
30
31    public TransitionRenderer () {
32       super();
33    }
34
35    public void paint(Graphics g) {
36       Transition tr=(Transition)view.getCell();
37       if (tr.hasCondition()) {
38          lineWidth=3;
39       } else {
40          lineWidth=1;
41       }
42       Color clr=Utils.getColor(JaWEConfig.getInstance().getTransitionColor());
43       String JavaDoc ttype=tr.getType();
44       if (ttype.equals(Condition.CONDITION_TYPE_DEFAULTEXCEPTION)) {
45          clr=Utils.getColor(JaWEConfig.getInstance().getDefaultExceptionTransitionColor());
46       } else if (ttype.equals(Condition.CONDITION_TYPE_EXCEPTION)) {
47          clr=Utils.getColor(JaWEConfig.getInstance().getExceptionTransitionColor());
48       } else if (ttype.equals(Condition.CONDITION_TYPE_OTHERWISE)) {
49          clr=Utils.getColor(JaWEConfig.getInstance().getOtherwiseTransitionColor());
50       }
51
52       //String condition=tr.getCondition();
53

54       Shape edgeShape = view.getShape();
55       // Sideeffect: beginShape, lineShape, endShape
56
if (edgeShape != null) {
57          Graphics2D g2 = (Graphics2D) g;
58          int c = BasicStroke.CAP_BUTT;
59          int j = BasicStroke.JOIN_MITER;
60          g2.setStroke(new BasicStroke(lineWidth, c, j));
61          translateGraphics(g);
62          //g.setColor(getForeground());
63
g.setColor(clr);
64          if (view.beginShape != null) {
65             if (beginFill)
66                g2.fill(view.beginShape);
67             g2.draw(view.beginShape);
68          }
69          if (view.endShape != null) {
70             if (endFill)
71                g2.fill(view.endShape);
72             g2.draw(view.endShape);
73          }
74          if (lineDash != null) // Dash For Line Only
75
g2.setStroke(
76                new BasicStroke(lineWidth, c, j, 10.0f, lineDash, 0.0f));
77          if (view.lineShape != null)
78             g2.draw(view.lineShape);
79
80          if (selected) { // Paint Selected
81
g2.setStroke(GraphConstants.SELECTION_STROKE);
82             g2.setColor(graph.getHighlightColor());
83             if (view.beginShape != null)
84                g2.draw(view.beginShape);
85             if (view.lineShape != null)
86                g2.draw(view.lineShape);
87             if (view.endShape != null)
88                g2.draw(view.endShape);
89          }
90          if (graph.getEditingCell() != view.getCell()) {
91             Object JavaDoc label = graph.convertValueToString(view);
92             if (label != null) {
93                g2.setStroke(new BasicStroke(1));
94                g.setFont(getFont());
95                paintLabel(g, label.toString());
96             }
97          }
98       }
99    }
100 }
101
102 /* End of TransitionRenderer.java */
103
Popular Tags