Search in sources :

Example 11 with EventHandler

use of javafx.event.EventHandler in project Minesweeper3D by SethDamiani.

the class Main method createCube.

private void createCube(Group cubeGroup, Group gX, Group gY, Scene scene, Stage stage) {
    cubeGroup.setTranslateZ(-200);
    sideB.setTranslateX(200);
    sideB.setTranslateZ(200);
    sideB.setRotationAxis(new Point3D(0, 1, 0));
    sideB.setRotate(90);
    sideC.setTranslateZ(200);
    sideC.setTranslateX(-200);
    sideC.setRotationAxis(new Point3D(0, 1, 0));
    sideC.setRotate(90);
    sideD.setTranslateZ(400);
    sideE.setRotationAxis(new Point3D(1, 0, 0));
    sideE.setRotate(90);
    sideE.setTranslateY(200);
    sideE.setTranslateZ(200);
    sideF.setRotationAxis(new Point3D(1, 0, 0));
    sideF.setRotate(90);
    sideF.setTranslateY(-200);
    sideF.setTranslateZ(200);
    RotateTransition rightRotate = new RotateTransition(Duration.millis(10000), gY);
    rightRotate.setAxis(Rotate.Y_AXIS);
    rightRotate.setByAngle(-1000);
    rightRotate.setInterpolator(Interpolator.LINEAR);
    RotateTransition leftRotate = new RotateTransition(Duration.millis(10000), gY);
    leftRotate.setAxis(Rotate.Y_AXIS);
    leftRotate.setByAngle(1000);
    leftRotate.setInterpolator(Interpolator.LINEAR);
    RotateTransition upRotate = new RotateTransition(Duration.millis(10000), gX);
    upRotate.setAxis(Rotate.X_AXIS);
    upRotate.setByAngle(-1000);
    upRotate.setInterpolator(Interpolator.LINEAR);
    RotateTransition downRotate = new RotateTransition(Duration.millis(10000), gX);
    downRotate.setAxis(Rotate.X_AXIS);
    downRotate.setByAngle(1000);
    downRotate.setInterpolator(Interpolator.LINEAR);
    EventHandler<KeyEvent> KeyPressHandler = event -> {
        if (event.getCode() == KeyCode.ESCAPE) {
            timeTask.pause();
            stage.setScene(confirmExit);
        } else if (event.getCode() == KeyCode.D || event.getCode() == KeyCode.RIGHT)
            rightRotate.play();
        else if (event.getCode() == KeyCode.A || event.getCode() == KeyCode.LEFT)
            leftRotate.play();
        else if (event.getCode() == KeyCode.W || event.getCode() == KeyCode.UP)
            upRotate.play();
        else if (event.getCode() == KeyCode.S || event.getCode() == KeyCode.DOWN)
            downRotate.play();
    };
    scene.addEventHandler(KeyEvent.KEY_PRESSED, KeyPressHandler);
    EventHandler<KeyEvent> KeyReleaseHandler = event -> {
        if (event.getCode() == KeyCode.D || event.getCode() == KeyCode.RIGHT)
            rightRotate.stop();
        else if (event.getCode() == KeyCode.A || event.getCode() == KeyCode.LEFT)
            leftRotate.stop();
        else if (event.getCode() == KeyCode.W || event.getCode() == KeyCode.UP)
            upRotate.stop();
        else if (event.getCode() == KeyCode.S || event.getCode() == KeyCode.DOWN)
            downRotate.stop();
    };
    scene.addEventHandler(KeyEvent.KEY_RELEASED, KeyReleaseHandler);
}
Also used : EventHandler(javafx.event.EventHandler) FontWeight(javafx.scene.text.FontWeight) Scene(javafx.scene.Scene) MouseButton(javafx.scene.input.MouseButton) java.util(java.util) Point3D(javafx.geometry.Point3D) javafx.scene.control(javafx.scene.control) Rotate(javafx.scene.transform.Rotate) MouseEvent(javafx.scene.input.MouseEvent) FXCollections(javafx.collections.FXCollections) TextFieldTableCell(javafx.scene.control.cell.TextFieldTableCell) Application(javafx.application.Application) TextAlignment(javafx.scene.text.TextAlignment) RotateTransition(javafx.animation.RotateTransition) PrintWriter(java.io.PrintWriter) KeyCode(javafx.scene.input.KeyCode) HBox(javafx.scene.layout.HBox) Color(javafx.scene.paint.Color) KeyFrame(javafx.animation.KeyFrame) PropertyValueFactory(javafx.scene.control.cell.PropertyValueFactory) Font(javafx.scene.text.Font) FileWriter(java.io.FileWriter) Timeline(javafx.animation.Timeline) ImagePattern(javafx.scene.paint.ImagePattern) Rectangle(javafx.scene.shape.Rectangle) IOException(java.io.IOException) KeyEvent(javafx.scene.input.KeyEvent) Group(javafx.scene.Group) File(java.io.File) Text(javafx.scene.text.Text) Duration(javafx.util.Duration) Interpolator(javafx.animation.Interpolator) Stage(javafx.stage.Stage) ObservableList(javafx.collections.ObservableList) Image(javafx.scene.image.Image) KeyEvent(javafx.scene.input.KeyEvent) Point3D(javafx.geometry.Point3D) RotateTransition(javafx.animation.RotateTransition)

Example 12 with EventHandler

use of javafx.event.EventHandler 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)

Aggregations

EventHandler (javafx.event.EventHandler)12 MouseEvent (javafx.scene.input.MouseEvent)7 KeyFrame (javafx.animation.KeyFrame)6 Timeline (javafx.animation.Timeline)6 FXCollections (javafx.collections.FXCollections)6 ObservableList (javafx.collections.ObservableList)6 ActionEvent (javafx.event.ActionEvent)5 Scene (javafx.scene.Scene)5 Duration (javafx.util.Duration)5 KeyValue (javafx.animation.KeyValue)4 Color (javafx.scene.paint.Color)4 Rectangle (javafx.scene.shape.Rectangle)4 Rotate (javafx.scene.transform.Rotate)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 ObjectProperty (javafx.beans.property.ObjectProperty)3 Insets (javafx.geometry.Insets)3 Pos (javafx.geometry.Pos)3 Button (javafx.scene.control.Button)3 Label (javafx.scene.control.Label)3