From ec6637728ae6f80b9ba7daaf22b6965f926affa5 Mon Sep 17 00:00:00 2001 From: Glavo Date: Mon, 6 Feb 2023 22:44:19 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=B8=85=E7=90=86=20(#2072)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Remove unused methods * newRaisedButton * update * update * update * update * update * toLowerCase and toUpperCase * update * update --- .../hmcl/game/HMCLGameRepository.java | 2 +- .../jackhuang/hmcl/game/LauncherHelper.java | 9 ++-- .../org/jackhuang/hmcl/setting/Theme.java | 4 +- .../java/org/jackhuang/hmcl/ui/FXUtils.java | 40 ++++-------------- .../jackhuang/hmcl/ui/GameCrashWindow.java | 8 +--- .../jackhuang/hmcl/ui/construct/HintPane.java | 4 +- .../ui/decorator/DecoratorController.java | 3 +- .../hmcl/ui/download/DownloadPage.java | 4 +- .../hmcl/ui/download/InstallersPage.java | 5 +-- .../hmcl/ui/download/ModpackPage.java | 4 +- .../ui/export/ModpackFileSelectionPage.java | 5 +-- .../hmcl/ui/export/ModpackInfoPage.java | 5 +-- .../org/jackhuang/hmcl/ui/main/RootPage.java | 7 ++-- .../hmcl/ui/profile/ProfilePage.java | 5 +-- .../hmcl/ui/versions/DownloadListPage.java | 5 +-- .../hmcl/ui/versions/ModUpdatesPage.java | 42 ++----------------- .../hmcl/ui/versions/VersionSettingsPage.java | 10 ++--- .../hmcl/ui/versions/WorldExportPageSkin.java | 4 +- .../org/jackhuang/hmcl/util/i18n/Locales.java | 2 +- .../AuthlibInjectorAccount.java | 2 +- .../AuthlibInjectorServer.java | 3 +- .../jackhuang/hmcl/task/FileDownloadTask.java | 2 +- .../org/jackhuang/hmcl/util/StringUtils.java | 9 ++-- .../gson/LowerCaseEnumTypeAdapterFactory.java | 4 +- .../hmcl/util/platform/OperatingSystem.java | 4 +- 25 files changed, 60 insertions(+), 132 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java index b50f1efc8..818b414e0 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java @@ -420,7 +420,7 @@ public class HMCLGameRepository extends DefaultGameRepository { return false; if (OperatingSystem.CURRENT_OS == OperatingSystem.WINDOWS && - FORBIDDEN_VERSION_IDS.contains(id.toLowerCase())) + FORBIDDEN_VERSION_IDS.contains(id.toLowerCase(Locale.ROOT))) return false; return OperatingSystem.isNameValid(id); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java b/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java index b76096150..25b4b234d 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java @@ -817,9 +817,12 @@ public final class LauncherHelper { Platform.runLater(() -> logWindow.logLine(filteredLog, level)); } - if (!lwjgl && (!detectWindow || filteredLog.toLowerCase().contains("lwjgl version") || filteredLog.toLowerCase().contains("lwjgl openal"))) { - lwjgl = true; - finishLaunch(); + if (!lwjgl) { + String lowerCaseLog = filteredLog.toLowerCase(Locale.ROOT); + if (!detectWindow || lowerCaseLog.contains("lwjgl version") || lowerCaseLog.contains("lwjgl openal")) { + lwjgl = true; + finishLaunch(); + } } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Theme.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Theme.java index 5571a9f6d..9a81e2301 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Theme.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Theme.java @@ -189,7 +189,7 @@ public class Theme { } public static String getColorDisplayName(Color c) { - return c != null ? String.format("#%02x%02x%02x", Math.round(c.getRed() * 255.0D), Math.round(c.getGreen() * 255.0D), Math.round(c.getBlue() * 255.0D)).toUpperCase() : null; + return c != null ? String.format("#%02x%02x%02x", Math.round(c.getRed() * 255.0D), Math.round(c.getGreen() * 255.0D), Math.round(c.getBlue() * 255.0D)).toUpperCase(Locale.ROOT) : null; } private static final ObjectBinding BLACK_FILL = Bindings.createObjectBinding(() -> BLACK); @@ -217,7 +217,7 @@ public class Theme { public static class TypeAdapter extends com.google.gson.TypeAdapter { @Override public void write(JsonWriter out, Theme value) throws IOException { - out.value(value.getName().toLowerCase()); + out.value(value.getName().toLowerCase(Locale.ROOT)); } @Override diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java index 426b2eba1..0d3e6b4ff 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/FXUtils.java @@ -68,7 +68,6 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import java.awt.*; -import java.awt.image.BufferedImage; import java.io.*; import java.lang.ref.WeakReference; import java.lang.reflect.Constructor; @@ -671,6 +670,13 @@ public final class FXUtils { } } + public static JFXButton newRaisedButton(String text) { + JFXButton button = new JFXButton(text); + button.getStyleClass().add("jfx-button-raised"); + button.setButtonType(JFXButton.ButtonType.RAISED); + return button; + } + public static void applyDragListener(Node node, FileFilter filter, Consumer> callback) { applyDragListener(node, filter, callback, null); } @@ -775,38 +781,6 @@ public final class FXUtils { }); } - // Based on https://stackoverflow.com/a/57552025 - // Fix #874: Use it instead of SwingFXUtils.toFXImage - public static WritableImage toFXImage(BufferedImage image) { - final int iw = image.getWidth(); - final int ih = image.getHeight(); - - WritableImage wr = new WritableImage(iw, ih); - PixelWriter pw = wr.getPixelWriter(); - - for (int x = 0; x < iw; x++) { - for (int y = 0; y < ih; y++) { - pw.setArgb(x, y, image.getRGB(x, y)); - } - } - return wr; - } - - public static BufferedImage fromFXImage(Image image) { - final int iw = (int) image.getWidth(); - final int ih = (int) image.getHeight(); - - PixelReader pr = image.getPixelReader(); - BufferedImage bufferedImage = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_ARGB); - for (int x = 0; x < iw; x++) { - for (int y = 0; y < ih; y++) { - bufferedImage.setRGB(x, y, pr.getArgb(x, y)); - } - } - - return bufferedImage; - } - public static void copyText(String text) { ClipboardContent content = new ClipboardContent(); content.putString(text); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/GameCrashWindow.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/GameCrashWindow.java index 8c80600ba..b5bcc132e 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/GameCrashWindow.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/GameCrashWindow.java @@ -354,14 +354,10 @@ public class GameCrashWindow extends Stage { HBox toolBar = new HBox(); { - JFXButton exportGameCrashInfoButton = new JFXButton(i18n("logwindow.export_game_crash_logs")); - exportGameCrashInfoButton.setButtonType(JFXButton.ButtonType.RAISED); - exportGameCrashInfoButton.getStyleClass().add("jfx-button-raised"); + JFXButton exportGameCrashInfoButton = FXUtils.newRaisedButton(i18n("logwindow.export_game_crash_logs")); exportGameCrashInfoButton.setOnMouseClicked(e -> exportGameCrashInfo()); - JFXButton logButton = new JFXButton(i18n("logwindow.title")); - logButton.setButtonType(JFXButton.ButtonType.RAISED); - logButton.getStyleClass().add("jfx-button-raised"); + JFXButton logButton = FXUtils.newRaisedButton(i18n("logwindow.title")); logButton.setOnMouseClicked(e -> showLogWindow()); toolBar.setPadding(new Insets(8)); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/HintPane.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/HintPane.java index a8442be07..4026da5fe 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/HintPane.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/HintPane.java @@ -31,6 +31,8 @@ import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.SVG; +import java.util.Locale; + public class HintPane extends VBox { private final Text label = new Text(); private final StringProperty text = new SimpleStringProperty(this, "text"); @@ -42,7 +44,7 @@ public class HintPane extends VBox { public HintPane(MessageDialogPane.MessageType type) { setFillWidth(true); - getStyleClass().addAll("hint", type.name().toLowerCase()); + getStyleClass().addAll("hint", type.name().toLowerCase(Locale.ROOT)); HBox hbox = new HBox(); hbox.setAlignment(Pos.CENTER_LEFT); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorController.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorController.java index 23adcac10..f26ff6c46 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorController.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorController.java @@ -52,6 +52,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; +import java.util.Locale; import java.util.Optional; import java.util.Random; import java.util.logging.Level; @@ -197,7 +198,7 @@ public class DecoratorController { candidates = stream .filter(Files::isReadable) .filter(it -> { - String ext = getExtension(it).toLowerCase(); + String ext = getExtension(it).toLowerCase(Locale.ROOT); return ext.equals("png") || ext.equals("jpg") || ext.equals("gif"); }) .collect(toList()); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/DownloadPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/DownloadPage.java index 0865d18b3..51b2fa4c4 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/DownloadPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/DownloadPage.java @@ -82,9 +82,7 @@ public class DownloadPage extends DecoratorAnimatedPage implements DecoratorPage modpackTab.setNodeSupplier(loadVersionFor(() -> { ModpackDownloadListPage page = new ModpackDownloadListPage(Versions::downloadModpackImpl, false); - JFXButton installLocalModpackButton = new JFXButton(i18n("install.modpack")); - installLocalModpackButton.setButtonType(JFXButton.ButtonType.RAISED); - installLocalModpackButton.getStyleClass().add("jfx-button-raised"); + JFXButton installLocalModpackButton = FXUtils.newRaisedButton(i18n("install.modpack")); installLocalModpackButton.setOnAction(e -> Versions.importModpack()); page.getActions().add(installLocalModpackButton); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallersPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallersPage.java index cbffb8e29..19235aa73 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallersPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallersPage.java @@ -34,6 +34,7 @@ import org.jackhuang.hmcl.download.DownloadProvider; import org.jackhuang.hmcl.download.RemoteVersion; import org.jackhuang.hmcl.game.HMCLGameRepository; import org.jackhuang.hmcl.ui.Controllers; +import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.InstallerItem; import org.jackhuang.hmcl.ui.construct.MessageDialogPane; import org.jackhuang.hmcl.ui.construct.RequiredValidator; @@ -162,10 +163,8 @@ public class InstallersPage extends Control implements WizardPage { { - JFXButton installButton = new JFXButton(i18n("button.install")); + JFXButton installButton = FXUtils.newRaisedButton(i18n("button.install")); installButton.disableProperty().bind(control.installable.not()); - installButton.getStyleClass().add("jfx-button-raised"); - installButton.setButtonType(JFXButton.ButtonType.RAISED); installButton.setPrefWidth(100); installButton.setPrefHeight(40); installButton.setOnMouseClicked(e -> control.onInstall()); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/ModpackPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/ModpackPage.java index 3c1ad859a..0f93bd0ce 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/ModpackPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/ModpackPage.java @@ -92,9 +92,7 @@ public abstract class ModpackPage extends SpinnerPane implements WizardPage { btnDescription.setOnAction(e -> onDescribe()); descriptionPane.setLeft(btnDescription); - btnInstall = new JFXButton(i18n("button.install")); - btnInstall.getStyleClass().add("jfx-button-raised"); - btnInstall.setButtonType(JFXButton.ButtonType.RAISED); + btnInstall = FXUtils.newRaisedButton(i18n("button.install")); btnInstall.setOnAction(e -> onInstall()); btnInstall.disableProperty().bind(createBooleanBinding(() -> !txtModpackName.validate(), txtModpackName.textProperty())); descriptionPane.setRight(btnInstall); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/export/ModpackFileSelectionPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/export/ModpackFileSelectionPage.java index 742a3a87f..af472d2b7 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/export/ModpackFileSelectionPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/export/ModpackFileSelectionPage.java @@ -29,6 +29,7 @@ import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import org.jackhuang.hmcl.mod.ModAdviser; import org.jackhuang.hmcl.setting.Profile; +import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.construct.NoneMultipleSelectionModel; import org.jackhuang.hmcl.ui.wizard.WizardController; import org.jackhuang.hmcl.ui.wizard.WizardPage; @@ -69,10 +70,8 @@ public final class ModpackFileSelectionPage extends BorderPane implements Wizard nextPane.setPadding(new Insets(16, 16, 16, 0)); nextPane.setAlignment(Pos.CENTER_RIGHT); { - JFXButton btnNext = new JFXButton(i18n("wizard.next")); - btnNext.getStyleClass().add("jfx-button-raised"); + JFXButton btnNext = FXUtils.newRaisedButton(i18n("wizard.next")); btnNext.setPrefSize(100, 40); - btnNext.setButtonType(JFXButton.ButtonType.RAISED); btnNext.setOnAction(e -> onNext()); nextPane.getChildren().setAll(btnNext); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/export/ModpackInfoPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/export/ModpackInfoPage.java index 20f07c4a4..ba77e77f5 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/export/ModpackInfoPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/export/ModpackInfoPage.java @@ -377,13 +377,10 @@ public final class ModpackInfoPage extends Control implements WizardPage { hbox.setAlignment(Pos.CENTER_RIGHT); borderPane.setBottom(hbox); - JFXButton nextButton = new JFXButton(); + JFXButton nextButton = FXUtils.newRaisedButton(i18n("wizard.next")); nextButton.onMouseClickedProperty().bind(skinnable.next); nextButton.setPrefWidth(100); nextButton.setPrefHeight(40); - nextButton.setButtonType(JFXButton.ButtonType.RAISED); - nextButton.setText(i18n("wizard.next")); - nextButton.getStyleClass().add("jfx-button-raised"); nextButton.disableProperty().bind( // Disable nextButton if any text of JFXTextFields in validatingFields does not fulfill // our requirement. diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/RootPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/RootPage.java index 94c282c07..378c16e29 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/RootPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/main/RootPage.java @@ -50,6 +50,7 @@ import java.io.File; import java.util.Comparator; import java.util.Date; import java.util.List; +import java.util.Locale; import java.util.stream.Collectors; import static org.jackhuang.hmcl.ui.FXUtils.runInFX; @@ -172,13 +173,13 @@ public class RootPage extends DecoratorAnimatedPage implements DecoratorPage { // the left sidebar AdvancedListBox sideBar = new AdvancedListBox() - .startCategory(i18n("account").toUpperCase()) + .startCategory(i18n("account").toUpperCase(Locale.ROOT)) .add(accountListItem) - .startCategory(i18n("version").toUpperCase()) + .startCategory(i18n("version").toUpperCase(Locale.ROOT)) .add(gameListItem) .add(gameItem) .add(downloadItem) - .startCategory(i18n("settings.launcher.general").toUpperCase()) + .startCategory(i18n("settings.launcher.general").toUpperCase(Locale.ROOT)) .add(multiplayerItem) .add(launcherSettingsItem); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfilePage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfilePage.java index dc306adad..962c71467 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfilePage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfilePage.java @@ -35,6 +35,7 @@ import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import org.jackhuang.hmcl.setting.Profile; import org.jackhuang.hmcl.setting.Profiles; +import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.construct.ComponentList; import org.jackhuang.hmcl.ui.construct.FileItem; import org.jackhuang.hmcl.ui.construct.OptionToggleButton; @@ -133,12 +134,10 @@ public final class ProfilePage extends BorderPane implements DecoratorPage { savePane.setStyle("-fx-padding: 20;"); StackPane.setAlignment(savePane, Pos.BOTTOM_RIGHT); { - JFXButton saveButton = new JFXButton(i18n("button.save")); + JFXButton saveButton = FXUtils.newRaisedButton(i18n("button.save")); savePane.setRight(saveButton); BorderPane.setAlignment(savePane, Pos.BOTTOM_RIGHT); StackPane.setAlignment(saveButton, Pos.BOTTOM_RIGHT); - saveButton.getStyleClass().add("jfx-button-raised"); - saveButton.setButtonType(JFXButton.ButtonType.RAISED); saveButton.setPrefSize(100, 40); saveButton.setOnAction(e -> onSave()); saveButton.disableProperty().bind(Bindings.createBooleanBinding( diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadListPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadListPage.java index d5a480ddc..110d86335 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadListPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/DownloadListPage.java @@ -334,10 +334,7 @@ public class DownloadListPage extends Control implements DecoratorPage, VersionP sortComboBox.getSelectionModel().select(0); searchPane.addRow(rowIndex++, new Label(i18n("mods.category")), categoryStackPane, new Label(i18n("search.sort")), sortStackPane); - JFXButton searchButton = new JFXButton(); - searchButton.setText(i18n("search")); - searchButton.getStyleClass().add("jfx-button-raised"); - searchButton.setButtonType(JFXButton.ButtonType.RAISED); + JFXButton searchButton = FXUtils.newRaisedButton(i18n("search")); ObservableList last = FXCollections.observableArrayList(searchButton); HBox searchBox = new HBox(8); actions.appendList(control.actions); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java index e47b4adc0..644697e34 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/ModUpdatesPage.java @@ -18,7 +18,6 @@ package org.jackhuang.hmcl.ui.versions; import com.jfoenix.controls.JFXButton; -import com.jfoenix.controls.JFXListView; import javafx.beans.property.*; import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; @@ -30,30 +29,24 @@ import javafx.scene.control.TableView; import javafx.scene.control.cell.CheckBoxTableCell; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; -import org.apache.commons.lang3.mutable.MutableObject; import org.jackhuang.hmcl.mod.LocalModFile; import org.jackhuang.hmcl.mod.ModManager; import org.jackhuang.hmcl.mod.RemoteMod; -import org.jackhuang.hmcl.mod.curse.CurseAddon; -import org.jackhuang.hmcl.mod.modrinth.ModrinthRemoteModRepository; import org.jackhuang.hmcl.task.FileDownloadTask; import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.ui.Controllers; -import org.jackhuang.hmcl.ui.construct.MDListCell; +import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.construct.MessageDialogPane; import org.jackhuang.hmcl.ui.construct.PageCloseEvent; -import org.jackhuang.hmcl.ui.construct.TwoLineListItem; import org.jackhuang.hmcl.ui.decorator.DecoratorPage; import org.jackhuang.hmcl.util.Pair; import org.jackhuang.hmcl.util.TaskCancellationAction; -import org.jackhuang.hmcl.util.i18n.I18n; import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.List; -import java.util.Locale; import java.util.function.Function; import java.util.stream.Collectors; @@ -107,14 +100,10 @@ public class ModUpdatesPage extends BorderPane implements DecoratorPage { actions.setPadding(new Insets(8)); actions.setAlignment(Pos.CENTER_RIGHT); - JFXButton nextButton = new JFXButton(i18n("mods.check_updates.update")); - nextButton.getStyleClass().add("jfx-button-raised"); - nextButton.setButtonType(JFXButton.ButtonType.RAISED); + JFXButton nextButton = FXUtils.newRaisedButton(i18n("mods.check_updates.update")); nextButton.setOnAction(e -> updateMods()); - JFXButton cancelButton = new JFXButton(i18n("button.cancel")); - cancelButton.getStyleClass().add("jfx-button-raised"); - cancelButton.setButtonType(JFXButton.ButtonType.RAISED); + JFXButton cancelButton = FXUtils.newRaisedButton(i18n("button.cancel")); cancelButton.setOnAction(e -> fireEvent(new PageCloseEvent())); onEscPressed(this, cancelButton::fire); @@ -156,31 +145,6 @@ public class ModUpdatesPage extends BorderPane implements DecoratorPage { return state; } - public static final class ModUpdateCell extends MDListCell { - TwoLineListItem content = new TwoLineListItem(); - - public ModUpdateCell(JFXListView listView, MutableObject lastCell) { - super(listView, lastCell); - - getContainer().getChildren().setAll(content); - } - - @Override - protected void updateControl(LocalModFile.ModUpdate item, boolean empty) { - if (empty) return; - ModTranslations.Mod mod = ModTranslations.MOD.getModById(item.getLocalMod().getId()); - content.setTitle(mod != null && I18n.getCurrentLocale().getLocale() == Locale.CHINA ? mod.getDisplayName() : item.getCurrentVersion().getName()); - content.setSubtitle(item.getLocalMod().getFileName()); - content.getTags().setAll(); - - if (item.getCurrentVersion().getSelf() instanceof CurseAddon.LatestFile) { - content.getTags().add("Curseforge"); - } else if (item.getCurrentVersion().getSelf() instanceof ModrinthRemoteModRepository.ProjectVersion) { - content.getTags().add("Modrinth"); - } - } - } - private static final class ModUpdateObject { final LocalModFile.ModUpdate data; final BooleanProperty enabled = new SimpleBooleanProperty(); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java index bb85bd1a4..2529e760e 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionSettingsPage.java @@ -53,6 +53,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; import java.util.List; +import java.util.Locale; import java.util.Optional; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; @@ -180,11 +181,8 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag enableSpecificCheckBox.setText(i18n("settings.type.special.enable")); BorderPane.setAlignment(enableSpecificCheckBox, Pos.CENTER_RIGHT); - JFXButton editGlobalSettingsButton = new JFXButton(); + JFXButton editGlobalSettingsButton = FXUtils.newRaisedButton(i18n("settings.type.global.edit")); settingsTypePane.setRight(editGlobalSettingsButton); - editGlobalSettingsButton.setText(i18n("settings.type.global.edit")); - editGlobalSettingsButton.getStyleClass().add("jfx-button-raised"); - editGlobalSettingsButton.setButtonType(JFXButton.ButtonType.RAISED); editGlobalSettingsButton.disableProperty().bind(enableSpecificCheckBox.selectedProperty()); BorderPane.setAlignment(editGlobalSettingsButton, Pos.CENTER_RIGHT); editGlobalSettingsButton.setOnMouseClicked(e -> editGlobalSettings()); @@ -546,10 +544,10 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag addEventHandler(Navigator.NavigationEvent.NAVIGATED, this::onDecoratorPageNavigating); cboLauncherVisibility.getItems().setAll(LauncherVisibility.values()); - cboLauncherVisibility.setConverter(stringConverter(e -> i18n("settings.advanced.launcher_visibility." + e.name().toLowerCase()))); + cboLauncherVisibility.setConverter(stringConverter(e -> i18n("settings.advanced.launcher_visibility." + e.name().toLowerCase(Locale.ROOT)))); cboProcessPriority.getItems().setAll(ProcessPriority.values()); - cboProcessPriority.setConverter(stringConverter(e -> i18n("settings.advanced.process_priority." + e.name().toLowerCase()))); + cboProcessPriority.setConverter(stringConverter(e -> i18n("settings.advanced.process_priority." + e.name().toLowerCase(Locale.ROOT)))); } private void initialize() { diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldExportPageSkin.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldExportPageSkin.java index ad388d129..38af59549 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldExportPageSkin.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/WorldExportPageSkin.java @@ -80,11 +80,9 @@ public class WorldExportPageSkin extends SkinBase { container.getChildren().add(list); - JFXButton btnExport = new JFXButton(i18n("button.export")); + JFXButton btnExport = FXUtils.newRaisedButton(i18n("button.export")); btnExport.disableProperty().bind(Bindings.createBooleanBinding(() -> txtWorldName.getText().isEmpty() || Files.exists(Paths.get(fileItem.getPath())), txtWorldName.textProperty().isEmpty(), fileItem.pathProperty())); - btnExport.setButtonType(JFXButton.ButtonType.RAISED); - btnExport.getStyleClass().add("jfx-button-raised"); btnExport.setOnMouseClicked(e -> skinnable.export()); HBox bottom = new HBox(); bottom.setAlignment(Pos.CENTER_RIGHT); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/Locales.java b/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/Locales.java index 8bfb06ee8..ff679635f 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/Locales.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/util/i18n/Locales.java @@ -74,7 +74,7 @@ public final class Locales { public static SupportedLocale getLocaleByName(String name) { if (name == null) return DEFAULT; - switch (name.toLowerCase()) { + switch (name.toLowerCase(Locale.ROOT)) { case "en": return EN; case "zh": diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorAccount.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorAccount.java index 003ff95c9..6be37269a 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorAccount.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorAccount.java @@ -187,7 +187,7 @@ public class AuthlibInjectorAccount extends YggdrasilAccount { return emptySet(); Set result = EnumSet.noneOf(TextureType.class); for (String val : prop.split(",")) { - val = val.toUpperCase(); + val = val.toUpperCase(Locale.ROOT); TextureType parsed; try { parsed = TextureType.valueOf(val); diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorServer.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorServer.java index 282c22599..5d124509d 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorServer.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/auth/authlibinjector/AuthlibInjectorServer.java @@ -29,6 +29,7 @@ import java.lang.reflect.Type; import java.net.HttpURLConnection; import java.net.URL; import java.util.LinkedHashMap; +import java.util.Locale; import java.util.Map; import java.util.Optional; import java.util.logging.Level; @@ -87,7 +88,7 @@ public class AuthlibInjectorServer implements Observable { } private static String addHttpsIfMissing(String url) { - String lowercased = url.toLowerCase(); + String lowercased = url.toLowerCase(Locale.ROOT); if (!lowercased.startsWith("http://") && !lowercased.startsWith("https://")) { url = "https://" + url; } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FileDownloadTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FileDownloadTask.java index 35b99efe5..1b4664130 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FileDownloadTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/task/FileDownloadTask.java @@ -266,7 +266,7 @@ public class FileDownloadTask extends FetchTask { } public static final IntegrityCheckHandler ZIP_INTEGRITY_CHECK_HANDLER = (filePath, destinationPath) -> { - String ext = FileUtils.getExtension(destinationPath).toLowerCase(); + String ext = FileUtils.getExtension(destinationPath).toLowerCase(Locale.ROOT); if (ext.equals("zip") || ext.equals("jar")) { try (FileSystem ignored = CompressingUtils.createReadOnlyZipFileSystem(filePath)) { // test for zip format diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/StringUtils.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/StringUtils.java index babeca000..e3fe3ff86 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/StringUtils.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/StringUtils.java @@ -181,16 +181,19 @@ public final class StringUtils { } public static boolean containsOne(Collection patterns, String... targets) { - for (String pattern : patterns) + for (String pattern : patterns) { + String lowerPattern = pattern.toLowerCase(Locale.ROOT); for (String target : targets) - if (pattern.toLowerCase().contains(target.toLowerCase())) + if (lowerPattern.contains(target.toLowerCase(Locale.ROOT))) return true; + } return false; } public static boolean containsOne(String pattern, String... targets) { + String lowerPattern = pattern.toLowerCase(Locale.ROOT); for (String target : targets) - if (pattern.toLowerCase().contains(target.toLowerCase())) + if (lowerPattern.contains(target.toLowerCase(Locale.ROOT))) return true; return false; } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/gson/LowerCaseEnumTypeAdapterFactory.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/gson/LowerCaseEnumTypeAdapterFactory.java index 58134410e..030f2e66a 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/gson/LowerCaseEnumTypeAdapterFactory.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/gson/LowerCaseEnumTypeAdapterFactory.java @@ -63,12 +63,12 @@ public final class LowerCaseEnumTypeAdapterFactory implements TypeAdapterFactory reader.nextNull(); return null; } - return lowercaseToConstant.get(reader.nextString().toLowerCase()); + return lowercaseToConstant.get(reader.nextString().toLowerCase(Locale.ROOT)); } }; } private static String toLowercase(Object o) { - return o.toString().toLowerCase(Locale.US); + return o.toString().toLowerCase(Locale.ROOT); } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/OperatingSystem.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/OperatingSystem.java index 724a7bce5..f662d3b7f 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/OperatingSystem.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/platform/OperatingSystem.java @@ -311,9 +311,9 @@ public enum OperatingSystem { int dot = name.indexOf('.'); // on windows, filename suffixes are not relevant to name validity String basename = dot == -1 ? name : name.substring(0, dot); - if (Arrays.binarySearch(INVALID_RESOURCE_BASENAMES, basename.toLowerCase()) >= 0) + if (Arrays.binarySearch(INVALID_RESOURCE_BASENAMES, basename.toLowerCase(Locale.ROOT)) >= 0) return false; - if (Arrays.binarySearch(INVALID_RESOURCE_FULLNAMES, name.toLowerCase()) >= 0) + if (Arrays.binarySearch(INVALID_RESOURCE_FULLNAMES, name.toLowerCase(Locale.ROOT)) >= 0) return false; if (INVALID_RESOURCE_CHARACTERS.matcher(name).find()) return false;