Beispiel #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}));
      }
    }
Beispiel #2
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}));
      }
    }