KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > client > grapheditor > BonitaActivityView


1 /**
2  *
3  * Bonita
4  * Copyright (C) 1999 Bull S.A.
5  * Bull 68 route de versailles 78434 Louveciennes Cedex France
6  * Further information: bonita@objectweb.org
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21  * USA
22  *
23  *
24 --------------------------------------------------------------------------
25  * $Id: BonitaActivityView.java,v 1.1 2004/07/30 14:57:57 mvaldes Exp $
26  *
27 --------------------------------------------------------------------------
28  */

29
30 package hero.client.grapheditor;
31
32 import java.awt.BasicStroke JavaDoc;
33 import java.awt.Color JavaDoc;
34 import java.awt.Dimension JavaDoc;
35 import java.awt.Font JavaDoc;
36 import java.awt.Graphics JavaDoc;
37 import java.awt.Graphics2D JavaDoc;
38
39 import com.jgraph.JGraph;
40 import com.jgraph.graph.CellMapper;
41 import com.jgraph.graph.CellViewRenderer;
42 import com.jgraph.graph.GraphConstants;
43 import com.jgraph.graph.VertexRenderer;
44 import com.jgraph.graph.VertexView;
45 import java.util.Map JavaDoc;
46 import javax.swing.ImageIcon JavaDoc;
47 import java.awt.Toolkit JavaDoc;
48
49 public class BonitaActivityView extends VertexView {
50
51     public ActivityRenderer renderer;
52
53     public BonitaActivityView(Object JavaDoc arg0, JGraph arg1, CellMapper arg2) {
54         super(arg0, arg1, arg2);
55         renderer = new ActivityRenderer((BonitaActivityCell) arg0);
56     }
57
58     public CellViewRenderer getRenderer() {
59         return renderer;
60     }
61
62     public static class ActivityRenderer extends VertexRenderer {
63
64         private BonitaActivityCell activity;
65
66         public ActivityRenderer(BonitaActivityCell rb) {
67             activity = rb;
68         }
69
70         public void paint(Graphics JavaDoc g) {
71
72             Graphics2D JavaDoc g2 = (Graphics2D JavaDoc) g;
73             Dimension JavaDoc d = getSize();
74             boolean tmp = selected;
75
76             // ??
77
try {
78                 setBorder(null);
79                 setOpaque(false);
80                 setText("");
81                 selected = false;
82                 super.paint(g);
83             } finally {
84                 selected = tmp;
85             }
86
87             // choice stroke style
88
if (selected) {
89                 g2.setStroke(GraphConstants.SELECTION_STROKE);
90             } else {
91                 g2.setStroke(new BasicStroke JavaDoc(1));
92             }
93
94             int y = ((getHeight() - 19) / 2) + 1;
95
96             Color JavaDoc contour = Color.decode("#3E6AAB");
97             Map JavaDoc props = activity.getAttributes();
98
99             // draw box
100
if (!selected) {
101                 g2.setColor(getBackground());
102                 if (((String JavaDoc)props.get("subProcess")).equals("yes"))
103                     g2.fillOval(4, 4, getWidth() - 9, getHeight() - 9);
104                 else
105                     g2.fillRoundRect(4, 4, getWidth() - 9, getHeight() - 9, 10, 10);
106             }
107             g2.setColor(contour);
108                     
109             if (((String JavaDoc)props.get("subProcess")).equals("yes"))
110                 g2.drawOval(4, 4, getWidth() - 9, getHeight() - 9);
111             else
112                 g2.drawRoundRect(4, 4, getWidth() - 9, getHeight() - 9, 10, 10);
113
114             // Set icon path
115
Map JavaDoc propers = activity.getAttributes();
116             String JavaDoc iteration = (String JavaDoc)propers.get("iterate");
117             if (!iteration.equals("false")) {
118                 String JavaDoc iconPath=null;
119                if (iteration.equals("from"))
120                  iconPath = "images/from.gif";
121                else
122                  iconPath = "images/to.gif";
123             // draw icon
124
try {
125                 java.net.URL JavaDoc iconUrl = Thread.currentThread().getContextClassLoader().getResource(iconPath);
126                 //g2.drawImage(IconManager.getIcon(iconPath),11,y,19,19,Frame.getFrame().getWorkflowGraph());
127
g2.drawImage(Toolkit.getDefaultToolkit().getImage(iconUrl),5,y,10,10,Frame.getFrame().getWorkflowGraph());
128               } catch(Exception JavaDoc e){
129                 System.out.println("Unable to load image " + iconPath);
130               }
131             }
132                     
133             // draw name
134
g2.setColor(Color.WHITE);
135             if (((String JavaDoc)props.get("subProcess")).equals("yes"))
136                 g2.setFont(g2.getFont().deriveFont((float) (12)));
137             else
138                g2.setFont(g2.getFont().deriveFont((float) (11)));
139             g2.setFont(g2.getFont().deriveFont(Font.ITALIC));
140             
141             String JavaDoc name = (String JavaDoc)props.get("name");
142             g2.drawString(name, 11, y + 12);
143         }
144     }
145
146 }
147
Popular Tags