Skip to content
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 build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ wrapper {

repositories {
mavenCentral()
maven { url 'https://jitpack.io' }
}

dependencies {
Expand All @@ -45,6 +46,7 @@ dependencies {
implementation platform('org.kordamp.ikonli:ikonli-bom:12.4.0')
implementation 'org.kordamp.ikonli:ikonli-fluentui-pack:12.4.0'
implementation 'org.kordamp.ikonli:ikonli-javafx:12.4.0'
implementation 'com.github.Dansoftowner:jSystemThemeDetector:3.9.1'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/com/synops/replayreader/JavaFxApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,34 @@

public class JavaFxApplication extends Application {

private ConfigurableApplicationContext applicationContext;
private static Class<?> springApplicationClass;
private ConfigurableApplicationContext springContext;

static void start(String[] args) {
JavaFxApplication.springApplicationClass = ReplayReaderApplication.class;
Application.launch(JavaFxApplication.class, args);
}

@Override
public void init() {
applicationContext = new SpringApplicationBuilder(ReplayReaderApplication.class)
.initializers(getInitializer())
.run();
springContext = new SpringApplicationBuilder(springApplicationClass).initializers(
getInitializer()).run(getParameters().getRaw().toArray(new String[0]));
}

@Override
public void start(Stage stage) {
Objects.requireNonNull(applicationContext);
applicationContext.publishEvent(new StageReadyEvent(stage));
Objects.requireNonNull(springContext);
springContext.publishEvent(new StageReadyEvent(stage));
}

@Override
public void stop() {
applicationContext.close();
springContext.close();
Platform.exit();
}

private ApplicationContextInitializer<GenericApplicationContext> getInitializer() {
return applicationContext -> applicationContext.registerBean(HostServices.class, this::getHostServices);
return applicationContext -> applicationContext.registerBean(HostServices.class,
this::getHostServices);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.synops.replayreader;

import javafx.application.Application;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class ReplayReaderApplication {

public static void main(String[] args) {
Application.launch(JavaFxApplication.class, args);
JavaFxApplication.start(args);
}
}
24 changes: 0 additions & 24 deletions src/main/java/com/synops/replayreader/common/util/LogUtil.java

This file was deleted.

22 changes: 20 additions & 2 deletions src/main/java/com/synops/replayreader/core/StageInitializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import atlantafx.base.theme.PrimerDark;
import atlantafx.base.theme.PrimerLight;
import com.jthemedetecor.OsThemeDetector;
import com.synops.replayreader.common.i18n.I18nUtils;
import com.synops.replayreader.ui.util.UiUtil;
import java.io.IOException;
Expand Down Expand Up @@ -44,8 +45,7 @@ public void onApplicationEvent(StageReadyEvent event) {
fxmlLoader.setControllerFactory(applicationContext::getBean);
Parent parent = fxmlLoader.load();
var stage = event.getStage();
// Application.setUserAgentStylesheet(new PrimerDark().getUserAgentStylesheet());
Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet());
handleDarkMode();
stage.setScene(new Scene(parent, applicationWidth, applicationHeight));
stage.setResizable(false);
stage.setTitle(resourceBundle.getString("main.title"));
Expand All @@ -56,4 +56,22 @@ public void onApplicationEvent(StageReadyEvent event) {
throw new RuntimeException(e);
}
}

private void handleDarkMode() {
final OsThemeDetector detector = OsThemeDetector.getDetector();
final boolean isDarkThemeUsed = detector.isDark();
if (isDarkThemeUsed) {
Application.setUserAgentStylesheet(new PrimerDark().getUserAgentStylesheet());
} else {
Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet());
}

detector.registerListener(isDark -> {
if (isDark) {
Application.setUserAgentStylesheet(new PrimerDark().getUserAgentStylesheet());
} else {
Application.setUserAgentStylesheet(new PrimerLight().getUserAgentStylesheet());
}
});
}
}
32 changes: 32 additions & 0 deletions src/main/java/com/synops/replayreader/core/Startup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.synops.replayreader.core;

import com.synops.replayreader.core.event.StartupEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

@Component
public class Startup implements ApplicationRunner {
private static final Logger LOGGER = LoggerFactory.getLogger(Startup.class);

private final ApplicationEventPublisher publisher;

public Startup(ApplicationEventPublisher publisher) {
this.publisher = publisher;
}

@Override
public void run(ApplicationArguments args) throws Exception {
publisher.publishEvent(new StartupEvent());
}

@EventListener
public void onApplicationEvent(ContextClosedEvent ignored) {
LOGGER.info("Application is shutting down");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.synops.replayreader.core.event;

public record StartupEvent() {

}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package com.synops.replayreader.core.service;

import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.layout.StackPane;

public interface NotificationService {

void alert(String message, StackPane stackPane);
void alert(String message, StackPane stackPane, Button... buttons);

void information(String message, StackPane stackPane);
void information(String message, StackPane stackPane, Button... buttons);

void warning(String message, StackPane stackPane);
void warning(String message, StackPane stackPane, Button... buttons);

void confirmation(String message, StackPane stackPane);
void confirmation(String message, StackPane stackPane, Button... buttons);

void notify(String message, AlertType alertType, StackPane stackPane);
void notify(String message, AlertType alertType, StackPane stackPane, Button... buttons);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.control.Alert.AlertType;
import javafx.scene.control.Button;
import javafx.scene.layout.Region;
import javafx.scene.layout.StackPane;
import javafx.util.Duration;
Expand All @@ -28,23 +29,23 @@ public class NotificationServiceImpl implements NotificationService {

private final Map<StackPane, ObservableList<Notification>> activeNotifications = new HashMap<>();

public void alert(String message, StackPane stackPane) {
notify(message, AlertType.ERROR, stackPane);
public void alert(String message, StackPane stackPane, Button... buttons) {
notify(message, AlertType.ERROR, stackPane, buttons);
}

public void information(String message, StackPane stackPane) {
notify(message, AlertType.INFORMATION, stackPane);
public void information(String message, StackPane stackPane, Button... buttons) {
notify(message, AlertType.INFORMATION, stackPane, buttons);
}

public void warning(String message, StackPane stackPane) {
notify(message, AlertType.WARNING, stackPane);
public void warning(String message, StackPane stackPane, Button... buttons) {
notify(message, AlertType.WARNING, stackPane, buttons);
}

public void confirmation(String message, StackPane stackPane) {
notify(message, AlertType.CONFIRMATION, stackPane);
public void confirmation(String message, StackPane stackPane, Button... buttons) {
notify(message, AlertType.CONFIRMATION, stackPane, buttons);
}

public void notify(String message, AlertType alertType, StackPane stackPane) {
public void notify(String message, AlertType alertType, StackPane stackPane, Button... buttons) {
var notificationList = activeNotifications.computeIfAbsent(stackPane,
_ -> FXCollections.observableArrayList());

Expand Down Expand Up @@ -81,6 +82,10 @@ public void notify(String message, AlertType alertType, StackPane stackPane) {
notification.getStyleClass().add(style);
}

if (buttons.length > 0) {
notification.setPrimaryActions(buttons);
}

notificationList.add(notification);
notification.setOnClose(_ -> {
removeNotification(notification, stackPane);
Expand Down
51 changes: 23 additions & 28 deletions src/main/java/com/synops/replayreader/maps/ui/MapListCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,15 @@

import static com.synops.replayreader.common.util.Constants.OVERALL;

import com.synops.replayreader.common.i18n.I18nUtils;
import com.synops.replayreader.common.comparator.PlayerAndVehicleAndMapToInt;
import com.synops.replayreader.common.i18n.I18nUtils;
import com.synops.replayreader.ui.control.BaseListCell;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import javafx.beans.property.StringProperty;
import javafx.scene.control.ListCell;
import javafx.scene.control.Tooltip;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.scene.text.TextFlow;

public class MapListCell extends ListCell<String> {
public class MapListCell extends BaseListCell<String> {

private final ResourceBundle resourceBundle = I18nUtils.getBundle();
private final PlayerAndVehicleAndMapToInt function;
Expand All @@ -28,32 +25,30 @@ public MapListCell(StringProperty player, StringProperty vehicle,
}

@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (!empty && item != null) {
var vehicleValue = vehicle.get();
if (OVERALL.equals(vehicleValue)) {
vehicleValue = null;
}

var textFlow = new TextFlow();
var textMap = new Text();
textMap.setText(getMapName(item) + " ");
var textCount = new Text();
textCount.setText(String.valueOf(function.apply(player.get(), vehicleValue, item)));
textCount.setFill(Color.ORANGE);
textFlow.getChildren().addAll(textMap, textCount);
this.setGraphic(textFlow);
this.setTooltip(new Tooltip(this.createTooltippText(item, vehicleValue)));
} else {
this.setGraphic(null);
protected TextFlow createTextFlow(String item) {
var vehicleValue = vehicle.get();
if (OVERALL.equals(vehicleValue)) {
vehicleValue = null;
}

this.setText(null);
var textFlow = new TextFlow();
var textMap = createRegularText(getMapName(item) + " ");
int count = function.apply(player.get(), vehicleValue, item);
var textCount = createCountText(count);
textFlow.getChildren().addAll(textMap, textCount);

return textFlow;
}

private String createTooltippText(String map, String vehicle) {
return getMapName(map) + " (" + function.apply(player.get(), vehicle, map) + ")";
@Override
protected String createToolTipText(String item) {
var vehicleValue = vehicle.get();
if (OVERALL.equals(vehicleValue)) {
vehicleValue = null;
}

int count = function.apply(player.get(), vehicleValue, item);
return getMapName(item) + " (" + count + ")";
}

private String getMapName(String map) {
Expand Down
Loading