Example #1
0
 public void mouseMove(MouseEvent e, int x, int y) {
   if (e.getSource() == getActiveView()) {
     if (fPolygon != null) {
       if (fPolygon.pointCount() > 1) {
         fPolygon.setPointAt(new Point(x, y), fPolygon.pointCount() - 1);
         getActiveView().checkDamage();
       }
     }
   }
 }
Example #2
0
  private void addPoint(int x, int y) {
    if (fPolygon == null) {
      fPolygon = new PolygonFigure(x, y);
      setAddedFigure(view().add(fPolygon));
      fPolygon.addPoint(x, y);
    } else if (fLastX != x || fLastY != y) {
      fPolygon.addPoint(x, y);
    }

    fLastX = x;
    fLastY = y;
  }
Example #3
0
 public void deactivate() {
   if (fPolygon != null) {
     fPolygon.smoothPoints();
     if (fPolygon.pointCount() < 3 || fPolygon.size().width < 4 || fPolygon.size().height < 4) {
       getActiveView().drawing().remove(fPolygon);
       // nothing to undo
       setUndoActivity(null);
     }
   }
   fPolygon = null;
   super.deactivate();
 }
 protected boolean resetPolygon() {
   FigureEnumeration fe = getAffectedFigures();
   if (!fe.hasNextFigure()) {
     return false;
   }
   PolygonFigure figure = (PolygonFigure) fe.nextFigure();
   Polygon backupPolygon = figure.getPolygon();
   figure.willChange();
   figure.setInternalPolygon(getPolygon());
   figure.changed();
   setPolygon(backupPolygon);
   return true;
 }
Example #5
0
  public void mouseDown(MouseEvent e, int x, int y) {
    super.mouseDown(e, x, y);
    // replace pts by actual event pts
    x = e.getX();
    y = e.getY();

    if (e.getClickCount() >= 2) {
      if (fPolygon != null) {
        fPolygon.smoothPoints();

        // use undo activity from paste command...
        setUndoActivity(createUndoActivity());

        // put created figure into a figure enumeration
        getUndoActivity().setAffectedFigures(new SingleFigureEnumerator(getAddedFigure()));

        editor().toolDone();
      }
      fPolygon = null;

    } else {
      // use original event coordinates to avoid
      // supress that the scribble is constrained to
      // the grid
      addPoint(e.getX(), e.getY());
    }
  }