1 package com.opensymphony.workflow.designer.views; 2 3 import java.awt.Dimension ; 4 import java.awt.Graphics ; 5 import java.awt.geom.Rectangle2D ; 6 import java.awt.geom.Point2D ; 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 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 object, JGraph graph, CellMapper mapper) 27 { 28 super(object, graph, mapper); 29 } 30 31 34 public Rectangle2D getBounds() 35 { 36 Point2D location = getLocation(null); 37 Rectangle2D bounds = new Rectangle2D.Double (location.getX() - WIDTH / 2, location.getY(), WIDTH, HEIGHT); 38 return bounds; 42 } 43 44 55 public CellViewRenderer getRenderer() 56 { 57 return RENDERER; 58 } 59 60 static class CustomPortRenderer extends PortRenderer 61 { 62 public void paint(Graphics g) 63 { 64 g.setColor(graph.getBackground()); 65 if(preview) 67 { 68 Dimension 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 |