1 18 19 package org.objectweb.jac.ide.diagrams; 20 21 import CH.ifa.draw.contrib.DragNDropTool; 22 import CH.ifa.draw.framework.DrawingEditor; 23 import CH.ifa.draw.framework.DrawingView; 24 import CH.ifa.draw.framework.Figure; 25 import CH.ifa.draw.framework.Handle; 26 import CH.ifa.draw.framework.Tool; 27 import CH.ifa.draw.standard.HandleTracker; 28 import CH.ifa.draw.standard.SelectAreaTracker; 29 import org.objectweb.jac.aspects.gui.DisplayContext; 30 import java.awt.event.MouseEvent ; 31 32 33 public class SelectionTool extends AbstractTool { 34 35 protected Tool fChild = null; 36 protected DisplayContext context; 37 38 public SelectionTool(DrawingEditor newDrawingEditor, DisplayContext context) { 39 super(newDrawingEditor); 40 this.context = context; 41 } 42 43 46 public void mouseDown(MouseEvent e, int x, int y) { 47 if (fChild != null) { 51 return; 52 } 53 54 view().freezeView(); 55 56 Handle handle = view().findHandle(e.getX(), e.getY()); 57 if (handle != null) { 58 fChild = createHandleTracker(view(), handle); 59 } else { 60 Figure figure = drawing().findFigureInside(e.getX(), e.getY()); 61 if (figure instanceof Selectable) { 62 ((Selectable)figure).onSelect(context); 63 } 64 figure = drawing().findFigure(e.getX(), e.getY()); 65 if (figure != null) { 66 fChild = createDragTracker(figure); 67 } else { 68 if (!e.isShiftDown()) { 69 view().clearSelection(); 70 } 71 fChild = createAreaTracker(); 72 } 73 } 74 fChild.mouseDown(e, x, y); 75 fChild.activate(); 76 view().repairDamage(); 77 } 78 79 83 public void mouseMove(MouseEvent evt, int x, int y) { 84 DragNDropTool.setCursor(evt.getX(), evt.getY(), view()); 85 ((DiagramView)editor()).setCoord(x,y); 86 view().repairDamage(); 87 } 88 89 93 public void mouseDrag(MouseEvent e, int x, int y) { 94 if (fChild != null) { fChild.mouseDrag(e, x, y); 96 } 97 view().repairDamage(); 98 } 99 100 104 public void mouseUp(MouseEvent e, int x, int y) { 105 view().unfreezeView(); 106 if (fChild != null) { fChild.mouseUp(e, x, y); 108 fChild.deactivate(); 109 fChild = null; 110 } 111 view().repairDamage(); 112 } 113 114 117 protected Tool createHandleTracker(DrawingView view, Handle handle) { 118 return new HandleTracker(editor(), handle); 119 } 120 121 124 protected Tool createDragTracker(Figure f) { 125 return new DragTracker(editor(), f); 126 } 127 128 132 protected Tool createAreaTracker() { 133 return new SelectAreaTracker(editor()); 134 } 135 136 } 137 | Popular Tags |