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

The following examples show how to use javafx.scene.Node#getParent() . 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: LabelSourceStatePaintHandler.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public EventHandler<Event> viewerHandler(final PainteraBaseView paintera, final KeyTracker keyTracker) {
	return event -> {
		final EventTarget target = event.getTarget();
		if (!(target instanceof Node))
			return;
		Node node = (Node) target;
		LOG.trace("Handling event {} in target {}", event, target);
		// kind of hacky way to accomplish this:
		while (node != null) {
			if (node instanceof ViewerPanelFX) {
				handlers.computeIfAbsent((ViewerPanelFX) node, k -> this.makeHandler(paintera, keyTracker, k)).handle(event);
				return;
			}
			node = node.getParent();
		}
	};
}
 
Example 2
Source File: Hand.java    From latexdraw with GNU General Public License v3.0 6 votes vote down vote up
/**
 * A tricky workaround to get the real plot view hidden behind its content views (Bezier curve, dots, etc.).
 * If the view has a ViewPlot as its user data, this view plot is returned. The source view is returned otherwise.
 * setMouseTransparency cannot be used since the mouse over would not work anymore.
 * @param view The view to check. Cannot be null.
 * @return The given view or the plot view.
 */
private static ViewShape<?> getRealViewShape(final ViewShape<?> view) {
	if(view == null) {
		return null;
	}

	// Checking whether the shape is not part of another shape
	ViewShape<?> currView = view;

	while(currView.getUserData() instanceof ViewShape) {
		currView = (ViewShape<?>) currView.getUserData();
	}

	// Checking whether the shape is not part of a group
	Node parent = currView;
	while(parent.getParent() != null && !(parent.getParent() instanceof ViewGroup)) {
		parent = parent.getParent();
	}

	if(parent.getParent() instanceof ViewGroup) {
		return (ViewShape<?>) parent.getParent();
	}

	return currView;
}
 
Example 3
Source File: JFXTreeTableCellSkin.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
private void updateDisclosureNode() {
    Node disclosureNode = ((JFXTreeTableCell<S, T>) getSkinnable()).getDisclosureNode();
    if (disclosureNode != null) {
        TreeItem<S> item = getSkinnable().getTreeTableRow().getTreeItem();
        final S value = item == null ? null : item.getValue();
        boolean disclosureVisible = value != null
                                    && !item.isLeaf()
                                    && value instanceof RecursiveTreeObject
                                    && ((RecursiveTreeObject) value).getGroupedColumn() == getSkinnable().getTableColumn();
        disclosureNode.setVisible(disclosureVisible);
        if (!disclosureVisible) {
            getChildren().remove(disclosureNode);
        } else if (disclosureNode.getParent() == null) {
            getChildren().add(disclosureNode);
            disclosureNode.toFront();
        } else {
            disclosureNode.toBack();
        }
        if (disclosureNode.getScene() != null) {
            disclosureNode.applyCss();
        }
    }
}
 
Example 4
Source File: FocusUtil.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** @param node Node from which to remove focus */
public static void removeFocus(Node node)
{
    // Cannot un-focus, can only focus on _other_ node.
    // --> Find the uppermost node and focus on that.
    Node parent = node.getParent();
    if (parent == null)
        return;
    while (parent.getParent() != null)
        parent = parent.getParent();
    parent.requestFocus();
}
 
Example 5
Source File: LogViewPane.java    From LogFX with GNU General Public License v3.0 5 votes vote down vote up
@MustCallOnJavaFXThread
private Optional<LogViewWrapper> getFocusedView() {
    Node node = pane.getScene().focusOwnerProperty().get();

    // go up in the hierarchy until we find a wrapper, or just hit null
    while ( node != null && !( node instanceof LogViewWrapper ) ) {
        node = node.getParent();
    }

    if ( node != null ) {
        return Optional.of( ( LogViewWrapper ) node );
    } else {
        return Optional.empty();
    }
}
 
Example 6
Source File: IntersectionFinder.java    From graph-editor with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Checks if the given connection is behind this one.
 *
 * @param other another {@link GConnection} instance
 * @return {@code true} if the given connection is behind this one
 */
private boolean checkIfBehind(final GConnection other) {

    final Node node = skinLookup.lookupConnection(connection).getRoot();
    final Node otherNode = skinLookup.lookupConnection(other).getRoot();

    if (node.getParent() == null) {
        return false;
    } else {
        final int connectionIndex = node.getParent().getChildrenUnmodifiable().indexOf(node);
        final int otherIndex = node.getParent().getChildrenUnmodifiable().indexOf(otherNode);

        return otherIndex < connectionIndex;
    }
}
 
Example 7
Source File: AdjacentSiblingSelector.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();
        index += 1;
        if (index < parent.getChildrenUnmodifiable().size()) {
            Node c = parent.getChildrenUnmodifiable().get(index);
            IJavaFXElement je2 = JavaFXElementFactory.createElement(c, driver, driver.switchTo().getTopContainer());
            List<IJavaFXElement> matched = sibling.matchesSelector(je2);
            for (IJavaFXElement javaElement : matched) {
                IJavaFXElement e = topContainer.addElement(javaElement);
                if (!r.contains(e)) {
                    r.add(e);
                }
            }
        }
    }
    return r;
}
 
Example 8
Source File: DesktopPane.java    From desktoppanefx with Apache License 2.0 5 votes vote down vote up
public static InternalWindow resolveInternalWindow(Node node) {
    if (node == null) {
        return null;
    }

    Node candidate = node;
    while (candidate != null) {
        if (candidate instanceof InternalWindow) {
            return (InternalWindow) candidate;
        }
        candidate = candidate.getParent();
    }

    return null;
}
 
Example 9
Source File: InternalWindow.java    From desktoppanefx with Apache License 2.0 5 votes vote down vote up
private static boolean isContainedInHierarchy(Node container, Node node) {
    Node candidate = node;
    do {
        if (candidate == container) {
            return true;
        }
        candidate = candidate.getParent();
    } while (candidate != null);
    return false;
}
 
Example 10
Source File: TabToolComponent.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Handle a click to a tab.
 */
private void processMouseClick(@NotNull final MouseEvent event) {
    final EventTarget target = event.getTarget();
    if (!(target instanceof Node)) return;

    final Node node = (Node) target;

    if (!(node instanceof Text) || node.getStyleClass().contains("tab-container")) {
        return;
    }

    final Parent label = node.getParent();

    if (!(label instanceof Label)) {
        return;
    }

    final Parent tabContainer = label.getParent();

    if (!tabContainer.getStyleClass().contains("tab-container")) {
        return;
    }

    if (isChangingTab()) {
        setChangingTab(false);
        return;
    }

    processExpandOrCollapse();
}
 
Example 11
Source File: ErrorHandling.java    From Recaf with MIT License 5 votes vote down vote up
/**
 * Update error list, hiding it if no errors are found.
 */
protected void toggleErrorDisplay() {
	Node content = errorList;
	while (!(content instanceof SplitPane) && content != null)
		content = content.getParent();
	if (content == null)
		return;
	SplitPane parent = (SplitPane) content;
	if(problems.isEmpty())
		parent.setDividerPositions(1);
	else if(parent.getDividerPositions()[0] > 0.98)
		parent.setDividerPositions(DEFAULT_ERROR_DISPLAY_PERCENT);
}
 
Example 12
Source File: FilterBox.java    From mcaselector with MIT License 5 votes vote down vote up
private boolean isChildOf(Node node) {
	Node parent = getParent();
	while (parent != null) {
		parent = parent.getParent();
		if (parent == node) {
			return true;
		}
	}
	return false;
}
 
Example 13
Source File: JavaFxUtils.java    From milkman with MIT License 5 votes vote down vote up
public static boolean isParent(Parent parent, Node child) {
    if (child == null) {
        return false;
    }
    Parent curr = child.getParent();
    while (curr != null) {
        if (curr == parent) {
            return true;
        }
        curr = curr.getParent();
    }
    return false;
}
 
Example 14
Source File: NodeHelper.java    From tornadofx-controls with Apache License 2.0 5 votes vote down vote up
public static <T> T findParentOfType( Node node, Class<T> type ){
    if( node == null ) return null;
    Parent parent = node.getParent();
    if( parent == null ) return null;
    if( type.isAssignableFrom(parent.getClass()) ) return (T)parent;
    return findParentOfType( parent, type );
}
 
Example 15
Source File: JFXNodesList.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
private static void setConstraint(Node node, Object key, Object value) {
    if (value == null) {
        node.getProperties().remove(key);
    } else {
        node.getProperties().put(key, value);
    }
    if (node.getParent() != null) {
        node.getParent().requestLayout();
    }
}
 
Example 16
Source File: DraggableBox.java    From graph-editor with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets the closest ancestor (e.g. parent, grandparent) to a node that is a subclass of {@link Region}.
 *
 * @param node a JavaFX {@link Node}
 * @return the node's closest ancestor that is a subclass of {@link Region}, or {@code null} if none exists
 */
private Region getContainer(final Node node) {

    final Parent parent = node.getParent();

    if (parent == null) {
        return null;
    } else if (parent instanceof Region) {
        return (Region) parent;
    } else {
        return getContainer(parent);
    }
}
 
Example 17
Source File: SVRemoteNodeAdapter.java    From scenic-view with GNU General Public License v3.0 5 votes vote down vote up
public SVRemoteNodeAdapter(final Node node, final boolean collapseControls, final boolean collapseContentControls, final boolean fillChildren, final SVRemoteNodeAdapter parent) {
    super(ConnectorUtils.nodeClass(node), node.getClass().getName());
    boolean mustBeExpanded = !(node instanceof Control) || !collapseControls;
    if (!mustBeExpanded && !collapseContentControls) {
        mustBeExpanded = node instanceof TabPane || node instanceof SplitPane || node instanceof ScrollPane || node instanceof Accordion || node instanceof TitledPane;
    }
    setExpanded(mustBeExpanded);
    this.id = node.getId();
    this.nodeId = ConnectorUtils.getNodeUniqueID(node);
    this.focused = node.isFocused();
    if (node.getParent() != null && parent == null) {
        this.parent = new SVRemoteNodeAdapter(node.getParent(), collapseControls, collapseContentControls, false, null);
    } else if (parent != null) {
        this.parent = parent;
    }
    /**
     * Check visibility and mouse transparency after calculating the parent
     */
    this.mouseTransparent = node.isMouseTransparent() || (this.parent != null && this.parent.isMouseTransparent());
    this.visible = node.isVisible() && (this.parent == null || this.parent.isVisible());

    /**
     * TODO This should be improved
     */
    if (fillChildren) {
        nodes = ChildrenGetter.getChildren(node)
                  .stream()
                  .map(childNode -> new SVRemoteNodeAdapter(childNode, collapseControls, collapseContentControls, true, this))
                  .collect(Collectors.toList());
    }
}
 
Example 18
Source File: Activity.java    From ApkToolPlus with Apache License 2.0 5 votes vote down vote up
protected void initRootView(Node node){
    Node parent = node.getParent();
    Node notNullParent = node;
    while(parent != null){
        notNullParent = parent;
        parent = parent.getParent();
    }
    mRootView = notNullParent;
}
 
Example 19
Source File: SelectionHandler.java    From LogFX with GNU General Public License v3.0 5 votes vote down vote up
private Node getTargetNode( Object objectTarget ) {
    if ( objectTarget instanceof Node ) {

        Node target = ( Node ) objectTarget;

        // try to go up in the hierarchy until we find a selectable node or the root node
        while ( target != root && !( target instanceof SelectableNode ) ) {
            target = target.getParent();
        }

        return target;
    } else {
        return root;
    }
}
 
Example 20
Source File: FxDump.java    From FxDock with Apache License 2.0 4 votes vote down vote up
protected void dump(Node n)
{
	SB sb = new SB(4096);
	sb.nl();
	
	while(n != null)
	{
		sb.a(CKit.getSimpleName(n));
		
		String id = n.getId();
		if(CKit.isNotBlank(id))
		{
			sb.a(" #");
			sb.a(id);
		}
		
		for(String s: n.getStyleClass())
		{
			sb.a(" .").a(s);
		}
		
		for(PseudoClass c: n.getPseudoClassStates())
		{
			sb.a(" :").a(c);
		}
		
		sb.nl();
		
		if(n instanceof Text)
		{
			sb.sp(4);
			sb.a("text: ");
			sb.a(TextTools.escapeControlsForPrintout(((Text)n).getText()));
			sb.nl();
		}
		
		CList<CssMetaData<? extends Styleable,?>> md = new CList<>(n.getCssMetaData());
		sort(md);
		
		for(CssMetaData d: md)
		{
			String k = d.getProperty();
			Object v = d.getStyleableProperty(n).getValue();
			if(shouldShow(v))
			{
				Object val = describe(v);
				sb.sp(4).a(k);
				sb.sp().a(val);
				if(d.isInherits())
				{
					sb.a(" *");
				}
				sb.nl();
			}
		}
		
		n = n.getParent();
	}
	D.print(sb);
}