Java Code Examples for javafx.stage.Window#getScene()

The following examples show how to use javafx.stage.Window#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: FXUtils.java    From scenic-view with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Retrieves the root window containing the given scene
 * @param s the scene to look window for
 * @return the window the scene belongs to, or null if it cannot be found
 */
@SuppressWarnings("deprecation")
public static Window windowOf(Scene s) {
    if (s == null) {
        return null;
    }

    ObservableList<Window> windows = Window.getWindows();
    for (Window w : windows) {
        if (s == w.getScene()) {
            return w;
        }
    }

    return null;
}
 
Example 2
Source File: FxHacksJava9.java    From FxDock with Apache License 2.0 6 votes vote down vote up
public void applyStyleSheet(String old, String cur)
{
	for(Window w: getWindows())
	{
		Scene scene = w.getScene();
		if(scene != null)
		{
			if(old != null)
			{
				scene.getStylesheets().remove(old);
			}
			
			scene.getStylesheets().add(cur);
		}
	}
}
 
Example 3
Source File: FXUtils.java    From scenic-view with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Retrieves the root window containing the given node
 * @param n the node to look window for
 * @return the window the node belongs to, or null if it cannot be found
 */
@SuppressWarnings("deprecation")
public static Window windowOf(Node n) {
    if (n == null) {
        return null;
    }

    Parent p = n.getParent();
    if (p != null) {
        return windowOf(p);
    }

    if (n instanceof Parent) {
        Parent container = (Parent) n;

        ObservableList<Window> windows = Window.getWindows();
        for (Window w : windows) {
            if (w.getScene() != null) {
                if (container == w.getScene().getRoot()) {
                    return w;
                }
            }
        }
    }

    return null;
}
 
Example 4
Source File: ConnectorUtils.java    From scenic-view with GNU General Public License v3.0 5 votes vote down vote up
public static boolean acceptWindow(final Window window) {
    if (window instanceof Stage) {
        final Node root = window.getScene() != null ? window.getScene().getRoot() : null;
        if (root != null && (root.getId() == null || !root.getId().startsWith(StageController.FX_CONNECTOR_BASE_ID))) {
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: EditorDialog.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Shows this dialog.
 *
 * @param owner the owner.
 */
@FxThread
public void show(@NotNull Window owner) {

    var scene = owner.getScene();

    if (scene instanceof EditorFxScene) {
        var editorFxScene = (EditorFxScene) scene;
        var container = editorFxScene.getContainer();
        container.setFocusTraversable(false);
    }

    focusOwner = scene.getFocusOwner();

    dialog.initOwner(owner);
    dialog.show();
    dialog.requestFocus();
    dialog.toFront();
    dialog.setOnCloseRequest(event -> hide());

    GAnalytics.sendPageView(getDialogId(), null, "/dialog/" + getDialogId());
    GAnalytics.sendEvent(GAEvent.Category.DIALOG, GAEvent.Action.DIALOG_OPENED, getDialogId());

    EditorUtil.addFxWindow(dialog);

    Platform.runLater(dialog::sizeToScene);
}
 
Example 6
Source File: FX.java    From FxDock with Apache License 2.0 5 votes vote down vote up
/** returns window decoration insets */
public static Insets getDecorationInsets(Window w)
{
	Scene s = w.getScene();
	double left = s.getX();
	double top = s.getY();
	double right = w.getWidth() - s.getWidth() - left;
	double bottom = w.getHeight() - s.getHeight() - top;
	return new Insets(top, right, bottom, left);
}
 
Example 7
Source File: DockTools.java    From FxDock with Apache License 2.0 5 votes vote down vote up
public static Insets getWindowInsets(Window w)
{
	Scene s = w.getScene();
	
	double left = s.getX();
	double top = s.getY();
	double right = w.getWidth() - s.getWidth() - left;
	double bottom = w.getHeight() - s.getHeight() - top;
	
	return new Insets(top, right, bottom, left);
}
 
Example 8
Source File: Util.java    From ResponsiveFX with Apache License 2.0 5 votes vote down vote up
public static void bindStyleSheetToWindow(Window window, StringProperty stylesheet) {
    window.sceneProperty().addListener(e -> {
        if (window.getScene() != null) {
            window.getScene().getStylesheets().add(stylesheet.get());
        }
    });
    if (window.getScene() != null) {
        window.getScene().getStylesheets().add(stylesheet.get());
    }

    stylesheet.addListener((obs, o, n) -> {
        if (window.getScene() != null) {
            int oldPos = -1;
            if (o != null) {
                oldPos = window.getScene().getStylesheets().indexOf(o);
                window.getScene().getStylesheets().remove(o);
            }
            if (n != null) {
                if (oldPos >= 0) {
                    window.getScene().getStylesheets().add(oldPos, n);
                } else {
                    window.getScene().getStylesheets().add(n);
                }
            }
        }
    });
}
 
Example 9
Source File: CSSFXMonitor.java    From cssfx with Apache License 2.0 5 votes vote down vote up
private void unregisterWindow(Window removedStage) {
    if (knownWindows.remove(removedStage)) {
        if (removedStage.getScene() != null) {
            unregisterScene(removedStage.getScene());
        }
        eventNotify(CSSFXEvent.newEvent(EventType.STAGE_REMOVED, removedStage));
    }
}
 
Example 10
Source File: CSSFXMonitor.java    From scenic-view with GNU General Public License v3.0 4 votes vote down vote up
private void unregisterStage(Window removedStage) {
    if (removedStage.getScene() != null) {
        accept(CSSFXEvent.newEvent(EventType.SCENE_REMOVED, removedStage.getScene()));
    }
    accept(CSSFXEvent.newEvent(EventType.STAGE_REMOVED, removedStage));
}