@Override
  public void drag(MouseEvent e, Dimension delta) {
    if (invalidGesture) {
      return;
    }

    if (selectionBounds == null) {
      return;
    }

    Rectangle sel = updateSelectionBounds(e);
    for (IContentPart<Node, ? extends Node> targetPart : targetParts) {
      // compute initial and new bounds for this target
      Bounds initialBounds = getBounds(selectionBounds, targetPart);
      Bounds newBounds = getBounds(sel, targetPart);

      // compute translation in scene coordinates
      double dx = newBounds.getMinX() - initialBounds.getMinX();
      double dy = newBounds.getMinY() - initialBounds.getMinY();

      // transform translation to parent coordinates
      Node visual = targetPart.getVisual();
      Point2D originInParent = visual.getParent().sceneToLocal(0, 0);
      Point2D deltaInParent = visual.getParent().sceneToLocal(dx, dy);
      dx = deltaInParent.getX() - originInParent.getX();
      dy = deltaInParent.getY() - originInParent.getY();

      // apply translation
      getTransformPolicy(targetPart).setPostTranslate(translateIndices.get(targetPart), dx, dy);

      // check if we can resize the part
      AffineTransform affineTransform = getTransformPolicy(targetPart).getCurrentNodeTransform();
      if (affineTransform.getRotation().equals(Angle.fromDeg(0))) {
        // no rotation => resize possible
        // TODO: special case 90 degree rotations
        double dw = newBounds.getWidth() - initialBounds.getWidth();
        double dh = newBounds.getHeight() - initialBounds.getHeight();
        Point2D originInLocal = visual.sceneToLocal(newBounds.getMinX(), newBounds.getMinY());
        Point2D dstInLocal =
            visual.sceneToLocal(newBounds.getMinX() + dw, newBounds.getMinY() + dh);
        dw = dstInLocal.getX() - originInLocal.getX();
        dh = dstInLocal.getY() - originInLocal.getY();
        getResizePolicy(targetPart).resize(dw, dh);
      } else {
        // compute scaling based on bounds change
        double sx = newBounds.getWidth() / initialBounds.getWidth();
        double sy = newBounds.getHeight() / initialBounds.getHeight();
        // apply scaling
        getTransformPolicy(targetPart).setPostScale(scaleIndices.get(targetPart), sx, sy);
      }
    }
  }
Beispiel #2
0
  @Test
  public void test_getAngle_withStraight() {
    Straight s1 = new Straight(new Vector(0, 0), new Vector(3, 3));
    Straight s2 = new Straight(new Vector(0, 4), new Vector(2, 2));
    assertTrue(s1.getAngle(s2).equals(Angle.fromDeg(0)));
    assertTrue(s1.getAngleCW(s2).equals(Angle.fromDeg(0)));
    assertTrue(s1.getAngleCCW(s2).equals(Angle.fromDeg(0)));

    s1 = new Straight(new Vector(0, 0), new Vector(5, 5));
    s2 = new Straight(new Vector(0, 5), new Vector(0, 5));
    assertTrue(s1.getAngle(s2).equals(Angle.fromDeg(45)));
    assertTrue(s1.getAngleCW(s2).equals(Angle.fromDeg(45)));
    assertTrue(s1.getAngleCCW(s2).equals(Angle.fromDeg(135)));
  }