Skip to content

Commit

Permalink
Merge pull request #8 from yoep/feature/java-17-cleanup
Browse files Browse the repository at this point in the history
Feature java 17 cleanup
  • Loading branch information
yoep authored Apr 21, 2024
2 parents f31b1b2 + cdeb2e1 commit fdaeb64
Show file tree
Hide file tree
Showing 23 changed files with 415 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,12 @@ on:
inputs: {}

jobs:
build:
test:
name: Test
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
Expand All @@ -28,4 +26,4 @@ jobs:
cache: 'maven'
- name: Maven test
run: |
mvn -B test
xvfb-run -a mvn -B test
15 changes: 11 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.2.0</version>
<version>3.2.5</version>
</parent>

<groupId>com.github.yoep</groupId>
Expand Down Expand Up @@ -48,12 +48,12 @@
<maven.compiler.target>17</maven.compiler.target>

<!-- Dependencies -->
<javafx.version>21.0.1</javafx.version>
<javafx.version>22.0.1</javafx.version>

<!-- Test Dependencies -->
<junit.jupiter.engine.version>5.10.1</junit.jupiter.engine.version>
<junit.jupiter.engine.version>5.10.2</junit.jupiter.engine.version>
<mockito.inline.version>5.2.0</mockito.inline.version>
<mockito.junit.jupiter.version>5.7.0</mockito.junit.jupiter.version>
<mockito.junit.jupiter.version>5.11.0</mockito.junit.jupiter.version>
<testfx.junit.version>4.0.17</testfx.junit.version>

<!-- Plugins -->
Expand Down Expand Up @@ -194,6 +194,13 @@
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>maven_central</id>
<name>Maven Central</name>
<url>https://repo.maven.apache.org/maven2/</url>
</repository>
</repositories>

<profiles>
<profile>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import org.springframework.context.annotation.Import;

/**
* The auto configuration for JavaFX.
* Configuration class for auto-configuring JavaFX related beans.
* This class imports other configuration classes responsible for configuring
* fonts, locale text, and views in a JavaFX application.
*/
@Configuration
@Import({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
package com.github.spring.boot.javafx.font;

import javafx.scene.text.Font;
import org.springframework.util.Assert;

import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

/**
Expand All @@ -29,15 +28,15 @@ public static FontRegistryImpl getInstance() {

@Override
public Font loadFont(String filename) {
Assert.notNull(filename, "filename cannot be null");
Font defaultFont = Font.getDefault();
Objects.requireNonNull(filename, "filename cannot be null");
var defaultFont = Font.getDefault();

return loadFont(filename, defaultFont.getSize());
}

@Override
public Font loadFont(String filename, double size) {
Assert.notNull(filename, "filename cannot be null");
Objects.requireNonNull(filename, "filename cannot be null");

if (loadedFonts.containsKey(filename))
return createFontFromAlreadyLoadedFont(loadedFonts.get(filename), size);
Expand All @@ -46,8 +45,8 @@ public Font loadFont(String filename, double size) {
}

private Font loadFontResource(String filename, double size) {
URL resource = getClass().getResource(FONT_DIRECTORY + filename);
Font font = Optional.ofNullable(Font.loadFont(resource.toExternalForm(), size))
var resource = getClass().getResource(FONT_DIRECTORY + filename);
var font = Optional.ofNullable(Font.loadFont(resource.toExternalForm(), size))
.orElseThrow(() -> new FontException(filename));

loadedFonts.put(filename, font);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,18 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
* Configuration class for configuring fonts in the application.
* This class provides a bean definition for FontRegistry if one is not already present.
*/
@Configuration
public class FontConfiguration {

/**
* Defines a bean for FontRegistry if no other bean of type FontRegistry is present.
*
* @return the FontRegistry bean instance
*/
@Bean
@ConditionalOnMissingBean(FontRegistry.class)
public FontRegistry fontRegistry() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private void init(String filename) {
}

private void initializeFont(String filename) {
Font font = FontRegistryImpl.getInstance().loadFont(filename);
var font = FontRegistryImpl.getInstance().loadFont(filename);

fontFamily = font.getFamily();
setFont(font);
Expand All @@ -76,8 +76,8 @@ private void initializeFont(String filename) {
private void initializeSizeFactor() {
sizeFactorProperty.addListener((observable, oldValue, newValue) -> {
updating = true;
Font oldFont = getFont();
double fontSize = getActualSize(newValue.doubleValue(), oldFont.getSize());
var oldFont = getFont();
var fontSize = getActualSize(newValue.doubleValue(), oldFont.getSize());

setFont(Font.font(fontFamily, FontWeight.findByName(oldFont.getStyle()), fontSize));
updating = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
import javafx.stage.StageStyle;
import lombok.Getter;
import org.springframework.lang.Nullable;
import org.springframework.util.Assert;

import java.util.Objects;

/**
* The {@link BorderlessStageWrapper} wraps around an existing stage and converts it into a borderless stage.
Expand Down Expand Up @@ -41,7 +42,7 @@ public class BorderlessStageWrapper {
//region Constructors

public BorderlessStageWrapper(Stage stage) {
Assert.notNull(stage, "stage cannot be null");
Objects.requireNonNull(stage, "stage cannot be null");
this.stage = stage;
init();
}
Expand Down Expand Up @@ -140,14 +141,14 @@ private void initializeListeners() {
}

private void removeSceneListeners(Scene scene) {
Assert.notNull(scene, "scene cannot be null");
Objects.requireNonNull(scene, "scene cannot be null");
scene.removeEventHandler(MouseEvent.MOUSE_MOVED, mouseMovedEventHandler);
scene.removeEventHandler(MouseEvent.MOUSE_PRESSED, mousePressedEventHandler);
scene.removeEventHandler(MouseEvent.MOUSE_DRAGGED, mouseDraggedEventHandler);
}

private void addSceneListeners(Scene scene) {
Assert.notNull(scene, "scene cannot be null");
Objects.requireNonNull(scene, "scene cannot be null");
scene.addEventHandler(MouseEvent.MOUSE_MOVED, mouseMovedEventHandler);
scene.addEventHandler(MouseEvent.MOUSE_PRESSED, mousePressedEventHandler);
scene.addEventHandler(MouseEvent.MOUSE_DRAGGED, mouseDraggedEventHandler);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
import org.springframework.context.support.MessageSourceAccessor;
import org.springframework.context.support.MessageSourceResourceBundle;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.util.Assert;

import java.util.Locale;
import java.util.Objects;
import java.util.ResourceBundle;

/**
Expand All @@ -30,7 +30,7 @@ public class LocaleTextImpl implements LocaleText {
* @param messageSource set the message source to use.
*/
public LocaleTextImpl(ResourceBundleMessageSource messageSource) {
Assert.notNull(messageSource, "messageSource cannot be null");
Objects.requireNonNull(messageSource, "messageSource cannot be null");
this.messageSource = messageSource;

init();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,21 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ResourceBundleMessageSource;

/**
* Configuration class for managing locale-specific text resources.
* This class provides a bean definition for LocaleText if one is not already present,
* using a ResourceBundleMessageSource as the underlying message source.
*/
@Configuration
public class LocaleTextConfiguration {

/**
* Defines a bean for LocaleText if no other bean of type LocaleText is present,
* using the provided ResourceBundleMessageSource as the message source.
*
* @param messageSource the ResourceBundleMessageSource instance to use for managing message sources
* @return the LocaleText bean instance
*/
@Bean
@ConditionalOnMissingBean(LocaleText.class)
public LocaleText localeText(ResourceBundleMessageSource messageSource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ public interface ViewLoader {
/**
* The directory containing the FXML files.
*/
String VIEW_DIRECTORY = "views";
String VIEW_DIRECTORY = "/views";
/**
* The directory contain
*/
String IMAGE_DIRECTORY = "images";
String IMAGE_DIRECTORY = "/images";

/**
* Set the UI scale of the views.
Expand Down
Loading

0 comments on commit fdaeb64

Please sign in to comment.