Ejemplo n.º 1
0
  private void updateMouse(Canvas canvas, int mx, int my, int mods) {
    if (active) {
      boolean shift = (mods & MouseEvent.SHIFT_DOWN_MASK) != 0;
      Location newEnd;
      if (shift) {
        newEnd = LineUtil.snapTo8Cardinals(mouseStart, mx, my);
      } else {
        newEnd = Location.create(mx, my);
      }

      if ((mods & InputEvent.CTRL_DOWN_MASK) != 0) {
        int x = newEnd.getX();
        int y = newEnd.getY();
        x = canvas.snapX(x);
        y = canvas.snapY(y);
        newEnd = Location.create(x, y);
      }

      if (!newEnd.equals(mouseEnd)) {
        mouseEnd = newEnd;
        repaintArea(canvas);
      }
    }
    lastMouseX = mx;
    lastMouseY = my;
  }
Ejemplo n.º 2
0
 @Override
 public void mouseReleased(Canvas canvas, MouseEvent e) {
   if (active) {
     updateMouse(canvas, e.getX(), e.getY(), e.getModifiersEx());
     Location start = mouseStart;
     Location end = mouseEnd;
     CanvasObject add = null;
     if (!start.equals(end)) {
       active = false;
       CanvasModel model = canvas.getModel();
       Location[] ends = {start, end};
       List<Location> locs = UnmodifiableList.create(ends);
       add = attrs.applyTo(new Poly(false, locs));
       add.setValue(DrawAttr.PAINT_TYPE, DrawAttr.PAINT_STROKE);
       canvas.doAction(new ModelAddAction(model, add));
       repaintArea(canvas);
     }
     canvas.toolGestureComplete(this, add);
   }
 }
Ejemplo n.º 3
0
 public Location getOtherEnd(Location loc) {
   return (loc.equals(e0) ? e1 : e0);
 }
Ejemplo n.º 4
0
 public boolean endsAt(Location pt) {
   return e0.equals(pt) || e1.equals(pt);
 }