1 21 22 package org.objectweb.util.explorer.swing.graph; 23 24 import java.awt.BasicStroke ; 25 import java.awt.Graphics ; 26 import java.awt.Graphics2D ; 27 import java.awt.Rectangle ; 28 import java.awt.Shape ; 29 import java.awt.geom.Rectangle2D ; 30 31 import org.jgraph.JGraph; 32 import org.jgraph.graph.CellViewRenderer; 33 import org.jgraph.graph.EdgeRenderer; 34 import org.jgraph.graph.EdgeView; 35 36 public class MyBindingView extends EdgeView { 37 38 private static int portCourantPosition = 0; 39 40 protected static MyEdgeRenderer renderer = new MyEdgeRenderer(); 41 42 public MyBindingView(JGraph graph, org.jgraph.graph.CellMapper cm, Object cell) { 43 super(cell, graph, cm); 44 } 45 46 49 public CellViewRenderer getRenderer() { 50 return renderer; 51 } 52 53 public static class MyEdgeRenderer extends EdgeRenderer { 54 55 public Rectangle2D getPaintBounds(EdgeView view) { 56 Rectangle r = super.getPaintBounds(view).getBounds(); 57 return new Rectangle (r.x-40,r.y-40,r.width+80,r.height+80); 58 } 59 60 61 public void paint(Graphics g) { 62 MyPortView sourceView = (MyPortView) view.getSource(); 63 MyPortView targetView = (MyPortView) view.getTarget(); 64 MyPort source = (MyPort)sourceView.getCell(); 65 MyPort target = (MyPort)targetView.getCell(); 66 67 Graphics2D g2 = (Graphics2D ) g; 68 int c = BasicStroke.CAP_BUTT; 69 int j = BasicStroke.JOIN_MITER; 70 g2.setStroke(new BasicStroke (lineWidth, c, j)); 71 translateGraphics(g); 74 g.setColor(getForeground()); 75 76 if (view.lineShape != null) { 78 Shape s = view.lineShape; 79 g2.draw(view.lineShape); 80 } 81 82 Object label = graph.convertValueToString(view); 84 g2.setStroke(new BasicStroke (1)); 85 g.setFont(getFont()); 86 String targetName = target.getName(); 87 g.drawString(source.getName(),(int)sourceView.getLocation(view).getX(),(int)sourceView.getLocation(view).getY()); 88 g.drawString(targetName,(int)targetView.getLocation(view).getX()-(targetName.length()*6),(int)targetView.getLocation(view).getY()); 89 } 90 } 91 92 } | Popular Tags |