Java Code Examples for javafx.scene.Parent#getChildrenUnmodifiable()

The following examples show how to use javafx.scene.Parent#getChildrenUnmodifiable() . 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: ResizeListener.java    From Path-of-Leveling with MIT License 6 votes vote down vote up
private void addListenerDeeply(Node node) {
    node.addEventHandler(MouseEvent.MOUSE_MOVED, this);
    node.addEventHandler(MouseEvent.MOUSE_PRESSED, this);
    node.addEventHandler(MouseEvent.MOUSE_DRAGGED, this);
    node.addEventHandler(MouseEvent.MOUSE_ENTERED, this);
    node.addEventHandler(MouseEvent.MOUSE_ENTERED_TARGET, this);
    node.addEventHandler(MouseEvent.MOUSE_EXITED, this);
    node.addEventHandler(MouseEvent.MOUSE_EXITED_TARGET, this);
    if (node instanceof Parent) {
        Parent parent = (Parent) node;
        ObservableList<Node> children = parent.getChildrenUnmodifiable();
        for (Node child : children) {
            addListenerDeeply(child);
        }
    }
}
 
Example 2
Source File: GeneralSiblingSelector.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private int getIndexOfComponentInParent(Node component) {
    Parent parent = component.getParent();
    if (parent == null) {
        return -1;
    }
    ObservableList<Node> components = parent.getChildrenUnmodifiable();
    for (int i = 0; i < components.size(); i++) {
        if (components.get(i) == component) {
            return i;
        }
    }
    return -1;
}
 
Example 3
Source File: StyledTextField.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private Node traverse( Parent p, Node from, int dir )
{
    if ( p == null ) return null;

    List<Node> nodeList = p.getChildrenUnmodifiable();
    int len = nodeList.size();
    int neighbor = -1;
    
    if ( from != null ) while ( ++neighbor < len && nodeList.get(neighbor) != from );
    else if ( dir == 1 ) neighbor = -1;
    else neighbor = len;
    
    for ( neighbor += dir; neighbor > -1 && neighbor < len; neighbor += dir ) {

        Node target = nodeList.get( neighbor );

        if ( target instanceof Pane || target instanceof Group ) {
            target = traverse( (Parent) target, null, dir ); // down
            if ( target != null ) return target;
        }
        else if ( target.isVisible() && ! target.isDisabled() && target.isFocusTraversable() ) {
            target.requestFocus();
            return target;
        }
    }

    return traverse( p.getParent(), p, dir ); // up
}
 
Example 4
Source File: Util.java    From ResponsiveFX with Apache License 2.0 5 votes vote down vote up
public static List<Node> getAllNodesInParent(Parent parent) {
    List<Node> ret = new ArrayList<>();
    for (Node child : parent.getChildrenUnmodifiable()) {
        ret.add(child);
        if (child instanceof Parent) {
            ret.addAll(getAllNodesInParent((Parent) child));
        }
    }
    return ret;
}
 
Example 5
Source File: ResizeHelper.java    From JavaFX-Chat with GNU General Public License v3.0 5 votes vote down vote up
public static void addListenerDeeply(Node node, EventHandler<MouseEvent> listener) {
    node.addEventHandler(MouseEvent.MOUSE_MOVED, listener);
    node.addEventHandler(MouseEvent.MOUSE_PRESSED, listener);
    node.addEventHandler(MouseEvent.MOUSE_DRAGGED, listener);
    node.addEventHandler(MouseEvent.MOUSE_EXITED, listener);
    node.addEventHandler(MouseEvent.MOUSE_EXITED_TARGET, listener);
    if (node instanceof Parent) {
        Parent parent = (Parent) node;
        ObservableList<Node> children = parent.getChildrenUnmodifiable();
        for (Node child : children) {
            addListenerDeeply(child, listener);
        }
    }
}
 
Example 6
Source File: DotHTMLNodePart.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
private Parent findFxPaneWithText(Parent group, javafx.scene.Node text) {
	for (javafx.scene.Node node : group.getChildrenUnmodifiable()) {
		if (node == text) {
			return group;
		} else if (node instanceof Parent) {
			Parent possibleParent = findFxPaneWithText((Parent) node, text);
			if (possibleParent != null) {
				return possibleParent;
			}
		}
	}
	return null;
}
 
Example 7
Source File: ViewUtils.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
/**
 * 反射注入字段值
 *
 * @param parent
 * @param controller
 */
public static void injectFields(Parent parent, Object controller){
    Class<?> controllerClass = controller.getClass();
    // injectFields
    for(Node node : parent.getChildrenUnmodifiable()){
        if(node.getId() != null){
            ReflectUtils.setFieldValue(controllerClass,controller,node.getId(),node);
        }
        if(node instanceof Parent){
            injectFields((Parent) node, controller);
        }
    }
}
 
Example 8
Source File: ResizeHelper.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
public static void addListenerDeeply(Node node, EventHandler<MouseEvent> listener) {
    node.addEventHandler(MouseEvent.MOUSE_MOVED, listener);
    node.addEventHandler(MouseEvent.MOUSE_PRESSED, listener);
    node.addEventHandler(MouseEvent.MOUSE_DRAGGED, listener);
    if (node instanceof Parent) {
        Parent parent = (Parent) node;
        ObservableList<Node> children = parent.getChildrenUnmodifiable();
        for (Node child : children) {
            addListenerDeeply(child, listener);
        }
    }
}
 
Example 9
Source File: Controller.java    From scan with GNU General Public License v3.0 5 votes vote down vote up
@FXML
private void clear(MouseEvent event) {
    Label label = (Label) event.getSource();
    Parent parent = label.getParent().getParent();
    ObservableList<Node> childrenUnmodifiable = parent.getChildrenUnmodifiable();
    for (Node node : childrenUnmodifiable) {
        if (node instanceof ListView) {
            ((ListView) node).getItems().clear();
        }
    }
}
 
Example 10
Source File: GeneralSiblingSelector.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
protected List<IJavaFXElement> found(List<IJavaFXElement> pElements, IJavaFXAgent driver) {
    List<IJavaFXElement> r = new ArrayList<IJavaFXElement>();
    for (IJavaFXElement je : pElements) {
        Node component = je.getComponent();
        if (!(component instanceof Parent)) {
            continue;
        }
        int index = getIndexOfComponentInParent(component);
        if (index < 0) {
            continue;
        }
        Parent parent = component.getParent();
        JFXWindow topContainer = driver.switchTo().getTopContainer();
        ObservableList<Node> children = parent.getChildrenUnmodifiable();
        for (int i = index + 1; i < children.size(); i++) {
            Node c = children.get(i);
            IJavaFXElement je2 = JavaFXElementFactory.createElement(c, driver, driver.switchTo().getTopContainer());
            if (sibling.matchesSelector(je2).size() > 0) {
                IJavaFXElement e = topContainer.addElement(JavaFXElementFactory.createElement(c, driver, topContainer));
                if (!r.contains(e)) {
                    r.add(e);
                }
            }
        }
    }
    return r;
}
 
Example 11
Source File: AdjacentSiblingSelector.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private int getIndexOfComponentInParent(Node component) {
    Parent parent = component.getParent();
    if (parent == null) {
        return -1;
    }
    ObservableList<Node> components = parent.getChildrenUnmodifiable();
    for (int i = 0; i < components.size(); i++) {
        if (components.get(i) == component) {
            return i;
        }
    }
    return -1;
}
 
Example 12
Source File: ResizeHelper.java    From CustomStage with Apache License 2.0 5 votes vote down vote up
private static void addListenerDeeply(Node node, EventHandler<MouseEvent> listener) {
    node.addEventHandler(MouseEvent.MOUSE_MOVED, listener);
    node.addEventHandler(MouseEvent.MOUSE_PRESSED, listener);
    node.addEventHandler(MouseEvent.MOUSE_DRAGGED, listener);
    node.addEventHandler(MouseEvent.MOUSE_EXITED, listener);
    node.addEventHandler(MouseEvent.MOUSE_EXITED_TARGET, listener);
    if (node instanceof Parent) {
        Parent parent = (Parent) node;
        ObservableList<Node> children = parent.getChildrenUnmodifiable();
        for (Node child : children) {
            addListenerDeeply(child, listener);
        }
    }
}
 
Example 13
Source File: LayoutHelpers.java    From houdoku with MIT License 5 votes vote down vote up
/**
 * Set whether all Button children of the given Parent are visible.
 *
 * @param parent  the parent node
 * @param visible whether the buttons should be visible
 */
public static void setChildButtonVisible(Parent parent, boolean visible) {
    for (Node child : parent.getChildrenUnmodifiable()) {
        if (child instanceof Button) {
            Button button = (Button) child;
            button.setVisible(visible);
            button.setManaged(visible);
        } else if (child instanceof Parent) {
            setChildButtonVisible((Parent) child, visible);
        }
    }
}
 
Example 14
Source File: ResizeHelper.java    From Path-of-Leveling with MIT License 5 votes vote down vote up
private static void addListenerDeeply(Node node, EventHandler<MouseEvent> listener) {
    node.addEventHandler(MouseEvent.MOUSE_MOVED, listener);
    node.addEventHandler(MouseEvent.MOUSE_PRESSED, listener);
    node.addEventHandler(MouseEvent.MOUSE_DRAGGED, listener);
    node.addEventHandler(MouseEvent.MOUSE_EXITED, listener);
    node.addEventHandler(MouseEvent.MOUSE_EXITED_TARGET, listener);
    if (node instanceof Parent) {
        Parent parent = (Parent) node;
        ObservableList<Node> children = parent.getChildrenUnmodifiable();
        for (Node child : children) {
            addListenerDeeply(child, listener);
        }
    }
}
 
Example 15
Source File: XYChartUtils.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
public static List<Label> getChildLabels(final List<? extends Parent> parents) {
    final List<Label> labels = new LinkedList<>();
    for (final Parent parent : parents) {
        for (final Node node : parent.getChildrenUnmodifiable()) {
            if (node instanceof Label) {
                labels.add((Label) node);
            }
        }
    }
    return labels;
}
 
Example 16
Source File: DockTitleBar.java    From DockFX with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Traverse the scene graph for all open stages and pick an event target for a dock event based on
 * the location. Once the event target is chosen run the event task with the target and the
 * previous target of the last dock event if one is cached. If an event target is not found fire
 * the explicit dock event on the stage root if one is provided.
 * 
 * @param location The location of the dock event in screen coordinates.
 * @param eventTask The event task to be run when the event target is found.
 * @param explicit The explicit event to be fired on the stage root when no event target is found.
 */
private void pickEventTarget(Point2D location, EventTask eventTask, Event explicit) {
  // RFE for public scene graph traversal API filed but closed:
  // https://bugs.openjdk.java.net/browse/JDK-8133331

  List<DockPane> dockPanes = DockPane.dockPanes;

  // fire the dock over event for the active stages
  for (DockPane dockPane : dockPanes) {
    Window window = dockPane.getScene().getWindow();
    if (!(window instanceof Stage)) continue;
    Stage targetStage = (Stage) window;

    // obviously this title bar does not need to receive its own events
    // though users of this library may want to know when their
    // dock node is being dragged by subclassing it or attaching
    // an event listener in which case a new event can be defined or
    // this continue behavior can be removed
    if (targetStage == this.dockNode.getStage())
      continue;

    eventTask.reset();

    Node dragNode = dragNodes.get(targetStage);

    Parent root = targetStage.getScene().getRoot();
    Stack<Parent> stack = new Stack<Parent>();
    if (root.contains(root.screenToLocal(location.getX(), location.getY()))
        && !root.isMouseTransparent()) {
      stack.push(root);
    }
    // depth first traversal to find the deepest node or parent with no children
    // that intersects the point of interest
    while (!stack.isEmpty()) {
      Parent parent = stack.pop();
      // if this parent contains the mouse click in screen coordinates in its local bounds
      // then traverse its children
      boolean notFired = true;
      for (Node node : parent.getChildrenUnmodifiable()) {
        if (node.contains(node.screenToLocal(location.getX(), location.getY()))
            && !node.isMouseTransparent()) {
          if (node instanceof Parent) {
            stack.push((Parent) node);
          } else {
            eventTask.run(node, dragNode);
          }
          notFired = false;
          break;
        }
      }
      // if none of the children fired the event or there were no children
      // fire it with the parent as the target to receive the event
      if (notFired) {
        eventTask.run(parent, dragNode);
      }
    }

    if (explicit != null && dragNode != null && eventTask.getExecutions() < 1) {
      Event.fireEvent(dragNode, explicit.copyFor(this, dragNode));
      dragNodes.put(targetStage, null);
    }
  }
}
 
Example 17
Source File: MainViewController.java    From examples-javafx-repos1 with Apache License 2.0 4 votes vote down vote up
private void applySecurity(Scene s, UserSecurity security, Node n) {

        if( n == null ) return;

        if( n.getProperties().containsKey(NodePropertiesKeyType.commandType) ) {

            //
            // This is a Node that should have security applied
            //
            CommandType command = (CommandType) n.getProperties().get(NodePropertiesKeyType.commandType );
            AccessType access = security.getAccess(command);

            if( log.isDebugEnabled() ) {
                log.debug("[APPLY] command={}, access={}", command, access);
            }

            switch( security.getAccess(command) ) {

                case SHOW:
                    n.setVisible(true);
                    n.setDisable(false);
                    n.setManaged(true);
                    break;
                case HIDE:
                    n.setVisible(false);
                    n.setDisable(true);
                    n.setManaged(false);
                    break;
                case DISABLE:
                    n.setVisible(true);
                    n.setDisable(true);
                    n.setManaged(true);
                    break;
            }
        }

        //
        // Menus and MenuItems are not Nodes
        //
        if( n instanceof MenuBar ) {
            MenuBar mb = (MenuBar)n;
            for( Menu toplevel : mb.getMenus() ) {
                applySecurity( s, security, toplevel );
            }
        }

        if( n instanceof Parent) {
            Parent p = (Parent)n;
            for( Node childNode : p.getChildrenUnmodifiable() ) {
                applySecurity( s, security, childNode );
            }
            p.layout();
        }
    }