Пример #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;
  }
Пример #2
0
  MoveInfo(ShapeGraphicalRepresentation graphicalRepresentation, DrawingController<?> controller) {
    view = controller.getDrawingView();

    startMovingLocationInDrawingView =
        GraphicalRepresentation.convertPointFromDrawableToDrawing(
            graphicalRepresentation.getParentGraphicalRepresentation(),
            new Point(
                graphicalRepresentation.getViewX(controller.getScale()),
                graphicalRepresentation.getViewY(controller.getScale())),
            controller.getScale());
    currentLocationInDrawingView = new Point(startMovingLocationInDrawingView);

    movedObject = graphicalRepresentation;

    if (!controller.getSelectedObjects().contains(movedObject)) {
      controller.setSelectedObject(movedObject);
    }

    movedObjects = new Hashtable<ShapeGraphicalRepresentation, FGEPoint>();
    movedObjects.put(movedObject, movedObject.getLocation());

    // Now see objects coming with
    for (GraphicalRepresentation d : controller.getSelectedObjects()) {
      if (d != graphicalRepresentation
          && d instanceof ShapeGraphicalRepresentation
          && ((ShapeGraphicalRepresentation) d).getContainer()
              == graphicalRepresentation.getContainer()
          && !d.getIsReadOnly()
          && ((ShapeGraphicalRepresentation) d).getLocationConstraints()
              != LocationConstraints.UNMOVABLE) {
        // OK, d comes with me
        movedObjects.put(
            ((ShapeGraphicalRepresentation) d), ((ShapeGraphicalRepresentation) d).getLocation());
      }
    }
  }