Ejemplo n.º 1
0
  boolean isDnDPattern(Point newLocationInDrawingView, MouseEvent event) {
    if (movedObjects.size() != 1) {
      return false;
    }

    FGEPoint startMovingPoint = movedObjects.get(movedObject);

    FGEPoint desiredLocation =
        new FGEPoint(
            startMovingPoint.x
                + (newLocationInDrawingView.x - startMovingLocationInDrawingView.x)
                    / view.getScale(),
            startMovingPoint.y
                + (newLocationInDrawingView.y - startMovingLocationInDrawingView.y)
                    / view.getScale());

    if (movedObject.getContainerGraphicalRepresentation() instanceof ShapeGraphicalRepresentation) {
      ShapeGraphicalRepresentation container =
          (ShapeGraphicalRepresentation<?>) movedObject.getContainerGraphicalRepresentation();
      FGERectangle bounds =
          new FGERectangle(
              0,
              0,
              container.getWidth() - movedObject.getWidth(),
              container.getHeight() - movedObject.getHeight(),
              Filling.FILLED);
      FGEPoint nearestPoint = bounds.getNearestPoint(desiredLocation);
      Point p1 =
          GraphicalRepresentation.convertPointFromDrawableToDrawing(
              movedObject.getContainerGraphicalRepresentation(),
              desiredLocation.toPoint(),
              view.getScale());
      Point p2 =
          GraphicalRepresentation.convertPointFromDrawableToDrawing(
              movedObject.getContainerGraphicalRepresentation(),
              nearestPoint.toPoint(),
              view.getScale());
      if (Point2D.distance(p1.x, p1.y, p2.x, p2.y) > FGEConstants.DND_DISTANCE) {
        return true;
      }
    }

    return false;
  }