Back to index

wims  3.65+svn20090927
ZoomerTool.java
Go to the documentation of this file.
00001 package rene.zirkel.tools;
00002 
00003 // file: Hider.java
00004 
00005 import java.awt.Cursor;
00006 import java.awt.event.MouseEvent;
00007 
00008 import rene.zirkel.Zirkel;
00009 import rene.zirkel.ZirkelCanvas;
00010 import rene.zirkel.construction.Construction;
00011 import rene.zirkel.constructors.*;
00012 
00018 public class ZoomerTool extends ObjectConstructor
00019 {      boolean Dragging=false,Zoom=false;
00020        double X,Y,W,X0,Y0;
00021        ObjectConstructor OC;
00022        
00023        public ZoomerTool ()
00024        {      super();
00025        }
00026        
00027        public ZoomerTool (ObjectConstructor oc, MouseEvent e, ZirkelCanvas zc)
00028        {      super();
00029               OC=oc;
00030               X0=zc.x(e.getX()); Y0=zc.y(e.getY());
00031               Construction c=zc.getConstruction();
00032               X=c.getX(); Y=c.getY(); W=c.getW();
00033               Zoom=false;
00034               zc.setCursor(new Cursor(Cursor.MOVE_CURSOR));
00035               Dragging=true;
00036        }
00037        
00038        public void mousePressed (MouseEvent e, ZirkelCanvas zc)
00039        {      X0=zc.x(e.getX()); Y0=zc.y(e.getY());
00040               Construction c=zc.getConstruction();
00041               X=c.getX(); Y=c.getY(); W=c.getW();
00042               Zoom=(Math.abs(X-X0)>W/4 || Math.abs(Y-Y0)>W/4);
00043               if (!Zoom) zc.setCursor(new Cursor(Cursor.MOVE_CURSOR));
00044               Dragging=true;
00045               OC=null;
00046        }
00047        
00048        public void mouseDragged (MouseEvent e, ZirkelCanvas zc)
00049        {      if (!Dragging) return;
00050               Construction c=zc.getConstruction();
00051               c.setXYW(X,Y,W);
00052               zc.recompute();
00053               double x=zc.x(e.getX()),y=zc.y(e.getY());
00054               if (Zoom) c.setXYW(X,Y,
00055                      Math.sqrt((X0-X)*(X0-X)+(Y0-Y)*(Y0-Y))/
00056                      Math.sqrt((x-X)*(x-X)+(y-Y)*(y-Y))*W);
00057               else c.setXYW(X-(x-X0),Y-(y-Y0),W);
00058               zc.recompute();
00059               zc.validate();
00060               zc.repaint();
00061        }
00062        
00063        public void mouseReleased (MouseEvent e, ZirkelCanvas zc)
00064        {      Dragging=Zoom=false;
00065               zc.setCursor(Cursor.getDefaultCursor());
00066               zc.repaint();
00067               if (OC!=null) zc.setTool(OC);
00068        }
00069 
00070        public void showStatus (ZirkelCanvas zc)
00071        {      zc.showStatus(Zirkel.name("message.zoom"));
00072        }
00073        
00074        public void reset (ZirkelCanvas zc)
00075        {      zc.clearSelected();
00076               zc.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
00077               Zoom=Dragging=false;
00078        }
00079        
00080        public void invalidate (ZirkelCanvas zc)
00081        {      zc.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
00082        }
00083        
00084        public void mouseMoved (MouseEvent e, ZirkelCanvas zc, boolean flag)
00085        {      X0=zc.x(e.getX()); Y0=zc.y(e.getY());
00086               Construction c=zc.getConstruction();
00087               X=c.getX(); Y=c.getY(); W=c.getW();
00088               Zoom=(Math.abs(X-X0)>W/4 || Math.abs(Y-Y0)>W/4);
00089               if (!Zoom) zc.setCursor(new Cursor(Cursor.MOVE_CURSOR));
00090               else zc.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
00091        }
00092 
00093        public boolean useSmartBoard ()
00094        {      return false;
00095        }
00096 }