KickJava   Java API By Example, From Geeks To Geeks.

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


1 /* ParticipantRenderer.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
15 import org.jgraph.graph.*;
16
17 import java.awt.*;
18 import javax.swing.*;
19
20 /**
21  * Class used to display participant object. It differs from other renderers
22  * because the super class paint method isn't called.
23  *
24  */

25 public class ParticipantRenderer extends VertexRenderer {
26
27    protected static final int participantNameWidth=JaWEConfig.getInstance().getParticipantNameWidth();
28
29    /**
30     * Paints participant. Overrides superclass paint to add specific painting.
31     *
32     * Basically, it draws a rectangle and vertical line, it draws it twice for
33     * selected participants. Eventually departmetns name is displayed rotated and
34     * in color to indicate selection.
35     *
36     * @param g Graphics to paint to
37     */

38    public void paint(Graphics g) {
39       String JavaDoc label = graph.convertValueToString(view.getCell());
40       Graphics2D g2 = (Graphics2D) g;
41       Dimension d = view.getBounds().getBounds().getSize();//HM, JGraph3.4.1
42

43       g2.setStroke(JaWEConstants.DEPARTMENT_STROKE);
44
45       Color bordCol=Utils.getColor(JaWEConfig.getInstance().getParticipantBorderColor());
46       g.setColor(bordCol);
47
48       // paint bounds
49
g.drawRect(0,0,d.width-1,d.height-1);
50
51       // width of name part
52
Participant p=(Participant)view.getCell();
53       if (p.getUserObject()==org.enhydra.jawe.xml.elements.Participant.
54           getFreeTextExpressionParticipant()) {
55          g.setColor(Utils.getColor(JaWEConfig.getInstance().getFreeTextExpressionParticipantColor()));
56          g.fillRect(1,1,d.width-3,d.height-3);
57          g.setColor(bordCol);
58       } else {
59          Color pc;
60          String JavaDoc pt=p.get("ParticipantType").toValue().toString();
61          if (pt.equals("RESOURCE_SET")) {
62             pc=Utils.getColor(JaWEConfig.getInstance().getResourceSetParticipantColor());
63          } else if (pt.equals("RESOURCE")) {
64             pc=Utils.getColor(JaWEConfig.getInstance().getResourceParticipantColor());
65          } else if (pt.equals("ROLE")) {
66             pc=Utils.getColor(JaWEConfig.getInstance().getRoleParticipantColor());
67          } else if (pt.equals("ORGANIZATIONAL_UNIT")) {
68             pc=Utils.getColor(JaWEConfig.getInstance().getOrganizationalUnitParticipantColor());
69          } else if (pt.equals("HUMAN")) {
70             pc=Utils.getColor(JaWEConfig.getInstance().getHumanParticipantColor());
71          } else { // it is system participant
72
pc=Utils.getColor(JaWEConfig.getInstance().getSystemParticipantColor());
73          }
74
75          g.setColor(pc);
76          g.fillRect(1,1,participantNameWidth-2,d.height-3);
77          g.setColor(bordCol);
78       }
79
80       // paint vertical line
81
g.drawLine(participantNameWidth,0,participantNameWidth,d.height-1);
82
83
84       // this section paints participant in a case when object is selected
85
// NOTE: hasFocus condition is removed because participant has focus
86
// when any of it's children has
87
if (selected) {// || hasFocus) {
88
g2.setStroke(GraphConstants.SELECTION_STROKE);
89          //if (hasFocus) g.setColor(graph.getGridColor());
90
//else if (selected) g.setColor(graph.getHighlightColor());
91
g.setColor(graph.getHighlightColor());
92          g.drawRect(0, 0, d.width-1, d.height-1);
93
94          g.drawLine(participantNameWidth,0,participantNameWidth,d.height-1);
95
96       }
97
98       // Eventually, participants (participants) name comes on. For selected
99
// one label is shown in highlight color (previously set), for others
100
// label color is same as for border. Translate and rotate calls set
101
// the drawing origin and direction, so label is displayed sidewise and
102
// vertically centered.
103
if (label != null) {
104          if (!selected) {
105             g2.setStroke(JaWEConstants.DEPARTMENT_STROKE);
106             g.setColor(Utils.getColor(JaWEConfig.getInstance().getParticipantTextColor()));
107          }
108          Font f=GraphConstants.getFont(view.getAllAttributes());
109          g2.setFont(f);
110          int h = getFontMetrics(f).stringWidth(label);
111
112          h = d.height / 2 + h / 2;
113          g2.translate(participantNameWidth/2, h);
114          g2.rotate(Math.toRadians(-90));
115          g2.drawString(label,0,0);
116       }
117    }
118
119 }
120
Popular Tags