Back to index

moin  1.9.0~rc2
CreationTool.java
Go to the documentation of this file.
00001 /*
00002  * @(#)CreationTool.java 5.1
00003  *
00004  */
00005 
00006 package CH.ifa.draw.standard;
00007 
00008 import java.awt.*;
00009 import java.awt.event.MouseEvent;
00010 
00011 import CH.ifa.draw.framework.*;
00012 
00028 public class CreationTool extends AbstractTool {
00029 
00033     private Point   fAnchorPoint;
00034 
00038     private Figure  fCreatedFigure;
00039 
00043     private Figure  fPrototype;
00044 
00045 
00049     public CreationTool(DrawingView view, Figure prototype) {
00050         super(view);
00051         fPrototype = prototype;
00052     }
00053 
00058     protected CreationTool(DrawingView view) {
00059         super(view);
00060         fPrototype = null;
00061     }
00062 
00066     public void activate() {
00067         view().setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
00068     }
00069 
00073     public void mouseDown(MouseEvent e, int x, int y) {
00074         fAnchorPoint = new Point(x,y);
00075         fCreatedFigure = createFigure();
00076         fCreatedFigure.displayBox(fAnchorPoint, fAnchorPoint);
00077         view().add(fCreatedFigure);
00078     }
00079 
00083     protected Figure createFigure() {
00084         if (fPrototype == null)
00085                   throw new HJDError("No protoype defined");
00086         return (Figure) fPrototype.clone();
00087     }
00088 
00092     public void mouseDrag(MouseEvent e, int x, int y) {
00093         fCreatedFigure.displayBox(fAnchorPoint, new Point(x,y));
00094     }
00095 
00101     public void mouseUp(MouseEvent e, int x, int y) {
00102         if (fCreatedFigure.isEmpty())
00103             drawing().remove(fCreatedFigure);
00104         fCreatedFigure = null;
00105         editor().toolDone();
00106     }
00107 
00111     protected Figure createdFigure() {
00112         return fCreatedFigure;
00113     }
00114 }