Java Code Examples for javafx.scene.Node#getBoundsInParent()

The following examples show how to use javafx.scene.Node#getBoundsInParent() . 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: DoughnutChart.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
private void updateInnerCircleLayout() {
    double minX = Double.MAX_VALUE, minY = Double.MAX_VALUE;
    double maxX = Double.MIN_VALUE, maxY = Double.MIN_VALUE;
    for (PieChart.Data data: getData()) {
        Node node = data.getNode();

        Bounds bounds = node.getBoundsInParent();
        if (bounds.getMinX() < minX) {
            minX = bounds.getMinX();
        }
        if (bounds.getMinY() < minY) {
            minY = bounds.getMinY();
        }
        if (bounds.getMaxX() > maxX) {
            maxX = bounds.getMaxX();
        }
        if (bounds.getMaxY() > maxY) {
            maxY = bounds.getMaxY();
        }
    }

    innerCircle.setCenterX(minX + (maxX - minX) / 2);
    innerCircle.setCenterY(minY + (maxY - minY) / 2);

    innerCircle.setRadius((maxX - minX) / 4);
}
 
Example 2
Source File: FXEventQueueDevice.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void checkHit(Node child, double x, double y, List<Node> hits, String indent) {
    Bounds boundsInParent = child.getBoundsInParent();
    if (boundsInParent.contains(x, y)) {
        hits.add(child);
        if (!(child instanceof Parent)) {
            return;
        }
        ObservableList<Node> childrenUnmodifiable = ((Parent) child).getChildrenUnmodifiable();
        for (Node node : childrenUnmodifiable) {
            checkHit(node, x, y, hits, "    " + indent);
        }
    }
}
 
Example 3
Source File: JavaFXTableCellElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public Point2D _getMidpoint() {
    Node cell = getPseudoComponent();
    Bounds boundsInParent = cell.getBoundsInParent();
    double x = boundsInParent.getWidth() / 2;
    double y = boundsInParent.getHeight() / 2;
    return cell.getParent().localToParent(cell.localToParent(x, y));
}
 
Example 4
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 5
Source File: JavaFXListViewItemElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public Point2D _getMidpoint() {
    Node cell = getPseudoComponent();
    Bounds boundsInParent = cell.getBoundsInParent();
    double x = boundsInParent.getWidth() / 2;
    double y = boundsInParent.getHeight() / 2;
    return cell.localToParent(x, y);
}
 
Example 6
Source File: JavaFXTreeTableViewCellElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@Override
public Point2D _getMidpoint() {
    Node cell = getPseudoComponent();
    Bounds boundsInParent = cell.getBoundsInParent();
    double x = boundsInParent.getWidth() / 2;
    double y = boundsInParent.getHeight() / 2;
    return cell.getParent().localToParent(cell.localToParent(x, y));
}
 
Example 7
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 8
Source File: HoverHandleContainerPart.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
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());
}
 
Example 9
Source File: MapPresenter.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
protected void layoutLayer() {
    for (Pair<MapPoint, Node> candidate : points) {
        MapPoint point = candidate.getKey();
        Node icon = candidate.getValue();
        Bounds bounds = icon.getBoundsInParent();
        Point2D mapPoint = baseMap.getMapPoint(point.getLatitude(), point.getLongitude());
        // translate icon so marker base point is at the center
        icon.setTranslateX(mapPoint.getX() - bounds.getWidth() / 2);
        icon.setTranslateY(mapPoint.getY() - bounds.getHeight() / 2 - 10);
    }
}
 
Example 10
Source File: HeatTabController.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private void createStateLabels() {
    Group overlay = map.getOverlayGroup();
    for(String state: Region.ALL_STATES) {
        Node stateNode = map.lookup("#"+state);
        if (stateNode != null) {
            Label label = new Label("+10");
            label.getStyleClass().add("heatmap-label");
            label.setTextAlignment(TextAlignment.CENTER);
            label.setAlignment(Pos.CENTER);
            label.setManaged(false);
            label.setOpacity(0);
            label.setVisible(false);
            Bounds stateBounds = stateNode.getBoundsInParent();
            if ("DE".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()-25, stateBounds.getMinY(), 
                        stateBounds.getWidth()+50, stateBounds.getHeight());
            } else if ("VT".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY()-25, 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("NH".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY()+30, 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("MA".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()-20, stateBounds.getMinY()-18, 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("RI".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY(), 
                        stateBounds.getWidth()+40, stateBounds.getHeight());
            } else if ("ID".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY()+60, 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("MI".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()+60, stateBounds.getMinY(), 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("FL".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()+95, stateBounds.getMinY(), 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("LA".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()-50, stateBounds.getMinY(), 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY(), 
                        stateBounds.getWidth(), stateBounds.getHeight());
            }
            stateLabelMap.put(state, label);
            overlay.getChildren().add(label);
        }
    }
}
 
Example 11
Source File: HeatTabController.java    From marathonv5 with Apache License 2.0 4 votes vote down vote up
private void createStateLabels() {
    Group overlay = map.getOverlayGroup();
    for(String state: Region.ALL_STATES) {
        Node stateNode = map.lookup("#"+state);
        if (stateNode != null) {
            Label label = new Label("+10");
            label.getStyleClass().add("heatmap-label");
            label.setTextAlignment(TextAlignment.CENTER);
            label.setAlignment(Pos.CENTER);
            label.setManaged(false);
            label.setOpacity(0);
            label.setVisible(false);
            Bounds stateBounds = stateNode.getBoundsInParent();
            if ("DE".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()-25, stateBounds.getMinY(), 
                        stateBounds.getWidth()+50, stateBounds.getHeight());
            } else if ("VT".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY()-25, 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("NH".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY()+30, 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("MA".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()-20, stateBounds.getMinY()-18, 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("RI".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY(), 
                        stateBounds.getWidth()+40, stateBounds.getHeight());
            } else if ("ID".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY()+60, 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("MI".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()+60, stateBounds.getMinY(), 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("FL".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()+95, stateBounds.getMinY(), 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else if ("LA".equals(state)) {
                label.resizeRelocate(stateBounds.getMinX()-50, stateBounds.getMinY(), 
                        stateBounds.getWidth(), stateBounds.getHeight());
            } else {
                label.resizeRelocate(stateBounds.getMinX(), stateBounds.getMinY(), 
                        stateBounds.getWidth(), stateBounds.getHeight());
            }
            stateLabelMap.put(state, label);
            overlay.getChildren().add(label);
        }
    }
}
 
Example 12
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 13
Source File: TextFlowLayout.java    From RichTextFX with BSD 2-Clause "Simplified" License 4 votes vote down vote up
int getLineCount() {
   
    if ( lineCount > -1 ) return lineCount;

    lineCount = 0;
    lineMetrics.clear();
    double totLines = 0.0, prevMinY = 1.0, prevMaxY = -1.0;
    int totCharSoFar = 0;

    for ( Node n : flow.getChildren() ) if ( n.isManaged() ) {
       
        Bounds nodeBounds = n.getBoundsInParent();
        int length = (n instanceof Text) ? ((Text) n).getText().length() : 1;
        PathElement[] shape = flow.rangeShape( totCharSoFar, totCharSoFar+length );
        double lines = Math.max( 1.0, Math.floor( shape.length / 5 ) );
        double nodeMinY = Math.max( 0.0, nodeBounds.getMinY() );
        
        if ( nodeMinY >= prevMinY && lines > 1 )  totLines += lines - 1;  // Multiline Text node 
        else if ( nodeMinY >= prevMaxY )  totLines += lines;

        if ( lineMetrics.size() < totLines ) {                            // Add additional lines
           
            if ( shape.length == 0 ) {
               lineMetrics.add( new TextFlowSpan( totCharSoFar, length, nodeMinY, nodeBounds.getWidth(), nodeBounds.getHeight() ) );
                totCharSoFar += length;
            }
            else for ( int ele = 1; ele < shape.length; ele += 5 ) {
                // Calculate the segment's line's length and width up to this point
                LineTo eleLine = (LineTo) shape[ele];
                double segWidth = eleLine.getX(), lineMinY = eleLine.getY();
                double charHeight = ((LineTo) shape[ele+1]).getY() - lineMinY;
                Point2D endPoint = new Point2D( segWidth-1, lineMinY + charHeight / 2 );

                // hitTest queries TextFlow layout internally and returns the position of the
                // last char (nearest endPoint) on the line, irrespective of the current Text node !
                int segLen = flow.hitTest( endPoint ).getCharIndex();
                segLen -= totCharSoFar - 1;

                if ( ele == 1 && nodeMinY < prevMaxY ) {
                    adjustLineMetrics( segLen, segWidth - ((MoveTo) shape[ele-1]).getX(), charHeight );
                }
                else {
                   lineMetrics.add( new TextFlowSpan( totCharSoFar, segLen, lineMinY, segWidth, charHeight ) );
                }

                totCharSoFar += segLen;
            }
        }
        else {
            // Adjust current line metrics with additional Text or Node embedded in this line 
            adjustLineMetrics( length, nodeBounds.getWidth(), nodeBounds.getHeight() );
            totCharSoFar += length;
        }

        prevMaxY = nodeBounds.getMaxY();
        prevMinY = nodeMinY;
    }
    
    lineCount = (int) totLines;
    return lineCount;
}