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

The following examples show how to use javafx.scene.Node#setLayoutY() . 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: DragResizerUtil.java    From chart-fx with Apache License 2.0 6 votes vote down vote up
protected void setNodeSize(final Node node, final double x, final double y, final double width, final double height) {
    node.setLayoutX(x);
    node.setLayoutY(y);
    // TODO find generic way to set width and height of any node
    // here we cannot set height and width to node directly.

    if (node instanceof Canvas) {
        ((Canvas) node).setWidth(width);
        ((Canvas) node).setHeight(height);
    } else if (node instanceof Rectangle) {
        ((Rectangle) node).setWidth(width);
        ((Rectangle) node).setHeight(height);
    } else if (node instanceof Region) {
        ((Region) node).setPrefWidth(width);
        ((Region) node).setPrefHeight(height);
    }
}
 
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: 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 4
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 5
Source File: WhitespaceOverlayFactory.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
void layoutOverlayNodes(int paragraphIndex, List<Node> nodes) {
	Insets insets = getInsets();
	double leftInsets = insets.getLeft();
	double topInsets = insets.getTop();

	// all paragraphs except last one have line separators
	boolean showEOL = (paragraphIndex < getTextArea().getParagraphs().size() - 1);
	Node eolNode = nodes.get(nodes.size() - 1);
	if (eolNode.isVisible() != showEOL)
		eolNode.setVisible(showEOL);

	for (Node node : nodes) {
		Range range = (Range) node.getUserData();
		Rectangle2D bounds = getBounds(range.start, range.end);
		node.setLayoutX(leftInsets + (node == eolNode ? bounds.getMaxX() : bounds.getMinX()));
		node.setLayoutY(topInsets + bounds.getMinY());
	}
}
 
Example 6
Source File: TargetEditorController.java    From ShootOFF with GNU General Public License v3.0 6 votes vote down vote up
@FXML
public void mouseMoved(MouseEvent event) {
	if (freeformButton.isSelected()) {
		drawTempPolygonEdge(event);
	}

	if (!cursorRegion.isPresent() || cursorButton.isSelected()) return;

	final Node selected = cursorRegion.get();

	lastMouseX = event.getX() - (selected.getLayoutBounds().getWidth() / 2);
	lastMouseY = event.getY() - (selected.getLayoutBounds().getHeight() / 2);

	if (lastMouseX < 0) lastMouseX = 0;
	if (lastMouseY < 0) lastMouseY = 0;

	if (event.getX() + (selected.getLayoutBounds().getWidth() / 2) <= canvasPane.getWidth())
		selected.setLayoutX(lastMouseX - selected.getLayoutBounds().getMinX());

	if (event.getY() + (selected.getLayoutBounds().getHeight() / 2) <= canvasPane.getHeight())
		selected.setLayoutY(lastMouseY - selected.getLayoutBounds().getMinY());

	event.consume();
}
 
Example 7
Source File: Undecorator.java    From DevToolBox with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
     * Set the layout of different layers of the stage
     */
    @Override
    public void layoutChildren() {
        Bounds b = super.getLayoutBounds();
        double w = b.getWidth();
        double h = b.getHeight();
        ObservableList<Node> list = super.getChildren();
//        ROUNDED_DELTA=shadowRectangle.getArcWidth()/4;
        ROUNDED_DELTA = 0;
        for (Node node : list) {
            if (node == shadowRectangle) {
                shadowRectangle.setWidth(w - SHADOW_WIDTH * 2);
                shadowRectangle.setHeight(h - SHADOW_WIDTH * 2);
                shadowRectangle.setX(SHADOW_WIDTH);
                shadowRectangle.setY(SHADOW_WIDTH);
            } else if (node == backgroundRect) {
                backgroundRect.setWidth(w - SHADOW_WIDTH * 2);
                backgroundRect.setHeight(h - SHADOW_WIDTH * 2);
                backgroundRect.setX(SHADOW_WIDTH);
                backgroundRect.setY(SHADOW_WIDTH);
            } else if (node == stageDecoration) {
                stageDecoration.resize(w - SHADOW_WIDTH * 2 - ROUNDED_DELTA * 2, h - SHADOW_WIDTH * 2 - ROUNDED_DELTA * 2);
                stageDecoration.setLayoutX(SHADOW_WIDTH + ROUNDED_DELTA);
                stageDecoration.setLayoutY(SHADOW_WIDTH + ROUNDED_DELTA);
            } //            else if (node == resizeRect) {
            //                resizeRect.setWidth(w - SHADOW_WIDTH * 2);
            //                resizeRect.setHeight(h - SHADOW_WIDTH * 2);
            //                resizeRect.setLayoutX(SHADOW_WIDTH);
            //                resizeRect.setLayoutY(SHADOW_WIDTH);
            //            }
            else {
                node.resize(w - SHADOW_WIDTH * 2 - ROUNDED_DELTA * 2, h - SHADOW_WIDTH * 2 - ROUNDED_DELTA * 2);
                node.setLayoutX(SHADOW_WIDTH + ROUNDED_DELTA);
                node.setLayoutY(SHADOW_WIDTH + ROUNDED_DELTA);
//                node.resize(w - SHADOW_WIDTH * 2 - RESIZE_PADDING * 2, h - SHADOW_WIDTH * 2 - RESIZE_PADDING * 2);
//                node.setLayoutX(SHADOW_WIDTH + RESIZE_PADDING);
//                node.setLayoutY(SHADOW_WIDTH + RESIZE_PADDING);
            }
        }
    }
 
Example 8
Source File: FxmlControl.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static void moveYCenter(Region pNnode, Node node) {
    if (node == null || pNnode == null) {
        return;
    }
    double yOffset = pNnode.getHeight() - node.getBoundsInLocal().getHeight();
    if (yOffset > 0) {
        node.setLayoutY(pNnode.getLayoutY() + yOffset / 2);
    }
}
 
Example 9
Source File: FxmlControl.java    From MyBox with Apache License 2.0 5 votes vote down vote up
public static void moveYCenter(Node node) {
    if (node == null || node.getParent() == null) {
        return;
    }
    double yOffset = node.getParent().getBoundsInLocal().getHeight() - node.getBoundsInLocal().getHeight();
    if (yOffset > 0) {
        node.setLayoutY(yOffset / 2);
    }
}
 
Example 10
Source File: OverlayStage.java    From DeskChan with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void relocate(Node node, double x, double y){
	node.setLayoutX(x - this.getX());
	node.setLayoutY(y - this.getY());
}
 
Example 11
Source File: TargetEditorController.java    From ShootOFF with GNU General Public License v3.0 4 votes vote down vote up
public void regionKeyPressed(KeyEvent event) {
	final Node selected = (Node) event.getTarget();
	final TargetRegion region = (TargetRegion) selected;

	switch (event.getCode()) {
	case DELETE:
	case BACK_SPACE:
		targetRegions.remove(selected);
		canvasPane.getChildren().remove(selected);
		toggleShapeControls(false);
		if (tagEditor.isPresent()) {
			tagsButton.setSelected(false);
			toggleTagEditor();
		}
		break;

	case LEFT:
		if (event.isShiftDown()) {
			region.changeWidth(SCALE_DELTA * -1);
		} else {
			selected.setLayoutX(selected.getLayoutX() - MOVEMENT_DELTA);
		}
		break;

	case RIGHT:
		if (event.isShiftDown()) {
			region.changeWidth(SCALE_DELTA);
		} else {
			selected.setLayoutX(selected.getLayoutX() + MOVEMENT_DELTA);
		}
		break;

	case UP:
		if (event.isShiftDown()) {
			region.changeHeight(SCALE_DELTA * -1);
		} else {
			selected.setLayoutY(selected.getLayoutY() - MOVEMENT_DELTA);
		}
		break;

	case DOWN:
		if (event.isShiftDown()) {
			region.changeHeight(SCALE_DELTA);
		} else {
			selected.setLayoutY(selected.getLayoutY() + MOVEMENT_DELTA);
		}
		break;

	default:
		break;
	}

	event.consume();
}