Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Base version of this sample JavaFX application #1

Merged
merged 1 commit into from
Dec 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,5 @@

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
/target/
/.idea/
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
# enchald
Java FX basic framework which separates menu, basic status bar and basic modules.

Intention is to provide basic sample framework for someone starting on Java FX.

JDK version used is 1.8.0.271


2 changes: 2 additions & 0 deletions enchald.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />
66 changes: 66 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>org.technagreek</groupId>
<artifactId>enchald</artifactId>
<version>1.0.0.0</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<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>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.technagreek.java.enchald.main.AppLauncher</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>
<resources>
<resource>
<filtering>false</filtering>
<directory>src/main/java</directory>
<includes>
<include>**/*.fxml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</build>
</project>
15 changes: 15 additions & 0 deletions src/main/java/org/technagreek/java/enchald/core/help/About.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<?language javascript?>
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.AnchorPane?>
<?import javafx.scene.text.Font?>
<AnchorPane xmlns:fx="http://javafx.com/fxml/1" fx:id="AboutPane" prefHeight="210.0" prefWidth="551.0"
xmlns="http://javafx.com/javafx/10.0.2-internal">
<Label layoutX="54.0" layoutY="65.0" prefHeight="16.0" prefWidth="327.0" text="Enchald sample for Java FX"/>
<Label layoutX="54.0" layoutY="96.0" text="v1.0.0.0"/>
<Label layoutX="54.0" layoutY="31.0" text="About">
<font>
<Font size="14.0"/>
</font>
</Label>
</AnchorPane>
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 javafx.scene.layout.BorderPane?>
<MenuBar xmlns:fx="http://javafx.com/fxml/1" BorderPane.alignment="CENTER"
xmlns="http://javafx.com/javafx/10.0.2-internal"
fx:controller="org.technagreek.java.enchald.core.menubar.MenuBarController">
<Menu mnemonicParsing="false" text="File">
<MenuItem mnemonicParsing="false" onAction="#showSample1" text="Sample 1"/>
<MenuItem mnemonicParsing="false" onAction="#showSample2" text="Sample 2"/>
<MenuItem mnemonicParsing="false" onAction="#onClickCloseMenu" text="Close"/>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<MenuItem mnemonicParsing="false" onAction="#showAbout" text="About"/>
</Menu>
</MenuBar>
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package org.technagreek.java.enchald.core.menubar;

import javafx.application.Platform;
import javafx.event.Event;
import javafx.fxml.FXMLLoader;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.BorderPane;
import org.technagreek.java.enchald.main.AppLauncher;
import org.technagreek.java.enchald.main.MainApplication;

import java.io.IOException;
import java.net.URL;

public class MenuBarController {
public void showSample1(Event event) throws IOException {
BorderPane mainPanel = AppLauncher.getMainModule().getMainPane();
URL sample1FXML = this.getClass().getResource("../../modules/sample1/sample1.fxml");

FXMLLoader loader = new FXMLLoader(sample1FXML);

AnchorPane centerScene = loader.load();
mainPanel.setCenter(centerScene);
}

public void showSample2(Event event) throws IOException {
BorderPane mainPanel = AppLauncher.getMainModule().getMainPane();
URL sample1FXML = this.getClass().getResource("../../modules/sample2/sample2.fxml");

FXMLLoader loader = new FXMLLoader(sample1FXML);

AnchorPane centerScene = loader.load();
mainPanel.setCenter(centerScene);
}

public void showAbout(Event event) throws IOException {
MainApplication.showAbout();
}

public void onClickCloseMenu(Event event) {
Platform.exit();
System.exit(0);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.technagreek.java.enchald.core.module;

import java.util.HashMap;

public interface BaseModule {
String getName();

HashMap<String, String> getParameterSet();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.technagreek.java.enchald.core.module;

import javafx.scene.control.ButtonType;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;

public interface MainModule extends BaseModule {

BorderPane getMainPane();

void setStatusBarText(String StatusText);

void setStatusBarText(String text, Color textColor);

void displayMessage(String msg);

void displayMessage(String title, String msg);

void displayErrorMessage(String msg);

void displayException(Exception e);

ButtonType displayConfirmation(String msg, ButtonType... buttonTypes);

void setProgressBarPercentage(Double i);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Label?>
<?import javafx.scene.control.ProgressBar?>
<?import javafx.scene.layout.*?>
<GridPane xmlns:fx="http://javafx.com/fxml/1"
xmlns="http://javafx.com/javafx/10.0.2-internal" alignment="CENTER_LEFT"
maxHeight="1.7976931348623157E308"
maxWidth="1.7976931348623157E308" minHeight="-Infinity" minWidth="-Infinity" prefHeight="34.0"

fx:controller="org.technagreek.java.enchald.core.statusbar.StatusBarController">
<columnConstraints>
<ColumnConstraints hgrow="ALWAYS" percentWidth="90.0"/>
<ColumnConstraints hgrow="ALWAYS" percentWidth="10.0"/>
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES"/>
</rowConstraints>
<Label fx:id="statusBarText" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"/>
<ProgressBar fx:id="statusBarProgress" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308"
progress="0.0" GridPane.columnIndex="1"/>
</GridPane>
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.technagreek.java.enchald.core.statusbar;

import javafx.application.Platform;
import javafx.fxml.FXML;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.paint.Color;

public class StatusBarController {
@FXML
Label statusBarText;
@FXML
ProgressBar statusBarProgress;

public static String convertToHex(final Color color) {
return String.format(
"#%02X%02X%02X",
(int) (color.getRed() * 255),
(int) (color.getGreen() * 255),
(int) (color.getBlue() * 255));
}

public void setStatusBarText(String StatusText) {
statusBarText.setText(StatusText);
}

public void setStatusBarText(String StatusText, Color textColor) {
Platform.runLater(
() -> {
statusBarText.setText(StatusText);
statusBarText.setStyle("-fx-text-fill: " + convertToHex(textColor));
});
}

public void updateProgress(Double progressPercentage) {
statusBarProgress.setProgress(progressPercentage);
}
}
35 changes: 35 additions & 0 deletions src/main/java/org/technagreek/java/enchald/main/AppLauncher.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.technagreek.java.enchald.main;

import javafx.application.Application;
import org.technagreek.java.enchald.core.module.MainModule;

import java.io.IOException;
import java.io.InputStream;
import java.util.logging.LogManager;
import java.util.logging.Logger;

public final class AppLauncher {
private static final Logger logger = Logger.getLogger(AppLauncher.class.getName());
private static MainModule mainModule;

public static void main(final String[] args) {
try {
InputStream in =
Thread.currentThread().getContextClassLoader().getResourceAsStream("logging.properties");
LogManager.getLogManager().readConfiguration(in);
} catch (SecurityException | IOException e1) {
e1.printStackTrace();
}

logger.info("Starting GUI");
Application.launch(MainApplication.class, args);
}

public static MainModule getMainModule() {
return mainModule;
}

public static void setMainModule(MainModule mainModule) {
AppLauncher.mainModule = mainModule;
}
}
22 changes: 22 additions & 0 deletions src/main/java/org/technagreek/java/enchald/main/Main.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.BorderPane?>
<?import javafx.scene.layout.Pane?>
<?import javafx.scene.Scene?>
<Scene xmlns:fx="http://javafx.com/fxml/1" xmlns="http://javafx.com/javafx/10.0.2-internal"
fx:controller="org.technagreek.java.enchald.main.MainController">
<BorderPane prefHeight="556.0" prefWidth="1000.0">
<top>
<fx:include fx:id="menuBar" source="../core/menubar/MenuBar.fxml"/>
</top>
<center>
<Pane id="centerScene" BorderPane.alignment="CENTER">
<Label layoutX="173.0" layoutY="100.0" prefHeight="16.0" prefWidth="299.0" text="Welcome To Enchald!"/>
</Pane>
</center>
<bottom>
<fx:include fx:id="statusBar" source="../core/statusbar/StatusBar.fxml"/>
</bottom>
</BorderPane>
</Scene>
Loading