Ejemplo 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}));
      }
    }
Ejemplo n.º 2
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();
   }
 }