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

The following examples show how to use javafx.scene.Node#getScene() . 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: AndroidKeyboardService.java    From attach with GNU General Public License v3.0 7 votes vote down vote up
private static void adjustPosition(Node node, Parent parent, double kh) {
    if (node == null || node.getScene() == null || node.getScene().getWindow() == null) {
        return;
    }
    double tTot = node.getScene().getHeight();
    double ty = node.getLocalToSceneTransform().getTy() + node.getBoundsInParent().getHeight() + 2;
    double y = 1;
    Parent root = parent == null ? node.getScene().getRoot() : parent;
    if (ty > tTot - kh) {
        y = tTot - ty - kh;
    } else if (kh == 0 && root.getTranslateY() != 0) {
        y = 0;
    }
    if (y <= 0) {
        if (debug) {
            LOG.log(Level.INFO, String.format("Moving %s %.2f pixels", root, y));
        }
        final TranslateTransition transition = new TranslateTransition(Duration.millis(100), root);
        transition.setFromY(root.getTranslateY());
        transition.setToY(y);
        transition.setInterpolator(Interpolator.EASE_OUT);
        transition.playFromStart();
    }
}
 
Example 2
Source File: IOSKeyboardService.java    From attach with GNU General Public License v3.0 6 votes vote down vote up
private static void adjustPosition(Node node, Parent parent, double kh) {
    if (node == null || node.getScene() == null || node.getScene().getWindow() == null) {
        return;
    }
    double tTot = node.getScene().getHeight();
    double ty = node.getLocalToSceneTransform().getTy() + node.getBoundsInParent().getHeight() + 2;
    double y = 1;
    Parent root = parent == null ? node.getScene().getRoot() : parent;
    if (ty > tTot - kh) {
        y = tTot - ty - kh;
    } else if (kh == 0 && root.getTranslateY() != 0) {
        y = 0;
    }
    if (y <= 0) {
        if (debug) {
            LOG.log(Level.INFO, String.format("Moving %s %.2f pixels", root, y));
        }
        final TranslateTransition transition = new TranslateTransition(Duration.millis(100), root);
        transition.setFromY(root.getTranslateY());
        transition.setToY(y);
        transition.setInterpolator(Interpolator.EASE_OUT);
        transition.playFromStart();
    }
}
 
Example 3
Source File: DockTools.java    From FxDock with Apache License 2.0 6 votes vote down vote up
public static FxDockWindow getWindow(Node n)
{
	if(n != null)
	{
		Scene sc = n.getScene();
		if(sc != null)
		{
			Window w = sc.getWindow();
			if(w instanceof FxDockWindow)
			{
				return (FxDockWindow)w;
			}
		}
	}
	return null;	
}
 
Example 4
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 5
Source File: JFXPopup.java    From JFoenix with Apache License 2.0 6 votes vote down vote up
/**
 * show the popup according to the specified position with a certain offset
 *
 * @param vAlign      can be TOP/BOTTOM
 * @param hAlign      can be LEFT/RIGHT
 * @param initOffsetX on the x axis
 * @param initOffsetY on the y axis
 */
public void show(Node node, PopupVPosition vAlign, PopupHPosition hAlign, double initOffsetX, double initOffsetY) {
    if (!isShowing()) {
        if (node.getScene() == null || node.getScene().getWindow() == null) {
            throw new IllegalStateException("Can not show popup. The node must be attached to a scene/window.");
        }
        Window parent = node.getScene().getWindow();
        final Point2D origin = node.localToScene(0, 0);
        final double anchorX = parent.getX() + origin.getX()
            + node.getScene().getX() + (hAlign == PopupHPosition.RIGHT ? ((Region) node).getWidth() : 0);
        final double anchorY = parent.getY() + origin.getY()
            + node.getScene()
                  .getY() + (vAlign == PopupVPosition.BOTTOM ? ((Region) node).getHeight() : 0);
        this.show(parent, anchorX, anchorY);
        ((JFXPopupSkin) getSkin()).reset(vAlign, hAlign, initOffsetX, initOffsetY);
        Platform.runLater(() -> ((JFXPopupSkin) getSkin()).animate());
    }
}
 
Example 6
Source File: ChartPlugin.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private <T extends InputEvent> void removeEventHandlers(final Node node) {
    if (node == null) {
        return;
    }
    for (final Pair<EventType<? extends InputEvent>, EventHandler<? extends InputEvent>> pair : mouseEventHandlers) {
        final EventType<T> type = (EventType<T>) pair.getKey();
        final EventHandler<T> handler = (EventHandler<T>) pair.getValue();
        node.removeEventHandler(type, handler);
        if (node.getScene() != null) {
            node.getScene().removeEventFilter(type, handler);
        }
    }
}
 
Example 7
Source File: StageControllerImpl.java    From scenic-view with GNU General Public License v3.0 5 votes vote down vote up
private void updateBoundsRects(final Node selectedNode) {
    /**
     * By node layout bounds only on main scene not on popups
     */
    if (selectedNode != null && selectedNode.getScene() == targetScene) {
        SCUtils.updateRect(overlayParent, selectedNode, selectedNode.getBoundsInParent(), 0, 0, boundsInParentRect);
        SCUtils.updateRect(overlayParent, selectedNode, selectedNode.getLayoutBounds(), selectedNode.getLayoutX(), selectedNode.getLayoutY(), layoutBoundsRect);
        boundsInParentRect.setVisible(true);
        layoutBoundsRect.setVisible(true);
    } else {
        boundsInParentRect.setVisible(false);
        layoutBoundsRect.setVisible(false);
    }
}
 
Example 8
Source File: ListPopup.java    From oim-fx with MIT License 5 votes vote down vote up
public void show(Node node) {

		if (node.getScene() == null || node.getScene().getWindow() == null)
			throw new IllegalStateException("Can not show popup. The node must be attached to a scene/window."); //$NON-NLS-1$

		if (isShowing()) {
			return;
		}

		Window parent = node.getScene().getWindow();
		this.show(parent, parent.getX() + node.localToScene(0, 0).getX() + node.getScene().getX(),
				parent.getY() + node.localToScene(0, 0).getY() + node.getScene().getY() + TITLE_HEIGHT);

	}
 
Example 9
Source File: ChatFunction.java    From oim-fx with MIT License 5 votes vote down vote up
public String getPicture(Node node) {
	Scene scene = node.getScene();
	Window w = (null == scene) ? null : scene.getWindow();
	String fullPath = null;
	if (null != w) {
		File file = imageFileChooser.showOpenDialog(w);
		if (file != null) {
			if (file.exists()) {
				fullPath = file.getAbsolutePath();
			}
		}
	}
	return fullPath;
}
 
Example 10
Source File: Initialization.java    From trex-stateless-gui with Apache License 2.0 5 votes vote down vote up
public static void initializeCloseEvent(Node root, EventHandler<WindowEvent> eventHandler) {
    Scene scene = root.getScene();
    if (scene == null) {
        root.sceneProperty().addListener(((observable, oldScene, newScene) -> {
            if (oldScene == null && newScene != null) {
                initializeCloseEvent(newScene, eventHandler);
            }
        }));
    } else {
        initializeCloseEvent(scene, eventHandler);
    }
}
 
Example 11
Source File: FX.java    From FxDock with Apache License 2.0 5 votes vote down vote up
public static FxWindow getWindow(Node n)
{
	Scene sc = n.getScene();
	if(sc != null)
	{
		Window w = sc.getWindow();
		if(w instanceof FxWindow)
		{
			return (FxWindow)w;
		}
	}
	return null;
}
 
Example 12
Source File: WindowsFx.java    From FxDock with Apache License 2.0 5 votes vote down vote up
protected FxWindow getFxWindow(Node n)
{
	Scene sc = n.getScene();
	if(sc != null)
	{
		Window w = sc.getWindow();
		if(w instanceof FxWindow)
		{
			return (FxWindow)w;
		}
	}
	return null;
}
 
Example 13
Source File: JFXAutoCompletePopup.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
public void show(Node node){
    if(!isShowing()){
        if(node.getScene() == null || node.getScene().getWindow() == null)
            throw new IllegalStateException("Can not show popup. The node must be attached to a scene/window.");
        Window parent = node.getScene().getWindow();
        this.show(parent, parent.getX() + node.localToScene(0, 0).getX() +
                          node.getScene().getX(),
            parent.getY() + node.localToScene(0, 0).getY() +
            node.getScene().getY() + ((Region)node).getHeight());
        ((JFXAutoCompletePopupSkin<T>)getSkin()).animate();
    }
}
 
Example 14
Source File: DragDropGesture.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @param target
 *            The targeted {@link Node}
 * @param event
 *            The original {@link DragEvent}
 */
protected void dragOver(final Node target, final DragEvent event) {
	final IViewer viewer = PartUtils.retrieveViewer(getDomain(), target);
	if (viewer == null) {
		return;
	}

	if (viewer instanceof InfiniteCanvasViewer) {
		final InfiniteCanvas canvas = ((InfiniteCanvasViewer) viewer)
				.getCanvas();
		// if any node in the target hierarchy is a scrollbar,
		// do not process the event
		if (event.getTarget() instanceof Node) {
			Node targetNode = (Node) event.getTarget();
			while (targetNode != null) {
				if (targetNode == canvas.getHorizontalScrollBar()
						|| targetNode == canvas.getVerticalScrollBar()) {
					return;
				}
				targetNode = targetNode.getParent();
			}
		}
	}

	final Scene scene = target.getScene();
	if (scene == null) {
		return;
	}

	// determine viewer that contains the given target part
	activeViewer = PartUtils.retrieveViewer(getDomain(), target);
	final List<? extends IOnDragDropHandler> dragDropPolicies = getHandlerResolver()
			.resolve(DragDropGesture.this, target, activeViewer,
					ON_DRAGDROP_HANDLER_KEY);
	setActiveHandlers(activeViewer, dragDropPolicies);
	if (dragDropPolicies != null && !dragDropPolicies.isEmpty()) {
		for (final IOnDragDropHandler dragDropPolicy : dragDropPolicies) {
			dragDropPolicy.dragOver(event);
		}
	}

}
 
Example 15
Source File: JFXTooltip.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
private Window getWindow(final Node node) {
    final Scene scene = node == null ? null : node.getScene();
    return scene == null ? null : scene.getWindow();
}