Skip to content

Commit

Permalink
Fixes #229 - Add desktop module
Browse files Browse the repository at this point in the history
  • Loading branch information
mnriem committed Dec 18, 2023
1 parent ffa145d commit 9d91d62
Show file tree
Hide file tree
Showing 8 changed files with 458 additions and 137 deletions.
88 changes: 88 additions & 0 deletions desktop/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8"?>
<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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>project</artifactId>
<groupId>com.manorrock.sphynx</groupId>
<version>23.1.0-SNAPSHOT</version>
</parent>
<groupId>com.manorrock.sphynx</groupId>
<artifactId>desktop</artifactId>
<version>23.1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>21</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>21</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.4</version>
<configuration>
<mainClass>com.manorrock.sphynx.desktop.App</mainClass>
</configuration>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
</execution>
<execution>
<!-- Configuration for manual attach debugging -->
<!-- Usage: mvn clean javafx:run@debug -->
<id>debug</id>
<configuration>
<options>
<option>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:8000</option>
</options>
</configuration>
</execution>
<execution>
<!-- Configuration for automatic IDE debugging -->
<id>ide-debug</id>
<configuration>
<options>
<option>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</option>
</options>
</configuration>
</execution>
<execution>
<!-- Configuration for automatic IDE profiling -->
<id>ide-profile</id>
<configuration>
<options>
<option>${profiler.jvmargs.arg1}</option>
<option>${profiler.jvmargs.arg2}</option>
<option>${profiler.jvmargs.arg3}</option>
<option>${profiler.jvmargs.arg4}</option>
<option>${profiler.jvmargs.arg5}</option>
</options>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
38 changes: 38 additions & 0 deletions desktop/src/main/java/com/manorrock/sphynx/desktop/App.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.manorrock.sphynx.desktop;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.stage.Stage;

import java.io.IOException;

/**
* JavaFX App
*/
public class App extends Application {

private static Scene scene;

@Override
public void start(Stage stage) throws IOException {
scene = new Scene(loadFXML("primary"), 640, 480);
stage.setScene(scene);
stage.show();
}

static void setRoot(String fxml) throws IOException {
scene.setRoot(loadFXML(fxml));
}

private static Parent loadFXML(String fxml) throws IOException {
FXMLLoader fxmlLoader = new FXMLLoader(App.class.getResource(fxml + ".fxml"));
return fxmlLoader.load();
}

public static void main(String[] args) {
launch();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.manorrock.sphynx.desktop;

import java.io.IOException;
import javafx.fxml.FXML;

public class PrimaryController {

@FXML
private void switchToSecondary() throws IOException {
App.setRoot("secondary");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.manorrock.sphynx.desktop;

import java.io.IOException;
import javafx.fxml.FXML;

public class SecondaryController {

@FXML
private void switchToPrimary() throws IOException {
App.setRoot("primary");
}
}
7 changes: 7 additions & 0 deletions desktop/src/main/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module com.manorrock.sphynx.desktop {
requires javafx.controls;
requires javafx.fxml;

opens com.manorrock.sphynx.desktop to javafx.fxml;
exports com.manorrock.sphynx.desktop;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Button?>
<?import javafx.geometry.Insets?>

<VBox alignment="CENTER" spacing="20.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.manorrock.sphynx.desktop.PrimaryController">
<children>
<Label text="Primary View" />
<Button fx:id="primaryButton" text="Switch to Secondary View" onAction="#switchToSecondary"/>
</children>
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
</VBox>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.layout.VBox?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.control.Button?>
<?import javafx.geometry.Insets?>

<VBox alignment="CENTER" spacing="20.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.manorrock.sphynx.desktop.SecondaryController">
<children>
<Label text="Secondary View" />
<Button fx:id="secondaryButton" text="Switch to Primary View" onAction="#switchToPrimary" />
</children>
<padding>
<Insets bottom="20.0" left="20.0" right="20.0" top="20.0" />
</padding>
</VBox>
Loading

0 comments on commit 9d91d62

Please sign in to comment.