Пример #1
0
 @Override
 public FGEPoint getNearestPoint(FGEPoint aPoint) {
   if (containsPoint(aPoint)) {
     return aPoint.clone();
   }
   return FGEPoint.getNearestPoint(
       aPoint, halfPlane1.line.getProjection(aPoint), halfPlane2.line.getProjection(aPoint));
 }
Пример #2
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;
  }
Пример #3
0
  void moveTo(Point newLocationInDrawingView) {

    if (!moveHasStarted) {
      startDragging();
    }

    for (ShapeGraphicalRepresentation<?> d : movedObjects.keySet()) {
      FGEPoint startMovingPoint = movedObjects.get(d);

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

      /*double authorizedRatio = d.getMoveAuthorizedRatio(desiredLocation,startMovingPoint);
      FGEPoint newLocation = new FGEPoint(
      		startMovingPoint.x+(desiredLocation.x-startMovingPoint.x)*authorizedRatio,
      		startMovingPoint.y+(desiredLocation.y-startMovingPoint.y)*authorizedRatio);
      logger.info("\n>>>>>>>>>>> setLocation() from "+d.getLocation()+" to "+newLocation+" on "+d);
      d.setLocation(newLocation.clone());*/

      d.setLocation(desiredLocation);

      if (d.isParentLayoutedAsContainer()) {
        FGEPoint resultingLocation = d.getLocation();
        if (!resultingLocation.equals(desiredLocation)) {
          double dx = resultingLocation.x - desiredLocation.x;
          double dy = resultingLocation.y - desiredLocation.y;
          startMovingPoint.x = startMovingPoint.x + dx;
          startMovingPoint.y = startMovingPoint.y + dy;
        }
      }
    }

    currentLocationInDrawingView = newLocationInDrawingView;
  }
  @Override
  public boolean dragToPoint(
      FGEPoint newRelativePoint,
      FGEPoint pointRelativeToInitialConfiguration,
      FGEPoint newAbsolutePoint,
      FGEPoint initialPoint,
      MouseEvent event) {
    FGEPoint pt = getNearestPointOnAuthorizedArea(newRelativePoint);

    if (pt == null) {
      logger.warning(
          "Unexpected null point while dragging AdjustableIntermediateSegment "
              + getDraggingAuthorizedArea()
              + " pt="
              + newRelativePoint);
      return false;
    }

    FGEPoint p1 = getPolylin().getPointAt(index);
    if (p1 == null) {
      logger.warning("Inconsistent data while managing adjustable segment in RectPolylinConnector");
      return false;
    }
    FGEPoint p2 = getPolylin().getPointAt(index + 1);
    if (p2 == null) {
      logger.warning("Inconsistent data while managing adjustable segment in RectPolylinConnector");
      return false;
    }

    if (currentOrientation.isHorizontal()) {
      p1.y = pt.y;
      p2.y = pt.y;
    } else if (currentOrientation.isVertical()) {
      p1.x = pt.x;
      p2.x = pt.x;
    } else {
      logger.warning("Inconsistent data while managing adjustable segment in RectPolylinConnector");
      return false;
    }

    getPolylin().updatePointAt(index, p1);
    getConnector()._getControlPoints().elementAt(index).setPoint(p1);

    getPolylin().updatePointAt(index + 1, p2);
    getConnector()._getControlPoints().elementAt(index + 1).setPoint(p2);

    getConnector()._connectorChanged(true);
    getGraphicalRepresentation().notifyConnectorChanged();

    return true;

    /*System.out.println("Index = "+index+" pour "+getGraphicalRepresentation().getText());
    System.out.println("getDraggingAuthorizedArea() = "+getDraggingAuthorizedArea());
    System.out.println("pt = "+pt);
    System.out.println("polylin = "+polylin);
    System.out.println("polylin.getSegmentNb() = "+polylin.getSegmentNb());
    System.out.println("polylin.getPointAt(index) = "+polylin.getPointAt(index));*/
    /*if (currentOrientation.isHorizontal()) {
    	FGEPoint p1 = getPolylin().getPointAt(index);
    	if (p1 == null) {
    		logger.warning("Inconsistent data while managing adjustable segment in RectPolylinConnector");
    		return false;
    	}
    	p1.y = pt.y;
    	getPolylin().updatePointAt(index,p1);
    	getConnector()._getControlPoints().elementAt(index).setPoint(p1);
    	FGEPoint p2 = getPolylin().getPointAt(index+1);
    	if (p2 == null) {
    		logger.warning("Inconsistent data while managing adjustable segment in RectPolylinConnector");
    		return false;
    	}
    	p2.y = pt.y;
    	getPolylin().updatePointAt(index+1,p2);
    	getConnector()._getControlPoints().elementAt(index+1).setPoint(p2);
    	getConnector().rememberLayout();
    	getGraphicalRepresentation().notifyConnectorChanged();
    	return true;
    }
    else if (currentOrientation.isVertical()) {
    	FGEPoint p1 = getPolylin().getPointAt(index);
    	if (p1 == null) {
    		logger.warning("Inconsistent data while managing adjustable segment in RectPolylinConnector");
    		return false;
    	}
    	p1.x = pt.x;
    	getPolylin().updatePointAt(index,p1);
    	getConnector()._getControlPoints().elementAt(index).setPoint(p1);
    	FGEPoint p2 = getPolylin().getPointAt(index+1);
    	if (p2 == null) {
    		logger.warning("Inconsistent data while managing adjustable segment in RectPolylinConnector");
    		return false;
    	}
    	p2.x = pt.x;
    	getPolylin().updatePointAt(index+1,p2);
    	getConnector()._getControlPoints().elementAt(index+1).setPoint(p2);
    	getConnector().rememberLayout();
    	getGraphicalRepresentation().notifyConnectorChanged();
    	return true;
    }
    else {
    	logger.warning("Inconsistent data while managing adjustable segment in RectPolylinConnector");
    	return false;
    }			*/
  }