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

The following examples show how to use javafx.scene.Node#getLayoutX() . 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: MultiTouchSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Override protected void layoutChildren() {
    final double w = getWidth();
    final double h = getHeight();
    clipRect.setWidth(w);
    clipRect.setHeight(h);
    for (Node child : getChildren()) {
        if (child == postView) {
            postView.relocate(w - 15 - postView.getLayoutBounds().getWidth(), 0);
        } else if (child.getLayoutX() == 0 && child.getLayoutY() == 0) {
            final double iw = child.getBoundsInParent().getWidth();
            final double ih = child.getBoundsInParent().getHeight();
            child.setLayoutX((w - iw) * Math.random() + 100);
            child.setLayoutY((h - ih) * Math.random() + 100);
        }
    }
}
 
Example 2
Source File: MultiTouchSample.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Override protected void layoutChildren() {
    final double w = getWidth();
    final double h = getHeight();
    clipRect.setWidth(w);
    clipRect.setHeight(h);
    for (Node child : getChildren()) {
        if (child == postView) {
            postView.relocate(w - 15 - postView.getLayoutBounds().getWidth(), 0);
        } else if (child.getLayoutX() == 0 && child.getLayoutY() == 0) {
            final double iw = child.getBoundsInParent().getWidth();
            final double ih = child.getBoundsInParent().getHeight();
            child.setLayoutX((w - iw) * Math.random() + 100);
            child.setLayoutY((h - ih) * Math.random() + 100);
        }
    }
}
 
Example 3
Source File: OverlayStage.java    From DeskChan with GNU Lesser General Public License v3.0 6 votes vote down vote up
SeparatedStage(Node node){
	super();
	position = new Point2D(node.getLayoutX(),node.getLayoutY());
	root.getChildren().add(node);
	//scene.setFill(Color.WHITE);
	this.node = node;
	setOnShowing(showHandler);
	setOnHiding(showHandler);
	root.setOnMouseDragged(startDragHandler);
	root.setOnMouseExited(stopDragHandler);
	root.setOnMouseReleased(stopDragHandler);
	setAlwaysOnTop();
	try {
		node.setLayoutX(0);
		node.setLayoutY(0);
	} catch (Exception e){ }
	show();
	stage.setX(position.getX());
	stage.setY(position.getY());
	Bounds bounds = node.getLayoutBounds();
	stage.setHeight(bounds.getHeight()+5);
	stage.setWidth(bounds.getWidth()+5);

}
 
Example 4
Source File: MouseDragSnippet.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
protected void onMousePress(MouseEvent event) {
	pressed = (Node) event.getTarget();
	System.out.println("press " + pressed);
	startMousePosition = new Point2D(event.getSceneX(), event.getSceneY());
	startLayoutPosition = new Point2D(pressed.getLayoutX(),
			pressed.getLayoutY());

	// add effect
	pressed.setEffect(new Bloom(0));
	IAnchor ifxAnchor = anchors.get(pressed);
	if (ifxAnchor != null) {
		Set<AnchorKey> keys = ifxAnchor.positionsUnmodifiableProperty()
				.keySet();
		for (AnchorKey key : keys) {
			key.getAnchored().setEffect(null);
		}
	}
}
 
Example 5
Source File: HorizontalTransition.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
public HorizontalTransition(boolean leftDirection, Node contentContainer, Node overlay) {
    super(contentContainer, new Timeline(
        new KeyFrame(Duration.ZERO,
            new KeyValue(contentContainer.translateXProperty(),
                (contentContainer.getLayoutX() + contentContainer.getLayoutBounds().getMaxX())
                * (leftDirection? -1 : 1), Interpolator.LINEAR),
            new KeyValue(overlay.opacityProperty(), 0, Interpolator.EASE_BOTH)
        ),
        new KeyFrame(Duration.millis(1000),
            new KeyValue(overlay.opacityProperty(), 1, Interpolator.EASE_BOTH),
            new KeyValue(contentContainer.translateXProperty(), 0, Interpolator.EASE_OUT)
        )));
    // reduce the number to increase the shifting , increase number to reduce shifting
    setCycleDuration(Duration.seconds(0.4));
    setDelay(Duration.seconds(0));
}
 
Example 6
Source File: FXTestUtils.java    From graph-editor with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Drags the given {@link Node} from the start location to the end location.
 *
 * @param node the {@link Node} which should be dragged
 * @param offsetX the x offset on the node where the drag gesture starts from
 * @param offsetY the y offset on the node where the drag gesture starts from
 * @param endX the x coordinate of the targeted location
 * @param endY the y coordinate of the targeted location
 */
public static void dragTo(final Node node, final double offsetX, final double offsetY, final double endX,
        final double endY) {

    final double startX = node.getLayoutX() + offsetX;
    final double startY = node.getLayoutY() + offsetY;

    final double dragX = startX + (endX - node.getLayoutX());
    final double dragY = startY + (endY - node.getLayoutY());

    final MouseEvent pressed = createMouseEvent(MouseEvent.MOUSE_PRESSED, startX, startY);
    final MouseEvent dragged = createMouseEvent(MouseEvent.MOUSE_DRAGGED, dragX, dragY);
    final MouseEvent released = createMouseEvent(MouseEvent.MOUSE_RELEASED, dragX, dragY);

    Event.fireEvent(node, pressed);
    Event.fireEvent(node, dragged);
    Event.fireEvent(node, released);
}
 
Example 7
Source File: DefaultNodeSkin.java    From graph-editor with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public Point2D getConnectorPosition(final GConnectorSkin connectorSkin) {

    final Node connectorRoot = connectorSkin.getRoot();

    final Side side = DefaultConnectorTypes.getSide(connectorSkin.getConnector().getType());

    // The following logic is required because the connectors are offset slightly from the node edges.
    final double x, y;
    if (side.equals(Side.LEFT)) {
        x = 0;
        y = connectorRoot.getLayoutY() + connectorSkin.getHeight() / 2;
    } else if (side.equals(Side.RIGHT)) {
        x = getRoot().getWidth();
        y = connectorRoot.getLayoutY() + connectorSkin.getHeight() / 2;
    } else if (side.equals(Side.TOP)) {
        x = connectorRoot.getLayoutX() + connectorSkin.getWidth() / 2;
        y = 0;
    } else {
        x = connectorRoot.getLayoutX() + connectorSkin.getWidth() / 2;
        y = getRoot().getHeight();
    }

    return new Point2D(x, y);
}
 
Example 8
Source File: TitledNodeSkin.java    From graph-editor with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Point2D getConnectorPosition(final GConnectorSkin connectorSkin) {

    final Node connectorRoot = connectorSkin.getRoot();

    final double x = connectorRoot.getLayoutX() + connectorSkin.getWidth() / 2;
    final double y = connectorRoot.getLayoutY() + connectorSkin.getHeight() / 2;

    if (inputConnectorSkins.contains(connectorSkin)) {
        return new Point2D(x, y);
    } else {
        // Subtract 1 to align start-of-connection correctly. Compensation for rounding errors?
        return new Point2D(x - 1, y);
    }
}
 
Example 9
Source File: XYChartUtils.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
public static double getLocationX(final Node node) {
    return node.getLayoutX() + node.getTranslateX();
}
 
Example 10
Source File: JFXNodesList.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
@Override
protected void layoutChildren() {
    performingLayout = true;

    List<Node> children = getChildren();

    Insets insets = getInsets();
    double width = getWidth();
    double rotate = getRotate();
    double height = getHeight();
    double left = snapSpace(insets.getLeft());
    double right = snapSpace(insets.getRight());
    double space = snapSpace(getSpacing());
    boolean isFillWidth = isFillWidth();
    double contentWidth = width - left - right;


    Pos alignment = getAlignment();
    alignment = alignment == null ? Pos.TOP_CENTER : alignment;
    final HPos hpos = alignment.getHpos();
    final VPos vpos = alignment.getVpos();

    double y = 0;

    for (int i = 0, size = children.size(); i < size; i++) {
        Node child = children.get(i);
        child.autosize();
        child.setRotate(rotate % 180 == 0 ? rotate : -rotate);

        // init child node if not added using addAnimatedChild method
        if (!animationsMap.containsKey(child)) {
            if (child instanceof JFXNodesList) {
                StackPane container = new StackPane(child);
                container.setPickOnBounds(false);
                getChildren().set(i, container);
            }
            initChild(child, i, null, true);
        }

        double x = 0;
        double childWidth = child.getLayoutBounds().getWidth();
        double childHeight = child.getLayoutBounds().getHeight();


        if(childWidth > width){
            switch (hpos) {
                case CENTER:
                    x = snapPosition(contentWidth - childWidth) / 2;
                    break;
            }
            Node alignToChild = getAlignNodeToChild(child);
            if (alignToChild != null && child instanceof Parent) {
                ((Parent) child).layout();
                double alignedWidth = alignToChild.getLayoutBounds().getWidth();
                double alignedX = alignToChild.getLayoutX();
                if(childWidth / 2 > alignedX + alignedWidth){
                    alignedWidth = -(childWidth / 2 - (alignedWidth/2 + alignedX));
                }else{
                    alignedWidth = alignedWidth/2 + alignedX - childWidth / 2;
                }
                child.setTranslateX(-alignedWidth * Math.cos(Math.toRadians(rotate)));
                child.setTranslateY(alignedWidth * Math.cos(Math.toRadians(90 - rotate)));
            }
        }else{
            childWidth = contentWidth;
        }

        final Insets margin = getMargin(child);
        if (margin != null) {
            childWidth += margin.getLeft() + margin.getRight();
            childHeight += margin.getTop() + margin.getRight();
        }

        layoutInArea(child, x, y, childWidth, childHeight,
            /* baseline shouldn't matter */0,
            margin, isFillWidth, true, hpos, vpos);

        y += child.getLayoutBounds().getHeight() + space;
        if (margin != null) {
            y += margin.getTop() + margin.getBottom();
        }
        y = snapPosition(y);
    }

    performingLayout = false;
}
 
Example 11
Source File: OrientationHelper.java    From Flowless with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public double layoutY(Node node) {
    return node.getLayoutX();
}
 
Example 12
Source File: OrientationHelper.java    From Flowless with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public double layoutX(Node node) {
    return node.getLayoutX();
}
 
Example 13
Source File: TreeNodeSkin.java    From graph-editor with Eclipse Public License 1.0 3 votes vote down vote up
@Override
public Point2D getConnectorPosition(final GConnectorSkin connectorSkin) {

    final Node connectorRoot = connectorSkin.getRoot();

    final double x = connectorRoot.getLayoutX() + connectorSkin.getWidth() / 2;
    final double y = connectorRoot.getLayoutY() + connectorSkin.getHeight() / 2;

    return new Point2D(x, y);
}