KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* ActivityRenderer.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.*;
15
16 import org.jgraph.graph.*;
17
18 import java.awt.*;
19 import javax.swing.*;
20
21 /**
22  * Class used to display activity object.
23  */

24 //public class ActivityRenderer extends VertexRenderer {
25
public class ActivityRenderer extends MultiLinedRenderer {
26
27    private BasicStroke borderStroke = new BasicStroke(2);
28
29    protected static final int actW=JaWEConfig.getInstance().getActivityWidth();
30    protected static final int actH=JaWEConfig.getInstance().getActivityHeight();
31    protected static final int innerW=JaWEConfig.getInstance().getInnerActivityWidth();
32    protected static final int innerH=JaWEConfig.getInstance().getInnerActivityHeight();
33    protected static final int xOff=(int)((actW-innerW)/2);
34    protected static final int yOff=(int)((actH-innerH)/2);
35
36    /**
37     * Paints activity. Overrides super class paint
38     * to add specific painting.
39     */

40    public void paint(Graphics g) {
41       Activity act=(Activity)view.getCell();
42       // read colors because they can change on-line
43
//Color preconditionColor=Utils.getColor(JaWEConfig.getInstance().getActivityPreconditionColor());
44
//Color postconditionColor=Utils.getColor(JaWEConfig.getInstance().getActivityPostconditionColor());
45
Color fillColor=getFillColor();
46
47       Color gridC=graph.getGridColor();
48       Color highlightC=graph.getHighlightColor();
49       Color bckgC=fillColor; //graph.getBackground();
50
Color borderC=bordercolor;
51       if (selected) {
52          bckgC=Utils.getColor(JaWEConfig.getInstance().getSelectedActivityColor());
53       }
54
55       super.setBackground(bckgC);
56
57       int xo[]=new int[]{0,actW-1,actW-1,actW-1,0,0};
58       int yo[]=new int[]{0,0,actH/2,actH-1,actH-1,actH/2};
59       int xi[]=new int[]{1,actW-2,actW-2,actW-2,1,1};
60       int yi[]=new int[]{1,1,actH/2,actH-2,actH-2,actH/2};
61       if (XMLUtil.isANDTypeSplitOrJoin((org.enhydra.jawe.xml.elements.Activity)act.getPropertyObject(),1)) {
62          xo[5]=xOff-3;
63          xi[5]=xOff-2;
64       }
65       if (XMLUtil.isANDTypeSplitOrJoin((org.enhydra.jawe.xml.elements.Activity)act.getPropertyObject(),0)) {
66          xo[1]=actW-xOff+3;
67          xo[3]=actW-xOff+3;
68          xi[1]=actW-xOff+2;
69          xi[3]=actW-xOff+2;
70       }
71
72       int points=6;
73
74       // drawing outer border
75
g.setColor(bckgC);
76       //g.fillRect(0,0,actW-1,actH-1);
77
g.fillPolygon(xo,yo,points);
78       g.setColor(bordercolor);
79       ((Graphics2D) g).setStroke(borderStroke);
80       //g.drawRect(1,1,actW-2,actH-2);
81
g.drawPolygon(xi,yi,points);
82
83       // if selected, or has focus draw with selection/focus attributes
84
if (selected || hasFocus) {
85          ((Graphics2D) g).setStroke(GraphConstants.SELECTION_STROKE);
86          if (hasFocus)
87             g.setColor(graph.getGridColor());
88          else if (selected)
89             g.setColor(graph.getHighlightColor());
90          //g.drawRect(0,0,actW-1,actH-1);
91
//g.drawRoundRect(0, 0, actW-1,actH-1,arc,0);
92
g.drawPolygon(xo,yo,points);
93       }
94
95       // drawing label
96
Graphics gl=g.create(xOff,yOff,innerW,innerH);
97       Rectangle labelRect=new Rectangle(new Dimension(innerW,innerH));
98       super.setBounds(labelRect);
99       graph.setGridColor(bckgC);
100       graph.setHighlightColor(bckgC);
101       setBorder(BorderFactory.createLineBorder(bckgC,borderWidth));
102       super.paint(gl);
103       setBorder(BorderFactory.createLineBorder(bordercolor,borderWidth));
104       setForeground(bordercolor);
105       graph.setGridColor(gridC);
106       graph.setHighlightColor(highlightC);
107
108
109       // filling pre/post condition rectangle if needed
110
/*if (act.hasAnyPrecondition()) {
111          g.setColor(preconditionColor);
112          // paint bounds of preconditions
113          g.fillRect(2,2,xOff-1,actH-4);
114       }
115       if (act.hasAnyPostcondition()) {
116          g.setColor(postconditionColor);
117          // paint bounds of postconditions
118          g.fillRect(innerW+xOff,2,xOff-2,actH-4);
119        }*/

120    }
121
122    protected Color getFillColor () {
123       Color c=Utils.getColor(JaWEConfig.getInstance().getGenericActivityColor());
124       return ActivityRenderer.getFillColor(c,(Activity)view.getCell());
125    }
126
127    protected static Color getFillColor (Color defaultColor,Activity act) {
128       if (!JaWEConfig.getInstance().getUseBubblesStatus()) {
129          boolean isStartingAct=Utils.isStartingActivity(act);
130          boolean isEndingAct=Utils.isEndingActivity(act);
131          if (isStartingAct && isEndingAct) {
132             return Utils.getColor(JaWEConfig.getInstance().getStartEndColor());
133          } else if (isStartingAct) {
134             return Utils.getColor(JaWEConfig.getInstance().getStartColor());
135          } else if (isEndingAct) {
136             return Utils.getColor(JaWEConfig.getInstance().getEndColor());
137          }
138       }
139       return defaultColor;
140    }
141
142 }
143
Popular Tags