001: /**
002: *
003: * Bonita
004: * Copyright (C) 1999 Bull S.A.
005: * Bull 68 route de versailles 78434 Louveciennes Cedex France
006: * Further information: bonita@objectweb.org
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public
010: * License as published by the Free Software Foundation; either
011: * version 2.1 of the License, or any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public
019: * License along with this library; if not, write to the Free Software
020: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
021: * USA
022: *
023: *
024: --------------------------------------------------------------------------
025: * $Id: BonitaActivityView.java,v 1.1 2004/07/30 14:57:57 mvaldes Exp $
026: *
027: --------------------------------------------------------------------------
028: */package hero.client.grapheditor;
029:
030: import java.awt.BasicStroke;
031: import java.awt.Color;
032: import java.awt.Dimension;
033: import java.awt.Font;
034: import java.awt.Graphics;
035: import java.awt.Graphics2D;
036:
037: import com.jgraph.JGraph;
038: import com.jgraph.graph.CellMapper;
039: import com.jgraph.graph.CellViewRenderer;
040: import com.jgraph.graph.GraphConstants;
041: import com.jgraph.graph.VertexRenderer;
042: import com.jgraph.graph.VertexView;
043: import java.util.Map;
044: import javax.swing.ImageIcon;
045: import java.awt.Toolkit;
046:
047: public class BonitaActivityView extends VertexView {
048:
049: public ActivityRenderer renderer;
050:
051: public BonitaActivityView(Object arg0, JGraph arg1, CellMapper arg2) {
052: super (arg0, arg1, arg2);
053: renderer = new ActivityRenderer((BonitaActivityCell) arg0);
054: }
055:
056: public CellViewRenderer getRenderer() {
057: return renderer;
058: }
059:
060: public static class ActivityRenderer extends VertexRenderer {
061:
062: private BonitaActivityCell activity;
063:
064: public ActivityRenderer(BonitaActivityCell rb) {
065: activity = rb;
066: }
067:
068: public void paint(Graphics g) {
069:
070: Graphics2D g2 = (Graphics2D) g;
071: Dimension d = getSize();
072: boolean tmp = selected;
073:
074: // ??
075: try {
076: setBorder(null);
077: setOpaque(false);
078: setText("");
079: selected = false;
080: super .paint(g);
081: } finally {
082: selected = tmp;
083: }
084:
085: // choice stroke style
086: if (selected) {
087: g2.setStroke(GraphConstants.SELECTION_STROKE);
088: } else {
089: g2.setStroke(new BasicStroke(1));
090: }
091:
092: int y = ((getHeight() - 19) / 2) + 1;
093:
094: Color contour = Color.decode("#3E6AAB");
095: Map props = activity.getAttributes();
096:
097: // draw box
098: if (!selected) {
099: g2.setColor(getBackground());
100: if (((String) props.get("subProcess")).equals("yes"))
101: g2.fillOval(4, 4, getWidth() - 9, getHeight() - 9);
102: else
103: g2.fillRoundRect(4, 4, getWidth() - 9,
104: getHeight() - 9, 10, 10);
105: }
106: g2.setColor(contour);
107:
108: if (((String) props.get("subProcess")).equals("yes"))
109: g2.drawOval(4, 4, getWidth() - 9, getHeight() - 9);
110: else
111: g2.drawRoundRect(4, 4, getWidth() - 9, getHeight() - 9,
112: 10, 10);
113:
114: // Set icon path
115: Map propers = activity.getAttributes();
116: String iteration = (String) propers.get("iterate");
117: if (!iteration.equals("false")) {
118: String 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 iconUrl = Thread.currentThread()
126: .getContextClassLoader().getResource(
127: iconPath);
128: //g2.drawImage(IconManager.getIcon(iconPath),11,y,19,19,Frame.getFrame().getWorkflowGraph());
129: g2.drawImage(Toolkit.getDefaultToolkit().getImage(
130: iconUrl), 5, y, 10, 10, Frame.getFrame()
131: .getWorkflowGraph());
132: } catch (Exception e) {
133: System.out.println("Unable to load image "
134: + iconPath);
135: }
136: }
137:
138: // draw name
139: g2.setColor(Color.WHITE);
140: if (((String) props.get("subProcess")).equals("yes"))
141: g2.setFont(g2.getFont().deriveFont((float) (12)));
142: else
143: g2.setFont(g2.getFont().deriveFont((float) (11)));
144: g2.setFont(g2.getFont().deriveFont(Font.ITALIC));
145:
146: String name = (String) props.get("name");
147: g2.drawString(name, 11, y + 12);
148: }
149: }
150:
151: }
|