Add main page

This commit is contained in:
Mateusz Kowalczyk 2020-01-05 20:10:44 +01:00
parent 49c7465f07
commit 1067221cfe
10 changed files with 114 additions and 23 deletions

View File

@ -1,5 +1,6 @@
package dev.mateuszkowalczyk.ffm;
import dev.mateuszkowalczyk.ffm.view.SceneEnum;
import dev.mateuszkowalczyk.ffm.view.StageController;
import javafx.application.Application;
import javafx.stage.Stage;
@ -8,6 +9,8 @@ public class Main extends Application {
@Override
public void start(Stage stage) throws Exception{
var test = SceneEnum.WelcomePage;
StageController.getInstance().initApp(stage);
}

View File

@ -3,15 +3,33 @@ package dev.mateuszkowalczyk.ffm.app;
import dev.mateuszkowalczyk.ffm.data.Chooser;
import dev.mateuszkowalczyk.ffm.utils.PropertiesLoader;
import dev.mateuszkowalczyk.ffm.utils.Property;
import dev.mateuszkowalczyk.ffm.view.SceneEnum;
import dev.mateuszkowalczyk.ffm.view.StageController;
import java.util.Properties;
import java.io.IOException;
public class WorkspaceService {
private static final WorkspaceService instance = new WorkspaceService();
private PropertiesLoader propertiesLoader = new PropertiesLoader();
private WorkspaceService(){}
public static WorkspaceService getInstance() {
return instance;
}
public void setupWorkspace() {
Chooser chooser = new Chooser();
String path = chooser.chooseDirectory();
this.propertiesLoader.set(Property.PATH_TO_DIRECTORY, path);
try {
StageController.getInstance().setScene(SceneEnum.MainPage);
} catch (IOException e) {
e.printStackTrace();
}
}
public void refreshWorkspace() {
System.out.println("Refreshing workspace");
}
}

View File

@ -0,0 +1,16 @@
package dev.mateuszkowalczyk.ffm.view;
public enum SceneEnum {
MainPage("templates/workspace/main_page.fxml"),
WelcomePage("templates/workspace/welcome_page.fxml");
private String path;
SceneEnum(String path) {
this.path = path;
}
public String getPath() {
return path;
}
}

View File

@ -31,15 +31,20 @@ public class StageController {
this.stage = stage;
this.stage.setTitle("Friend Face Matcher");
URL sceneUrl;
if (this.propertiesLoader.get(Property.PATH_TO_DIRECTORY) != null) {
sceneUrl = this.resourceLoader.getResource("welcomePage.fxml");
this.setScene(SceneEnum.MainPage);
} else {
sceneUrl = this.resourceLoader.getResource("welcomePage.fxml");
this.setScene(SceneEnum.WelcomePage);
}
Scene scene = new Scene(FXMLLoader.load(sceneUrl));
this.stage.setScene(scene);
this.stage.show();
}
public void setScene(SceneEnum sceneEnum) throws IOException {
URL sceneUrl = this.resourceLoader.getResource(sceneEnum.getPath());
Scene scene = new Scene(FXMLLoader.load(sceneUrl));
this.stage.setScene(scene);
}
}

View File

@ -1,16 +0,0 @@
package dev.mateuszkowalczyk.ffm.view.controller;
import dev.mateuszkowalczyk.ffm.app.WorkspaceService;
import javafx.fxml.FXML;
public class WelcomePageController {
public WelcomePageController() {
System.out.println("Controller work");
}
@FXML
public void startNewApp(){
var workspaceService = new WorkspaceService();
workspaceService.setupWorkspace();
}
}

View File

@ -0,0 +1,10 @@
package dev.mateuszkowalczyk.ffm.view.workspace;
import dev.mateuszkowalczyk.ffm.app.WorkspaceService;
public class MainPageController {
public MainPageController() {
WorkspaceService.getInstance().refreshWorkspace();
}
}

View File

@ -0,0 +1,13 @@
package dev.mateuszkowalczyk.ffm.view.workspace;
import dev.mateuszkowalczyk.ffm.app.WorkspaceService;
import javafx.fxml.FXML;
public class WelcomePageController {
public WelcomePageController() { }
@FXML
public void startNewApp(){
WorkspaceService.getInstance().setupWorkspace();
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 139 B

View File

@ -0,0 +1,42 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.geometry.Insets?>
<?import javafx.geometry.Rectangle2D?>
<?import javafx.scene.control.Button?>
<?import javafx.scene.control.ScrollPane?>
<?import javafx.scene.image.Image?>
<?import javafx.scene.image.ImageView?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.VBox?>
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="800.0" prefWidth="1200.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="dev.mateuszkowalczyk.ffm.view.workspace.MainPageController">
<left>
<VBox prefHeight="400.0" prefWidth="50.0" BorderPane.alignment="CENTER">
<children>
<Button mnemonicParsing="false" prefWidth="50.0" style="-fx-background-color: trasparent;">
<graphic>
<ImageView fitHeight="20.0" fitWidth="20.0">
<image>
<Image url="@../../icons/dashboard.png" />
</image>
<viewport>
<Rectangle2D />
</viewport>
</ImageView>
</graphic>
</Button>
</children>
<BorderPane.margin>
<Insets top="20.0" />
</BorderPane.margin>
</VBox>
</left>
<center>
<ScrollPane prefHeight="200.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<content>
<VBox prefWidth="200.0" />
</content>
</ScrollPane>
</center>
</BorderPane>

View File

@ -6,7 +6,7 @@
<?import javafx.scene.layout.VBox?>
<?import javafx.scene.text.Font?>
<VBox prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="dev.mateuszkowalczyk.ffm.view.controller.WelcomePageController">
<VBox prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="dev.mateuszkowalczyk.ffm.view.workspace.WelcomePageController">
<children>
<AnchorPane maxHeight="-1.0" maxWidth="-1.0" prefHeight="-1.0" prefWidth="-1.0" VBox.vgrow="ALWAYS">
<children>