| @@ -2,33 +2,110 @@ package de.uniluebeck.mi.projmi6; | |||
| import de.uniluebeck.mi.projmi6.controller.MainController; | |||
| import javafx.application.Application; | |||
| import javafx.concurrent.Task; | |||
| import javafx.fxml.FXMLLoader; | |||
| import javafx.geometry.Insets; | |||
| import javafx.geometry.Pos; | |||
| import javafx.scene.Parent; | |||
| import javafx.scene.Scene; | |||
| import javafx.scene.image.Image; | |||
| import javafx.scene.image.ImageView; | |||
| import javafx.scene.layout.Background; | |||
| import javafx.scene.layout.BackgroundFill; | |||
| import javafx.scene.layout.CornerRadii; | |||
| import javafx.scene.layout.VBox; | |||
| import javafx.scene.paint.Paint; | |||
| import javafx.scene.text.Font; | |||
| import javafx.scene.text.Text; | |||
| import javafx.stage.Stage; | |||
| import javafx.stage.StageStyle; | |||
| public class Main extends Application { | |||
| /** | |||
| * Cuz building the GUI from FXML is a bit costly, | |||
| * it's done from its own thread. | |||
| */ | |||
| private Task<Parent> loadMainWindowTask = new Task<Parent>(){ | |||
| @Override | |||
| protected Parent call() throws Exception { | |||
| FXMLLoader fxmlLoader = new FXMLLoader(); | |||
| fxmlLoader.setLocation(getClass().getClassLoader().getResource("main.fxml")); | |||
| MainController mainController = new MainController(); | |||
| fxmlLoader.setControllerFactory(mainController.getControllerFactory()); | |||
| Parent root = fxmlLoader.load(); | |||
| return root; | |||
| } | |||
| }; | |||
| /** | |||
| * The applications logo (an owl). | |||
| */ | |||
| private Image icon = new Image("icon.png", true); | |||
| @Override | |||
| public void start(Stage primaryStage) throws Exception { | |||
| public void start(Stage primaryStage) { | |||
| System.out.println(getClass().getClassLoader().getResource("").toExternalForm()); | |||
| FXMLLoader fxmlLoader = new FXMLLoader(); | |||
| fxmlLoader.setLocation(getClass().getClassLoader().getResource("main.fxml")); | |||
| primaryStage.getIcons().add(icon); | |||
| Stage loadingMessage = createLoadWindow(); | |||
| MainController mainController = new MainController(); | |||
| fxmlLoader.setControllerFactory(mainController.getControllerFactory()); | |||
| primaryStage.getIcons().add(new Image("icon.png")); | |||
| Parent root = fxmlLoader.load(); | |||
| loadMainWindowTask.setOnSucceeded(event -> { | |||
| Parent root = loadMainWindowTask.getValue(); | |||
| loadingMessage.close(); | |||
| primaryStage.setTitle("KIS Gruppe 06"); | |||
| primaryStage.setScene(new Scene(root, 1000, 800)); | |||
| primaryStage.show(); | |||
| }); | |||
| Thread thread = new Thread(loadMainWindowTask); | |||
| thread.setDaemon(true); | |||
| thread.start(); | |||
| primaryStage.setTitle("KIS Gruppe 06"); | |||
| primaryStage.setScene(new Scene(root, 1000, 800)); | |||
| primaryStage.show(); | |||
| } | |||
| /** | |||
| * Creates a small, undecorated stage for | |||
| * showing a splash-screen to the user. | |||
| * | |||
| * @return the splash screen | |||
| */ | |||
| public Stage createLoadWindow(){ | |||
| Text kis = new Text("KIS"); | |||
| kis.setFont(Font.font(50)); | |||
| Text gruppe6 = new Text("Gruppe 06"); | |||
| gruppe6.setFont(Font.font(20)); | |||
| VBox root = new VBox(gruppe6, new ImageView(icon), kis); | |||
| root.setSpacing(20); | |||
| root.setAlignment(Pos.CENTER); | |||
| Scene scene = new Scene(root, 400, 400); | |||
| Stage stage = new Stage(StageStyle.UNDECORATED); | |||
| stage.getIcons().add(icon); | |||
| root.setBackground(new Background(new BackgroundFill(Paint.valueOf("#0093D1"), CornerRadii.EMPTY, Insets.EMPTY))); | |||
| stage.setScene(scene); | |||
| stage.show(); | |||
| return stage; | |||
| } | |||
| /** | |||
| * Applications entry point. | |||
| * | |||
| * @param args Commandline parameters | |||
| */ | |||
| public static void main(String[] args) { | |||
| launch(args); | |||
| } | |||