private static Bounds computeUnclippedBounds(Node node) {
    final Bounds layoutBounds;
    double minX, minY, maxX, maxY, minZ, maxZ;

    assert node != null;
    assert node.getLayoutBounds().isEmpty() == false;

    layoutBounds = node.getLayoutBounds();
    minX = layoutBounds.getMinX();
    minY = layoutBounds.getMinY();
    maxX = layoutBounds.getMaxX();
    maxY = layoutBounds.getMaxY();
    minZ = layoutBounds.getMinZ();
    maxZ = layoutBounds.getMaxZ();

    if (node instanceof Parent) {
      final Parent parent = (Parent) node;

      for (Node child : parent.getChildrenUnmodifiable()) {
        final Bounds childBounds = child.getBoundsInParent();
        minX = Math.min(minX, childBounds.getMinX());
        minY = Math.min(minY, childBounds.getMinY());
        maxX = Math.max(maxX, childBounds.getMaxX());
        maxY = Math.max(maxY, childBounds.getMaxY());
        minZ = Math.min(minZ, childBounds.getMinZ());
        maxZ = Math.max(maxZ, childBounds.getMaxZ());
      }
    }

    assert minX <= maxX;
    assert minY <= maxY;
    assert minZ <= maxZ;

    return new BoundingBox(minX, minY, minZ, maxX - minX, maxY - minY, maxZ - minZ);
  }
  private static Bounds computeExtensionBounds(
      Bounds backgroundBounds, Bounds unclippedContentBounds) {
    final Bounds totalBounds = unionOfBounds(backgroundBounds, unclippedContentBounds);
    final double backgroundCenterX, backgroundCenterY;
    backgroundCenterX = (backgroundBounds.getMinX() + backgroundBounds.getMaxX()) / 2.0;
    backgroundCenterY = (backgroundBounds.getMinY() + backgroundBounds.getMaxY()) / 2.0;
    assert totalBounds.contains(backgroundCenterX, backgroundCenterY);
    double extensionHalfWidth, extensionHalfHeight;
    extensionHalfWidth =
        Math.max(
            backgroundCenterX - totalBounds.getMinX(), totalBounds.getMaxX() - backgroundCenterX);
    extensionHalfHeight =
        Math.max(
            backgroundCenterY - totalBounds.getMinY(), totalBounds.getMaxY() - backgroundCenterY);

    // We a few pixels in order the parent ring of root object
    // to fit inside the extension rect.
    extensionHalfWidth += 20.0;
    extensionHalfHeight += 20.0;

    return new BoundingBox(
        backgroundCenterX - extensionHalfWidth,
        backgroundCenterY - extensionHalfHeight,
        extensionHalfWidth * 2,
        extensionHalfHeight * 2);
  }
Exemplo n.º 3
0
 /** Transforms the given bounds in the given scene to the screen's coordinate system. */
 public static Bounds boundsOnScreen(Bounds boundsInScene, Scene scene) {
   Bounds sceneBoundsInWindow = bounds(scene);
   Bounds windowBoundsOnScreen = bounds(scene.getWindow());
   return translateBounds(
       boundsInScene,
       byOffset(
           sceneBoundsInWindow.getMinX() + windowBoundsOnScreen.getMinX(),
           sceneBoundsInWindow.getMinY() + windowBoundsOnScreen.getMinY()));
 }
Exemplo n.º 4
0
 private static Bounds intersectBounds(Bounds a, Bounds b) {
   double minX = Math.max(a.getMinX(), b.getMinX());
   double minY = Math.max(a.getMinY(), b.getMinY());
   double maxX = Math.min(a.getMaxX(), b.getMaxX());
   double maxY = Math.min(a.getMaxY(), b.getMaxY());
   double width = maxX - minX;
   double height = maxY - minY;
   return new BoundingBox(minX, minY, width, height);
 }
  @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);
      }
    }
  }
Exemplo n.º 6
0
 private static Bounds translateBounds(Bounds bounds, Point2D offset) {
   return new BoundingBox(
       bounds.getMinX() + offset.getX(),
       bounds.getMinY() + offset.getY(),
       bounds.getWidth(),
       bounds.getHeight());
 }
Exemplo n.º 7
0
  private void advanceBall() {
    double refAngle = 0;
    boolean doBounce = false;
    double jitter = 0;

    if (ballBounds.getMaxY() >= rectBounds.getMinY()) {
      if (ballBounds.getMaxX() < rectBounds.getMinX()
          || ballBounds.getMinX() > rectBounds.getMaxX()) {
        isExploding = true;
        ball.setFill(Color.RED);
      } else {
        // calculate a value between -0.5 and 0.5 which corresponds to the
        // position within the platform where the ball bounces
        double pos = (ball.getTranslateX() - rect.getTranslateX()) / rect.getWidth();
        if (pos < 0) {
          pos = 0;
        }
        if (pos > 1) {
          pos = 1;
        }
        pos = pos - 0.5;

        // system.err.printf("%s\n", pos);
        jitter = pos;
        doBounce = true;
      }
    }

    if (ballBounds.getMinY() <= areaBounds.getMinY()
        || ballBounds.getMaxY() >= areaBounds.getMaxY()) { // this must never happen!
      doBounce = true;
    } else if (ballBounds.getMinX() <= areaBounds.getMinX()
        || ballBounds.getMaxX() >= areaBounds.getMaxX()) {
      doBounce = true;
      refAngle = Math.PI / 2;
    }

    if (doBounce) {
      ballAngle = calculateExitAngle(ballAngle, refAngle) + jitter;
      dx = ballSpeed * Math.cos(ballAngle);
      dy = ballSpeed * Math.sin(ballAngle);
    }

    ball.setTranslateX(ball.getTranslateX() + dx);
    ball.setTranslateY(ball.getTranslateY() - dy);
  }
Exemplo n.º 8
0
  public void setLayoutBounds(Bounds layoutBounds) {

    // Setup layoutX/layoutY on the image view and the region (1)
    region.setLayoutX(layoutBounds.getMinX());
    region.setLayoutY(layoutBounds.getMinY());
    region.setPrefWidth(layoutBounds.getWidth());
    region.setPrefHeight(layoutBounds.getHeight());
  }
Exemplo n.º 9
0
 private void handleExplode() {
   if (ballBounds.getMinY() > areaBounds.getMaxY()) {
     isExploding = false;
     resetBall();
   } else {
     ball.setTranslateX(ball.getTranslateX() + dx);
     ball.setTranslateY(ball.getTranslateY() - dy);
   }
 }
Exemplo n.º 10
0
 /* This code has been taken from:
  * https://community.oracle.com/thread/2534556?tstart=0
  * AND WAS MODIFIED!*/
 public static final Point2D getNodeLocation(Node node) {
   double x = 0, y = 0;
   for (Node n = node; n != null; n = n.getParent()) {
     Bounds parentBounds = n.getBoundsInParent();
     x += parentBounds.getMinX();
     y += parentBounds.getMinY();
   }
   return new Point2D(x, y);
 }
Exemplo n.º 11
0
 protected void animateComputeBox(double frac, Context context) {
   bounds = label.getBoundsInParent();
   bounds =
       new BoundingBox(
           bounds.getMinX() - HMARGIN,
           bounds.getMinY() - VMARGIN,
           bounds.getWidth() + 2 * HMARGIN,
           bounds.getHeight() + 2 * VMARGIN);
   rectangle.setFill(Color.TRANSPARENT);
   context.styles.get(StyleId.LineColor).apply(rectangle);
   context.styles.get(StyleId.PenWidth).apply(rectangle);
   context.styles.get(StyleId.Dash).apply(rectangle);
   context.styles.get(StyleId.Opacity).apply(rectangle);
   rectangle.setX(bounds.getMinX());
   rectangle.setY(bounds.getMinY());
   rectangle.setWidth(0d);
   rectangle.setHeight(0d);
   rectangle.setVisible(false);
 }
 // as of JDK 1.6: @Override
 public int getScreenLocationY() {
   // this code is never called?
   Bounds lBoundsInScenenode = node.localToScene(node.getBoundsInLocal());
   int v =
       (int)
           Math.ceil(
               node.getScene().getY() + node.getScene().getY() + lBoundsInScenenode.getMinY());
   // for debugging System.out.println(getComponent() + " getScreenLocationX =" + v);
   return v;
 }
Exemplo n.º 13
0
 protected void refreshHandleLocation(Node hostVisual) {
   // position vbox top-right next to the host
   Bounds hostBounds = hostVisual.getBoundsInParent();
   Parent parent = hostVisual.getParent();
   if (parent != null) {
     hostBounds = parent.localToScene(hostBounds);
   }
   Point2D location =
       getVisual().getParent().sceneToLocal(hostBounds.getMaxX(), hostBounds.getMinY());
   getVisual().setLayoutX(location.getX());
   getVisual().setLayoutY(location.getY());
 }
  private SequentialTransition CalculateTransition(
      Card c, HBox PlayerCardBox, ImageView imView, int iCardDrawn) {
    // This is the card that is going to be dealt to the player.
    String strCard = "/res/img/" + c.getCardImg();
    ImageView imgvCardDealt =
        new ImageView(new Image(getClass().getResourceAsStream(strCard), 96, 71, true, true));

    // imgvCardFaceDown - There's already a place holder card
    // sitting in
    // the player's hbox. It's face down. Find it
    // and then determine it's bounds and top left hand handle.
    ImageView imgvCardFaceDown = (ImageView) PlayerCardBox.getChildren().get(iCardDrawn - 1);
    Bounds bndCardDealt = imgvCardFaceDown.localToScene(imgvCardFaceDown.getBoundsInLocal());
    Point2D pntCardDealt = new Point2D(bndCardDealt.getMinX(), bndCardDealt.getMinY());

    // imgvDealerDeck = the card in the common area, where dealer's
    // card
    // is located. Find the boundary top left point.
    ImageView imgvDealerDeck = (ImageView) HboxCommonArea.getChildren().get(0);
    Bounds bndCardDeck = imgvDealerDeck.localToScene(imgvDealerDeck.getBoundsInLocal());
    Point2D pntCardDeck = new Point2D(bndCardDeck.getMinX(), bndCardDeck.getMinY());

    // Add a sequential transition to the card (move, rotate)
    SequentialTransition transMoveRotCard = createTransition(pntCardDeck, pntCardDealt, imView);

    // Add a parallel transition to the card (fade in/fade out).
    final ParallelTransition transFadeCardInOut =
        createFadeTransition(
            imgvCardFaceDown,
            new Image(getClass().getResourceAsStream(strCard), 75, 75, true, true));

    SequentialTransition transAllActions = new SequentialTransition();
    transAllActions.getChildren().addAll(transMoveRotCard, transFadeCardInOut);

    return transAllActions;
  }
  private static Bounds unionOfBounds(Bounds b1, Bounds b2) {
    final Bounds result;

    if (b1.isEmpty()) {
      result = b2;
    } else if (b2.isEmpty()) {
      result = b1;
    } else {
      final double minX = Math.min(b1.getMinX(), b2.getMinX());
      final double minY = Math.min(b1.getMinY(), b2.getMinY());
      final double minZ = Math.min(b1.getMinZ(), b2.getMinZ());
      final double maxX = Math.max(b1.getMaxX(), b2.getMaxX());
      final double maxY = Math.max(b1.getMaxY(), b2.getMaxY());
      final double maxZ = Math.max(b1.getMaxZ(), b2.getMaxZ());

      assert minX <= maxX;
      assert minY <= maxY;
      assert minZ <= maxZ;

      result = new BoundingBox(minX, minY, minZ, maxX - minX, maxY - minY, maxZ - minZ);
    }

    return result;
  }
Exemplo n.º 16
0
 private void handleEvents(final String EVENT_TYPE) {
   if ("RESIZE".equals(EVENT_TYPE)) {
     resize();
     redraw();
   } else if ("REDRAW".equals(EVENT_TYPE)) {
     redraw();
   } else if ("RECALC".equals(EVENT_TYPE)) {
     angleRange = Helper.clamp(90.0, 180.0, getSkinnable().getAngleRange());
     startAngle = getStartAngle();
     minValue = getSkinnable().getMinValue();
     range = getSkinnable().getRange();
     sections = getSkinnable().getSections();
     angleStep = angleRange / range;
     redraw();
   } else if ("FINISHED".equals(EVENT_TYPE)) {
     needleTooltip.setText(String.format(locale, formatString, getSkinnable().getValue()));
     double value = getSkinnable().getValue();
     if (getSkinnable().isValueVisible()) {
       Bounds bounds = pane.localToScreen(pane.getBoundsInLocal());
       double xFactor = value > getSkinnable().getRange() * 0.8 ? 0.0 : 0.25;
       double tooltipAngle = value * angleStep;
       double sinValue = Math.sin(Math.toRadians(180 + angleRange * 0.5 - tooltipAngle));
       double cosValue = Math.cos(Math.toRadians(180 + angleRange * 0.5 - tooltipAngle));
       double needleTipX =
           bounds.getMinX() + bounds.getWidth() * 0.5 + bounds.getHeight() * sinValue;
       double needleTipY =
           bounds.getMinY() + bounds.getHeight() * 0.72 + bounds.getHeight() * cosValue;
       needleTooltip.show(needle, needleTipX, needleTipY);
       needleTooltip.setAnchorX(needleTooltip.getX() - needleTooltip.getWidth() * xFactor);
     }
     if (sections.isEmpty() || sectionsAlwaysVisible) return;
     for (Section section : sections) {
       if (section.contains(value)) {
         barTooltip.setText(section.getText());
         break;
       }
     }
   } else if ("VISIBILITY".equals(EVENT_TYPE)) {
     Helper.enableNode(titleText, !getSkinnable().getTitle().isEmpty());
   }
 }
  private void adjustWorkspace() {
    final Bounds backgroundBounds, extensionBounds;

    final Object userSceneGraph;
    if (fxomDocument == null) {
      userSceneGraph = null;
    } else {
      userSceneGraph = fxomDocument.getSceneGraphRoot();
    }
    if ((userSceneGraph instanceof Node) && (layoutException == null)) {
      final Node rootNode = (Node) userSceneGraph;

      final Bounds rootBounds = rootNode.getLayoutBounds();

      if (rootBounds.isEmpty()
          || (rootBounds.getWidth() == 0.0)
          || (rootBounds.getHeight() == 0.0)) {
        backgroundBounds = new BoundingBox(0.0, 0.0, 0.0, 0.0);
        extensionBounds = new BoundingBox(0.0, 0.0, 0.0, 0.0);
      } else {
        final double scale;
        if ((rootBounds.getDepth() > 0) && autoResize3DContent) {
          // Content is 3D
          final double scaleX = AUTORESIZE_SIZE / rootBounds.getWidth();
          final double scaleY = AUTORESIZE_SIZE / rootBounds.getHeight();
          final double scaleZ = AUTORESIZE_SIZE / rootBounds.getDepth();
          scale = Math.min(scaleX, Math.min(scaleY, scaleZ));
        } else {
          scale = 1.0;
        }
        contentGroup.setScaleX(scale);
        contentGroup.setScaleY(scale);
        contentGroup.setScaleZ(scale);

        final Bounds contentBounds = rootNode.localToParent(rootBounds);
        backgroundBounds =
            new BoundingBox(
                0.0,
                0.0,
                contentBounds.getMinX() + contentBounds.getWidth(),
                contentBounds.getMinY() + contentBounds.getHeight());

        final Bounds unclippedRootBounds = computeUnclippedBounds(rootNode);
        assert unclippedRootBounds.getHeight() != 0.0;
        assert unclippedRootBounds.getWidth() != 0.0;
        assert rootNode.getParent() == contentGroup;

        final Bounds unclippedContentBounds = rootNode.localToParent(unclippedRootBounds);
        extensionBounds = computeExtensionBounds(backgroundBounds, unclippedContentBounds);
      }
    } else {
      backgroundBounds = new BoundingBox(0.0, 0.0, 320.0, 150.0);
      extensionBounds = new BoundingBox(0.0, 0.0, 0.0, 0.0);
    }

    backgroundPane.setPrefWidth(backgroundBounds.getWidth());
    backgroundPane.setPrefHeight(backgroundBounds.getHeight());
    extensionRect.setX(extensionBounds.getMinX());
    extensionRect.setY(extensionBounds.getMinY());
    extensionRect.setWidth(extensionBounds.getWidth());
    extensionRect.setHeight(extensionBounds.getHeight());

    contentSubScene.setWidth(contentGroup.getLayoutBounds().getWidth());
    contentSubScene.setHeight(contentGroup.getLayoutBounds().getHeight());
  }
Exemplo n.º 18
0
 /** Translates the given bounds in the given window to the screen's coordinate system */
 public static Bounds boundsOnScreen(Bounds boundsInWindow, Window window) {
   Bounds windowBoundsOnScreen = bounds(window);
   return translateBounds(
       boundsInWindow, byOffset(windowBoundsOnScreen.getMinX(), windowBoundsOnScreen.getMinY()));
 }