Java Code Examples for javafx.geometry.Bounds#getHeight()

The following examples show how to use javafx.geometry.Bounds#getHeight() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FxIconBuilder.java    From FxDock with Apache License 2.0 8 votes vote down vote up
/** auto fit last node, useful for svg paths */
public void autoFitLastElement()
{
	Node n = last();
	double w = n.prefHeight(width);
	double h = n.prefWidth(height);
	double sx = width / w;
	double sy = height / h;
	
	double sc = Math.min(sx, sy);
	n.setScaleX(sc);
	n.setScaleY(sc);
	
	Bounds b = n.getBoundsInLocal();
	double dx = (width / 2.0) - b.getMinX() - (b.getWidth() / 2.0);
	double dy = (height / 2.0) - b.getMinY() - (b.getHeight() / 2.0);
	n.setTranslateX(dx);
	n.setTranslateY(dy);
}
 
Example 2
Source File: CanvasManager.java    From ShootOFF with GNU General Public License v3.0 6 votes vote down vote up
public Bounds translateCanvasToCamera(Bounds bounds) {
	if (config.getDisplayWidth() == cameraManager.getFeedWidth()
			&& config.getDisplayHeight() == cameraManager.getFeedHeight())
		return bounds;

	final double scaleX = (double) cameraManager.getFeedWidth() / (double) config.getDisplayWidth();
	final double scaleY = (double) cameraManager.getFeedHeight() / (double) config.getDisplayHeight();

	final double minX = (bounds.getMinX() * scaleX);
	final double minY = (bounds.getMinY() * scaleY);
	final double width = (bounds.getWidth() * scaleX);
	final double height = (bounds.getHeight() * scaleY);

	logger.trace("translateCanvasToCamera {} {} {} {} - {} {} {} {}", bounds.getMinX(), bounds.getMinY(),
			bounds.getWidth(), bounds.getHeight(), minX, minY, width, height);

	return new BoundingBox(minX, minY, width, height);
}
 
Example 3
Source File: TextUtils.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** Compute the preferred size for a text
 *
 *  <p>Must be called on the UI thread,
 *  because it's using one shared text helper.
 *
 *  @param font Font
 *  @param text Text
 *  @return Width, height
 */
public static Dimension2D computeTextSize(final Font font, final String text)
{
    // com.sun.javafx.scene.control.skin.Utils contains related code,
    // but is private
    
    // Unclear if order of setting text, font, spacing matters;
    // copied from skin.Utils
    helper.setText(text);
    helper.setFont(font);
    // With default line spacing of 0.0,
    // height of multi-line text is too small...
    helper.setLineSpacing(3);

    final Bounds measure = helper.getLayoutBounds();
    return new Dimension2D(measure.getWidth(), measure.getHeight());
}
 
Example 4
Source File: HelperTest.java    From latexdraw with GNU General Public License v3.0 6 votes vote down vote up
default <T extends Node> void assertNotEqualsSnapshot(final T node, final CmdFXVoid toExecBetweenSnap) {
	Bounds bounds = node.getBoundsInLocal();
	final SnapshotParameters params = new SnapshotParameters();

	final WritableImage oracle = new WritableImage((int) bounds.getWidth(), (int) bounds.getHeight());
	Platform.runLater(() -> node.snapshot(params, oracle));
	WaitForAsyncUtils.waitForFxEvents();

	if(toExecBetweenSnap != null) {
		toExecBetweenSnap.execute();
	}

	bounds = node.getBoundsInLocal();
	final WritableImage observ = new WritableImage((int) bounds.getWidth(), (int) bounds.getHeight());
	Platform.runLater(() -> node.snapshot(params, observ));
	WaitForAsyncUtils.waitForFxEvents();

	assertNotEquals("The two snapshots do not differ.", 100d, computeSnapshotSimilarity(oracle, observ), 0.001);
}
 
Example 5
Source File: PopOver.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** @param owner_bounds Bounds of active owner
 *  @return Suggested Side for the popup
 */
private Side determineSide(final Bounds owner_bounds)
{
    // Determine center of active owner
    final double owner_x = owner_bounds.getMinX() + owner_bounds.getWidth()/2;
    final double owner_y = owner_bounds.getMinY() + owner_bounds.getHeight()/2;

    // Locate screen
    Rectangle2D screen_bounds = ScreenUtil.getScreenBounds(owner_x, owner_y);
    if (screen_bounds == null)
        return Side.BOTTOM;

    // left .. right as -0.5 .. +0.5
    double lr = (owner_x - screen_bounds.getMinX())/screen_bounds.getWidth() - 0.5;
    // top..buttom as -0.5 .. +0.5
    double tb = (owner_y - screen_bounds.getMinY())/screen_bounds.getHeight() - 0.5;

    // More left/right from center, or top/bottom from center of screen?
    if (Math.abs(lr) > Math.abs(tb))
        return (lr < 0) ? Side.RIGHT : Side.LEFT;
    else
        return (tb < 0) ? Side.BOTTOM : Side.TOP;
}
 
Example 6
Source File: GraphLayoutBehavior.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Determines the layout bounds for the graph.
 *
 * @return The bounds used to layout the graph.
 */
protected Rectangle computeLayoutBounds() {
	Rectangle newBounds = new Rectangle();
	if (nestingVisual != null) {
		// nested graph uses layout bounds of nesting node
		Bounds layoutBounds = nestingVisual.getLayoutBounds();
		newBounds = new Rectangle(0, 0, layoutBounds.getWidth() / NodePart.DEFAULT_NESTED_CHILDREN_ZOOM_FACTOR,
				layoutBounds.getHeight() / NodePart.DEFAULT_NESTED_CHILDREN_ZOOM_FACTOR);
	} else {
		// root graph uses infinite canvas bounds
		InfiniteCanvas canvas = getInfiniteCanvas();
		// XXX: Use minimum of window size and canvas size, because the
		// canvas size is invalid when its scene is changed.
		double windowWidth = canvas.getScene().getWindow().getWidth();
		double windowHeight = canvas.getScene().getWindow().getHeight();
		newBounds = new Rectangle(0, 0,
				Double.isFinite(windowWidth) ? Math.min(canvas.getWidth(), windowWidth) : canvas.getWidth(),
				Double.isFinite(windowHeight) ? Math.min(canvas.getHeight(), windowHeight) : canvas.getHeight());
	}
	return newBounds;
}
 
Example 7
Source File: JavaFXTreeViewNodeElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public Point2D _getMidpoint() {
    TreeView<?> treeView = (TreeView<?>) getComponent();
    Node cell = getCellAt(treeView, getPath(treeView, path));
    Bounds boundsInParent = cell.getBoundsInParent();
    double x = boundsInParent.getWidth() / 2;
    double y = boundsInParent.getHeight() / 2;
    return cell.localToParent(x, y);
}
 
Example 8
Source File: ShapeConverter.java    From Enzo with Apache License 2.0 5 votes vote down vote up
public static String convertRectangle(final Rectangle RECTANGLE) {
    final StringBuilder fxPath = new StringBuilder();
    final Bounds bounds = RECTANGLE.getBoundsInLocal();
    if (Double.compare(RECTANGLE.getArcWidth(), 0.0) == 0 && Double.compare(RECTANGLE.getArcHeight(), 0.0) == 0) {
        fxPath.append("M ").append(bounds.getMinX()).append(" ").append(bounds.getMinY()).append(" ")
              .append("H ").append(bounds.getMaxX()).append(" ")
              .append("V ").append(bounds.getMaxY()).append(" ")
              .append("H ").append(bounds.getMinX()).append(" ")
              .append("V ").append(bounds.getMinY()).append(" ")
              .append("Z");
    } else {
        double x         = bounds.getMinX();
        double y         = bounds.getMinY();
        double width     = bounds.getWidth();
        double height    = bounds.getHeight();
        double arcWidth  = RECTANGLE.getArcWidth();
        double arcHeight = RECTANGLE.getArcHeight();
        double r         = x + width;
        double b         = y + height;
        fxPath.append("M ").append(x + arcWidth).append(" ").append(y).append(" ")
              .append("L ").append(r - arcWidth).append(" ").append(y).append(" ")
              .append("Q ").append(r).append(" ").append(y).append(" ").append(r).append(" ").append(y + arcHeight).append(" ")
              .append("L ").append(r).append(" ").append(y + height - arcHeight).append(" ")
              .append("Q ").append(r).append(" ").append(b).append(" ").append(r - arcWidth).append(" ").append(b).append(" ")
              .append("L ").append(x + arcWidth).append(" ").append(b).append(" ")
              .append("Q ").append(x).append(" ").append(b).append(" ").append(x).append(" ").append(b - arcHeight).append(" ")
              .append("L ").append(x).append(" ").append(y + arcHeight).append(" ")
              .append("Q ").append(x).append(" ").append(y).append(" ").append(x + arcWidth).append(" ").append(y).append(" ")
              .append("Z");
    }
    return fxPath.toString();
}
 
Example 9
Source File: IndicatorSkin.java    From Medusa with Apache License 2.0 5 votes vote down vote up
@Override protected void handleEvents(final String EVENT_TYPE) {
    super.handleEvents(EVENT_TYPE);
    if ("RECALC".equals(EVENT_TYPE)) {
        angleRange = Helper.clamp(90.0, 180.0, gauge.getAngleRange());
        startAngle = getStartAngle();
        minValue   = gauge.getMinValue();
        range      = gauge.getRange();
        sections   = gauge.getSections();
        angleStep  = angleRange / range;
        redraw();
        rotateNeedle(gauge.getCurrentValue());
    } else if ("FINISHED".equals(EVENT_TYPE)) {
        String text = String.format(locale, formatString, gauge.getValue());
        needleTooltip.setText(text);
        double value = gauge.getValue();
        if (gauge.isValueVisible()) {
            Bounds bounds       = barBackground.localToScreen(barBackground.getBoundsInLocal());
            double tooltipAngle = needleRotate.getAngle();
            double sinValue     = Math.sin(Math.toRadians(90 + angleRange * 0.5 - tooltipAngle));
            double cosValue     = Math.cos(Math.toRadians(90 + angleRange * 0.5 - tooltipAngle));
            double needleTipX   = bounds.getMinX() + bounds.getWidth() * 0.5 + bounds.getHeight() * sinValue;
            double needleTipY   = bounds.getMinY() + bounds.getHeight() * 0.8 + bounds.getHeight() * cosValue;
            if (value < (gauge.getMinValue() + (gauge.getRange() * 0.5))) {
                needleTipX -= text.length() * 7;
            }
            needleTooltip.show(needle, needleTipX, needleTipY);
        }
        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, !gauge.getTitle().isEmpty());
    }
}
 
Example 10
Source File: JavaFXTabPaneTabJavaElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public Point2D _getMidpoint() {
    StackPane tabRegion = getTabRegion();
    Bounds boundsInParent = tabRegion.getBoundsInParent();
    double x = boundsInParent.getWidth() / 2;
    double y = boundsInParent.getHeight() / 2;
    return tabRegion.localToParent(x, y);
}
 
Example 11
Source File: GenericStyledArea.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static Bounds extendLeft(Bounds b, double w) {
    if(w == 0) {
        return b;
    } else {
        return new BoundingBox(
                b.getMinX() - w, b.getMinY(),
                b.getWidth() + w, b.getHeight());
    }
}
 
Example 12
Source File: FxmlControl.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static void setScrollPane(ScrollPane scrollPane, double xOffset,
        double yOffset) {
    final Bounds visibleBounds = scrollPane.getViewportBounds();
    double scrollWidth = scrollPane.getContent().getBoundsInParent().getWidth() - visibleBounds.getWidth();
    double scrollHeight = scrollPane.getContent().getBoundsInParent().getHeight() - visibleBounds.getHeight();

    scrollPane.setHvalue(scrollPane.getHvalue() + xOffset / scrollWidth);
    scrollPane.setVvalue(scrollPane.getVvalue() + yOffset / scrollHeight);
}
 
Example 13
Source File: FontDetails.java    From dm3270 with Apache License 2.0 5 votes vote down vote up
public FontDetails (String name, int size, Font font)
{
  this.font = font;
  this.name = name;
  this.size = size;

  Text text = new Text ("W");
  text.setFont (font);
  Bounds bounds = text.getLayoutBounds ();
  height = (int) (bounds.getHeight () + 0.5);
  width = (int) (bounds.getWidth () + 0.5);
  ascent = (int) (-bounds.getMinY () + 0.5);
  descent = height - ascent;
}
 
Example 14
Source File: Flyout.java    From mars-sim with GNU General Public License v3.0 5 votes vote down vote up
private Pair<Double, Double> initPopupLocation(Bounds anchorBounds) {
    Point2D fp = anchor.localToScreen(0.0, 0.0);
    
    switch(flyoutSide) {
        case BOTTOM : return new Pair<>(fp.getX(), fp.getY() + anchorBounds.getHeight());
        case TOP : return new Pair<>(fp.getX(), fp.getY() - userNodeContainer.getHeight());
        case LEFT : return new Pair<>(fp.getX() - userNodeContainer.getWidth(), fp.getY());
        case RIGHT : return new Pair<>(fp.getX() + anchorBounds.getWidth(), fp.getY());
        case TOP_RIGHT : return new Pair<>(fp.getX() + anchorBounds.getWidth(), fp.getY() - userNodeContainer.getHeight());
        default : return null;
    }
}
 
Example 15
Source File: GuiUtils.java    From CircuitSim with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static void drawName(GraphicsContext graphics, ComponentPeer<?> component, Direction direction) {
	if(!component.getComponent().getName().isEmpty()) {
		Bounds bounds = GuiUtils.getBounds(graphics.getFont(), component.getComponent().getName());
		
		double x, y;
		switch(direction) {
			case EAST:
				x = component.getScreenX() + component.getScreenWidth() + 5;
				y = component.getScreenY() + (component.getScreenHeight() + bounds.getHeight()) * 0.4;
				break;
			case WEST:
				x = component.getScreenX() - bounds.getWidth() - 3;
				y = component.getScreenY() + (component.getScreenHeight() + bounds.getHeight()) * 0.4;
				break;
			case SOUTH:
				x = component.getScreenX() + (component.getScreenWidth() - bounds.getWidth()) * 0.5;
				y = component.getScreenY() + component.getScreenHeight() + bounds.getHeight();
				break;
			case NORTH:
				x = component.getScreenX() + (component.getScreenWidth() - bounds.getWidth()) * 0.5;
				y = component.getScreenY() - 5;
				break;
			default:
				throw new IllegalArgumentException("How can Direction be anything else??");
		}
		
		graphics.setFill(Color.BLACK);
		graphics.fillText(component.getComponent().getName(), x, y);
	}
}
 
Example 16
Source File: MovingImageView.java    From neural-style-gui with GNU General Public License v3.0 5 votes vote down vote up
public void scaleImageViewport(double scale) {
    this.scale = scale;
    Bounds layoutBounds = imageView.getLayoutBounds();
    double layoutWidth = layoutBounds.getWidth();
    double layoutHeight = layoutBounds.getHeight();

    // center the image's x&y
    double newWidth = layoutWidth * scale;
    double newHeight = layoutHeight * scale;
    double offsetX = (this.width - newWidth) / 2;
    double offsetY = (this.height - newHeight) / 2;

    imageView.setViewport(new Rectangle2D(offsetX, offsetY,
            layoutWidth * scale, layoutHeight * scale));
}
 
Example 17
Source File: UndecoratorController.java    From DevToolBox with GNU Lesser General Public License v2.1 4 votes vote down vote up
public boolean isBottomEdge(double x, double y, Bounds boundsInParent) {
    return y < boundsInParent.getHeight() && y > boundsInParent.getHeight() - RESIZE_PADDING;
}
 
Example 18
Source File: JavaFXElementPropertyAccessor.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
public Point2D _getMidpoint() {
    Bounds d = node.getBoundsInLocal();
    Point2D p = new Point2D(d.getWidth() / 2, d.getHeight() / 2);
    return p;
}
 
Example 19
Source File: TargetView.java    From ShootOFF with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Optional<Hit> isHit(double x, double y) {
	if (targetGroup.getBoundsInParent().contains(x, y)) {
		// Target was hit, see if a specific region was hit
		for (int i = targetGroup.getChildren().size() - 1; i >= 0; i--) {
			final Node node = targetGroup.getChildren().get(i);

			if (!(node instanceof TargetRegion)) continue;

			final Bounds nodeBounds = targetGroup.getLocalToParentTransform().transform(node.getBoundsInParent());

			final int adjustedX = (int) (x - nodeBounds.getMinX());
			final int adjustedY = (int) (y - nodeBounds.getMinY());

			if (nodeBounds.contains(x, y)) {
				// If we hit an image region on a transparent pixel,
				// ignore it
				final TargetRegion region = (TargetRegion) node;

				// Ignore regions where ignoreHit tag is true
				if (region.tagExists(TargetView.TAG_IGNORE_HIT)
						&& Boolean.parseBoolean(region.getTag(TargetView.TAG_IGNORE_HIT)))
					continue;

				if (region.getType() == RegionType.IMAGE) {
					// The image you get from the image view is its
					// original size. We need to resize it if it has
					// changed size to accurately determine if a pixel
					// is transparent
					final Image currentImage = ((ImageRegion) region).getImage();

					if (adjustedX < 0 || adjustedY < 0) {
						logger.debug(
								"An adjusted pixel is negative: Adjusted ({}, {}), Original ({}, {}), "
										+ " nodeBounds.getMin ({}, {})",
								adjustedX, adjustedY, x, y, nodeBounds.getMaxX(),
								nodeBounds.getMinY());
						return Optional.empty();
					}

					if (Math.abs(currentImage.getWidth() - nodeBounds.getWidth()) > .0000001
							|| Math.abs(currentImage.getHeight() - nodeBounds.getHeight()) > .0000001) {

						final BufferedImage bufferedOriginal = SwingFXUtils.fromFXImage(currentImage, null);

						final java.awt.Image tmp = bufferedOriginal.getScaledInstance((int) nodeBounds.getWidth(),
								(int) nodeBounds.getHeight(), java.awt.Image.SCALE_SMOOTH);
						final BufferedImage bufferedResized = new BufferedImage((int) nodeBounds.getWidth(),
								(int) nodeBounds.getHeight(), BufferedImage.TYPE_INT_ARGB);

						final Graphics2D g2d = bufferedResized.createGraphics();
						g2d.drawImage(tmp, 0, 0, null);
						g2d.dispose();

						try {
							if (adjustedX >= bufferedResized.getWidth() || adjustedY >= bufferedResized.getHeight()
									|| bufferedResized.getRGB(adjustedX, adjustedY) >> 24 == 0) {
								continue;
							}
						} catch (final ArrayIndexOutOfBoundsException e) {
							final String message = String.format(
									"Index out of bounds while trying to find adjusted coordinate (%d, %d) "
											+ "from original (%.2f, %.2f) in adjusted BufferedImage for target %s "
											+ "with width = %d, height = %d",
									adjustedX, adjustedY, x, y, getTargetFile().getPath(),
									bufferedResized.getWidth(), bufferedResized.getHeight());
							logger.error(message, e);
							return Optional.empty();
						}
					} else {
						if (adjustedX >= currentImage.getWidth() || adjustedY >= currentImage.getHeight()
								|| currentImage.getPixelReader().getArgb(adjustedX, adjustedY) >> 24 == 0) {
							continue;
						}
					}
				} else {
					// The shot is in the bounding box but make sure it
					// is in the shape's
					// fill otherwise we can get a shot detected where
					// there isn't actually
					// a region showing
					final Point2D localCoords = targetGroup.parentToLocal(x, y);
					if (!node.contains(localCoords)) continue;
				}

				return Optional.of(new Hit(this, (TargetRegion) node, adjustedX, adjustedY));
			}
		}
	}

	return Optional.empty();
}
 
Example 20
Source File: AbstractEdgeViewer.java    From JetUML with GNU General Public License v3.0 4 votes vote down vote up
@Override
public Rectangle getBounds(Edge pEdge)
{
	Bounds bounds = getShape(pEdge).getBoundsInLocal();
	return new Rectangle((int)bounds.getMinX(), (int)bounds.getMinY(), (int)bounds.getWidth(), (int)bounds.getHeight());
}