Search in sources :

Example 1 with WindowEvent

use of javafx.stage.WindowEvent in project sakuli by ConSol.

the class UiTestApplication method run.

@Override
public void run() {
    Rectangle2D bounds = Screen.getPrimary().getVisualBounds();
    //create Login scene
    Scene loginScene = gotoLogin();
    width = bounds.getWidth();
    height = bounds.getHeight() * HEIGHT_PERCENTAGE;
    Stage stage = StageBuilder.create().x(0).y(0).width(width).height(height).title("Sakuli Login Sample").scene(loginScene).onCloseRequest(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent event) {
            LOGGER.info("PLATFORM exit!");
        }
    }).build();
    LOGGER.info("set width '{}' and height '{}'", width, height);
    start(stage);
}
Also used : WindowEvent(javafx.stage.WindowEvent) Rectangle2D(javafx.geometry.Rectangle2D) Stage(javafx.stage.Stage) EventHandler(javafx.event.EventHandler) Scene(javafx.scene.Scene)

Example 2 with WindowEvent

use of javafx.stage.WindowEvent in project Gargoyle by callakrsos.

the class DockNode method setFloating.

/**
	 * Whether the node is currently floating.
	 *
	 * @param floating Whether the node is currently floating.
	 * @param translation null The offset of the node after being set floating. Used for aligning it
	 *        with its layout bounds inside the dock pane when it becomes detached. Can be null
	 *        indicating no translation.
	 *
	 *
	 *        tansalation param value is value set (screenX,screenY)
	 */
public void setFloating(boolean floating, Point2D translation) {
    if (floating && !this.isFloating()) {
        // position the new stage relative to the old scene offset
        Point2D floatScene = this.localToScene(0, 0);
        Point2D floatScreen = this.localToScreen(0, 0);
        // setup window stage
        dockTitleBar.setVisible(this.isCustomTitleBar());
        dockTitleBar.setManaged(this.isCustomTitleBar());
        if (this.isDocked()) {
            this.undock();
        }
        stage = new Stage();
        stage.initStyle(stageStyle);
        stage.titleProperty().bind(titleProperty);
        if (dockPane != null && dockPane.getScene() != null && dockPane.getScene().getWindow() != null) {
            stage.initOwner(dockPane.getScene().getWindow());
        }
        if (null == stage.getOwner() && null != this.owner)
            stage.initOwner(this.owner);
        /* append close handler. 2017-05-29 by kyj.*/
        EventHandler<WindowEvent> closeHandler = ev -> {
            try {
                ObservableList<Node> childrenUnmodifiable = null;
                if (dockPane != null)
                    dockPane.getChildrenUnmodifiable();
                else
                    childrenUnmodifiable = FXCollections.observableArrayList(getContents());
                Consumer<Closeable> clo = n -> {
                    try {
                        n.close();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                };
                childrenUnmodifiable.stream().filter(n -> n instanceof Closeable).map(n -> (Closeable) n).forEach(clo);
            } catch (Exception e) {
                e.printStackTrace();
            }
        };
        //			stage.setOnCloseRequest(value);
        stage.addEventHandler(WindowEvent.WINDOW_CLOSE_REQUEST, closeHandler);
        // offset the new stage to cover exactly the area the dock was local to the scene
        // this is useful for when the user presses the + sign and we have no information
        // on where the mouse was clicked
        // the border pane allows the dock node to
        // have a drop shadow effect on the border
        // but also maintain the layout of contents
        // such as a tab that has no content
        borderPane = new BorderPane();
        borderPane.getStyleClass().add("dock-node-border");
        borderPane.setCenter(this);
        borderPane.applyCss();
        Scene scene = new Scene(borderPane);
        scene.getStylesheets().add(SkinManager.getInstance().getSkin());
        // apply the floating property so we can get its padding size
        // while it is floating to offset it by the drop shadow
        // this way it pops out above exactly where it was when docked
        this.floatingProperty.set(floating);
        this.applyCss();
        /*
			 * 2016-10-26 apply default value by kyj
			 * tanslation param value is empty , i call api that stage will be located center
			 */
        if (translation != null) {
            Point2D stagePosition = new Point2D(0, 0);
            if (this.isDecorated()) {
                Window owner = this.owner;
                if (null != owner)
                    stagePosition = floatScene.add(new Point2D(owner.getX(), owner.getY()));
                else
                    stagePosition = floatScene.add(new Point2D(0, 0));
            } else {
                if (floatScreen != null)
                    stagePosition = floatScreen;
            }
            if (translation != null) {
                stagePosition = stagePosition.add(translation);
            }
            //				Insets insetsDelta = borderPane.getInsets();
            stage.setX(/*stagePosition.getX() - insetsDelta.getLeft()*/
            translation.getX());
            stage.setY(/*stagePosition.getY() - insetsDelta.getTop()*/
            translation.getY());
        } else
            stage.centerOnScreen();
        if (stageStyle == StageStyle.TRANSPARENT) {
            scene.setFill(null);
        }
        stage.setResizable(this.isStageResizable());
        if (this.isStageResizable()) {
            stage.addEventFilter(MouseEvent.MOUSE_PRESSED, this);
            stage.addEventFilter(MouseEvent.MOUSE_MOVED, this);
            stage.addEventFilter(MouseEvent.MOUSE_DRAGGED, this);
        }
        // we want to set the client area size
        // without this it subtracts the native border sizes from the scene
        // size
        stage.sizeToScene();
        stage.setScene(scene);
        stage.show();
    } else if (!floating && this.isFloating()) {
        this.floatingProperty.set(floating);
        stage.removeEventFilter(MouseEvent.MOUSE_PRESSED, this);
        stage.removeEventFilter(MouseEvent.MOUSE_MOVED, this);
        stage.removeEventFilter(MouseEvent.MOUSE_DRAGGED, this);
        stage.close();
    }
}
Also used : EventHandler(javafx.event.EventHandler) StageStyle(javafx.stage.StageStyle) Scene(javafx.scene.Scene) PseudoClass(javafx.css.PseudoClass) SimpleStringProperty(javafx.beans.property.SimpleStringProperty) MouseEvent(javafx.scene.input.MouseEvent) FXCollections(javafx.collections.FXCollections) VBox(javafx.scene.layout.VBox) Insets(javafx.geometry.Insets) Point2D(javafx.geometry.Point2D) WindowEvent(javafx.stage.WindowEvent) ObjectProperty(javafx.beans.property.ObjectProperty) Rectangle2D(javafx.geometry.Rectangle2D) Node(javafx.scene.Node) Screen(javafx.stage.Screen) Consumer(java.util.function.Consumer) Cursor(javafx.scene.Cursor) Priority(javafx.scene.layout.Priority) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Stage(javafx.stage.Stage) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Closeable(java.io.Closeable) Window(javafx.stage.Window) SkinManager(com.kyj.fx.voeditor.visual.momory.SkinManager) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) StringProperty(javafx.beans.property.StringProperty) Window(javafx.stage.Window) BorderPane(javafx.scene.layout.BorderPane) Consumer(java.util.function.Consumer) Point2D(javafx.geometry.Point2D) ObservableList(javafx.collections.ObservableList) Closeable(java.io.Closeable) WindowEvent(javafx.stage.WindowEvent) Stage(javafx.stage.Stage) Scene(javafx.scene.Scene)

Example 3 with WindowEvent

use of javafx.stage.WindowEvent in project Gargoyle by callakrsos.

the class DateChooserExam method start.

@Override
public void start(final Stage primaryStage) {
    primaryStage.setTitle("Hello Calendar!");
    StackPane root = new StackPane();
    final DateChooser dateChooser = new DateChooser();
    root.getChildren().add(dateChooser);
    Scene scene = new Scene(root, 300, 250);
    primaryStage.setScene(scene);
    primaryStage.setOnHiding(new EventHandler<WindowEvent>() {

        public void handle(WindowEvent event) {
            System.out.println("date " + dateChooser.getDate());
        }
    });
    primaryStage.show();
}
Also used : WindowEvent(javafx.stage.WindowEvent) DateChooser(com.kyj.fx.voeditor.visual.component.date.DateChooser) Scene(javafx.scene.Scene) StackPane(javafx.scene.layout.StackPane)

Example 4 with WindowEvent

use of javafx.stage.WindowEvent in project trex-stateless-gui by cisco-system-traffic-generator.

the class ImportPcapWizardController method closeDialog.

/**
     * Close import dialog
     */
private void closeDialog() {
    Stage currentStage = (Stage) wizardViewContainer.getScene().getWindow();
    currentStage.fireEvent(new WindowEvent(currentStage, WindowEvent.WINDOW_CLOSE_REQUEST));
}
Also used : WindowEvent(javafx.stage.WindowEvent) Stage(javafx.stage.Stage)

Example 5 with WindowEvent

use of javafx.stage.WindowEvent in project trex-stateless-gui by cisco-system-traffic-generator.

the class MainViewController method initializeInlineComponent.

/**
     * Initialize in-line built component
     */
private void initializeInlineComponent() {
    updateBtn.setGraphic(new ImageView(new Image("/icons/apply.png")));
    newProfileBtn.setGraphic(new ImageView(new Image("/icons/add_profile.png")));
    stopUpdateBtn.setGraphic(new ImageView(new Image("/icons/stop_update.png")));
    devicesTreeArrowContainer.setImage(leftArrow);
    // mapped profiles enabling with property
    profileListBox.disableProperty().bind(disableProfileProperty);
    newProfileBtn.disableProperty().bind(disableProfileProperty);
    profileDetailLabel.disableProperty().bind(disableProfileProperty);
    profileListBox.getItems().clear();
    profileListBox.setItems(FXCollections.observableArrayList(getProfilesNameList()));
    profileListBox.valueProperty().addListener(new UpdateProfileListener<>(profileListBox.getSelectionModel()));
    updateProfileListProperty.bind(ProfileManager.getInstance().getUpdatedProperty());
    updateProfileListProperty.addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
        List<String> profiles = getProfilesNameList();
        profileListBox.setItems(FXCollections.observableArrayList(profiles));
        if (!profiles.contains(currentSelectedProfile)) {
            tableView.reset();
            profileDetailContainer.setVisible(false);
        }
    });
    tableView = new PacketTableView(230, this, true);
    profileTableViewContainer.getChildren().add(tableView);
    serverStatusIcon.setImage(new Image("/icons/offline.png"));
    // initialize right click menu
    rightClickPortMenu = new ContextMenu();
    addMenuItem(rightClickPortMenu, "Acquire", ContextMenuClickType.ACQUIRE, false);
    addMenuItem(rightClickPortMenu, "Force Acquire", ContextMenuClickType.FORCE_ACQUIRE, false);
    addMenuItem(rightClickPortMenu, "Release Acquire", ContextMenuClickType.RELEASE_ACQUIRE, false);
    rightClickProfileMenu = new ContextMenu();
    addMenuItem(rightClickProfileMenu, "Play", ContextMenuClickType.PLAY, false);
    addMenuItem(rightClickProfileMenu, "Pause", ContextMenuClickType.PAUSE, false);
    addMenuItem(rightClickProfileMenu, "Stop", ContextMenuClickType.STOP, false);
    rightClickGlobalMenu = new ContextMenu();
    addMenuItem(rightClickGlobalMenu, "Release All Ports", ContextMenuClickType.RELEASE_ALL, false);
    addMenuItem(rightClickGlobalMenu, "Acquire All Ports", ContextMenuClickType.ACQUIRE_ALL, false);
    addMenuItem(rightClickGlobalMenu, "Force Acquire All Ports", ContextMenuClickType.FORCE_ACQUIRE_ALL, false);
    addMenuItem(rightClickGlobalMenu, "Re-Acquire my Ports", ContextMenuClickType.ACQUIRE_MY_PORT, false);
    // initialize multiplexer
    multiplierView = new MultiplierView(this);
    multiplierOptionContainer.getChildren().add(multiplierView);
    notificationPanel = new NotificationPanel();
    notificationPanel.setNotificationMsg(DISABLED_MULTIPLIER_MSG);
    notificationPanelHolder.getChildren().add(notificationPanel);
    // add close
    TrexApp.getPrimaryStage().setOnCloseRequest(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent event) {
            // handle aplpication close
            DialogManager.getInstance().closeAll();
            handleAppClose();
        }
    });
    TrexApp.getPrimaryStage().setOnShown(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent event) {
            TrexApp.getPrimaryStage().focusedProperty().addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
                if (newValue && tableView.isStreamEditingWindowOpen()) {
                    tableView.setStreamEditingWindowOpen(false);
                    streamTableUpdated();
                }
            });
        }
    });
    TrexApp.getPrimaryStage().setOnCloseRequest(new EventHandler<WindowEvent>() {

        @Override
        public void handle(WindowEvent event) {
            System.exit(0);
        }
    });
    logContainer.getChildren().add(LogsController.getInstance().getView());
    consoleLogContainer.getChildren().add(LogsController.getInstance().getConsoleLogView());
    // initialize countdown service
    countdownService = new CountdownService();
    countdownService.setPeriod(Duration.seconds(Constants.REFRESH_ONE_INTERVAL_SECONDS));
    countdownService.setRestartOnFailure(false);
    countdownService.setOnSucceeded((WorkerStateEvent event) -> {
        int count = (int) event.getSource().getValue();
        countdownValue.setText(String.valueOf(count) + " Sec");
        if (count == 0) {
            doUpdateAssignedProfile(getSelectedPortIndex());
        }
    });
    devicesTree.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() {

        @Override
        public void changed(ObservableValue observable, Object oldValue, Object newValue) {
            handleTreeItemSelectionChanged();
        }
    });
}
Also used : ObservableValue(javafx.beans.value.ObservableValue) Image(javafx.scene.image.Image) NotificationPanel(com.exalttech.trex.ui.components.NotificationPanel) CountdownService(com.exalttech.trex.ui.views.services.CountdownService) WindowEvent(javafx.stage.WindowEvent) WorkerStateEvent(javafx.concurrent.WorkerStateEvent) ChangeListener(javafx.beans.value.ChangeListener) JsonObject(com.google.gson.JsonObject) ImageView(javafx.scene.image.ImageView)

Aggregations

WindowEvent (javafx.stage.WindowEvent)5 Scene (javafx.scene.Scene)3 Stage (javafx.stage.Stage)3 EventHandler (javafx.event.EventHandler)2 Rectangle2D (javafx.geometry.Rectangle2D)2 NotificationPanel (com.exalttech.trex.ui.components.NotificationPanel)1 CountdownService (com.exalttech.trex.ui.views.services.CountdownService)1 JsonObject (com.google.gson.JsonObject)1 DateChooser (com.kyj.fx.voeditor.visual.component.date.DateChooser)1 SkinManager (com.kyj.fx.voeditor.visual.momory.SkinManager)1 Closeable (java.io.Closeable)1 Consumer (java.util.function.Consumer)1 BooleanProperty (javafx.beans.property.BooleanProperty)1 ObjectProperty (javafx.beans.property.ObjectProperty)1 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)1 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)1 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)1 StringProperty (javafx.beans.property.StringProperty)1 ChangeListener (javafx.beans.value.ChangeListener)1 ObservableValue (javafx.beans.value.ObservableValue)1