Java Code Examples for javafx.stage.Stage#addEventHandler()
The following examples show how to use
javafx.stage.Stage#addEventHandler() .
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: DesignerRootImpl.java From pmd-designer with BSD 2-Clause "Simplified" License | 6 votes |
public DesignerRootImpl(Stage mainStage, DesignerParams params, HostServices hostServices) { this.mainStage = mainStage; this.developerMode = params.isDeveloperMode(); registerService(LOGGER, new EventLoggerImpl(this)); // vetoed by any other key press, so that eg CTRL+V repeatedly vetoes it mainStage.addEventHandler(KeyEvent.KEY_PRESSED, e -> isCtrlDown.setValue( e.isControlDown() && e.getCode() == KeyCode.CONTROL)); mainStage.addEventHandler(KeyEvent.KEY_RELEASED, e -> isCtrlDown.setValue( e.isControlDown() && e.getCode() == KeyCode.CONTROL)); GlobalDiskManagerImpl diskManager = new GlobalDiskManagerImpl(this, params.getSettingsDirectory()); registerService(DISK_MANAGER, diskManager); params.processDefaults(diskManager.defaultAppStateFile()); registerService(HOST_SERVICES, hostServices); registerService(PERSISTENCE_MANAGER, new OnDiskPersistenceManager(this, params.getPersistedInputFile(), params.getPersistedOutputFile())); registerService(NODE_SELECTION_CHANNEL, new MessageChannel<>(Category.SELECTION_EVENT_TRACING)); registerService(LATEST_XPATH, new MessageChannel<>(Category.SELECTION_EVENT_TRACING)); registerService(TEST_LOADER, new MessageChannel<>(Category.TEST_LOADING_EVENT)); registerService(TEST_CREATOR, new TestCreatorService()); registerService(TREE_RENDERER_REGISTRY, new TreeRendererRegistry(this)); registerService(IS_NODE_BEING_DRAGGED, Var.newSimpleVar(false)); }
Example 2
Source File: ActivityStage.java From PeerWasp with MIT License | 6 votes |
private void load() { try { FXMLLoader loader = fxmlLoaderProvider.create(ViewNames.ACTIVITY_VIEW); Parent root = loader.load(); Scene scene = new Scene(root, WINDOW_WIDTH, WINDOW_HEIGHT); stage = new Stage(); stage.setTitle(WINDOW_TITLE); Collection<Image> icons = IconUtils.createWindowIcons(); stage.getIcons().addAll(icons); stage.setScene(scene); stage.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, new WindowCloseRequestEventHandler()); } catch (IOException e) { logger.error("Could not load activity stage: {}", e.getMessage(), e); } }
Example 3
Source File: SettingsStage.java From PeerWasp with MIT License | 6 votes |
private void load() { try { Preconditions.checkNotNull(appContext.getCurrentClientContext(), "ClientContext must not be null."); // important: use injector for client here because of client specific instances. FXMLLoader loader = fxmlLoaderProvider.create(ViewNames.SETTINGS_MAIN, appContext.getCurrentClientContext().getInjector()); Parent root = loader.load(); Scene scene = new Scene(root, WINDOW_WIDTH, WINDOW_HEIGHT); stage = new Stage(); stage.setTitle(WINDOW_TITLE); Collection<Image> icons = IconUtils.createWindowIcons(); stage.getIcons().addAll(icons); stage.setScene(scene); stage.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, new WindowCloseRequestEventHandler()); } catch (IOException e) { logger.error("Could not load settings stage: {}", e.getMessage(), e); } }
Example 4
Source File: ScenicViewGui.java From scenic-view with GNU General Public License v3.0 | 5 votes |
public static void show(final ScenicViewGui scenicview, final Stage stage) { final Scene scene = new Scene(scenicview.rootBorderPane); scene.getStylesheets().addAll(STYLESHEETS); stage.setScene(scene); stage.getIcons().add(APP_ICON); if (scenicview.activeStage != null && scenicview.activeStage instanceof StageControllerImpl) ((StageControllerImpl) scenicview.activeStage).placeStage(stage); stage.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, event -> { Runtime.getRuntime().removeShutdownHook(scenicview.shutdownHook); scenicview.close(); }); stage.show(); }
Example 5
Source File: TreeViewApp.java From oim-fx with MIT License | 5 votes |
@Override public void start(Stage primaryStage) throws Exception { primaryStage.initStyle(StageStyle.TRANSPARENT); primaryStage.setScene(new Scene(createContent())); primaryStage.show(); EventType<MouseEvent> type = MouseEvent.MOUSE_CLICKED; primaryStage.addEventHandler(type,e->{ System.out.println(e); }); }
Example 6
Source File: MainController.java From neural-style-gui with GNU General Public License v3.0 | 5 votes |
void setStage(Stage stage) { this.stage = stage; log.log(Level.FINER, "Setting keyboard shortcuts."); final KeyCombination enter = new KeyCodeCombination(KeyCode.ENTER); final KeyCombination ctrlS = new KeyCodeCombination(KeyCode.S, KeyCombination.CONTROL_DOWN); final KeyCombination ctrlC = new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_DOWN); final KeyCombination ctrlL = new KeyCodeCombination(KeyCode.L, KeyCombination.CONTROL_DOWN); final KeyCombination ctrlO = new KeyCodeCombination(KeyCode.O, KeyCombination.CONTROL_DOWN); final KeyCombination ctrlEnter = new KeyCodeCombination(KeyCode.ENTER, KeyCombination.CONTROL_DOWN); final KeyCombination ctrlShiftEnter = new KeyCodeCombination(KeyCode.ENTER, KeyCombination.CONTROL_DOWN, KeyCombination.SHIFT_DOWN); stage.addEventHandler(KeyEvent.KEY_RELEASED, event -> { if (enter.match(event)) { // TODO: Suppress } else if (ctrlS.match(event)) { tabs.getSelectionModel().select(inputTab); styleImageGrid.requestFocus(); } else if (ctrlC.match(event)) { tabs.getSelectionModel().select(inputTab); contentImageGrid.requestFocus(); } else if (ctrlL.match(event)) { tabs.getSelectionModel().select(layersTab); styleLayersTable.requestFocus(); } else if (ctrlO.match(event)) { tabs.getSelectionModel().select(outputTab); } else if (ctrlEnter.match(event)) { showTooltipNextTo(queueButton, resources.getString("queueButtonHit")); queueStyle(); } else if (ctrlShiftEnter.match(event)) { startService(); } }); }
Example 7
Source File: MainScene.java From mars-sim with GNU General Public License v3.0 | 5 votes |
public void setEscapeEventHandler(boolean value, Stage stage) { if (value) { stage.addEventHandler(KeyEvent.KEY_PRESSED, esc); } else { stage.removeEventHandler(KeyEvent.KEY_PRESSED, esc); } }
Example 8
Source File: StageState.java From markdown-writer-fx with BSD 2-Clause "Simplified" License | 5 votes |
public StageState(Stage stage, Preferences state) { this.stage = stage; this.state = state; restore(); stage.addEventHandler(WindowEvent.WINDOW_HIDING, e -> save()); stage.xProperty().addListener((ob, o, n) -> boundsChanged()); stage.yProperty().addListener((ob, o, n) -> boundsChanged()); stage.widthProperty().addListener((ob, o, n) -> boundsChanged()); stage.heightProperty().addListener((ob, o, n) -> boundsChanged()); }
Example 9
Source File: JavaFX3D.java From JavaFX-Tutorial-Codes with Apache License 2.0 | 4 votes |
@Override public void start(Stage primaryStage) { Box box = new Box(100, 20, 50); SmartGroup group = new SmartGroup(); group.getChildren().add(box); Camera camera = new PerspectiveCamera(); Scene scene = new Scene(group, WIDTH, HEIGHT); scene.setFill(Color.SILVER); scene.setCamera(camera); group.translateXProperty().set(WIDTH / 2); group.translateYProperty().set(HEIGHT / 2); group.translateZProperty().set(-1500); initMouseControl(group, scene); primaryStage.addEventHandler(KeyEvent.KEY_PRESSED, event -> { switch (event.getCode()) { case W: group.translateZProperty().set(group.getTranslateZ() + 100); break; case S: group.translateZProperty().set(group.getTranslateZ() - 100); break; case Q: group.rotateByX(10); break; case E: group.rotateByX(-10); break; case NUMPAD6: group.rotateByY(10); break; case NUMPAD4: group.rotateByY(-10); break; } }); primaryStage.setTitle("Genuine Coder"); primaryStage.setScene(scene); primaryStage.show(); }
Example 10
Source File: RobotAPIDemo.java From Java-11-Cookbook-Second-Edition with MIT License | 4 votes |
@Override public void start(Stage stage) throws Exception{ robot = new Robot(); GridPane gridPane = new GridPane(); gridPane.setAlignment(Pos.CENTER); gridPane.setHgap(10); gridPane.setVgap(10); gridPane.setPadding(new Insets(25, 25, 25, 25)); Text appTitle = new Text("Robot Demo"); appTitle.setFont(Font.font("Arial", FontWeight.NORMAL, 15)); gridPane.add(appTitle, 0, 0, 2, 1); Label nameLbl = new Label("Name"); nameField = new TextField(); gridPane.add(nameLbl, 0, 1); gridPane.add(nameField, 1, 1); greeting = new Button("Greet"); gridPane.add(greeting, 1, 2); Text resultTxt = new Text(); resultTxt.setFont(Font.font("Arial", FontWeight.NORMAL, 15)); gridPane.add(resultTxt, 0, 5, 2, 1); greeting.setOnAction((event) -> { String name = nameField.getText(); StringBuilder resultBuilder = new StringBuilder(); if ( name != null && name.length() > 0 ){ resultBuilder.append("Hello, ").append(name).append("\n"); }else{ resultBuilder.append("Please enter the name"); } resultTxt.setText(resultBuilder.toString()); btnActionLatch.countDown(); }); Scene scene = new Scene(gridPane, 300, 250); stage.setTitle("Age calculator"); stage.setScene(scene); stage.setAlwaysOnTop(true); stage.addEventHandler(WindowEvent.WINDOW_SHOWN, e -> Platform.runLater(appStartLatch::countDown)); stage.show(); appStage = stage; }
Example 11
Source File: WindowController.java From logbook-kai with MIT License | 4 votes |
final void initWindow(Stage window) { window.addEventHandler(WindowEvent.WINDOW_HIDDEN, this::onWindowHidden); window.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, this::onWindowCloseRequest); this.setWindow(window); }
Example 12
Source File: Main.java From logbook-kai with MIT License | 4 votes |
@Override public void start(Stage stage) throws Exception { String fxmlName = "main"; if (AppConfig.get().getWindowStyle() != null) { fxmlName = AppConfig.get().getWindowStyle(); } FXMLLoader loader = InternalFXMLLoader.load("logbook/gui/" + fxmlName + ".fxml"); //$NON-NLS-1$ Parent root = InternalFXMLLoader.setGlobal(loader.load()); stage.setScene(new Scene(root)); WindowController controller = loader.getController(); controller.initWindow(stage); // アイコンの設定 Tools.Windows.setIcon(stage); // 最前面に表示する stage.setAlwaysOnTop(AppConfig.get().isOnTop()); stage.setTitle("航海日誌 " + Version.getCurrent()); stage.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, e -> { if (AppConfig.get().isCheckDoit()) { Alert alert = new Alert(AlertType.INFORMATION); alert.getDialogPane().getStylesheets().add("logbook/gui/application.css"); InternalFXMLLoader.setGlobal(alert.getDialogPane()); alert.initOwner(stage); alert.setTitle("終了の確認"); alert.setHeaderText("終了の確認"); alert.setContentText("航海日誌を終了しますか?"); alert.getButtonTypes().clear(); alert.getButtonTypes().addAll(ButtonType.YES, ButtonType.NO); alert.showAndWait() .filter(ButtonType.NO::equals) .ifPresent(t -> e.consume()); } if (!e.isConsumed()) { AppConfig.get() .getWindowLocationMap() .put(controller.getClass().getCanonicalName(), controller.getWindowLocation()); } }); Tools.Windows.defaultOpenAction(controller); stage.show(); }
Example 13
Source File: JavaFXNES.java From halfnes with GNU General Public License v3.0 | 4 votes |
@Override public void start(Stage stage) throws Exception { this.stage = stage; //Rectangle2D bounds = Screen.getPrimary().getBounds(); Rectangle2D bounds = new Rectangle2D(0,0,640,480); gameCanvas = new Canvas(256, 240); stage.addEventHandler(javafx.stage.WindowEvent.WINDOW_CLOSE_REQUEST, e -> nes.quit()); menu = new OnScreenMenu(this); //menu.setPadding(extraOverscan); menu.setPrefWidth(256); menu.setPrefHeight(240); Group root = new Group(gameCanvas, menu); Scene scene = new Scene(root, bounds.getWidth(), bounds.getHeight(), Color.BLACK); stage.setScene(scene); //stage.setFullScreen(true); stage.setFullScreenExitKeyCombination(KeyCombination.valueOf("F11")); stage.addEventHandler(javafx.scene.input.KeyEvent.KEY_PRESSED, e -> { if (e.getCode().equals(KeyCode.ESCAPE)) { menu.show(); } }); root.setLayoutX(overscan.getRight() - overscan.getLeft() - extraOverscan.getLeft() * bounds.getWidth() / 256); root.setLayoutY(overscan.getBottom() - overscan.getTop() - extraOverscan.getTop() * bounds.getHeight() / 240); root.getTransforms().add(new Scale( (bounds.getWidth() - (overscan.getRight() - overscan.getLeft())) / (256 - extraOverscan.getLeft() - extraOverscan.getRight()), (bounds.getHeight() - (overscan.getBottom() - overscan.getTop())) / (240 - extraOverscan.getTop() - extraOverscan.getBottom()))); nes = new NES(this); ControllerImpl padController1 = new ControllerImpl(scene, 0); ControllerImpl padController2 = new ControllerImpl(scene, 1); padController1.startEventQueue(); padController2.startEventQueue(); nes.setControllers(padController1, padController2); final List<String> params = getParameters().getRaw(); new Thread(() -> { if (params.isEmpty()) { nes.run(); } else { nes.run(params.get(0)); } }, "Game Thread").start(); }