public int compare(GraphNode o1, GraphNode o2) { double x1 = o1.getPos().getX(); double y1 = o1.getPos().getY(); double x2 = o2.getPos().getX(); double y2 = o2.getPos().getY(); double h1 = FastMath.hypot(x1, y1); double h2 = FastMath.hypot(x2, y2); if (h1 > h2) return -1; else if (h1 < h2) return +1; else return 0; } }
/** * Handle mouse dragged event * * @param e the mouse event */ public void mouseDragged(MouseEvent e) { if (selectedNode != null && !connectingSourceFromHead && !connectingSourceFromTail) { final Point p = new Point(e.getX() - (lastMousePos.x - selectedNode.getPos().x), e.getY() - (lastMousePos.y - selectedNode.getPos().y)); selectedNode.setPos(p); lastMousePos = e.getPoint(); repaint(); } if (connectingSourceFromHead || connectingSourceFromTail) { connectingSourcePos = e.getPoint(); repaint(); } }
private GraphNode findNode(Point p) { for (GraphNode n : graphEx.GetGraphNodes()) { if (isWithinRect(n.getPos(), n.getWidth(), n.getHeight(), p)) return n; } return null; }
@Test public void testPosition() { Point p1 = new Point(1, 2); graphNode.setPos(p1); Point p2 = graphNode.getPos(); assertEquals(p1, p2); }