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

The following examples show how to use javafx.scene.Node#isVisible() . 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: 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 2
Source File: UtilitiesJavaFX.java    From JavaFXSmartGraph with MIT License 5 votes vote down vote up
/**
 * Determines the closest node that resides in the x,y scene position, if any.
 * <br>
 * Obtained from: http://fxexperience.com/2016/01/node-picking-in-javafx/
 * 
 * @param node      parent node
 * @param sceneX    x-coordinate of picking point
 * @param sceneY    y-coordinate of picking point
 * 
 * @return          topmost node containing (sceneX, sceneY) point
 */
public static Node pick(Node node, double sceneX, double sceneY) {
    Point2D p = node.sceneToLocal(sceneX, sceneY, true /* rootScene */);

    // check if the given node has the point inside it, or else we drop out
    if (!node.contains(p)) {
        return null;
    }

    // at this point we know that _at least_ the given node is a valid
    // answer to the given point, so we will return that if we don't find
    // a better child option
    if (node instanceof Parent) {
        // we iterate through all children in reverse order, and stop when we find a match.
        // We do this as we know the elements at the end of the list have a higher
        // z-order, and are therefore the better match, compared to children that
        // might also intersect (but that would be underneath the element).
        Node bestMatchingChild = null;
        List<Node> children = ((Parent) node).getChildrenUnmodifiable();
        for (int i = children.size() - 1; i >= 0; i--) {
            Node child = children.get(i);
            p = child.sceneToLocal(sceneX, sceneY, true /* rootScene */);
            if (child.isVisible() && !child.isMouseTransparent() && child.contains(p)) {
                bestMatchingChild = child;
                break;
            }
        }

        if (bestMatchingChild != null) {
            return pick(bestMatchingChild, sceneX, sceneY);
        }
    }

    return node;
}
 
Example 3
Source File: ThreeDOM.java    From scenic-view with GNU General Public License v3.0 5 votes vote down vote up
private Tile3D from2Dto3D(SVNode root2D, Group root3D, double depth) {
    Tile3D childNode3D = null;
    // Currently, only work with internal usage. Remote is not yet possible, mainly due to the node.snapshot() calls
    if (ConnectorUtils.nodeClass(root2D).contains("SVRemoteNodeAdapter")) {
        Label label = new Label("The 3D view of ScenicView is only accessible when you invoke the tool from your source code. Remote access is not yet available.");
        label.setStyle("-fx-text-fill: #ff0000; -fx-font-size: 16pt;");
        label.setWrapText(true);
        label.setPadding(new Insets(10,10,10,10));
        controls.setExpanded(false);
        accordion.setExpandedPane(null);
        subSceneContainer.setCenter(label);
        return null;
    }
    Tile3D node3D = nodeToTile3D(root2D, FACTOR2D3D, depth);
    root3D.getChildren().add(node3D);
    depth += 3;
    List<SVNode> childrenUnmodifiable = root2D.getChildren();
    for (SVNode svnode : childrenUnmodifiable) {

        if (!ConnectorUtils.isNormalNode(svnode)) {
            continue;
        }
        Node node = svnode.getImpl();
        if (node.isVisible() && node instanceof Parent) {
            childNode3D = from2Dto3D(svnode, root3D, depth);
        } else if (node.isVisible()) {
            childNode3D = nodeToTile3D(svnode, FACTOR2D3D, depth);
            root3D.getChildren().add(childNode3D);

        }
        // Since 3D model is flat, keep "hierarchy" to child nodes
        if (childNode3D != null) {
            node3D.addChildrenTile(childNode3D);
        }
    }
    if (depth > maxDepth) {
        maxDepth = depth;
    }
    return node3D;
}
 
Example 4
Source File: DetailsTab.java    From scenic-view with GNU General Public License v3.0 5 votes vote down vote up
private void updatedDetailPane(final GDetailPane pane) {
    boolean detailVisible = false;
    for (final Node gridChild : pane.gridpane.getChildren()) {
        detailVisible = gridChild.isVisible();
        if (detailVisible)
            break;
    }
    pane.setExpanded(detailVisible);
    pane.setManaged(detailVisible);
    pane.setVisible(detailVisible);
    updateDump();
}
 
Example 5
Source File: ConnectorUtils.java    From scenic-view with GNU General Public License v3.0 5 votes vote down vote up
public static boolean isNodeVisible(final Node node) {
    if (node == null) {
        return true;
    } else {
        return node.isVisible() && isNodeVisible(node.getParent());
    }
}
 
Example 6
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 7
Source File: DisplayCanvas.java    From Quelea with GNU General Public License v3.0 5 votes vote down vote up
private boolean isVisibleInScene() {
    Node parent = DisplayCanvas.this;
    boolean visible = isVisible();
    if (!visible) {
        return visible;
    }
    while ((parent = parent.getParent()) != null) {
        if (!parent.isVisible()) {
            visible = false;
            break;
        }
    }
    return visible;
}
 
Example 8
Source File: JavaFXElement.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public boolean isVisible() {
    Node c = node;
    while (c != null) {
        if (!c.isVisible())
            return false;
        c = c.getParent();
    }
    return true;
}
 
Example 9
Source File: JFXTreeTableCellSkin.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
@Override
protected void layoutChildren(double x, double y, double w, double h) {
    updateDisclosureNode();
    double disclosureWidth = 0;
    Node disclosureNode = ((JFXTreeTableCell<S, T>) getSkinnable()).getDisclosureNode();
    if (disclosureNode.isVisible()) {
        Pos alignment = getSkinnable().getAlignment();
        alignment = alignment == null ? Pos.CENTER_LEFT : alignment;
        layoutInArea(disclosureNode, x + 8, y, w, h, 0, Insets.EMPTY, false, false, HPos.LEFT, VPos.CENTER);
        disclosureWidth = disclosureNode.getLayoutBounds().getWidth() + 18;
    }
    super.layoutChildren(x + disclosureWidth, y, w - disclosureWidth, h);
}
 
Example 10
Source File: HangmanMain.java    From FXTutorials with MIT License 5 votes vote down vote up
public void takeAwayLife() {
    for (Node n : getChildren()) {
        if (!n.isVisible()) {
            n.setVisible(true);
            lives.set(lives.get() - 1);
            break;
        }
    }
}
 
Example 11
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 12
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 13
Source File: AutoScalingGroup.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override protected void layoutChildren() {
    if (autoScale) {
        List<Node> children = getChildren();
        double minX = Double.MAX_VALUE, minY = Double.MAX_VALUE, minZ = Double.MAX_VALUE;
        double maxX = Double.MIN_VALUE, maxY = Double.MIN_VALUE, maxZ = Double.MIN_VALUE;
        boolean first = true;
        for (int i=0, max=children.size(); i<max; i++) {
            final Node node = children.get(i);
            if (node.isVisible()) {
                Bounds bounds = node.getBoundsInLocal();
                // if the bounds of the child are invalid, we don't want
                // to use those in the remaining computations.
                if (bounds.isEmpty()) continue;
                if (first) {
                    minX = bounds.getMinX();
                    minY = bounds.getMinY();
                    minZ = bounds.getMinZ();
                    maxX = bounds.getMaxX();
                    maxY = bounds.getMaxY();
                    maxZ = bounds.getMaxZ();
                    first = false;
                } else {
                    minX = Math.min(bounds.getMinX(), minX);
                    minY = Math.min(bounds.getMinY(), minY);
                    minZ = Math.min(bounds.getMinZ(), minZ);
                    maxX = Math.max(bounds.getMaxX(), maxX);
                    maxY = Math.max(bounds.getMaxY(), maxY);
                    maxZ = Math.max(bounds.getMaxZ(), maxZ);
                }
            }
        }

        final double w = maxX-minX;
        final double h = maxY-minY;
        final double d = maxZ-minZ;

        final double centerX = minX + (w/2);
        final double centerY = minY + (h/2);
        final double centerZ = minZ + (d/2);

        double scaleX = twoSize/w;
        double scaleY = twoSize/h;
        double scaleZ = twoSize/d;

        double scale = Math.min(scaleX, Math.min(scaleY,scaleZ));
        this.scale.setX(scale);
        this.scale.setY(scale);
        this.scale.setZ(scale);

        this.translate.setX(-centerX);
        this.translate.setY(-centerY);
    }
}