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

The following examples show how to use javafx.stage.Window#getWindows() . 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: WindowsMenu.java    From mzmine3 with GNU General Public License v2.0 5 votes vote down vote up
private void fillWindowsMenu() {
  while (getItems().size() > 2)
    getItems().remove(2);
  for (Window win : Window.getWindows()) {
    if (win instanceof Stage) {
      Stage stage = (Stage) win;
      final MenuItem item = new MenuItem(stage.getTitle());
      item.setOnAction(e -> {
        stage.toFront();
      });
      getItems().add(item);
    }
  }
}
 
Example 3
Source File: WindowChecker.java    From scenic-view with GNU General Public License v3.0 5 votes vote down vote up
public static List<Window> getValidWindows(final WindowFilter filter) {
    ObservableList<Window> windows = Window.getWindows();
    if (windows.isEmpty()) {
        return Collections.emptyList();
    }

    final List<Window> validWindows = new ArrayList<>();
    for (Window window : windows) {
        if (filter.accept(window)) {
            validWindows.add(window);
        }
    }
    return validWindows;
}
 
Example 4
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 5
Source File: DockStage.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** @param id Unique ID of a stage
 *  @return That Stage or <code>null</code> if not found
 */
public static Stage getDockStageByID(final String id)
{
    for (Window window : Window.getWindows())
        // id.equals(null) is OK, will return false
        if (id.equals(window.getProperties().get(KEY_ID)))
            return (Stage) window;
    return null;
}
 
Example 6
Source File: DockStage.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** @return All currently open dock stages (safe copy) */
public static List<Stage> getDockStages()
{
    final List<Stage> dock_windows = new ArrayList<>();
    // Having a KEY_ID property implies that the Window
    // is a Stage that was configured as a DockStage
    for (Window window : Window.getWindows())
        if (window.getProperties().containsKey(KEY_ID))
            dock_windows.add((Stage) window);

    return dock_windows;
}
 
Example 7
Source File: FxmlStage.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static void appExit() {
        try {
//            if (AppVariables.backgroundTasks != null && !AppVariables.backgroundTasks.isEmpty()) {
//                Alert alert = new Alert(Alert.AlertType.CONFIRMATION);
//                alert.setContentText(MessageFormat.format(message("BackgroundTasksRunning"), AppVariables.backgroundTasks.size()));
//                alert.getDialogPane().setMinHeight(Region.USE_PREF_SIZE);
//                Stage stage = (Stage) alert.getDialogPane().getScene().getWindow();
//                stage.setAlwaysOnTop(true);
//                stage.toFront();
//                Optional<ButtonType> result = alert.showAndWait();
//                if (result.get() == null || result.get() != ButtonType.OK) {
//                    return;
//                }
//            }

            if (Window.getWindows() != null) {
                List<Window> windows = new ArrayList<>();
                windows.addAll(Window.getWindows());
                for (Window window : windows) {
                    window.hide();
                }
            }

            if (AppVariables.scheduledTasks != null && !AppVariables.scheduledTasks.isEmpty()) {
                if (AppVariables.getUserConfigBoolean("StopAlarmsWhenExit")) {
                    for (Long key : AppVariables.scheduledTasks.keySet()) {
                        ScheduledFuture future = AppVariables.scheduledTasks.get(key);
                        future.cancel(true);
                    }
                    AppVariables.scheduledTasks = null;
                    if (AppVariables.executorService != null) {
                        AppVariables.executorService.shutdownNow();
                        AppVariables.executorService = null;
                    }
                }

            } else {
                if (AppVariables.scheduledTasks != null) {
                    AppVariables.scheduledTasks = null;
                }
                if (AppVariables.executorService != null) {
                    AppVariables.executorService.shutdownNow();
                    AppVariables.executorService = null;
                }
            }

            if (AppVariables.scheduledTasks == null || AppVariables.scheduledTasks.isEmpty()) {

//                logger.debug("Shut down Derby server...");
//                DerbyBase.shutdownDerbyServer();
                logger.debug("Exit now. Bye!");
                Platform.exit(); // Some thread may still be alive after this
                System.exit(0);  // Go
            }

        } catch (Exception e) {
            logger.debug(e.toString());
        }

    }
 
Example 8
Source File: FxHacksJava9.java    From FxDock with Apache License 2.0 4 votes vote down vote up
public List<Window> getWindows()
{
	return new CList(Window.getWindows());
}
 
Example 9
Source File: CSSFX.java    From cssfx with Apache License 2.0 4 votes vote down vote up
/**
 * Start monitoring CSS resources with the config parameters collected until now. 
 * @return a Runnable object to stop CSSFX monitoring
 */
public Runnable start() {
    if (!CSSFXLogger.isInitialized()) {
        if (Boolean.getBoolean("cssfx.log")) {
            LogLevel toActivate = LogLevel.INFO;
            String levelStr = System.getProperty("cssfx.log.level", "INFO");
            try {
                toActivate = LogLevel.valueOf(levelStr);
            } catch (Exception ignore) {
                System.err.println("[CSSFX] invalid value for cssfx.log.level, '" + levelStr + "' is not allowed. Select one in: " + Arrays.asList(LogLevel.values()));
            }
            CSSFXLogger.setLogLevel(toActivate);
            
            String logType = System.getProperty("cssfx.log.type", "console");
            switch (logType) {
            case "noop":
                CSSFXLogger.noop();
                break;
            case "console":
                CSSFXLogger.console();
                break;
            case "jul":
                CSSFXLogger.jul();
                break;
            default:
                System.err.println("[CSSFX] invalid value for cssfx.log.type, '" + logType + "' is not allowed. Select one in: " + Arrays.asList("noop", "console", "jul"));
                break;
            }
        } else {
            CSSFXLogger.noop();
        }
    }
    
    CSSFXMonitor m = new CSSFXMonitor();
    
    if (restrictedToWindow != null) {
        m.setWindows(FXCollections.singletonObservableList(restrictedToWindow));
    } else if (restrictedToScene != null) {
        m.setScenes(FXCollections.singletonObservableList(restrictedToScene));
    } else if (restrictedToNode != null) {
        m.setNodes(FXCollections.singletonObservableList(restrictedToNode));
    } else {
        // we monitor all the stages
        // THIS CANNOT WORK!
        ObservableList<Window> monitoredStages = (restrictedToWindow == null)?Window.getWindows():FXCollections.singletonObservableList(restrictedToWindow);
        m.setWindows(monitoredStages);
    }
    
    return start(() -> m);
}