KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opensymphony > workflow > designer > views > CustomPortView


1 package com.opensymphony.workflow.designer.views;
2
3 import java.awt.Dimension JavaDoc;
4 import java.awt.Graphics JavaDoc;
5 import java.awt.geom.Rectangle2D JavaDoc;
6 import java.awt.geom.Point2D JavaDoc;
7 import javax.swing.*;
8
9 import org.jgraph.JGraph;
10 import org.jgraph.graph.*;
11
12 import com.opensymphony.workflow.designer.ResourceManager;
13
14 /**
15  * User: Hani Suleiman
16  * Date: Oct 16, 2003
17  * Time: 10:23:47 AM
18  */

19 public class CustomPortView extends PortView
20 {
21   private static final ImageIcon ICON = ResourceManager.getIcon("port");
22   private static final CellViewRenderer RENDERER = new CustomPortRenderer();
23   private static final int WIDTH = ICON.getIconWidth();
24   private static final int HEIGHT = ICON.getIconHeight();
25
26   public CustomPortView(Object JavaDoc object, JGraph graph, CellMapper mapper)
27   {
28     super(object, graph, mapper);
29   }
30
31   /**
32    * Returns the bounds for the port view.
33    */

34   public Rectangle2D JavaDoc getBounds()
35   {
36     Point2D JavaDoc location = getLocation(null);
37     Rectangle2D JavaDoc bounds = new Rectangle2D.Double JavaDoc(location.getX() - WIDTH / 2, location.getY(), WIDTH, HEIGHT);
38     //bounds.x = bounds.x - WIDTH / 2;
39
//bounds.width = WIDTH;
40
//bounds.height = HEIGHT;
41
return bounds;
42   }
43
44   //public Point2D getLocation(EdgeView edge)
45
//{
46
// Point p = super.getLocation(edge);
47
// if(edge!=null && edge.getSource()==edge.getTarget())
48
// {
49
// int index = ((WorkflowPort)getCell()).getEdgeIndex((Edge)edge.getCell());
50
// p.y = p.y - (5 * index);
51
// }
52
// return p;
53
// }
54

55   public CellViewRenderer getRenderer()
56   {
57     return RENDERER;
58   }
59
60   static class CustomPortRenderer extends PortRenderer
61   {
62     public void paint(Graphics JavaDoc g)
63     {
64       g.setColor(graph.getBackground());
65       //g.setXORMode(graph.getBackground());
66
if(preview)
67       {
68         Dimension JavaDoc d = getSize();
69         g.setColor(java.awt.Color.red);
70         g.drawRect(1, 1, d.width - 3, d.height - 3);
71         g.drawRect(2, 2, d.width - 5, d.height - 5);
72       }
73       else
74         ICON.paintIcon(graph, g, 0, 0);
75     }
76
77   }
78 }
79
Popular Tags