public void register(@Nonnull String id, @Nonnull Stage stage) {
		// Validate input, ensuring duplicate allocations are not allowed.
		if (windowMappings.containsKey(id))
			throw new IllegalStateException("The stage ID was already registered: " + id);

		// Add custom stylesheets if any are registered.
		if (!windowStyling.getStylesheetUris().isEmpty())
			NodeEvents.runOnceIfPresentOrOnChange(stage.sceneProperty(),
					scene -> scene.getStylesheets().addAll(windowStyling.getStylesheetUris()));

		// Record when windows are 'active' based on visibility.
		// We're using event filters so users can still do things like 'stage.setOnShown(...)' and not interfere with
		// our window tracking logic in here
		stage.addEventFilter(WindowEvent.WINDOW_SHOWN, e -> {
			logger.trace("Stage showing: {}", id);
			activeWindows.add(stage);
		});
		stage.addEventFilter(WindowEvent.WINDOW_HIDDEN, e -> {
			logger.trace("Stage hiding: {}", id);
			activeWindows.remove(stage);

			// Anonymous stages can be pruned from the id->stage map.
			// They are not meant to be persistent. But, we register them anyway for our duplicate register check above.
			if (id.startsWith(ANON_PREFIX)) {
				logger.trace("Stage pruned: {} ({})", id, stage.getTitle());
				windowMappings.remove(id);
			}
		});

		// If state is already visible, add it right away.
		if (stage.isShowing()) activeWindows.add(stage);

		// Register id --> stage
		windowMappings.put(id, stage);
		logger.trace("Register stage: {}", id);
	}
Register listeners on the stage to monitor active state.

@param id
		Unique stage identifier.
@param stage
		Stage to register.
recaf-ui/src/main/java/software/coley/recaf/services/window/WindowManager.java