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

The following examples show how to use javafx.geometry.Bounds#getWidth() . 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: 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 2
Source File: CanvasManager.java    From ShootOFF with GNU General Public License v3.0 6 votes vote down vote up
public Pair<Double, Double> translateCanvasToCameraPoint(double x, double y) {
	if (cameraManager == null)
	{
		logger.error("Called when cameraManager == null");
		return new Pair<Double, Double>(x,y);
	}
	
	if (!cameraManager.getProjectionBounds().isPresent() || !arenaPane.isPresent())
	{
		logger.error("Called when projectionBounds is not available");
		return new Pair<Double, Double>(x,y);
	}
	
	final Bounds b = cameraManager.getProjectionBounds().get();

	final double x_scale = b.getWidth() / arenaPane.get().getWidth();
	final double y_scale = b.getHeight() / arenaPane.get().getHeight();
	
	logger.trace("translateCanvasToCameraPoint scale x {} y {}", x_scale, y_scale);

	return new Pair<Double, Double>(b.getMinX() + (x * x_scale), b.getMinY() + (y*y_scale));
}
 
Example 3
Source File: DemoHelper.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
public static void refresh(final Canvas canvas)
{
    final GraphicsContext gc = canvas.getGraphicsContext2D();

    final Bounds bounds = canvas.getBoundsInLocal();
    final double width = bounds.getWidth();
    final double height = bounds.getHeight();

    gc.clearRect(0, 0, width, height);
    gc.strokeRect(0, 0, width, height);

    for (int i=0; i<ITEMS; ++i)
    {
        gc.setFill(Color.hsb(Math.random()*360.0,
                             Math.random(),
                             Math.random()));
        final double size = 5 + Math.random() * 40;
        final double x = Math.random() * (width-size);
        final double y = Math.random() * (height-size);
        gc.fillOval(x, y, size, size);
    }
}
 
Example 4
Source File: JFXFontCalibration.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public double getCalibrationFactor() throws Exception
{
    final Font font = Font.font(FontCalibration.FONT, FontCalibration.SIZE);
    if (! font.getName().startsWith(FontCalibration.FONT))
    {
        logger.log(Level.SEVERE, "Cannot obtain font " + FontCalibration.FONT + " for calibration. Got " + font.getName());
        logger.log(Level.SEVERE, "Font calibration will default to 1.0. Check installation of calibration font");
        return 1.0;
    }
    text.setFont(font);

    final Bounds measure = text.getLayoutBounds();
    logger.log(Level.FINE,
               "Font calibration measure: " + measure.getWidth() + " x " + measure.getHeight());
    final double factor = FontCalibration.PIXEL_WIDTH / measure.getWidth();
    logger.log(Level.CONFIG, "JFX font calibration factor: {0}", factor);
    return factor;
}
 
Example 5
Source File: InfiniteCanvas.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Ensures that the specified child {@link Node} is visible to the user by
 * scrolling to its position. The effect and style of the node are taken
 * into consideration. After revealing a node, it will be fully visible if
 * it fits within the current viewport bounds.
 * <p>
 * When the child node's left side is left to the viewport, it will touch
 * the left border of the viewport after revealing. When the child node's
 * right side is right to the viewport, it will touch the right border of
 * the viewport after revealing. When the child node's top side is above the
 * viewport, it will touch the top border of the viewport after revealing.
 * When the child node's bottom side is below the viewport, it will touch
 * the bottom border of the viewport after revealing.
 * <p>
 * The top and left sides have preference over the bottom and right sides,
 * i.e. when the top side is aligned with the viewport, the bottom side will
 * not be aligned, and when the left side is aligned with the viewport, the
 * right side will not be aligned.
 *
 * @param child
 *            The child {@link Node} to reveal.
 */
public void reveal(Node child) {
	Bounds bounds = sceneToLocal(
			child.localToScene(child.getBoundsInLocal()));
	if (bounds.getHeight() <= getHeight()) {
		if (bounds.getMinY() < 0) {
			setVerticalScrollOffset(
					getVerticalScrollOffset() - bounds.getMinY());
		} else if (bounds.getMaxY() > getHeight()) {
			setVerticalScrollOffset(getVerticalScrollOffset() + getHeight()
					- bounds.getMaxY());
		}
	}
	if (bounds.getWidth() <= getWidth()) {
		if (bounds.getMinX() < 0) {
			setHorizontalScrollOffset(
					getHorizontalScrollOffset() - bounds.getMinX());
		} else if (bounds.getMaxX() > getWidth()) {
			setHorizontalScrollOffset(getHorizontalScrollOffset()
					+ getWidth() - bounds.getMaxX());
		}
	}
}
 
Example 6
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 7
Source File: SelectionStripSkin.java    From WorkbenchFX with Apache License 2.0 5 votes vote down vote up
private void scrollTo(T item) {
  Node node = nodeMap.get(item);

  if (node != null) {
    SelectionStrip strip = getSkinnable();

    strip.getProperties().remove(SCROLL_TO_KEY);

    final Bounds nodeBounds = node.localToParent(node.getLayoutBounds());

    final double x = -nodeBounds.getMinX() + strip.getWidth() / 2 - nodeBounds.getWidth() / 2;

    final double x1 = -translateX.get();
    final double x2 = x1 + strip.getLayoutBounds().getWidth();

    if (x1 > nodeBounds.getMinX() || x2 < nodeBounds.getMaxX()) {
      if (strip.isAnimateScrolling()) {
        KeyValue keyValue = new KeyValue(translateX, x);
        KeyFrame keyFrame = new KeyFrame(strip.getAnimationDuration(), keyValue);

        Timeline timeline = new Timeline(keyFrame);
        timeline.play();
      } else {
        translateX.set(x);
      }
    }
  }
}
 
Example 8
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 9
Source File: TestCanvasSelection.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDnDToSelectShapeSelectsIt() {
	Cmds.of(addLines).execute();
	final Bounds bounds = getPane().getChildren().get(0).getBoundsInParent();
	final double x = canvas.getScene().getWindow().getX() + Canvas.ORIGIN.getX() + bounds.getMinX() + bounds.getWidth() / 2d - 20d;
	final double y = canvas.getScene().getWindow().getY() + Canvas.ORIGIN.getY() + bounds.getMinY() + bounds.getHeight() / 2d;
	Cmds.of(() -> clickOn(x, y), () -> drag(x + 10, y + 10),
		() -> drag(x + 50, y), () -> drag(x + 100, y)).execute();
	assertEquals(1, canvas.getDrawing().getSelection().size());
	assertSame(addedPolyline, canvas.getDrawing().getSelection().getShapeAt(0).orElseThrow());
}
 
Example 10
Source File: JavaFxRecorderHook.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public MouseEvent getContextMenuMouseEvent(Node source) {
    Bounds boundsInParent = source.getBoundsInParent();
    double x = boundsInParent.getWidth() / 2;
    double y = boundsInParent.getHeight() / 2;
    Point2D screenXY = source.localToScreen(x, y);
    MouseEvent e = new MouseEvent(source, source, MouseEvent.MOUSE_PRESSED, x, y, screenXY.getX(), screenXY.getY(),
            MouseButton.SECONDARY, 1, false, true, false, false, false, false, true, true, true, false, null);
    return e;
}
 
Example 11
Source File: DragResizerUtil.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
protected boolean isInDragZone(MouseEvent event) {
    final Bounds bounds = node.getBoundsInParent();
    final double xPos = bounds.getMinX() + event.getX();
    final double yPos = bounds.getMinY() + event.getY();
    final double nodeX = bounds.getMinX() + MARGIN;
    final double nodeY = bounds.getMinY() + MARGIN;
    final double nodeX0 = bounds.getMinX() + bounds.getWidth() - MARGIN;
    final double nodeY0 = bounds.getMinY() + bounds.getHeight() - MARGIN;

    return (xPos > nodeX && xPos < nodeX0) && (yPos > nodeY && yPos < nodeY0);
}
 
Example 12
Source File: TestCanvasSelection.java    From latexdraw with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDnDInsideEmptyShapeDoesNotSelectIt() {
	Cmds.of(addLines).execute();
	final Bounds bounds = getPane().getChildren().get(0).getBoundsInParent();
	final double x = canvas.getScene().getWindow().getX() + Canvas.ORIGIN.getX() + bounds.getMinX() + bounds.getWidth() / 2d;
	final double y = canvas.getScene().getWindow().getY() + Canvas.ORIGIN.getY() + bounds.getMinY() + bounds.getHeight() / 2d;
	Cmds.of(() -> clickOn(x, y), () -> drag(x + 5, y + 5)).execute();
	assertTrue(canvas.getDrawing().getSelection().isEmpty());
}
 
Example 13
Source File: NodeLabelPart.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Point computeLabelPosition() {
	IVisualPart<? extends javafx.scene.Node> firstAnchorage = getFirstAnchorage();
	// determine bounds of anchorage visual
	Rectangle anchorageBounds = NodeUtils
			.sceneToLocal(getVisual().getParent(), NodeUtils.localToScene(firstAnchorage.getVisual(),
					FX2Geometry.toRectangle(firstAnchorage.getVisual().getLayoutBounds())))
			.getBounds();
	// determine text bounds
	Bounds textBounds = getVisual().getLayoutBounds();
	// TODO: compute better label position
	return new Point(anchorageBounds.getX() + anchorageBounds.getWidth() / 2 - textBounds.getWidth() / 2,
			anchorageBounds.getY() + anchorageBounds.getHeight());
}
 
Example 14
Source File: AbstractInterpolator.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void interpolate(Connection connection) {
	// compute new curve (this can lead to another refreshGeometry() call
	// which is not executed)
	ICurve newGeometry = computeCurve(connection);

	// XXX: we can only deal with geometry nodes so far
	@SuppressWarnings("unchecked")
	final GeometryNode<ICurve> curveNode = (GeometryNode<ICurve>) connection
			.getCurve();
	if (curveNode instanceof GeometryNode
			&& !newGeometry.equals(curveNode.getGeometry())) {
		// TODO: we need to prevent positions are re-calculated as a
		// result of the changed geometry. -> the static anchors should not
		// update their positions because of layout bounds changes.
		// System.out.println("New geometry: " + newGeometry);
		curveNode.setGeometry(newGeometry);
	}

	Node startDecoration = connection.getStartDecoration();
	if (startDecoration != null) {
		arrangeStartDecoration(startDecoration, newGeometry,
				newGeometry.getP1());
	}

	Node endDecoration = connection.getEndDecoration();
	if (endDecoration != null) {
		arrangeEndDecoration(endDecoration, newGeometry,
				newGeometry.getP2());
	}

	if (!newGeometry.getBounds().isEmpty()
			&& (startDecoration != null || endDecoration != null)) {
		// XXX Use scene coordinates, as the clip node does not provide a
		// parent.

		// union curve node's children's bounds-in-parent
		org.eclipse.gef.geometry.planar.Rectangle unionBoundsInCurveNode = new org.eclipse.gef.geometry.planar.Rectangle();
		ObservableList<Node> childrenUnmodifiable = curveNode
				.getChildrenUnmodifiable();
		for (Node child : childrenUnmodifiable) {
			Bounds boundsInParent = child.getBoundsInParent();
			org.eclipse.gef.geometry.planar.Rectangle rectangle = FX2Geometry
					.toRectangle(boundsInParent);
			unionBoundsInCurveNode.union(rectangle);
		}

		// convert unioned bounds to scene coordinates
		Bounds visualBounds = curveNode.localToScene(
				Geometry2FX.toFXBounds(unionBoundsInCurveNode));

		// create clip
		Shape clip = new Rectangle(visualBounds.getMinX(),
				visualBounds.getMinY(), visualBounds.getWidth(),
				visualBounds.getHeight());
		clip.setFill(Color.RED);

		// can only clip Shape decorations
		if (startDecoration != null && startDecoration instanceof Shape) {
			clip = clipAtDecoration(curveNode.getGeometricShape(), clip,
					(Shape) startDecoration);
		}
		// can only clip Shape decorations
		if (endDecoration != null && endDecoration instanceof Shape) {
			clip = clipAtDecoration(curveNode.getGeometricShape(), clip,
					(Shape) endDecoration);
		}

		// XXX: All CAG operations deliver result shapes that reflect areas
		// in scene coordinates.
		AffineTransform sceneToLocalTx = NodeUtils
				.getSceneToLocalTx(curveNode);
		clip.getTransforms().add(Geometry2FX.toFXAffine(sceneToLocalTx));

		// set clip
		curveNode.setClip(clip);
	} else {
		curveNode.setClip(null);
	}
}
 
Example 15
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());
}
 
Example 16
Source File: StringViewer.java    From JetUML with GNU General Public License v3.0 4 votes vote down vote up
/**
    * Draws the string inside a given rectangle.
    * @param pString The string to draw.
    * @param pGraphics the graphics context
    * @param pRectangle the rectangle into which to place the string
 */
public void draw(String pString, GraphicsContext pGraphics, Rectangle pRectangle)
{
	Text label = getLabel(pString);
	
	pGraphics.setTextAlign(label.getTextAlignment());
	
	int textX = 0;
	int textY = 0;
	if(aAlignment == Align.CENTER) 
	{
		textX = pRectangle.getWidth()/2;
		textY = pRectangle.getHeight()/2;
		pGraphics.setTextBaseline(VPos.CENTER);
	}
	else
	{
		pGraphics.setTextBaseline(VPos.TOP);
		textX = HORIZONTAL_TEXT_PADDING;
	}
	
	pGraphics.translate(pRectangle.getX(), pRectangle.getY());
	ViewUtils.drawText(pGraphics, textX, textY, pString.trim(), getFont());
	
	if(aUnderlined && pString.trim().length() > 0)
	{
		int xOffset = 0;
		int yOffset = 0;
		Bounds bounds = label.getLayoutBounds();
		if(aAlignment == Align.CENTER)
		{
			xOffset = (int) (bounds.getWidth()/2);
			yOffset = (int) (getFont().getSize()/2) + 1;
		}
		else if(aAlignment == Align.RIGHT)
		{
			xOffset = (int) bounds.getWidth();
		}
		
		ViewUtils.drawLine(pGraphics, textX-xOffset, textY+yOffset, 
				(int) (textX-xOffset+bounds.getWidth()), textY+yOffset, LineStyle.SOLID);
	}
	pGraphics.translate(-pRectangle.getX(), -pRectangle.getY());
}
 
Example 17
Source File: Zoomer.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
private void zoomInDragged(final MouseEvent event) {
    final Bounds plotAreaBounds = getChart().getPlotArea().getBoundsInLocal();
    zoomEndPoint = limitToPlotArea(event, plotAreaBounds);

    double zoomRectX = plotAreaBounds.getMinX();
    double zoomRectY = plotAreaBounds.getMinY();
    double zoomRectWidth = plotAreaBounds.getWidth();
    double zoomRectHeight = plotAreaBounds.getHeight();

    if (isAutoZoomEnabled()) {
        final double diffX = zoomEndPoint.getX() - zoomStartPoint.getX();
        final double diffY = zoomEndPoint.getY() - zoomStartPoint.getY();

        final int limit = Math.abs(getAutoZoomThreshold());

        // pixel distance based algorithm + aspect ratio to prevent flickering when starting selection
        final boolean isZoomX = Math.abs(diffY) <= limit && Math.abs(diffX) >= limit
                                && Math.abs(diffX / diffY) > DEFAULT_FLICKER_THRESHOLD;
        final boolean isZoomY = Math.abs(diffX) <= limit && Math.abs(diffY) >= limit
                                && Math.abs(diffY / diffX) > DEFAULT_FLICKER_THRESHOLD;

        // alternate angle-based algorithm
        // final int angle = (int) Math.toDegrees(Math.atan2(diffY, diffX));
        // final boolean isZoomX = Math.abs(angle) <= limit || Math.abs((angle - 180) % 180) <= limit;
        // final boolean isZoomY = Math.abs((angle - 90) % 180) <= limit || Math.abs((angle - 270) % 180) <= limit;

        if (isZoomX) {
            this.setAxisMode(AxisMode.X);
        } else if (isZoomY) {
            this.setAxisMode(AxisMode.Y);
        } else {
            this.setAxisMode(AxisMode.XY);
        }
    }

    if (getAxisMode().allowsX()) {
        zoomRectX = Math.min(zoomStartPoint.getX(), zoomEndPoint.getX());
        zoomRectWidth = Math.abs(zoomEndPoint.getX() - zoomStartPoint.getX());
    }
    if (getAxisMode().allowsY()) {
        zoomRectY = Math.min(zoomStartPoint.getY(), zoomEndPoint.getY());
        zoomRectHeight = Math.abs(zoomEndPoint.getY() - zoomStartPoint.getY());
    }
    zoomRectangle.setX(zoomRectX);
    zoomRectangle.setY(zoomRectY);
    zoomRectangle.setWidth(zoomRectWidth);
    zoomRectangle.setHeight(zoomRectHeight);
}
 
Example 18
Source File: JavaFXElement.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
@Override
public Dimension2D getSize() {
    Bounds bounds = node.getBoundsInParent();
    return new Dimension2D(bounds.getWidth(), bounds.getHeight());
}
 
Example 19
Source File: DataPointTooltip.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
private void updateLabel(final MouseEvent event, final Bounds plotAreaBounds, final DataPoint dataPoint) {
    label.setText(formatLabel(dataPoint));
    final double mouseX = event.getX();
    final double spaceLeft = mouseX - plotAreaBounds.getMinX();
    final double spaceRight = plotAreaBounds.getWidth() - spaceLeft;
    double width = label.prefWidth(-1);
    boolean atSide = true; // set to false if we cannot print the tooltip beside the point

    double xLocation;
    if (spaceRight >= width + LABEL_X_OFFSET) { // place to right if enough space
        xLocation = mouseX + DataPointTooltip.LABEL_X_OFFSET;
    } else if (spaceLeft >= width + LABEL_X_OFFSET) { // place left if enough space
        xLocation = mouseX - DataPointTooltip.LABEL_X_OFFSET - width;
    } else if (width < plotAreaBounds.getWidth()) {
        xLocation = spaceLeft > spaceRight ? plotAreaBounds.getMaxX() - width : plotAreaBounds.getMinX();
        atSide = false;
    } else {
        width = plotAreaBounds.getWidth();
        xLocation = plotAreaBounds.getMinX();
        atSide = false;
    }

    final double mouseY = event.getY();
    final double spaceTop = mouseY - plotAreaBounds.getMinY();
    final double spaceBottom = plotAreaBounds.getHeight() - spaceTop;
    double height = label.prefHeight(width);

    double yLocation;
    if (height < spaceBottom) {
        yLocation = mouseY + DataPointTooltip.LABEL_Y_OFFSET;
    } else if (height < spaceTop) {
        yLocation = mouseY - DataPointTooltip.LABEL_Y_OFFSET - height;
    } else if (atSide && height < plotAreaBounds.getHeight()) {
        yLocation = spaceTop < spaceBottom ? plotAreaBounds.getMaxY() - height : plotAreaBounds.getMinY();
    } else if (atSide) {
        yLocation = plotAreaBounds.getMinY();
        height = plotAreaBounds.getHeight();
    } else if (spaceBottom > spaceTop) {
        yLocation = mouseY + DataPointTooltip.LABEL_Y_OFFSET;
        height = spaceBottom - LABEL_Y_OFFSET;
    } else {
        yLocation = plotAreaBounds.getMinY();
        height = spaceTop - LABEL_Y_OFFSET;
    }
    label.resizeRelocate(xLocation, yLocation, width, height);
}
 
Example 20
Source File: ResizableTransformableBoundsProvider.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public IGeometry get() {
	IVisualPart<? extends Node> part = getAdaptable();
	Bounds boundsInParent = part.getVisual().getBoundsInLocal();// getBoundsInParent();

	// determine x and y offset
	double x, y;
	if (part instanceof IBendableContentPart) {
		// return null if there are no free bend points
		boolean isEmpty = true;
		List<BendPoint> bendPoints = ((IBendableContentPart<?>) part)
				.getVisualBendPoints();
		for (BendPoint bp : bendPoints) {
			if (!bp.isAttached()) {
				isEmpty = false;
				break;
			}
		}
		if (isEmpty) {
			return null;
		}

		// TODO: generalize for ITransformableContentPart (transform corner
		// points of local bounds to scene and take axis parallel bounds
		// around that)
		Affine visualTransform = ((ITransformableContentPart<? extends Node>) part)
				.getVisualTransform();
		x = visualTransform.getTx();
		y = visualTransform.getTy();
	} else {
		x = boundsInParent.getMinX();
		y = boundsInParent.getMinY();
	}

	// determine width and height
	double w, h;
	if (part instanceof IBendableContentPart) {
		// TODO: generalize for IResizableContentPart (transform corner
		// points of local bounds to scene and take axis parallel bounds
		// around that)
		Dimension visualSize = ((IResizableContentPart<? extends Node>) part)
				.getVisualSize();
		w = visualSize.width;
		h = visualSize.height;
	} else {
		w = boundsInParent.getWidth();
		h = boundsInParent.getHeight();
	}

	// construct bounds and transform to local
	return // FX2Geometry.toRectangle(part.getVisual().parentToLocal(
			// Geometry2FX.toFXBounds(
	new Rectangle(x, y, w, h);
	// )));
}