Exemplo n.º 1
0
    @Override
    public void handleDrag(MouseEvent e) {
      DrawingItem item = getItem();
      if (item.getPoints().size() < 2) {
        item.addPoint(getMapPoint(e));
      } else {
        Double p1 = item.getPoints().get(0);
        Double p2 = item.getPoints().get(1);
        Double p3 = getMapPoint(e);

        MouseEvent lastEvent = getFirstEvent();
        boolean movingLeft = e.getX() - lastEvent.getX() < 0;
        boolean movingDown = e.getY() - lastEvent.getY() > 0;

        if (p3.x > p2.x) p2.x = p3.x;
        else if (p3.x > p1.x) {
          if (movingLeft) p1.x = p3.x;
          else p2.x = p3.x;
        } else if (p3.x < p1.x) p1.x = p3.x;

        if (p3.y > p2.y) p2.y = p3.y;
        else if (p3.y > p1.y) {
          if (movingDown) p1.y = p3.y;
          else p2.y = p3.y;
        } else if (p3.y < p1.y) p1.y = p3.y;

        item.setPoints(Arrays.asList(new Point2D.Double[] {p1, p2}));
      }
    }
Exemplo n.º 2
0
 @Override
 protected void handlePress(MouseEvent e) {
   super.handlePress(e);
   DrawingItem item = getItem();
   DragHandle handle = getHandle();
   if (handle != null && item != null) {
     int index = (Integer) handle.getData();
     Double p = item.getPoints().get(Math.abs(index - 1)); // opposite is the anchor
     anchor = new Double(p.getX(), p.getY());
   }
 }
Exemplo n.º 3
0
 @Override
 protected void handlePress(MouseEvent e) {
   DrawingItem item = getItem();
   if (item.getPoints().isEmpty()) {
     setLastEvent(e);
     setFirstEvent(e);
     setDragging(item);
     item.addPoint(getMapPoint(e));
     e.consume();
   }
 }
Exemplo n.º 4
0
    @Override
    protected void handleDrag(MouseEvent e) {
      DragHandle handle = getHandle();
      DrawingItem item = getItem();
      if (anchor != null && handle != null && handle.getType() == DragHandle.TYPE_POINT) {

        Double p1 = item.getPoints().get(0);
        Double p2 = item.getPoints().get(1);
        Double p3 = getMapPoint(getInverslyRotatedPoint(e));

        if (p3.x < anchor.x) p1.x = p3.x;
        else if (p3.x > anchor.x) p2.x = p3.x;

        if (p3.y > anchor.y) p2.y = p3.y;
        else if (p3.y < anchor.y) p1.y = p3.y;

        item.setPoints(Arrays.asList(new Point2D.Double[] {p1, p2}));
      }
    }