Java Code Examples for javafx.scene.Scene#setOnKeyReleased()

The following examples show how to use javafx.scene.Scene#setOnKeyReleased() . 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: EventHandler.java    From Aidos with GNU General Public License v3.0 8 votes vote down vote up
public static void attachEventHandlers(Scene s){
    keyReleaseHanlder krh = new keyReleaseHanlder();
    keyPressedHandler kph = new keyPressedHandler();
    s.setOnKeyReleased(krh);
    s.setOnKeyPressed(kph);
}
 
Example 2
Source File: Main.java    From FXTutorials with MIT License 8 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
    Scene scene = new Scene(appRoot);
    scene.setOnKeyPressed(event -> keys.put(event.getCode(), true));
    scene.setOnKeyReleased(event -> keys.put(event.getCode(), false));
    primaryStage.setTitle("Tutorial 14 Platformer");
    primaryStage.setScene(scene);
    primaryStage.show();

    AnimationTimer timer = new AnimationTimer() {
        @Override
        public void handle(long now) {
            update();
        }
    };
    timer.start();
}
 
Example 3
Source File: LogStage.java    From pdfsam with GNU Affero General Public License v3.0 8 votes vote down vote up
@Inject
public LogStage(LogPane logPane, LogListView logView, List<Image> logos, StylesConfig styles) {
    BorderPane containerPane = new BorderPane();
    containerPane.getStyleClass().addAll(Style.CONTAINER.css());
    containerPane.setCenter(logPane);
    containerPane.setBottom(new ClosePane((a) -> eventStudio().broadcast(HideStageRequest.INSTANCE, "LogStage")));
    Scene scene = new Scene(containerPane);
    scene.getStylesheets().addAll(styles.styles());
    scene.setOnKeyReleased(k -> {
        if (this.isShowing() && new KeyCodeCombination(KeyCode.ESCAPE).match(k)) {
            eventStudio().broadcast(HideStageRequest.INSTANCE, "LogStage");
        }
    });
    setScene(scene);
    setTitle(DefaultI18nContext.getInstance().i18n("Log register"));
    getIcons().addAll(logos);
    setMaximized(true);
    eventStudio().addAnnotatedListeners(this);
    this.onShowingProperty().addListener((o, oldVal, newVal) -> logView.scrollToBottomIfShowing());
    eventStudio().add(logView, LOGSTAGE_EVENTSTATION);
}
 
Example 4
Source File: Window.java    From mcaselector with MIT License 7 votes vote down vote up
@Override
public void start(Stage primaryStage) {
	try {
		primaryStage.setTitle("MCA Selector " + FileHelper.getManifestAttributes().getValue("Application-Version"));
	} catch (IOException ex) {
		primaryStage.setTitle("MCA Selector - dev");
	}
	primaryStage.getIcons().add(FileHelper.getIconFromResources("img/icon"));

	TileMap tileMap = new TileMap(this, width, height);

	BorderPane pane = new BorderPane();

	//menu bar
	OptionBar optionBar = new OptionBar(tileMap, primaryStage);
	pane.setTop(optionBar);

	//tilemap
	TileMapBox tileMapBox = new TileMapBox(tileMap, primaryStage);
	pane.setCenter(tileMapBox);

	//status bar
	pane.setBottom(new StatusBar(tileMap));

	Scene scene = new Scene(pane, width, height);

	URL cssRes = Window.class.getClassLoader().getResource("style.css");
	if (cssRes != null) {
		String styleSheet = cssRes.toExternalForm();
		scene.getStylesheets().add(styleSheet);
	}

	scene.setOnKeyPressed(e -> pressedKeys.add(e.getCode()));
	scene.setOnKeyReleased(e -> pressedKeys.remove(e.getCode()));

	primaryStage.setOnCloseRequest(e -> System.exit(0));
	primaryStage.setScene(scene);
	primaryStage.show();
}
 
Example 5
Source File: ADCWindow.java    From arma-dialog-creator with MIT License 7 votes vote down vote up
public void initialize() {
	preInit = false;
	rootElement = new VBox();
	Scene scene = stage.getScene();
	scene.setRoot(rootElement);

	FXUtil.runWhenVisible(rootElement, new Runnable() {
		@Override
		public void run() {
			canvasView = new ADCCanvasView();
			mainMenuBar = new ADCMenuBar();

			rootElement.getChildren().addAll(mainMenuBar, canvasView);

			//force canvas to render at proper size
			autoResizeCanvasView();
		}
	});


	EventHandler<KeyEvent> keyEvent = new EventHandler<KeyEvent>() {
		@Override
		public void handle(KeyEvent event) {
			canvasView.keyEvent(event.getText(), event.getEventType() == KeyEvent.KEY_PRESSED, event.isShiftDown(), event.isControlDown(), event.isAltDown());
		}
	};
	scene.setOnKeyPressed(keyEvent);
	scene.setOnKeyReleased(keyEvent);
	scene.getMnemonics().clear();

}
 
Example 6
Source File: DrawingApp.java    From FXTutorials with MIT License 7 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {
    Scene scene = new Scene(createContent());
    scene.setOnKeyReleased(e -> {
        if (e.getCode() == KeyCode.ENTER) {
            saveScreenshot(scene);
        }
    });

    stage.setScene(scene);
    stage.show();
}
 
Example 7
Source File: Main.java    From FXTutorials with MIT License 7 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
    Scene scene = new Scene(createContent());
    scene.setOnKeyPressed(event -> {
        switch (event.getCode()) {
            case A:
                action = UserAction.LEFT;
                break;
            case D:
                action = UserAction.RIGHT;
                break;
        }
    });

    scene.setOnKeyReleased(event -> {
        switch (event.getCode()) {
            case A:
                action = UserAction.NONE;
                break;
            case D:
                action = UserAction.NONE;
                break;
        }
    });

    primaryStage.setTitle("Tutorial");
    primaryStage.setScene(scene);
    primaryStage.show();
    startGame();
}
 
Example 8
Source File: Main.java    From FXTutorials with MIT License 7 votes vote down vote up
@Override
public void start(Stage primaryStage) throws Exception {
    initContent();

    Scene scene = new Scene(appRoot);
    scene.setOnKeyPressed(event -> keys.put(event.getCode(), true));
    scene.setOnKeyReleased(event -> keys.put(event.getCode(), false));
    primaryStage.setTitle("Tutorial 14 Platformer");
    primaryStage.setScene(scene);
    primaryStage.show();

    AnimationTimer timer = new AnimationTimer() {
        @Override
        public void handle(long now) {
            if (running) {
                update();
            }

            if (dialogEvent) {
                dialogEvent = false;
                keys.keySet().forEach(key -> keys.put(key, false));

                GameDialog dialog = new GameDialog();
                dialog.setOnCloseRequest(event -> {
                    if (dialog.isCorrect()) {
                        System.out.println("Correct");
                    }
                    else {
                        System.out.println("Wrong");
                    }

                    running = true;
                });
                dialog.open();
            }
        }
    };
    timer.start();
}
 
Example 9
Source File: InfoStage.java    From pdfsam with GNU Affero General Public License v3.0 7 votes vote down vote up
@Inject
public InfoStage(InfoPane infoPane, List<Image> logos, StylesConfig styles) {
    BorderPane containerPane = new BorderPane();
    containerPane.getStyleClass().addAll(Style.CONTAINER.css());
    containerPane.setCenter(infoPane);
    containerPane.setBottom(new ClosePane());
    Scene scene = new Scene(containerPane);
    scene.getStylesheets().addAll(styles.styles());
    scene.setOnKeyReleased(new HideOnEscapeHandler(this));
    setScene(scene);
    setTitle(DefaultI18nContext.getInstance().i18n("Document details"));
    getIcons().addAll(logos);
    setMaximized(true);
}
 
Example 10
Source File: OpenWithDialog.java    From pdfsam with GNU Affero General Public License v3.0 7 votes vote down vote up
@Inject
public OpenWithDialog(StylesConfig styles, List<Module> modules) {
    initModality(Modality.WINDOW_MODAL);
    initStyle(StageStyle.UTILITY);
    setResizable(false);
    setTitle(DefaultI18nContext.getInstance().i18n("Open with"));

    this.modules = modules.stream().sorted(comparing(m -> m.descriptor().getName())).collect(toList());

    messageTitle.getStyleClass().add("-pdfsam-open-with-dialog-title");

    BorderPane containerPane = new BorderPane();
    containerPane.getStyleClass().addAll(Style.CONTAINER.css());
    containerPane.getStyleClass().addAll("-pdfsam-open-with-dialog", "-pdfsam-open-with-container");
    containerPane.setTop(messageTitle);
    BorderPane.setAlignment(messageTitle, Pos.TOP_CENTER);

    filesList.setPrefHeight(150);
    containerPane.setCenter(filesList);

    buttons.getStyleClass().addAll(Style.CONTAINER.css());
    containerPane.setBottom(buttons);
    BorderPane.setAlignment(buttons, Pos.CENTER);

    Scene scene = new Scene(containerPane);
    scene.getStylesheets().addAll(styles.styles());
    scene.setOnKeyReleased(new HideOnEscapeHandler(this));
    setScene(scene);
    eventStudio().addAnnotatedListeners(this);
}
 
Example 11
Source File: ConfKeybinding.java    From Recaf with MIT License 4 votes vote down vote up
/**
 * Register window-level keybinds.
 *
 * @param controller
 * 		Controller to call actions on.
 * @param stage
 * 		Window to register keys on.
 * @param scene
 * 		Scene in the window.
 */
public void registerWindowKeys(GuiController controller, Stage stage, Scene scene) {
	scene.setOnKeyReleased(e -> handleWindowKeyEvents(e, controller, stage, false));
}
 
Example 12
Source File: ConfKeybinding.java    From Recaf with MIT License 4 votes vote down vote up
/**
 * Register window-level keybinds.
 *
 * @param controller
 * 		Controller to call actions on.
 * @param stage
 * 		Window to register keys on.
 * @param scene
 * 		Scene in the window.
 */
public void registerMainWindowKeys(GuiController controller, Stage stage, Scene scene) {
	scene.setOnKeyReleased(e -> handleWindowKeyEvents(e, controller, stage, true));
}