1 18 19 20 package org.objectweb.jac.ide.diagrams; 21 22 import CH.ifa.draw.framework.DrawingEditor; 23 import CH.ifa.draw.framework.Figure; 24 import CH.ifa.draw.framework.FigureEnumeration; 25 import CH.ifa.draw.standard.AbstractTool; 26 import java.awt.event.MouseEvent ; 27 import java.util.HashSet ; 28 29 33 public class DragTracker extends AbstractTool { 34 35 Figure anchorFigure; 36 int lastX, lastY; 38 public DragTracker(DrawingEditor newDrawingEditor, Figure anchor) { 39 super(newDrawingEditor); 40 anchorFigure = anchor; 41 } 42 43 public void mouseDown(MouseEvent e, int x, int y) { 44 super.mouseDown(e, x, y); 45 lastX = x; 46 lastY = y; 47 48 if (e.isShiftDown()) { 49 view().toggleSelection(anchorFigure); 50 anchorFigure = null; 51 } else if (!view().isFigureSelected(anchorFigure)) { 52 view().clearSelection(); 53 view().addToSelection(anchorFigure); 54 } 55 view().repairDamage(); 56 } 57 58 public void mouseDrag(MouseEvent e, int x, int y) { 59 super.mouseDrag(e, x, y); 60 61 if ((Math.abs(x - fAnchorX) > 4) || (Math.abs(y - fAnchorY) > 4)) { 62 org.objectweb.jac.util.Log.trace("tools","MOVED!"); 63 64 HashSet linkFigures = new HashSet (); 66 FigureEnumeration figures = view().selectionElements(); 67 while (figures.hasMoreElements()) { 68 Figure figure = figures.nextFigure(); 69 if (figure instanceof LinkFigure) { 70 linkFigures.add(((LinkFigure)figure).getSubstance()); 71 } 72 } 73 74 figures = view().selectionElements(); 75 while (figures.hasMoreElements()) { 76 Figure figure = figures.nextFigure(); 77 if (! ((figure instanceof AttachedTextFigure) 78 && linkFigures.contains(((AttachedTextFigure)figure).getSubstance()))) { 79 figure.moveBy(x - lastX, y - lastY); 80 } 81 } 82 } 83 lastX = x; 84 lastY = y; 85 } 86 87 public void activate() { 88 } 89 90 public void deactivate() { 91 } 92 } 93 | Popular Tags |