Skip to content
This repository was archived by the owner on Nov 26, 2019. It is now read-only.

Commit 6232044

Browse files
committed
# Minor Dark theme improvements and refactorings
1 parent 35ba544 commit 6232044

File tree

18 files changed

+128
-76
lines changed

18 files changed

+128
-76
lines changed

client/src/main/java/com/msc/serverbrowser/Client.java

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import com.msc.serverbrowser.util.UpdateUtility;
3434
import com.msc.serverbrowser.util.basic.ArrayUtility;
3535
import com.msc.serverbrowser.util.basic.FileUtility;
36+
import com.msc.serverbrowser.util.basic.OptionalUtility;
3637
import com.msc.serverbrowser.util.windows.OSUtility;
3738

3839
import javafx.application.Application;
@@ -77,13 +78,13 @@ public final class Client extends Application {
7778
/**
7879
* RessourceBundle which contains all the localized strings.
7980
*/
80-
public static ResourceBundle lang;
81+
private static ResourceBundle lang;
8182

8283
/**
8384
* This property that indicates if an update check / download progress is
8485
* ongoing.
8586
*/
86-
public final BooleanProperty updatingProperty = new SimpleBooleanProperty(false);
87+
public final BooleanProperty updateOngoingProperty = new SimpleBooleanProperty(false);
8788

8889
/**
8990
* @return the clients singleton instance
@@ -184,8 +185,8 @@ private void loadUI(final Stage primaryStage) {
184185

185186
final TrayNotification trayNotification = new TrayNotificationBuilder()
186187
.type(NotificationTypeImplementations.INFORMATION)
187-
.title(Client.lang.getString("updated"))
188-
.message(Client.lang.getString("clickForChangelog"))
188+
.title(Client.getString("updated"))
189+
.message(Client.getString("clickForChangelog"))
189190
.animation(Animations.SLIDE).build();
190191

191192
trayNotification.setOnMouseClicked(__ -> {
@@ -224,7 +225,7 @@ private static void createFolderStructure() {
224225
public void checkForUpdates() {
225226
Logging.info("Checking for updates.");
226227

227-
if (updatingProperty.get()) {
228+
if (updateOngoingProperty.get()) {
228229
// If an update is ongoing already, then we won't start another.
229230
return;
230231
}
@@ -233,7 +234,7 @@ public void checkForUpdates() {
233234
mainController.setGlobalProgressText("Checking for updates");
234235

235236
new Thread(() -> {
236-
updatingProperty.set(true);
237+
updateOngoingProperty.set(true);
237238
try {
238239
if (UpdateUtility.isUpToDate()) {
239240
Logging.info("Client is up to date.");
@@ -259,13 +260,13 @@ public void checkForUpdates() {
259260
mainController.setGlobalProgressText("");
260261
mainController.progressProperty().set(0);
261262
});
262-
updatingProperty.set(false);
263+
updateOngoingProperty.set(false);
263264
}).start();
264265
}
265266

266267
private static void displayUpdateNotification() {
267-
final TrayNotification trayNotification = new TrayNotificationBuilder().title(Client.lang.getString("updateInstalled"))
268-
.message(Client.lang.getString("clickToRestart"))
268+
final TrayNotification trayNotification = new TrayNotificationBuilder().title(Client.getString("updateInstalled"))
269+
.message(Client.getString("clickToRestart"))
269270
.animation(Animations.SLIDE).build();
270271

271272
trayNotification.setOnMouseClicked(__ -> {
@@ -276,9 +277,9 @@ private static void displayUpdateNotification() {
276277
}
277278

278279
private static void displayCantRetrieveUpdate() {
279-
final TrayNotification trayNotification = new TrayNotificationBuilder().message(Client.lang.getString("couldntRetrieveUpdate"))
280+
final TrayNotification trayNotification = new TrayNotificationBuilder().message(Client.getString("couldntRetrieveUpdate"))
280281
.animation(Animations.POPUP)
281-
.type(NotificationTypeImplementations.ERROR).title(Client.lang.getString("updating")).build();
282+
.type(NotificationTypeImplementations.ERROR).title(Client.getString("updating")).build();
282283

283284
trayNotification.setOnMouseClicked(clicked -> {
284285
OSUtility.browse("https://github.com/Bios-Marcel/ServerBrowser/releases/latest");
@@ -327,8 +328,8 @@ private static void finishUpdate() {
327328
}
328329
catch (final IOException exception) {
329330
Logging.error("Failed to update.", exception);
330-
final TrayNotification notification = new TrayNotificationBuilder().title(Client.lang.getString("applyingUpdate"))
331-
.message(Client.lang.getString("couldntApplyUpdate"))
331+
final TrayNotification notification = new TrayNotificationBuilder().title(Client.getString("applyingUpdate"))
332+
.message(Client.getString("couldntApplyUpdate"))
332333
.type(NotificationTypeImplementations.ERROR).build();
333334

334335
notification.setOnMouseClicked(__ -> {
@@ -452,4 +453,12 @@ public void selectSampPathTextField() {
452453
}
453454
mainController.getSettingsController().ifPresent(SettingsController::selectSampPathTextField);
454455
}
456+
457+
public static ResourceBundle getLangaugeResourceBundle() {
458+
return lang;
459+
}
460+
461+
public static String getString(final String key) {
462+
return OptionalUtility.attempt(() -> lang.getString(key)).orElse("Invalid Key");
463+
}
455464
}

client/src/main/java/com/msc/serverbrowser/gui/components/SampServerTable.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ private void setMenuItemDefaultActions() {
115115
}
116116

117117
private void deleteSelectedFavourites() {
118-
final Alert alert = new Alert(AlertType.CONFIRMATION, Client.lang.getString("sureYouWantToDeleteFavourites"), ButtonType.YES, ButtonType.NO);
118+
final Alert alert = new Alert(AlertType.CONFIRMATION, Client.getString("sureYouWantToDeleteFavourites"), ButtonType.YES, ButtonType.NO);
119119
Client.insertAlertOwner(alert);
120-
alert.setTitle(Client.lang.getString("deleteFavourites"));
120+
alert.setTitle(Client.getString("deleteFavourites"));
121121
final Optional<ButtonType> result = alert.showAndWait();
122122

123123
result.ifPresent(buttonType -> {

client/src/main/java/com/msc/serverbrowser/gui/controllers/implementations/FilesController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ private void clearChatLog() {
7070
new TrayNotificationBuilder()
7171
.type(NotificationTypeImplementations.ERROR)
7272
.animation(Animations.POPUP)
73-
.title(Client.lang.getString("couldntClearChatLog"))
74-
.message(Client.lang.getString("checkLogsForMoreInformation")).build().showAndDismiss(Client.DEFAULT_TRAY_DISMISS_TIME);
73+
.title(Client.getString("couldntClearChatLog"))
74+
.message(Client.getString("checkLogsForMoreInformation")).build().showAndDismiss(Client.DEFAULT_TRAY_DISMISS_TIME);
7575

7676
Logging.warn("Couldn't clear chatlog", exception);
7777
}

client/src/main/java/com/msc/serverbrowser/gui/controllers/implementations/MainController.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,14 +135,12 @@ public void loadView(final View view) {
135135
mainView.removeNodesFromBottomBar();
136136

137137
final Parent loadedNode;
138-
switch (view) {
139-
case FILES:
140-
loadedNode = loadFilesView();
141-
break;
142-
// $CASES-OMITTED$
143-
default:
144-
loadedNode = loadFXML(view);
145-
break;
138+
139+
if (view == View.FILES) {
140+
loadedNode = loadFilesView();
141+
}
142+
else {
143+
loadedNode = loadFXML(view);
146144
}
147145

148146
initViewData(view, loadedNode);
@@ -159,7 +157,7 @@ private Parent loadFXML(final View view) {
159157
try {
160158
final FXMLLoader loader = new FXMLLoader();
161159
loader.setLocation(getClass().getResource(view.getFXMLPath()));
162-
loader.setResources(Client.lang);
160+
loader.setResources(Client.getLangaugeResourceBundle());
163161

164162
// Creating a new instance of the specified controller, controllers never have
165163
// constructor arguments, therefore this is supposedly fine.

client/src/main/java/com/msc/serverbrowser/gui/controllers/implementations/ServerListController.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ public class ServerListController implements ViewController {
6767
private static Thread serverLookup;
6868
private static Thread serverInfoUpdateThread;
6969

70-
private final String RETRIEVING = Client.lang.getString("retrieving");
70+
private final String RETRIEVING = Client.getString("retrieving");
7171

72-
private final String TOO_MUCH_PLAYERS = Client.lang.getString("tooMuchPlayers");
73-
private final String SERVER_OFFLINE = Client.lang.getString("serverOffline");
74-
private final String SERVER_EMPTY = Client.lang.getString("serverEmpty");
72+
private final String TOO_MUCH_PLAYERS = Client.getString("tooMuchPlayers");
73+
private final String SERVER_OFFLINE = Client.getString("serverOffline");
74+
private final String SERVER_EMPTY = Client.getString("serverEmpty");
7575

7676
@FXML private ToggleGroup tableTypeToggleGroup;
7777

@@ -191,19 +191,19 @@ private void toggleMode(final SampServerTableMode mode) {
191191
switch (mode) {
192192
case ALL:
193193
columnLastJoin.setVisible(false);
194-
serverTable.setPlaceholder(new Label(Client.lang.getString("fetchingServers")));
194+
serverTable.setPlaceholder(new Label(Client.getString("fetchingServers")));
195195
fillTableWithOnlineServerList();
196196
break;
197197
case FAVOURITES:
198198
columnLastJoin.setVisible(false);
199199
// TODO-localize
200-
serverTable.setPlaceholder(new Label(Client.lang.getString("noFavouriteServers")));
200+
serverTable.setPlaceholder(new Label(Client.getString("noFavouriteServers")));
201201
serverTable.addAll(FavouritesController.getFavourites());
202202
ServerConfig.initLastJoinData(serverTable.getDataList());
203203
break;
204204
case HISTORY:
205205
// TODO-localize
206-
serverTable.setPlaceholder(new Label(Client.lang.getString("noServerHistory")));
206+
serverTable.setPlaceholder(new Label(Client.getString("noServerHistory")));
207207
columnLastJoin.setVisible(true);
208208
final List<SampServer> servers = ServerConfig.getLastJoinedServers();
209209
servers.forEach(server -> updateServerInfo(server, false));
@@ -229,7 +229,7 @@ private void fillTableWithOnlineServerList() {
229229
}
230230
catch (final IOException exception) {
231231
Logging.error("Couldn't retrieve data from announce api.", exception);
232-
Platform.runLater(() -> serverTable.setPlaceholder(new Label(Client.lang.getString("errorFetchingServers"))));
232+
Platform.runLater(() -> serverTable.setPlaceholder(new Label(Client.getString("errorFetchingServers"))));
233233
}
234234

235235
Platform.runLater(() -> updateGlobalInfo());
@@ -252,7 +252,7 @@ private static void setupInfoLabel(final Label label) {
252252
* the number of active players
253253
*/
254254
protected void setPlayerCount(final int activePlayers) {
255-
playerCount.setText(MessageFormat.format(Client.lang.getString("activePlayers"), activePlayers));
255+
playerCount.setText(MessageFormat.format(Client.getString("activePlayers"), activePlayers));
256256
}
257257

258258
/**
@@ -262,7 +262,7 @@ protected void setPlayerCount(final int activePlayers) {
262262
* the number of active servers
263263
*/
264264
private void setServerCount(final int activeServers) {
265-
serverCount.setText(MessageFormat.format(Client.lang.getString("servers"), activeServers));
265+
serverCount.setText(MessageFormat.format(Client.getString("servers"), activeServers));
266266
}
267267

268268
private void setPlayerComparator() {
@@ -312,7 +312,7 @@ else if (ipAndPort.length == 2 && ServerUtility.isPortValid(ipAndPort[1])) {
312312
addServerToFavourites(ipAndPort[0], Integer.parseInt(ipAndPort[1]));
313313
}
314314
else {
315-
new TrayNotificationBuilder().type(NotificationTypeImplementations.ERROR).title(Client.lang.getString("addToFavourites"))
315+
new TrayNotificationBuilder().type(NotificationTypeImplementations.ERROR).title(Client.getString("addToFavourites"))
316316
.message("cantAddToFavouritesAddressInvalid").animation(Animations.POPUP).build().showAndDismiss(Client.DEFAULT_TRAY_DISMISS_TIME);
317317
}
318318
}
@@ -477,7 +477,7 @@ private void displayNoServerInfo() {
477477
private void applyData(final SampServer server, final ObservableList<Player> playerList, final long ping) {
478478
if (!serverInfoUpdateThread.isInterrupted()) {
479479
Platform.runLater(() -> {
480-
serverPassword.setText(server.isPassworded() ? Client.lang.getString("yes") : Client.lang.getString("no"));
480+
serverPassword.setText(server.isPassworded() ? Client.getString("yes") : Client.getString("no"));
481481
serverPing.setText(String.valueOf(ping));
482482
mapLabel.setText(server.getMap());
483483
websiteLink.setText(server.getWebsite());

client/src/main/java/com/msc/serverbrowser/gui/controllers/implementations/SettingsController.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
package com.msc.serverbrowser.gui.controllers.implementations;
22

33
import java.text.MessageFormat;
4-
import java.util.Locale;
54
import java.util.Optional;
65
import java.util.Properties;
7-
import java.util.ResourceBundle;
86

97
import com.github.plushaze.traynotification.animations.Animations;
108
import com.github.plushaze.traynotification.notification.NotificationTypeImplementations;
@@ -18,6 +16,7 @@
1816
import com.msc.serverbrowser.gui.controllers.interfaces.ViewController;
1917
import com.msc.serverbrowser.util.Language;
2018
import com.msc.serverbrowser.util.UpdateUtility;
19+
import com.msc.serverbrowser.util.basic.MathUtility;
2120
import com.msc.serverbrowser.util.basic.StringUtility;
2221

2322
import javafx.application.Platform;
@@ -98,9 +97,8 @@ private void initPropertyComponents() {
9897
final Language toSelectLanguage = Language.getByShortcut(ClientPropertiesController.getPropertyAsString(Property.LANGUAGE)).get();
9998
languageComboBox.getSelectionModel().select(toSelectLanguage);
10099
languageComboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldVal, newVal) -> {
101-
final Locale locale = new Locale(newVal.getShortcut());
102-
Client.lang = ResourceBundle.getBundle("com.msc.serverbrowser.localization.Lang", locale);
103100
ClientPropertiesController.setProperty(Property.LANGUAGE, newVal.getShortcut());
101+
Client.initLanguageFiles();
104102
Client.getInstance().reloadViewIfLoaded(View.SETTINGS);
105103
});
106104

@@ -132,7 +130,7 @@ private void initPropertyComponents() {
132130
setupCheckBox(allowCachingDownloadsCheckBox, Property.ALLOW_CACHING_DOWNLOADS);
133131

134132
// Adding a listener to disable the update button incase an update is ongoing
135-
final BooleanProperty updatingProperty = Client.getInstance().updatingProperty;
133+
final BooleanProperty updatingProperty = Client.getInstance().updateOngoingProperty;
136134
updatingProperty.addListener((observable, oldVal, newVal) -> {
137135
manualUpdateButton.setDisable(newVal);
138136
});
@@ -143,8 +141,14 @@ private void configureSampLegacyPropertyComponents() {
143141
final Properties legacyProperties = LegacySettingsController.getLegacyProperties().orElse(new Properties());
144142
initLegacySettings(legacyProperties);
145143

146-
fpsLimitSpinner.valueProperty().addListener(__ -> changeLegacyIntegerSetting(LegacySettingsController.FPS_LIMIT, fpsLimitSpinner.getValue()));
147-
pageSizeSpinner.valueProperty().addListener(__ -> changeLegacyIntegerSetting(LegacySettingsController.PAGE_SIZE, pageSizeSpinner.getValue()));
144+
fpsLimitSpinner.valueProperty().addListener(__ -> {
145+
final int value = MathUtility.limitUpperAndLower(fpsLimitSpinner.getValue(), 20, 90);
146+
changeLegacyIntegerSetting(LegacySettingsController.FPS_LIMIT, value);
147+
});
148+
pageSizeSpinner.valueProperty().addListener(__ -> {
149+
final int value = MathUtility.limitUpperAndLower(pageSizeSpinner.getValue(), 10, 20);
150+
changeLegacyIntegerSetting(LegacySettingsController.PAGE_SIZE, value);
151+
});
148152

149153
multicoreCheckbox.setOnAction(__ -> changeLegacyBooleanSetting(LegacySettingsController.MULTICORE, multicoreCheckbox.isSelected()));
150154
audioMsgCheckBox.setOnAction(__ -> changeLegacyBooleanSetting(LegacySettingsController.AUDIO_MESSAGE_OFF, !audioMsgCheckBox.isSelected()));
@@ -160,7 +164,7 @@ private void initInformationArea() {
160164
final StringBuilder builder = new StringBuilder(40);
161165

162166
builder.append("SA-MP Server Browser").append(System.lineSeparator()).append(System.lineSeparator())
163-
.append(MessageFormat.format(Client.lang.getString("versionInfo"), UpdateUtility.VERSION));
167+
.append(MessageFormat.format(Client.getString("versionInfo"), UpdateUtility.VERSION));
164168

165169
informationLabel.setText(builder.toString());
166170
}
@@ -264,8 +268,8 @@ private void onClickClearDownloadCache() {
264268
*/
265269
@FXML
266270
private void onClickRestore() {
267-
final Alert alert = new Alert(AlertType.CONFIRMATION, Client.lang.getString("sureYouWantToRestoreSettings"), ButtonType.YES, ButtonType.NO);
268-
alert.setTitle(Client.lang.getString("restoreSettingsToDefault"));
271+
final Alert alert = new Alert(AlertType.CONFIRMATION, Client.getString("sureYouWantToRestoreSettings"), ButtonType.YES, ButtonType.NO);
272+
alert.setTitle(Client.getString("restoreSettingsToDefault"));
269273
Client.insertAlertOwner(alert);
270274

271275
final Optional<ButtonType> result = alert.showAndWait();

client/src/main/java/com/msc/serverbrowser/gui/controllers/implementations/VersionChangeController.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
* @since 02.07.2017
2828
*/
2929
public class VersionChangeController implements ViewController {
30-
private final String INSTALL_TEXT = Client.lang.getString("install");
31-
private final String INSTALLED_TEXT = Client.lang.getString("installed");
32-
private final String INSTALLING_TEXT = Client.lang.getString("installing");
33-
private final String SAMP_VERSION = Client.lang.getString("sampVersion");
30+
private final String INSTALL_TEXT = Client.getString("install");
31+
private final String INSTALLED_TEXT = Client.getString("installed");
32+
private final String INSTALLING_TEXT = Client.getString("installing");
33+
private final String SAMP_VERSION = Client.getString("sampVersion");
3434

3535
private static Optional<InstallationCandidate> currentlyInstalling = Optional.empty();
3636
private final List<Button> buttons = new ArrayList<>();

client/src/main/java/com/msc/serverbrowser/gui/views/FilesView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ public FilesView() {
4343
chatLogTextArea = new TextArea();
4444
chatLogTextArea.setEditable(false);
4545

46-
clearLogsButton = new Button(Client.lang.getString("clear"));
47-
loadLogsButton = new Button(Client.lang.getString("reload"));
46+
clearLogsButton = new Button(Client.getString("clear"));
47+
loadLogsButton = new Button(Client.getString("reload"));
4848

4949
final ButtonBar buttonBar = new ButtonBar();
5050
buttonBar.getButtons().addAll(loadLogsButton, clearLogsButton);
5151

5252
final VBox chatLogsTabContent = new VBox(5.0, chatLogTextArea, buttonBar);
5353
VBox.setVgrow(chatLogTextArea, Priority.ALWAYS);
5454

55-
chatLogsTab = new Tab(Client.lang.getString("chatlogs"), chatLogsTabContent);
55+
chatLogsTab = new Tab(Client.getString("chatlogs"), chatLogsTabContent);
5656

5757
rootPane = new TabPane(chatLogsTab);
5858
rootPane.setTabClosingPolicy(TabClosingPolicy.UNAVAILABLE);

client/src/main/java/com/msc/serverbrowser/gui/views/MainView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,15 @@ public MainView() {
9595

9696
githubLink = new Hyperlink("\uf09b");
9797
githubLink.getStyleClass().add("info-icon");
98-
githubLink.setTooltip(new Tooltip(Client.lang.getString("openGithubTooltip")));
98+
githubLink.setTooltip(new Tooltip(Client.getString("openGithubTooltip")));
9999
githubLink.setFocusTraversable(false);
100100
helpLink = new Hyperlink("\uf059");
101101
helpLink.getStyleClass().add("info-icon");
102-
helpLink.setTooltip(new Tooltip(Client.lang.getString("openGithubWikiTooltip")));
102+
helpLink.setTooltip(new Tooltip(Client.getString("openGithubWikiTooltip")));
103103
helpLink.setFocusTraversable(false);
104104
donateLink = new Hyperlink("Donate \uf0d6");
105105
donateLink.getStyleClass().add("donate-button");
106-
donateLink.setTooltip(new Tooltip(Client.lang.getString("openDonationPageTooltip")));
106+
donateLink.setTooltip(new Tooltip(Client.getString("openDonationPageTooltip")));
107107
donateLink.setMaxHeight(Double.MAX_VALUE);
108108
donateLink.setFocusTraversable(false);
109109

client/src/main/java/com/msc/serverbrowser/util/Language.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public String getShortcut() {
4747

4848
@Override
4949
public String toString() {
50-
if (Objects.nonNull(Client.lang)) {
51-
final String languageName = Client.lang.getString(shortcut);
50+
if (Objects.nonNull(Client.getLangaugeResourceBundle())) {
51+
final String languageName = Client.getString(shortcut);
5252

5353
if (ClientPropertiesController.getPropertyAsString(Property.LANGUAGE).equalsIgnoreCase(EN.shortcut)) {
5454
return languageName;

0 commit comments

Comments
 (0)