1 26 package org.objectweb.util.explorer.swing.graph; 27 28 import java.awt.Point ; 29 import java.awt.Rectangle ; 30 import java.awt.event.MouseEvent ; 31 import java.awt.geom.Line2D ; 32 import java.awt.geom.Point2D ; 33 import java.awt.geom.Rectangle2D ; 34 35 import org.jgraph.graph.EdgeView; 36 import org.jgraph.graph.GraphConstants; 37 import org.jgraph.graph.GraphContext; 38 39 43 public class MyEdgeHandle extends EdgeView.EdgeHandle { 44 45 public MyEdgeHandle(EdgeView edge, GraphContext ctx) { 46 super(edge, ctx); 47 } 48 49 public void mousePressed(MouseEvent event) { 51 System.out.println("mouse event"); 52 53 boolean bendable = 54 graph.isBendable() 55 && GraphConstants.isBendable(edge.getAllAttributes()); 56 boolean disconnectable = 57 graph.isDisconnectable() 58 && GraphConstants.isDisconnectable(orig.getAllAttributes()); 59 int x = event.getX(); 60 int y = event.getY(); 61 int index = 0; 63 for (index = 0; index < r.length; index++) { 64 if (r[index].contains(x, y)) { 65 currentPoint = edge.getPoint(index); 66 source = 67 index == 0 68 && (edge.getSource() == null 69 || (disconnectable 70 && GraphConstants.isDisconnectable( 71 edge 72 .getSource() 73 .getParentView() 74 .getAllAttributes()))); 75 target = 76 index == r.length - 1 77 && (edge.getTarget() == null 78 || (disconnectable 79 && GraphConstants.isDisconnectable( 80 edge 81 .getTarget() 82 .getParentView() 83 .getAllAttributes()))); 84 break; 85 } 86 } 87 if (!isEditing() 89 && graph.isMoveable() 90 && GraphConstants.isMoveable(edge.getAllAttributes()) 91 && loc != null 92 && loc.contains(x, y) 93 && !isAddPointEvent(event) 94 && !isRemovePointEvent(event)) { 95 if (event.getClickCount() == graph.getEditClickCount()) 96 graph.startEditingAtCell(edge); 97 else 98 label = true; 99 } 101 if (isRemovePointEvent(event) 102 && currentPoint != null 103 && !source && !target 104 && bendable) { 105 edge.removePoint(index); 106 mouseReleased(event); 107 } else if (isAddPointEvent(event) && !isEditing() && bendable) { 109 int s = graph.getHandleSize(); 110 Rectangle2D rect = 111 graph.fromScreen(new Rectangle (x - s, y - s, 2 * s, 2 * s)); 112 if (edge.intersects(graph.getGraphics(), rect)) { 113 Point2D point = 114 graph.fromScreen( 115 graph.snap(new Point (event.getPoint()))); 116 double min = Double.MAX_VALUE, dist = 0; 117 for (int i = 0; i < edge.getPointCount() - 1; i++) { 118 Point2D p = edge.getPoint(i); 119 Point2D p1 = edge.getPoint(i + 1); 120 dist = new Line2D.Double (p, p1).ptLineDistSq(point); 121 if (dist < min) { 122 min = dist; 123 index = i + 1; 124 } 125 } 126 edge.addPoint(index, point); 127 currentPoint = point; 128 reloadPoints(edge); 129 paint(graph.getGraphics()); 130 } 131 } 132 if (isEditing()) 133 event.consume(); 134 } 135 136 } | Popular Tags |