sclass CirclesRelater extends MouseAdapter { Canvas canvas; CirclesAndLines cal; Circle circle; Pt p; bool popupTrigger; componentPopupMenu_Adapter popup; int minDist = 20; *(Canvas *canvas, CirclesAndLines *cal) { if (containsInstance(canvas.tools, CirclesRelater)) ret; canvas.tools.add(this); canvas.addMouseListener(this); canvas.addMouseMotionListener(this); popup = findMouseListener(canvas, componentPopupMenu_Adapter); canvas.removeMouseListener(popup); } public void mousePressed(MouseEvent e) { popupTrigger = e.isPopupTrigger(); if (e.getButton() != MouseEvent.BUTTON1) circle = findCircle(p = canvas.pointFromEvent(e)); else circle = null; } public void mouseDragged(MouseEvent e) { } public void mouseReleased(MouseEvent e) { Pt pt = canvas.pointFromEvent(e); int d = (int) pointDistance(p, pt); print("Dist: " + d); if (circle == null || d < minDist) { if (popupTrigger && popup != null) popup.displayMenu2(e); ret; } if (circle != null) { final Circle circle2 = findCircle(pt); final Circle circle1 = circle; if (circle1 != circle2 && circle2 != null) { final JTextField tf = jTextField(); showFormTitled("Link nodes", "Node 1", circle1.text, "Connection Name", tf, "Node 2", circle2.text, r { cal.arrow(circle1, toUpper(getTextTrim(tf)), circle2); canvas.update(); }); } } circle = null; } Circle findCircle(Pt p) { ret cal.findCircle(canvas, p); } }