Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
2.9 kB
1
Indexable
Never
package com.hcm.smartsheet.gui;

import javafx.application.Application;
import javafx.event.EventHandler;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.stage.Stage;
import javafx.stage.StageStyle;

import java.util.Objects;

public class MainApplication extends Application {

    private double xOffset = 0;
    private double yOffset = 0;

    @Override
    public void start(Stage stage) throws Exception {
        System.out.println(getClass().getResource("."));
        Parent root = FXMLLoader.load(Objects.requireNonNull(getClass().getClassLoader().getResource("fxml/MainApplication.fxml")));
        root.getStylesheets().add("css/styling.css");
        Scene scene = new Scene(root);
        //Scene scene = new Scene(new JFXDecorator(stage,root));
        stage.getIcons().add(new Image("graphics/Application-Icon-256.png"));
        stage.setTitle("Nexus");

        stage.initStyle(StageStyle.UNDECORATED);

        stage.setScene(scene);
        stage.show();

        root.setOnMousePressed(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                xOffset = event.getSceneX();
                yOffset = event.getSceneY();
            }
        });

        root.setOnMouseDragged(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent event) {
                if (stage.isFullScreen()) {}

                else {
                    stage.setX(event.getScreenX() - xOffset);
                    stage.setY(event.getScreenY() - yOffset);
                }
            }
        });

        root.setOnMouseClicked(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent mouseEvent) {
                MainController controller = new MainController();

                if (mouseEvent.getButton().equals(MouseButton.PRIMARY)) {
                    if (mouseEvent.getClickCount() == 2) {
                        if (stage.isFullScreen()) {
                            stage.setFullScreen(false);
                            controller.isRestoreIcon(false);
                        }

                        else {
                            stage.setFullScreenExitHint("");
                            stage.setFullScreen(true);
                            controller.isRestoreIcon(true);
                        }
                    }
                }
            }
        });
    }

    public static void main(String[] args) {
        System.setProperty("prism.lcdtext", "false");
        System.setProperty("prism.subpixeltext", "false");
        launch(args);
    }
}