Skip to content

Commit

Permalink
Clean up fxml
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Oct 9, 2023
1 parent 92eb007 commit d2114c1
Show file tree
Hide file tree
Showing 24 changed files with 93 additions and 72 deletions.
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ buildscript {
mavenCentral()
}
dependencies {
classpath files('../fx2j/gradle-plugin/build/libs/gradle-plugin-all.jar')
classpath files('../fx2j/gradle-plugin/build/libs/fx2j-gradle-plugin-unspecified.jar')
}
}

Expand All @@ -21,7 +21,7 @@ plugins {
}

apply plugin: 'io.spring.dependency-management'
apply plugin: 'com.github.sheikah45.fx2j'
apply plugin: 'io.github.sheikah45.fx2j'

// source: https://github.com/mendhak/Gradle-Travis-Colored-Output/blob/master/ColoredOutput.gradle
tasks.withType(Test).configureEach {
Expand Down Expand Up @@ -214,6 +214,10 @@ install4j {
}
}

fx2j {
basePackage = "com.faforever.client.fx2j"
}

tasks.register('buildInstall4jMediaFiles', Install4jTask) {
group "distribution"
description 'Creates install4j media files'
Expand Down Expand Up @@ -345,8 +349,8 @@ dependencies {

implementation("org.javassist:javassist:3.29.2-GA")

implementation(files("../fx2j/api/build/libs/fx2j-api-unspecified.jar"))
implementation("com.install4j:install4j-runtime:10.0.6")
implementation(files("../fx2j/api/build/libs/api.jar"))

testImplementation("com.squareup.okhttp3:okhttp")
testImplementation("com.squareup.okhttp3:mockwebserver")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.faforever.client.i18n.I18n;
import com.faforever.client.theme.UiService;
import com.google.common.net.MediaType;
import javafx.scene.Node;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -70,8 +69,9 @@ public CompletableFuture<Optional<Preview>> resolvePreview(String urlString) {
long contentLength = connection.getContentLengthLong();
String contentType = connection.getContentType();

Node root = uiService.loadFxml("theme/image_preview.fxml");
ImageView imageView = (ImageView) root.lookup("#imageView");
ImageView imageView = new ImageView();
imageView.setFitHeight(200.0);
imageView.setFitWidth(300.0);

if (MediaType.JPEG.toString().equals(contentType)
|| MediaType.PNG.toString().equals(contentType)) {
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/faforever/client/config/ClientProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import com.faforever.client.update.ClientConfiguration.UrlEndpoint;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.web.reactive.socket.WebSocketHandler;
import org.springframework.web.reactive.socket.WebSocketSession;
import reactor.core.publisher.Mono;

import java.net.URI;
import java.time.Duration;
Expand Down Expand Up @@ -155,6 +158,14 @@ public void updateFromEndpoint(ServerEndpoints serverEndpoints) {
server.setPort(lobby.getPort());
}

new WebSocketHandler() {

@Override
public Mono<Void> handle(WebSocketSession session) {
return session.receive().map(message -> message.);
}
}

SocketEndpoint liveReplay = serverEndpoints.getLiveReplay();
if (liveReplay != null) {
replay.setRemoteHost(liveReplay.getHost());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.faforever.client.fx.contextmenu;

import javafx.scene.control.Button;
import javafx.scene.control.ColorPicker;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

@Slf4j
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Component
@RequiredArgsConstructor
public abstract class AbstractColorPickerCustomMenuItemController<T> extends AbstractCustomMenuItemController<T> {


public ColorPicker colorPicker;
public Button removeCustomColorButton;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import com.faforever.client.fx.JavaFxUtil;
import com.faforever.client.preferences.ChatPrefs;
import com.faforever.client.util.Assert;
import javafx.scene.control.Button;
import javafx.scene.control.ColorPicker;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
Expand All @@ -19,13 +17,10 @@
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@Component
@RequiredArgsConstructor
public class ChatCategoryColorPickerCustomMenuItemController extends AbstractCustomMenuItemController<ChatUserCategory> {
public class ChatCategoryColorPickerCustomMenuItemController extends AbstractColorPickerCustomMenuItemController<ChatUserCategory> {

private final ChatPrefs chatPrefs;

public ColorPicker colorPicker;
public Button removeCustomColorButton;

public void initialize() {
removeCustomColorButton.setOnAction(event -> colorPicker.setValue(null));
removeCustomColorButton.visibleProperty().bind(chatPrefs.chatColorModeProperty().flatMap(chatColorMode -> colorPicker.valueProperty().isNotNull().map(isNotNull -> isNotNull && RANDOM != chatColorMode)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import com.faforever.client.fx.JavaFxUtil;
import com.faforever.client.preferences.ChatPrefs;
import com.faforever.client.util.Assert;
import javafx.scene.control.Button;
import javafx.scene.control.ColorPicker;
import javafx.scene.paint.Color;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -22,10 +20,7 @@
@Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
@RequiredArgsConstructor
@Slf4j
public class ChatUserColorPickerCustomMenuItemController extends AbstractCustomMenuItemController<ChatChannelUser> {

public ColorPicker colorPicker;
public Button removeCustomColorButton;
public class ChatUserColorPickerCustomMenuItemController extends AbstractColorPickerCustomMenuItemController<ChatChannelUser> {

private final ChatPrefs chatPrefs;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public void onMajorDivisionPicked() {
.getDivision()
.getIndex())
.forEach(subdivision -> {
SubDivisionTabController controller = uiService.loadFxml("theme/leaderboard/subDivisionTab.fxml");
SubDivisionTabController controller = uiService.loadFxml("theme/leaderboard/sub_division_tab.fxml");
controller.getRoot().setUserData(subdivision.getIndex());
controller.populate(subdivision);
fxApplicationThreadExecutor.execute(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public void initialize() {

nameColumn.setCellValueFactory(param -> param.getValue().getPlayer().usernameProperty());
nameColumn.setCellFactory(param -> new StringCell<>(name -> name));
nameColumn.prefWidthProperty().bind(ratingTable.widthProperty().subtract(250));

gamesPlayedColumn.setCellValueFactory(param -> param.getValue().gamesPlayedProperty());
gamesPlayedColumn.setCellFactory(param -> new StringCell<>(count -> i18n.number(count.intValue())));
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/faforever/client/map/MapDetailController.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public class MapDetailController implements Controller<Node> {
private final ContextMenuBuilder contextMenuBuilder;

private final ObjectProperty<MapVersionBean> mapVersion = new SimpleObjectProperty<>();
private final ObservableList<MapVersionReviewBean> reviews = FXCollections.observableArrayList();
private final ObservableList<MapVersionReviewBean> mapReviews = FXCollections.observableArrayList();

public Label progressLabel;
public Button uninstallButton;
Expand Down Expand Up @@ -192,13 +192,13 @@ private void initializeReviewsController() {
review.setMapVersion(mapVersion.get());
return review;
});
reviewsController.bindReviews(reviews);
reviewsController.bindReviews(mapReviews);
}

private void onMapVersionChanged(MapVersionBean newValue) {
if (newValue == null) {
reviewsController.setCanWriteReview(false);
reviews.clear();
mapReviews.clear();
installButton.setText("");
return;
}
Expand All @@ -215,7 +215,7 @@ private void onMapVersionChanged(MapVersionBean newValue) {
reviewService.getMapReviews(newValue.getMap())
.collectList()
.publishOn(fxApplicationThreadExecutor.asScheduler())
.subscribe(reviews::setAll, throwable -> log.error("Unable to populate reviews", throwable));
.subscribe(mapReviews::setAll, throwable -> log.error("Unable to populate reviews", throwable));

mapService.getFileSize(newValue).thenAcceptAsync(mapFileSize -> {
if (mapFileSize > -1) {
Expand Down Expand Up @@ -245,17 +245,17 @@ void onDeleteReview(MapVersionReviewBean review) {
.subscribe(null, throwable -> {
log.error("Review could not be deleted", throwable);
notificationService.addImmediateErrorNotification(throwable, "review.delete.error");
}, () -> reviews.remove(review));
}, () -> mapReviews.remove(review));
}

@VisibleForTesting
void onSendReview(MapVersionReviewBean review) {
reviewService.saveMapVersionReview(review)
.filter(savedReview -> !reviews.contains(savedReview))
.filter(savedReview -> !mapReviews.contains(savedReview))
.publishOn(fxApplicationThreadExecutor.asScheduler())
.subscribe(savedReview -> {
reviews.remove(review);
reviews.add(savedReview);
mapReviews.remove(review);
mapReviews.add(savedReview);
}, throwable -> {
log.error("Review could not be saved", throwable);
notificationService.addImmediateErrorNotification(throwable, "review.save.error");
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/com/faforever/client/mod/ModDetailController.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public class ModDetailController implements Controller<Node> {
private final FxApplicationThreadExecutor fxApplicationThreadExecutor;

private final ObjectProperty<ModVersionBean> modVersion = new SimpleObjectProperty<>();
private final ObservableList<ModVersionReviewBean> reviews = FXCollections.observableArrayList();
private final ObservableList<ModVersionReviewBean> modReviews = FXCollections.observableArrayList();

public Label updatedLabel;
public Label sizeLabel;
Expand Down Expand Up @@ -157,7 +157,7 @@ public void setModVersion(ModVersionBean modVersion) {
private void onModVersionChanged(ModVersionBean newValue) {
if (newValue == null) {
reviewsController.setCanWriteReview(false);
reviews.clear();
modReviews.clear();
installButton.setText("");
return;
}
Expand All @@ -172,7 +172,7 @@ private void onModVersionChanged(ModVersionBean newValue) {
reviewService.getModReviews(newValue.getMod())
.collectList()
.publishOn(fxApplicationThreadExecutor.asScheduler())
.subscribe(reviews::setAll, throwable -> log.error("Unable to populate reviews", throwable));
.subscribe(modReviews::setAll, throwable -> log.error("Unable to populate reviews", throwable));

modService.getFileSize(newValue)
.thenAcceptAsync(modFileSize -> {
Expand All @@ -197,7 +197,7 @@ private void initializeReviewsController() {
review.setModVersion(modVersion.get());
return review;
});
reviewsController.bindReviews(reviews);
reviewsController.bindReviews(modReviews);
}

@VisibleForTesting
Expand All @@ -207,17 +207,17 @@ void onDeleteReview(ModVersionReviewBean review) {
.subscribe(null, throwable -> {
log.error("Review could not be deleted", throwable);
notificationService.addImmediateErrorNotification(throwable, "review.delete.error");
}, () -> reviews.remove(review));
}, () -> modReviews.remove(review));
}

@VisibleForTesting
void onSendReview(ModVersionReviewBean review) {
reviewService.saveModVersionReview(review)
.filter(savedReview -> !reviews.contains(savedReview))
.filter(savedReview -> !modReviews.contains(savedReview))
.publishOn(fxApplicationThreadExecutor.asScheduler())
.subscribe(savedReview -> {
reviews.remove(review);
reviews.add(savedReview);
modReviews.remove(review);
modReviews.add(savedReview);
}, throwable -> {
log.error("Review could not be saved", throwable);
notificationService.addImmediateErrorNotification(throwable, "review.save.error");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public class ReplayDetailController implements Controller<Node> {

private final ArrayList<TeamCardController> teamCardControllers = new ArrayList<>();
private final ObjectProperty<ReplayBean> replay = new SimpleObjectProperty<>();
private final ObservableList<ReplayReviewBean> reviews = FXCollections.observableArrayList();
private final ObservableList<ReplayReviewBean> replayReviews = FXCollections.observableArrayList();
private final ObjectProperty<Map<String, List<GamePlayerStatsBean>>> teams = new SimpleObjectProperty<>();
private final SimpleChangeListener<Map<String, List<GamePlayerStatsBean>>> teamsListener = this::populateTeamsContainer;

Expand Down Expand Up @@ -293,7 +293,7 @@ private void bindProperties() {
private void onReplayChanged(ReplayBean newValue) {
if (newValue == null) {
reviewsController.setCanWriteReview(false);
reviews.clear();
replayReviews.clear();
return;
}

Expand All @@ -306,7 +306,7 @@ private void onReplayChanged(ReplayBean newValue) {
reviewService.getReplayReviews(newValue)
.collectList()
.publishOn(fxApplicationThreadExecutor.asScheduler())
.subscribe(reviews::setAll, throwable -> log.error("Unable to populate reviews", throwable));
.subscribe(replayReviews::setAll, throwable -> log.error("Unable to populate reviews", throwable));
}

public void setReplay(ReplayBean replay) {
Expand Down Expand Up @@ -352,7 +352,7 @@ private void initializeReviewsController() {
review.setReplay(replay.get());
return review;
});
reviewsController.bindReviews(reviews);
reviewsController.bindReviews(replayReviews);
}

@VisibleForTesting
Expand All @@ -362,17 +362,17 @@ void onDeleteReview(ReplayReviewBean review) {
.subscribe(null, throwable -> {
log.error("Review could not be saved", throwable);
notificationService.addImmediateErrorNotification(throwable, "review.delete.error");
}, () -> reviews.remove(review));
}, () -> replayReviews.remove(review));
}

@VisibleForTesting
void onSendReview(ReplayReviewBean review) {
reviewService.saveReplayReview(review)
.filter(savedReview -> !reviews.contains(savedReview))
.filter(savedReview -> !replayReviews.contains(savedReview))
.publishOn(fxApplicationThreadExecutor.asScheduler())
.subscribe(savedReview -> {
reviews.remove(review);
reviews.add(savedReview);
replayReviews.remove(review);
replayReviews.add(savedReview);
}, throwable -> {
log.error("Review could not be saved", throwable);
notificationService.addImmediateErrorNotification(throwable, "review.save.error");
Expand Down
20 changes: 7 additions & 13 deletions src/main/java/com/faforever/client/theme/UiService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.faforever.client.ui.dialog.Dialog;
import com.faforever.client.ui.dialog.Dialog.DialogTransition;
import com.faforever.client.ui.dialog.DialogLayout;
import com.github.sheikah45.fx2j.api.Fx2jLoader;
import io.github.sheikah45.fx2j.api.Fx2jLoader;
import javafx.beans.binding.BooleanExpression;
import javafx.beans.property.ObjectProperty;
import javafx.beans.property.ReadOnlyObjectProperty;
Expand Down Expand Up @@ -298,12 +298,16 @@ private String getSceneStyleSheet() throws IOException {


public String getThemeFile(String relativeFile) throws IOException {
return getThemeFileUrl(relativeFile).toString();
}

public URL getThemeFileUrl(String relativeFile) throws IOException {
String strippedRelativeFile = relativeFile.replace("theme/", "");
Path externalFile = getThemeDirectory(currentTheme.get()).resolve(strippedRelativeFile);
if (Files.notExists(externalFile)) {
return new ClassPathResource("/" + relativeFile).getURL().toString();
return new ClassPathResource("/" + relativeFile).getURL();
}
return externalFile.toUri().toURL().toString();
return externalFile.toUri().toURL();
}

/**
Expand All @@ -326,16 +330,6 @@ public Image getImage(String relativeImage) {
return new Image(relativeImage, true);
}


public URL getThemeFileUrl(String relativeFile) throws IOException {
String themeFile = getThemeFile(relativeFile);
if (themeFile.startsWith("file:") || themeFile.startsWith("jar:")) {
return new URL(themeFile);
}
return new ClassPathResource(getThemeFile(relativeFile)).getURL();
}


public void setTheme(Theme theme) {
stopWatchingOldThemes();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class VaultEntityShowRoomController implements Controller<Node> {
@Override
public void initialize() {
JavaFxUtil.bindManagedToVisible(root);
label.prefWidthProperty().bind(root.widthProperty());
}

public void setChildren(List<Node> children) {
Expand Down
Loading

0 comments on commit d2114c1

Please sign in to comment.