Java Code Examples for javafx.scene.layout.Pane#getChildren()

The following examples show how to use javafx.scene.layout.Pane#getChildren() . 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: JavaFxGazeUtils.java    From tet-java-client with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Utility method that deregisters all types of TETListeners for parameter View and its children
 *
 * @param n
 */
public static void detachTETListenersRecursive(Node n)
{
    Pane p;
    if(n instanceof Pane)
    {
        p = ((Pane)n);
        detachTETListeners(p);

        ObservableList<Node> children = p.getChildren();
        for(int i=0; i<children.size(); ++i)
        {
            Node nextChild = children.get(i);

            if(nextChild instanceof Pane)
                detachTETListenersRecursive(nextChild);
            else
                detachTETListeners(nextChild);
        }
    }
    else
    {
        detachTETListeners(n);
    }
}
 
Example 2
Source File: Palette.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** De-select buttons
 *  @param keep The one button to keep (or <code>null</code>)
 */
private void deselectButtons(final ToggleButton keep)
{
    // De-select all buttons
    for (Pane pane : groups)
        for (Node other : pane.getChildren())
            if (other instanceof ToggleButton  &&
                other != keep)
                ((ToggleButton)other).setSelected(false);
}
 
Example 3
Source File: UiUtils.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Clear children of a pane.
 *
 * @param pane the pane.
 */
@FxThread
public static void clear(@NotNull final Pane pane) {
    final ObservableList<Node> children = pane.getChildren();
    children.forEach(UiUtils::unbind);
    children.clear();
}
 
Example 4
Source File: TemplateBox.java    From DeskChan with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void printHTML(Pane node, int indent){
	if (node == null) return;

	String _indent = "";
	for (int i=0; i<indent; i++) _indent += "  ";

	String itemClass = getClassName(node);
	switch (itemClass){
		case "grid-pane": {
			System.out.println(_indent + "<table realclass=\"GridPane\"" + (node.getId() != null ? (" id=\"" + node.getId() + "\"") : "") + ">");
			GridPane grid = (GridPane) node;
			int w=0,h=0;
			for (Node item : grid.getChildren()) {
				Integer index = GridPane.getRowIndex(item);
				if (index != null) h = Math.max(h, index + 1);
				index = GridPane.getColumnIndex(item);
				if (index != null) w = Math.max(w, index + 1);
			}
			for (int i=0; i<h; i++) {
				System.out.println(_indent+" <tr>");
				for (int j=0; j<w; j++) {
					Node cell = getNodeFromGridPane(grid, i, j);
					System.out.println(_indent+"  <td>");
					printHTML(cell, indent + 2);
					System.out.println(_indent+"  </td>");
				}
				System.out.println(_indent+"</tr>");
			}
			System.out.println(_indent + "</table>");
		} break;
		default: {
			String c = node.getClass().getSimpleName();
			System.out.println(_indent + "<" + c + (node.getId() != null ? (" id=\"" + node.getId() + "\"") : "") + " class=\"" + itemClass + "\">");
			for (Node child : node.getChildren())
				printHTML(child, indent + 1);
			System.out.println(_indent + "</"+c+">");
		} break;
	}
}
 
Example 5
Source File: NodeHelper.java    From tornadofx-controls with Apache License 2.0 5 votes vote down vote up
public static <T> List<T> findChildrenOfType(Pane parent, Class<T> type) {
    List<T> elements = new ArrayList<>();
    for (Node node : parent.getChildren()) {
        if (type.isAssignableFrom(node.getClass())) {
            elements.add((T) node);
        } else if (node instanceof Pane) {
            elements.addAll(findChildrenOfType((Pane) node, type));
        }
    }
    return Collections.unmodifiableList(elements);
}
 
Example 6
Source File: JavaFxGazeUtils.java    From tet-java-client with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static void checkGazeCollisionRecursive(Node n, Point2D gaze, List<Node> result)
{
    if(null == n || null == gaze || null == result)
        return;

    Pane p;
    Rectangle roi = new Rectangle();
    if(n instanceof Pane)
    {
        p = ((Pane)n);

        if(!p.isDisabled() && checkViewCollision(p, gaze, roi))
            result.add(p);

        ObservableList<Node> children = p.getChildren();
        for(int i=0; i<children.size(); ++i)
        {
            Node nextChild = children.get(i);

            if(nextChild instanceof Pane)
                checkGazeCollisionRecursive(nextChild, gaze, result);
            else if(checkViewCollision(nextChild, gaze, roi))
                result.add(nextChild);
        }
    }
    else
    {
        if(checkViewCollision(n, gaze, roi))
            result.add(n);
    }
}
 
Example 7
Source File: JavaFxGazeUtils.java    From tet-java-client with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Utility method that registers all types of TETListeners for parameter View and its children
 *
 * @param n
 * @param checkVisibility
 */
public static void attachTETListenersRecursive(Node n, boolean checkVisibility)
{
    Pane p;
    if(n instanceof Pane)
    {
        p = ((Pane)n);

        if(!checkVisibility || (checkVisibility && p.isVisible()))
            attachTETListeners(p);

        ObservableList<Node> children = p.getChildren();
        for(int i=0; i<children.size(); ++i)
        {
            Node nextChild = children.get(i);

            if(!checkVisibility || (checkVisibility && nextChild.isVisible()))
            {
                if(nextChild instanceof Pane)
                    attachTETListenersRecursive(nextChild, checkVisibility);
                else
                    attachTETListeners(nextChild);
            }
        }
    }
    else
    {
        if(!checkVisibility || (checkVisibility && n.isVisible()))
            attachTETListeners(n);
    }
}
 
Example 8
Source File: ZoneView.java    From Cardshifter with Apache License 2.0 5 votes vote down vote up
public void highlightCard(int cardId) {
	Pane pane = this.getPane(cardId).getRootPane();
	List<Node> children = pane.getChildren();
	for (Node node : children) {
		if (node.getId().equals("backgroundRectangle")) {
			Rectangle rectangle = (Rectangle)node;
			rectangle.setFill(Color.YELLOW);
		}
	}
}
 
Example 9
Source File: JFXUtil.java    From jfxutils with Apache License 2.0 5 votes vote down vote up
/**
 * Make a best attempt to replace the original component with the replacement, and keep the same
 * position and layout constraints in the container.
 * <p>
 * Currently this method is probably not perfect. It uses three strategies:
 * <ol>
 *   <li>If the original has any properties, move all of them to the replacement</li>
 *   <li>If the parent of the original is a {@link BorderPane}, preserve the position</li>
 *   <li>Preserve the order of the children in the parent's list</li>
 * </ol>
 * <p>
 * This method does not transfer any handlers (mouse handlers for example).
 *
 * @param original    non-null Node whose parent is a {@link Pane}.
 * @param replacement non-null Replacement Node
 */
public static void replaceComponent( Node original, Node replacement ) {
	Pane parent = (Pane) original.getParent();
	//transfer any properties (usually constraints)
	replacement.getProperties().putAll( original.getProperties() );
	original.getProperties().clear();

	ObservableList<Node> children = parent.getChildren();
	int originalIndex = children.indexOf( original );
	if ( parent instanceof BorderPane ) {
		BorderPane borderPane = (BorderPane) parent;
		if ( borderPane.getTop() == original ) {
			children.remove( original );
			borderPane.setTop( replacement );

		} else if ( borderPane.getLeft() == original ) {
			children.remove( original );
			borderPane.setLeft( replacement );

		} else if ( borderPane.getCenter() == original ) {
			children.remove( original );
			borderPane.setCenter( replacement );

		} else if ( borderPane.getRight() == original ) {
			children.remove( original );
			borderPane.setRight( replacement );

		} else if ( borderPane.getBottom() == original ) {
			children.remove( original );
			borderPane.setBottom( replacement );
		}
	} else {
		//Hope that preserving the properties and position in the list is sufficient
		children.set( originalIndex, replacement );
	}
}