Back to index

moin  1.9.0~rc2
ScribbleTool.java
Go to the documentation of this file.
00001 /*
00002  * @(#)ScribbleTool.java 5.1
00003  *
00004  */
00005 
00006 package CH.ifa.draw.figures;
00007 
00008 import java.awt.*;
00009 import java.awt.event.MouseEvent;
00010 import java.io.IOException;
00011 import CH.ifa.draw.framework.*;
00012 import CH.ifa.draw.standard.AbstractTool;
00013 
00018 public class ScribbleTool extends AbstractTool {
00019 
00020     private PolyLineFigure  fScribble;
00021     private int             fLastX, fLastY;
00022 
00023     public ScribbleTool(DrawingView view) {
00024         super(view);
00025     }
00026 
00027     public void activate() {
00028         super.activate();
00029         fScribble = null;
00030     }
00031 
00032     public void deactivate() {
00033         super.deactivate();
00034         if (fScribble != null) {
00035             if (fScribble.size().width < 4 || fScribble.size().height < 4)
00036                 drawing().remove(fScribble);
00037         }
00038     }
00039 
00040     private void point(int x, int y) {
00041         if (fScribble == null) {
00042             fScribble = new PolyLineFigure(x, y);
00043             view().add(fScribble);
00044         } else if (fLastX != x || fLastY != y)
00045             fScribble.addPoint(x, y);
00046 
00047         fLastX = x;
00048         fLastY = y;
00049     }
00050 
00051     public void mouseDown(MouseEvent e, int x, int y) {
00052         if (e.getClickCount() >= 2) {
00053             fScribble = null;
00054             editor().toolDone();
00055         }
00056         else {
00057             // use original event coordinates to avoid
00058             // supress that the scribble is constrained to
00059             // the grid
00060             point(e.getX(), e.getY());
00061         }
00062     }
00063 
00064     public void mouseDrag(MouseEvent e, int x, int y) {
00065         if (fScribble != null)
00066             point(e.getX(), e.getY());
00067     }
00068 }