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);
  }
  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);
  }
示例#3
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);
 }
示例#4
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()));
 }
  @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);
      }
    }
  }
示例#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());
 }
  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());
  }
示例#8
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);
  }
示例#9
0
文件: Utils2.java 项目: sunecz/SSP
 /* 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);
 }
示例#10
0
  private void handlePlatform() {

    switch (currentDirection) {
      case NONE:
        break;

      case LEFT:
        {
          double newPos = rect.getTranslateX() - SPEED;
          if (newPos < areaBounds.getMinX()) {
            newPos = areaBounds.getMinX();
          }
          rect.setTranslateX(newPos);
        }
        break;

      case RIGHT:
        {
          double newPos = rect.getTranslateX() + SPEED;
          if (newPos > areaBounds.getMaxX() - rectBounds.getWidth()) {
            newPos = areaBounds.getMaxX() - rectBounds.getWidth();
          }
          rect.setTranslateX(newPos);
        }
        break;

      case UP:
        sceneSpeed += 0.1;
        if (sceneSpeed > 10) {
          sceneSpeed = 10;
        }
        break;

      case DOWN:
        sceneSpeed -= 0.1;
        if (sceneSpeed < 0) {
          sceneSpeed = 0;
        }
        break;

      default:
        break;
    }
  }
示例#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 getScreenLocationX() {
   // this code is never called?
   Bounds lBoundsInScenenode = node.localToScene(node.getBoundsInLocal());
   int v =
       (int)
           Math.ceil(
               node.getScene().getX() + node.getScene().getX() + lBoundsInScenenode.getMinX());
   // for debugging System.out.println(getComponent() + " getScreenLocationX =" + v);
   return v;
 }
示例#13
0
 public Pair<CoordinatePair, CoordinatePair> addAnchorLines(ComponentView componentView) {
   Bounds bounds = componentView.getBoundsInParent();
   // Left Anchor wire
   CoordinatePair pair1 =
       new CoordinatePair(bounds.getMinX() - Component.OFFSET, bounds.getMaxY() / 2);
   // Right Anchor wire
   CoordinatePair pair2 =
       new CoordinatePair(bounds.getMaxX() + Component.OFFSET, bounds.getMaxY() / 2);
   Line line1 =
       new Line(
           bounds.getMinX(),
           bounds.getMaxY() / 2,
           bounds.getMinX() - Component.OFFSET,
           bounds.getMaxY() / 2);
   Line line2 =
       new Line(
           bounds.getMaxX(),
           bounds.getMaxY() / 2,
           bounds.getMaxX() + Component.OFFSET,
           bounds.getMaxY() / 2);
   componentView.getChildren().addAll(line1, line2);
   return new Pair(pair1, pair2);
 }
  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;
  }
  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 void animateTransitionToLabel(Label newLabel) {
    final Bounds newLabelBounds = newLabel.getBoundsInParent();

    final double newX = newLabelBounds.getMinX();
    final double newWidth = newLabelBounds.getWidth();

    animation.getKeyFrames().clear();
    animation
        .getKeyFrames()
        .add(
            new KeyFrame(
                TRANSITION_DURATION,
                new KeyValue(selectedBackground.xProperty(), newX),
                new KeyValue(selectedBackground.widthProperty(), newWidth)));

    animation.play();
  }
  /** Update the popup location below the anchor node. */
  @Override
  protected void updatePopupLocation() {
    final Bounds anchorBounds = getAnchor().getLayoutBounds();
    Point2D popupLocation;

    assert anchorBounds != null;

    // At exit time, closeRequestHandler() is not always called.
    // So this method can be invoked after the anchor has been removed the
    // scene. This looks like a bug in FX...
    // Anway we protect ourself by checking.
    if (getAnchor().getScene() != null) {
      popupLocation = getAnchor().localToScreen(anchorBounds.getMinX(), anchorBounds.getMaxY());
      getPopup().setX(popupLocation.getX());
      getPopup().setY(popupLocation.getY());
    }
  }
示例#18
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());
   }
 }
  public TreeTableColumnResizer(TreeTableColumn<?, ?> treeTableColumn) {
    assert treeTableColumn != null;
    assert treeTableColumn.getTreeTableView() != null;

    this.treeTableColumn = treeTableColumn;
    this.originalSizing = new ColumnSizing(this.treeTableColumn);

    final List<?> columns;
    if (this.treeTableColumn.getParentColumn() != null) {
      columns = this.treeTableColumn.getParentColumn().getColumns();
    } else {
      columns = this.treeTableColumn.getTreeTableView().getColumns();
    }
    final int columnIndex = columns.indexOf(this.treeTableColumn);
    if (columnIndex + 1 < columns.size()) {
      this.treeTableColumnNext = (TreeTableColumn<?, ?>) columns.get(columnIndex + 1);
      this.originalSizingNext = new ColumnSizing(this.treeTableColumnNext);
    } else {
      this.treeTableColumnNext = null;
      this.originalSizingNext = null;
    }

    //
    //  Case #1 : treeTableColumnNext != null
    //
    //         x1                x2                       x3
    //       --+-----------------+------------------------+--
    //         |      col n      |         col n+1        |
    //         |                 |                        |
    //
    //       Range for moving x2 is [x1, x3]
    //
    //
    //  Case #2 : treeTableColumnNext == null
    //
    //      Case #2.1: treeTableColumn.getParentColumn() != null
    //
    //         x1                x2                       x3
    //       --+-----------------+                        |
    //         |      col n      |                        |
    //         |                 |                        |
    //                                               parentColumn maxX
    //
    //
    //      Case #2.2: treeTableColumn.getParentColumn() == null
    //
    //         x1                x2                       x3
    //       --+-----------------+                        |
    //         |      col n      |                        |
    //         |                 |                        |
    //                                               treeTableView maxX
    //
    //       Range for moving x2 is [x1, x3]
    //
    //

    final TreeTableViewDesignInfoX di = new TreeTableViewDesignInfoX();
    final Bounds columnBounds = di.getColumnBounds(treeTableColumn);
    x1 = columnBounds.getMinX();
    x2 = columnBounds.getMaxX();
    if (treeTableColumnNext != null) {
      final Bounds nextBounds = di.getColumnBounds(treeTableColumnNext);
      x3 = nextBounds.getMaxX();
    } else {
      if (treeTableColumn.getParentColumn() != null) {
        final TableColumnBase<?, ?> parentColumn =
            (TableColumnBase<?, ?>) this.treeTableColumn.getParentColumn();
        assert parentColumn instanceof TreeTableColumn<?, ?>;
        final Bounds parentBounds = di.getColumnBounds((TreeTableColumn<?, ?>) parentColumn);
        x3 = parentBounds.getMaxX();
      } else {
        final Bounds layoutBounds = treeTableColumn.getTreeTableView().getLayoutBounds();
        x3 = layoutBounds.getMaxX();
      }
    }
  }
  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());
  }
示例#21
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()));
 }