Skip to content
This repository has been archived by the owner on Oct 21, 2024. It is now read-only.

Commit

Permalink
Initial: JavaFX
Browse files Browse the repository at this point in the history
Copied javafx-spring project.
  • Loading branch information
MarioCodes committed Nov 28, 2017
1 parent 0f5064c commit c423fef
Show file tree
Hide file tree
Showing 10 changed files with 333 additions and 0 deletions.
94 changes: 94 additions & 0 deletions javafx-spring/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>es.implementations.frameworks</groupId>
<artifactId>JavaFx-Spring</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>JavaFx-Spring</name>
<description>Implementation of JavaFX with Spring IoC</description>
<packaging>jar</packaging>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>

<plugin> <!-- Plugin for fat-jar build -->
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>impl.javafx.launcher.Starter</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<!-- Normal Dependencies -->

<!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.16</version>
<scope>provided</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.11.RELEASE</version>
</dependency>

<!-- Test Dependencies -->

<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.assertj/assertj-core -->
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.8.0</version>
<scope>test</scope>
</dependency>

<!-- https://mvnrepository.com/artifact/org.mockito/mockito-core -->
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.10.0</version>
<scope>test</scope>
</dependency>



</dependencies>
</project>
21 changes: 21 additions & 0 deletions javafx-spring/src/main/java/impl/javafx/config/Files.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package impl.javafx.config;

import lombok.AllArgsConstructor;

@AllArgsConstructor
public enum Files {
PATH_MAIN("fxml/main/"),
PATH_OVERVIEWS("fxml/overviews/"),

ROOT_LAYOUT(PATH_MAIN + "RootLayout.fxml"),
DASHBOARD_OVERVIEW(PATH_MAIN + "DefaultOverview.fxml"),

SECOND_OVERVIEW(PATH_OVERVIEWS + "SecondOverview.fxml");

private final String address;

@Override
public String toString() {
return this.address;
}
}
23 changes: 23 additions & 0 deletions javafx-spring/src/main/java/impl/javafx/config/SpringConfig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package impl.javafx.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;

import javafx.fxml.FXMLLoader;

/**
*
* @author msanchez
*
*/
@Configuration
@ComponentScan("impl.javafx.controllers.**")
public class SpringConfig {
@Bean
@Scope("prototype")
FXMLLoader fxmlLoader() {
return new FXMLLoader();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package impl.javafx.controllers.overviews;

import org.springframework.stereotype.Component;

import impl.javafx.launcher.Starter;
import javafx.fxml.FXML;
import lombok.Setter;

@Component
public class ControllerOverview {
@Setter
private Starter starter;

@FXML
private void prepareDashboard() {
this.starter.prepareDashboard();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package impl.javafx.controllers.root;

import org.springframework.stereotype.Component;

import impl.javafx.launcher.Starter;
import javafx.fxml.FXML;
import lombok.Setter;

@Component
public class ControllerDashboard {
@Setter
private Starter starter;

@FXML
private void prepareSecondOverview() {
this.starter.prepareSecondOverview();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package impl.javafx.controllers.root;

import org.springframework.stereotype.Component;

import impl.javafx.launcher.Starter;
import javafx.fxml.FXML;
import lombok.Setter;

@Component
public class ControllerRoot {
@Setter
private Starter starter;

@FXML
private void shutdown() {
System.exit(0);
}
}
99 changes: 99 additions & 0 deletions javafx-spring/src/main/java/impl/javafx/launcher/Starter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
package impl.javafx.launcher;

import java.io.IOException;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

import impl.javafx.config.Files;
import impl.javafx.config.SpringConfig;
import impl.javafx.controllers.overviews.ControllerOverview;
import impl.javafx.controllers.root.ControllerDashboard;
import impl.javafx.controllers.root.ControllerRoot;
import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import javafx.stage.Stage;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class Starter extends Application {
private BorderPane rootLayout;

private FXMLLoader fxmlLoader;

@Override
public void start(final Stage primaryStage) throws Exception {
loadRoot(primaryStage);
prepareDashboard();
}

public void prepareDashboard() {
this.prepareFxmlLoader(Files.DASHBOARD_OVERVIEW.toString());
final AnchorPane root = this.prepareAnchorPane();
this.rootLayout.setCenter(root);
this.setControllerDashboard();
}

public void prepareSecondOverview() {
this.prepareFxmlLoader(Files.SECOND_OVERVIEW.toString());
final AnchorPane root = this.prepareAnchorPane();
this.rootLayout.setCenter(root);

ControllerOverview overview = this.fxmlLoader.getController();
overview.setStarter(this);
}

private void loadRoot(Stage primaryStage) {
prepareFxmlLoader(Files.ROOT_LAYOUT.toString());
prepareRootLayout();
manipulateScene(primaryStage);
setControllerRoot();
}

private AnchorPane prepareAnchorPane() {
try {
final AnchorPane root = this.fxmlLoader.load();
return root;
} catch (final IOException ex) {
ex.printStackTrace();
}
return null;
}

private void setControllerDashboard() {
final ControllerDashboard dashboard = this.fxmlLoader.getController();
dashboard.setStarter(this);
}

private void prepareFxmlLoader(final String fxmlPath) {
final ApplicationContext context = new AnnotationConfigApplicationContext(
SpringConfig.class);
this.fxmlLoader = context.getBean(FXMLLoader.class);
this.fxmlLoader.setControllerFactory(context::getBean);
this.fxmlLoader.setLocation(getClass().getClassLoader().getResource(fxmlPath));
}

private void prepareRootLayout() {
try {
this.rootLayout = this.fxmlLoader.load();
} catch (final IOException ex) {
ex.printStackTrace();
}
}

private void manipulateScene(final Stage primaryStage) {
final Scene scene = new Scene(this.rootLayout);
primaryStage.setScene(scene);
primaryStage.show();
}

private void setControllerRoot() {
final ControllerRoot root = this.fxmlLoader.getController();
root.setStarter(this);
}
}
13 changes: 13 additions & 0 deletions javafx-spring/src/main/resources/fxml/main/DefaultOverview.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="440.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="impl.javafx.controllers.root.ControllerDashboard">
<children>
<Button layoutX="323.0" layoutY="396.0" mnemonicParsing="false" onAction="#prepareSecondOverview" text="To Second Overview" />
<Label layoutX="326.0" layoutY="232.0" text="First Default Overview" />
</children>
</AnchorPane>
16 changes: 16 additions & 0 deletions javafx-spring/src/main/resources/fxml/main/RootLayout.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.BorderPane?>

<BorderPane prefHeight="480.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="impl.javafx.controllers.root.ControllerRoot">
<top>
<ToolBar prefHeight="40.0" prefWidth="200.0" BorderPane.alignment="CENTER">
<items>
<Button mnemonicParsing="false" onAction="#shutdown" text="Close" />
</items>
</ToolBar>
</top>
</BorderPane>
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.AnchorPane?>

<AnchorPane prefHeight="440.0" prefWidth="800.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="impl.javafx.controllers.overviews.ControllerOverview">
<children>
<Button layoutX="354.0" layoutY="392.0" mnemonicParsing="false" onAction="#prepareDashboard" text="To Dashboard" />
<Label layoutX="349.0" layoutY="208.0" text="Second Overview" />
</children>
</AnchorPane>

0 comments on commit c423fef

Please sign in to comment.