01: package com.opensymphony.workflow.designer.views;
02:
03: import java.awt.Dimension;
04: import java.awt.Graphics;
05: import java.awt.geom.Rectangle2D;
06: import java.awt.geom.Point2D;
07: import javax.swing.*;
08:
09: import org.jgraph.graph.*;
10:
11: import com.opensymphony.workflow.designer.ResourceManager;
12:
13: /**
14: * User: Hani Suleiman
15: * Date: Oct 16, 2003
16: * Time: 10:23:47 AM
17: */
18: public class CustomPortView extends PortView {
19: private static final ImageIcon ICON = ResourceManager
20: .getIcon("port");
21: private static final CellViewRenderer RENDERER = new CustomPortRenderer();
22: private static final int WIDTH = ICON.getIconWidth();
23: private static final int HEIGHT = ICON.getIconHeight();
24:
25: public CustomPortView(Object object) {
26: super (object);
27: }
28:
29: /**
30: * Returns the bounds for the port view.
31: */
32: public Rectangle2D getBounds() {
33: Point2D location = getLocation(null);
34: Rectangle2D bounds = new Rectangle2D.Double(location.getX()
35: - WIDTH / 2, location.getY(), WIDTH, HEIGHT);
36: //bounds.x = bounds.x - WIDTH / 2;
37: //bounds.width = WIDTH;
38: //bounds.height = HEIGHT;
39: return bounds;
40: }
41:
42: //public Point2D getLocation(EdgeView edge)
43: //{
44: // Point p = super.getLocation(edge);
45: // if(edge!=null && edge.getSource()==edge.getTarget())
46: // {
47: // int index = ((WorkflowPort)getCell()).getEdgeIndex((Edge)edge.getCell());
48: // p.y = p.y - (5 * index);
49: // }
50: // return p;
51: // }
52:
53: public CellViewRenderer getRenderer() {
54: return RENDERER;
55: }
56:
57: static class CustomPortRenderer extends PortRenderer {
58: public void paint(Graphics g) {
59: g.setColor(graph.getBackground());
60: //g.setXORMode(graph.getBackground());
61: if (preview) {
62: Dimension d = getSize();
63: g.setColor(java.awt.Color.red);
64: g.drawRect(1, 1, d.width - 3, d.height - 3);
65: g.drawRect(2, 2, d.width - 5, d.height - 5);
66: } else
67: ICON.paintIcon(graph, g, 0, 0);
68: }
69:
70: }
71: }
|