javafx.stage.WindowEvent Java Examples

The following examples show how to use javafx.stage.WindowEvent. 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: HelpBox.java    From scenic-view with GNU General Public License v3.0 7 votes vote down vote up
public HelpBox(final String title, final String url, final double x, final double y) {
    final BorderPane pane = new BorderPane();
    pane.setId(StageController.FX_CONNECTOR_BASE_ID + "HelpBox");
    pane.setPrefWidth(SCENE_WIDTH);
    pane.setPrefHeight(SCENE_HEIGHT);
    final ProgressWebView wview = new ProgressWebView();
    wview.setPrefHeight(SCENE_HEIGHT);
    wview.setPrefWidth(SCENE_WIDTH);
    wview.doLoad(url);
    pane.setCenter(wview);
    final Scene scene = new Scene(pane, SCENE_WIDTH, SCENE_HEIGHT); 
    stage = new Stage();
    stage.setTitle(title);
    stage.setScene(scene);
    stage.getIcons().add(HELP_ICON);
    stage.setOnCloseRequest(new EventHandler<WindowEvent>() {

        @Override public void handle(final WindowEvent arg0) {
            DisplayUtils.showWebView(false);
        }
    });
    stage.show();
}
 
Example #2
Source File: StudentDetailController.java    From Hostel-Management-System with MIT License 6 votes vote down vote up
@FXML
private void viewPayBillAction(ActionEvent event)
{
    MainProgramSceneController.mainTopAnchorPane.setEffect(new BoxBlur());
    billStage = new Stage();
    billStage.setOnCloseRequest(new EventHandler<WindowEvent>()
    {
        @Override
        public void handle(WindowEvent t)
        {
            MainProgramSceneController.mainTopAnchorPane.effectProperty().setValue(null);
        }
    });
    billStage.setTitle("View And Pay Due Bills");
    billStage.initModality(Modality.APPLICATION_MODAL);
    billStage.initStyle(StageStyle.UTILITY);
    billStage.setResizable(false);
    try
    {
        Parent passwordParent = FXMLLoader.load(getClass().getResource("viewPayBill.fxml"));
        billStage.setScene(new Scene(passwordParent));
        billStage.show();
    } catch (IOException ex)
    {
    }
}
 
Example #3
Source File: TrafficProfileDialogController.java    From trex-stateless-gui with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize current stage
 */
public void init() {
    currentStage = (Stage) profileViewWrapper.getScene().getWindow();

    currentStage.setOnShown(new EventHandler<WindowEvent>() {
        @Override
        public void handle(WindowEvent event) {
            currentStage.focusedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
                if (newValue && tableView.isStreamEditingWindowOpen()) {
                    Util.optimizeMemory();
                    loadStreamTable();
                    tableView.setStreamEditingWindowOpen(false);
                }
            });
        }
    });
}
 
Example #4
Source File: SideScroller.java    From Project-16x16 with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Called by Processing after settings().
 */
@Override
protected PSurface initSurface() {
	surface = (PSurfaceFX) super.initSurface();
	canvas = (Canvas) surface.getNative();
	canvas.widthProperty().unbind(); // used for scaling
	canvas.heightProperty().unbind(); // used for scaling
	scene = canvas.getScene();
	stage = (Stage) scene.getWindow();
	stage.setTitle("Project-16x16");
	stage.setResizable(false); // prevent abitrary user resize
	stage.setFullScreenExitHint(""); // disable fullscreen toggle hint
	stage.setFullScreenExitKeyCombination(KeyCombination.NO_MATCH); // prevent ESC toggling fullscreen
	scene.getWindow().addEventFilter(WindowEvent.WINDOW_CLOSE_REQUEST, this::closeWindowEvent);
	return surface;
}
 
Example #5
Source File: ExitRequestHandler.java    From VocabHunter with Apache License 2.0 6 votes vote down vote up
private boolean processCloseRequest(final WindowEvent e) {
    boolean isContinue = guiFileHandler.unsavedChangesCheck();

    if (isContinue) {
        WindowSettings windowSettings = new WindowSettings();

        windowSettings.setX(stage.getX());
        windowSettings.setY(stage.getY());
        windowSettings.setWidth(stage.getWidth());
        windowSettings.setHeight(stage.getHeight());
        model.getSessionModel().ifPresent(s -> saveSplitPositions(windowSettings, s));

        settingsManager.setWindowSettings(windowSettings);
    } else {
        e.consume();
    }

    return isContinue;
}
 
Example #6
Source File: OpcDaTrendController.java    From OEE-Designer with MIT License 6 votes vote down vote up
public SplitPane initializeTrend() throws Exception {
	if (trendChartController == null) {
		// Load the fxml file and create the anchor pane
		FXMLLoader loader = FXMLLoaderFactory.trendChartLoader();
		spTrendChart = (SplitPane) loader.getRoot();

		trendChartController = loader.getController();
		trendChartController.initialize(getApp());

		// data provider
		trendChartController.setProvider(this);

		setImages();

		getDialogStage().setOnCloseRequest((WindowEvent event1) -> {
			onDisconnect();
		});
	}
	return spTrendChart;
}
 
Example #7
Source File: PreferencesFxPresenter.java    From PreferencesFX with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void setupEventHandlers() {
  // As the scene is null here, listen to scene changes and make sure
  // that when the window is closed, the settings are saved beforehand.

  // NOTE: this only applies to the main stage. When opening PreferencesFX as a Node in a new
  // window, the implementor needs to take care that Settings are saved by themself!
  // This is intentional by design to ensure that if the implementor wants to make their own
  // PreferencesFX dialog to not override settings in case they are discarded.
  preferencesFxView.sceneProperty().addListener((observable, oldScene, newScene) -> {
    LOGGER.trace("new Scene: " + newScene);
    if (newScene != null && newScene.getWindow() != null) {
      LOGGER.trace("addEventHandler on Window close request to save settings");
      newScene.getWindow().addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, event -> {
        LOGGER.trace("saveSettings because of WINDOW_CLOSE_REQUEST");
        model.saveSettings();
      });
    }
  });
}
 
Example #8
Source File: FXStockChartWindow.java    From Rails with GNU General Public License v2.0 6 votes vote down vote up
@Override
public void start(Stage primaryStage) {
    // set the stock-chart window to hide, if it has been closed
    Platform.setImplicitExit(false);

    Scene scene = new Scene(new FXStockChart(gameUIManager));

    primaryStage.setTitle("Rails: Stock Chart");
    primaryStage.setScene(scene);

    // uncheck market checkbox in the menu if the stock-chart has been closed
    primaryStage.addEventFilter(WindowEvent.WINDOW_CLOSE_REQUEST, event -> {
        gameUIManager.uncheckMenuItemBox(StatusWindow.MARKET_CMD);
    });

    // TODO: save relocation and resizing information of the window

    stage = primaryStage;
}
 
Example #9
Source File: SingleImageCheck.java    From FakeImageDetection with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {
    Parent root = FXMLLoader.load(getClass().getResource("/resources/fxml/singleimage.fxml"));

    Scene scene = new Scene(root);

    stage.resizableProperty().setValue(false);
    stage.setTitle("Single Image Checker");
    stage.setScene(scene);
    stage.show();
    CommonUtil.attachIcon(stage);

    stage.setOnCloseRequest((WindowEvent event) -> {
        System.exit(0);
    });
}
 
Example #10
Source File: HideTaskBar.java    From oim-fx with MIT License 6 votes vote down vote up
@Override
public void start(final Stage stage) throws Exception {
	stage.initStyle(StageStyle.UTILITY);
	stage.setScene(new Scene(new Group(), 100, 100));
	stage.setX(0);
	stage.setY(Screen.getPrimary().getBounds().getHeight() + 100);
	stage.show();

	Stage app = new Stage();
	app.setScene(new Scene(new Group(), 300, 200));
	app.setTitle("JavaFX隐藏任务栏");
	app.initOwner(stage);
	app.initModality(Modality.APPLICATION_MODAL);
	app.setOnCloseRequest(new EventHandler<WindowEvent>() {
		@Override
		public void handle(WindowEvent event) {
			event.consume();
			stage.close();
		}
	});

	app.show();
}
 
Example #11
Source File: Main.java    From xJavaFxTool-spring with Apache License 2.0 6 votes vote down vote up
@Override
public void beforeInitialView(Stage stage, ConfigurableApplicationContext ctx) {
    super.beforeInitialView(stage, ctx);
    Scene scene = JavaFxViewUtil.getJFXDecoratorScene(stage, "", null, new AnchorPane());
    stage.setScene(scene);
    stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
        @Override
        public void handle(WindowEvent event) {
            if (AlertUtil.showConfirmAlert("确定要退出吗?")) {
                System.exit(0);
            } else {
                event.consume();
            }
        }
    });
    GUIState.setScene(scene);
    Platform.runLater(() -> {
        StageUtils.updateStageStyle(GUIState.getStage());
    });
}
 
Example #12
Source File: TrayDemo.java    From oim-fx with MIT License 6 votes vote down vote up
@Override
public void start(final Stage stage) throws Exception {
	enableTray(stage);

	GridPane grid = new GridPane();
	grid.setAlignment(Pos.CENTER);
	grid.setHgap(20);
	grid.setVgap(20);
	grid.setGridLinesVisible(true);
	grid.setPadding(new Insets(25, 25, 25, 25));

	Button b1 = new Button("测试1");
	Button b2 = new Button("测试2");
	grid.add(b1, 0, 0);
	grid.add(b2, 1, 1);

	Scene scene = new Scene(grid, 800, 600);
	stage.setScene(scene);
	stage.setOnCloseRequest(new EventHandler<WindowEvent>() {

		@Override
		public void handle(WindowEvent arg0) {
			stage.hide();
		}
	});
}
 
Example #13
Source File: HugoPane.java    From Lipi with MIT License 6 votes vote down vote up
@FXML
private void onLiveBlogServerToggle() {
    toggleLiveBlogServer();
    updateBlogServerToggleButton();

    TimedUpdaterUtil.callAfter(new CallbackVisitor() {
        @Override
        public void call() {
            if (!openBlogInBrowserButton.isDisabled() && !liveServerRunning) {
                updateBlogServerToggleButton();
                ExceptionAlerter.showException(new Exception("Hugo faced a catastrophic error \n" +
                        hugoServer.getHugoOut()));
            }
        }
    });

    this.getScene().getWindow().setOnCloseRequest(new EventHandler<WindowEvent>() {
        @Override
        public void handle(WindowEvent event) {
            stopLiveBlogServer();
        }
    });
}
 
Example #14
Source File: ActivityStage.java    From PeerWasp with MIT License 6 votes vote down vote up
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 #15
Source File: SettingsStage.java    From PeerWasp with MIT License 6 votes vote down vote up
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 #16
Source File: Main.java    From pattypan with MIT License 6 votes vote down vote up
@Override
public void start(Stage stage) {
  Image logo = new Image(getClass().getResourceAsStream("/pattypan/resources/logo.png"));

  Scene scene = new Scene(new StartPane(stage), Settings.getSettingInt("windowWidth"), Settings.getSettingInt("windowHeight"));
  stage.setResizable(true);
  stage.setTitle("pattypan " + Settings.VERSION);
  stage.getIcons().add(logo);
  stage.setScene(scene);
  stage.show();

  stage.setOnCloseRequest((WindowEvent we) -> {
    Settings.setSetting("windowWidth", (int) scene.getWidth() + "");
    Settings.setSetting("windowHeight", (int) scene.getHeight() + "");
    Settings.setSetting("version", Settings.VERSION);
    Settings.saveProperties();
  });
}
 
Example #17
Source File: PopOverWrapper.java    From pmd-designer with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * This is a weird hack to preload the FXML and CSS, so that the
 * first opening of the popover doesn't look completely broken
 * (twitching and obviously being restyled).
 *
 * <p>We show the popover briefly with opacity 0, just the time for its
 * content graph to load. When hidden the opacity is reset to 1.
 */
public void doFirstLoad(Stage stage) {
    myPopover.ifPresent(pop -> {
        pop.setOpacity(0);
        pop.setAnimated(false);
        pop.show(stage, 40000, 40000);

        EventStreams.eventsOf(pop, WindowEvent.WINDOW_HIDDEN)
                    .subscribeForOne(e -> pop.setOpacity(1));

        Platform.runLater(() -> {
            pop.hide();
            pop.setAnimated(true);
        });
    });
}
 
Example #18
Source File: MainProgramSceneController.java    From Hostel-Management-System with MIT License 6 votes vote down vote up
@FXML
private void activityLogButtonAction(ActionEvent event)
{
    mainTopAnchorPane.setEffect(new BoxBlur());
    passwordStage = new Stage();
    passwordStage.setOnCloseRequest(new EventHandler<WindowEvent>()
    {
        @Override
        public void handle(WindowEvent t)
        {
            mainTopAnchorPane.effectProperty().setValue(null);
        }
    });
    passwordStage.setTitle("Activity Log");
    passwordStage.initModality(Modality.APPLICATION_MODAL);
    passwordStage.initStyle(StageStyle.UTILITY);
    passwordStage.setResizable(false);
    try
    {
        Parent passwordParent = FXMLLoader.load(getClass().getResource("activityLog.fxml"));
        passwordStage.setScene(new Scene(passwordParent));
        passwordStage.show();
    } catch (IOException ex)
    {
    }
}
 
Example #19
Source File: ExitRequestHandler.java    From VocabHunter with Apache License 2.0 5 votes vote down vote up
public void handleExitRequest(final WindowEvent e) {
    if (model.isLocaleDefined() && statusManager.beginExit()) {
        try {
            if (processCloseRequest(e)) {
                statusManager.markSuccess();
            }
        } finally {
            statusManager.completeAction();
        }
    }
}
 
Example #20
Source File: CalcExpSeaAreaEditorController.java    From logbook-kai with MIT License 5 votes vote down vote up
@Override
protected void onWindowHidden(WindowEvent e) {
    AppSeaAreaExpCollection.get()
            .setList(this.table.getItems().stream()
                    .map(SeaAreaExpItem::toBean)
                    .collect(Collectors.toList()));
    this.apply.run();
}
 
Example #21
Source File: LaunchScreeenController.java    From FakeImageDetection with GNU General Public License v3.0 5 votes vote down vote up
@FXML
private void loadTrainer(ActionEvent event) throws Exception {
    TrainerMain trainer = new TrainerMain();
    Stage stage = new Stage();
    stage.initOwner(rootPane.getScene().getWindow());
    stage.initModality(Modality.APPLICATION_MODAL);
    trainer.start(stage);
    stage.setOnCloseRequest((WindowEvent event1) -> {
        event1.consume();
        stage.close();
    });
}
 
Example #22
Source File: JFXMenuShowListenerManager.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void handle(WindowEvent event) {
	if(!this.control.isIgnoreEvents()) {
		this.onMenuShow(new UIMenuEvent(this.control));
		
		event.consume();
	}
}
 
Example #23
Source File: FrameworkBase.java    From FxDock with Apache License 2.0 5 votes vote down vote up
protected void handleClose(FxDockWindow w, WindowEvent ev)
{
	if(getWindowCount() == 1)
	{
		saveLayout();
	}
	
	OnWindowClosing ch = new OnWindowClosing(false);
	w.confirmClosing(ch);
	if(ch.isCancelled())
	{
		// don't close the window
		ev.consume();
	}
}
 
Example #24
Source File: CloseWindowOnEscape.java    From erlyberly with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void handle(KeyEvent evt) {
    if (evt.getCode().equals(KeyCode.ESCAPE)) {
        EventHandler<WindowEvent> onCloseRequest = stage.getOnCloseRequest();
        if(onCloseRequest != null) {
            onCloseRequest.handle(null);
        }
        stage.close();
    }
}
 
Example #25
Source File: JFXMenuHideListenerManager.java    From tuxguitar with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void handle(WindowEvent event) {
	if(!this.control.isIgnoreEvents()) {
		this.onMenuHide(new UIMenuEvent(this.control));
		
		event.consume();
	}
}
 
Example #26
Source File: FXMLSetupHeadersController.java    From pikatimer with GNU General Public License v3.0 5 votes vote down vote up
public void cancelButtonAction(ActionEvent fxevent){
    // We will just kick off the onClose action below
    ((Node) fxevent.getSource()).getScene().getWindow().fireEvent(
        new WindowEvent((
                (Node) fxevent.getSource()).getScene().getWindow(),
                WindowEvent.WINDOW_CLOSE_REQUEST
        )
    );
}
 
Example #27
Source File: ConnectDialogController.java    From trex-stateless-gui with Apache License 2.0 5 votes vote down vote up
@Override
public void setupStage(final Stage stage) {
    super.setupStage(stage);
    stage.setOnCloseRequest((WindowEvent event) -> {
        if (isConnectionInProgress.get()) {
            event.consume();
        }
    });
}
 
Example #28
Source File: CustomizedTreeCell.java    From PeerWasp with MIT License 5 votes vote down vote up
private void showProperties(PathItem item) {
	try {
		FXMLLoader loader = new FXMLLoader();
		loader.setLocation(getClass().getResource(ViewNames.PROPERTIES_VIEW));
		loader.setController(new Properties(getItem()));

		Parent root = loader.load();

		// load UI on Application thread and show window
		Runnable showStage = new Runnable() {
			@Override
			public void run() {
				Scene scene = new Scene(root);
				stage = new Stage();
				stage.setTitle("Properties of "
						+ getItem().getPath().getFileName());
				stage.setScene(scene);
				stage.setOnCloseRequest(new EventHandler<WindowEvent>() {
					@Override
					public void handle(WindowEvent event) {
						stage = null;
					}
				});

				stage.show();
			}
		};

		if (Platform.isFxApplicationThread()) {
			showStage.run();
		} else {
			Platform.runLater(showStage);
		}
	} catch (IOException e) {
		logger.warn("Exception while showing properties.", e);
	}
}
 
Example #29
Source File: OpenLabelerController.java    From OpenLabeler with Apache License 2.0 5 votes vote down vote up
public void handleWindowEvent(WindowEvent event) {
    if (event.getEventType() == WindowEvent.WINDOW_SHOWN) {
        // Initial focus
        tagBoard.requestFocus();

        // Open last media file/folder
        if (Settings.isOpenLastMedia() && Settings.recentFilesProperty.size() > 0) {
            File fileOrDir = new File(Settings.recentFilesProperty.get(0));
            openFileOrDir(fileOrDir);
        }
    }
}
 
Example #30
Source File: BattleDetail.java    From logbook-kai with MIT License 5 votes vote down vote up
/**
 * ウインドウを閉じる時のアクション
 *
 * @param e WindowEvent
 */
@Override
protected void onWindowHidden(WindowEvent e) {
    if (this.timeline != null) {
        this.timeline.stop();
    }
}