Back to index

moin  1.9.0~rc2
SelectionTool.java
Go to the documentation of this file.
00001 /*
00002  * @(#)SelectionTool.java 5.1
00003  *
00004  */
00005 
00006 package CH.ifa.draw.standard;
00007 
00008 import java.awt.*;
00009 import java.awt.event.MouseEvent;
00010 import java.util.Vector;
00011 import CH.ifa.draw.framework.*;
00012 
00028 public class SelectionTool extends AbstractTool {
00029 
00030     private Tool fChild = null;
00031 
00032     public SelectionTool(DrawingView view) {
00033         super(view);
00034     }
00035 
00039     public void mouseDown(MouseEvent e, int x, int y)
00040     {
00041         // on Windows NT: AWT generates additional mouse down events
00042         // when the left button is down && right button is clicked.
00043         // To avoid dead locks we ignore such events
00044         if (fChild != null)
00045             return;
00046 
00047         view().freezeView();
00048 
00049         Handle handle = view().findHandle(e.getX(), e.getY());
00050         if (handle != null) {
00051             fChild = createHandleTracker(view(), handle);
00052         }
00053         else {
00054             Figure figure = drawing().findFigure(e.getX(), e.getY());
00055             if (figure != null) {
00056                 fChild = createDragTracker(view(), figure);
00057             }
00058             else {
00059                 if (!e.isShiftDown()) {
00060                     view().clearSelection();
00061                 }
00062                 fChild = createAreaTracker(view());
00063             }
00064         }
00065         fChild.mouseDown(e, x, y);
00066     }
00067 
00072     public void mouseDrag(MouseEvent e, int x, int y) {
00073         if (fChild != null) // JDK1.1 doesn't guarantee mouseDown, mouseDrag, mouseUp
00074             fChild.mouseDrag(e, x, y);
00075     }
00076 
00081     public void mouseUp(MouseEvent e, int x, int y) {
00082         view().unfreezeView();
00083         if (fChild != null) // JDK1.1 doesn't guarantee mouseDown, mouseDrag, mouseUp
00084             fChild.mouseUp(e, x, y);
00085         fChild = null;
00086     }
00087 
00091     protected Tool createHandleTracker(DrawingView view, Handle handle) {
00092         return new HandleTracker(view, handle);
00093     }
00094 
00098     protected Tool createDragTracker(DrawingView view, Figure f) {
00099         return new DragTracker(view, f);
00100     }
00101 
00106     protected Tool createAreaTracker(DrawingView view) {
00107         return new SelectAreaTracker(view);
00108     }
00109 }