From 84fbca7905dce88fbb8728736ac491bff48e6dfa Mon Sep 17 00:00:00 2001 From: yushijinhun Date: Sat, 23 Feb 2019 23:48:23 +0800 Subject: [PATCH] Remove unused code --- .../hmcl/game/HMCLGameRepository.java | 3 - .../jackhuang/hmcl/game/LauncherHelper.java | 24 +-- .../org/jackhuang/hmcl/setting/Profile.java | 10 +- .../hmcl/setting/VersionSetting.java | 101 +++++----- .../org/jackhuang/hmcl/ui/Controllers.java | 7 +- .../java/org/jackhuang/hmcl/ui/LogWindow.java | 10 +- .../org/jackhuang/hmcl/ui/SettingsPage.java | 4 +- .../hmcl/ui/construct/MessageBox.java | 172 ------------------ .../hmcl/ui/construct/MessageDialogPane.java | 23 ++- .../ui/download/InstallerWizardProvider.java | 8 +- .../ModpackInstallWizardProvider.java | 12 +- .../hmcl/ui/download/ModpackPage.java | 4 +- .../hmcl/ui/versions/VersionSettingsPage.java | 27 +-- .../TaskExecutorDialogWizardDisplayer.java | 10 +- .../jackhuang/hmcl/upgrade/UpdateHandler.java | 6 +- .../jackhuang/hmcl/util/CrashReporter.java | 9 +- .../org/jackhuang/hmcl/util/i18n/Locales.java | 4 - .../download/game/VersionJsonSaveTask.java | 3 - .../java/org/jackhuang/hmcl/mod/ModInfo.java | 10 +- .../java/org/jackhuang/hmcl/util/Lang.java | 22 --- .../util/javafx/ImmediateBooleanProperty.java | 55 ------ .../util/javafx/ImmediateIntegerProperty.java | 55 ------ .../util/javafx/ImmediateObjectProperty.java | 55 ------ .../util/javafx/ImmediateStringProperty.java | 75 -------- 24 files changed, 145 insertions(+), 564 deletions(-) delete mode 100644 HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MessageBox.java delete mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/util/javafx/ImmediateBooleanProperty.java delete mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/util/javafx/ImmediateIntegerProperty.java delete mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/util/javafx/ImmediateObjectProperty.java delete mode 100644 HMCLCore/src/main/java/org/jackhuang/hmcl/util/javafx/ImmediateStringProperty.java 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 563aba480..6390e31ca 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/HMCLGameRepository.java @@ -20,9 +20,6 @@ package org.jackhuang.hmcl.game; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import javafx.scene.image.Image; -import org.jackhuang.hmcl.event.EventBus; -import org.jackhuang.hmcl.event.RefreshedVersionsEvent; -import org.jackhuang.hmcl.event.RefreshingVersionsEvent; import org.jackhuang.hmcl.setting.EnumGameDirectory; import org.jackhuang.hmcl.setting.Profile; import org.jackhuang.hmcl.setting.VersionSetting; 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 de641b771..d684dbbbb 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/game/LauncherHelper.java @@ -38,7 +38,7 @@ import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.DialogController; import org.jackhuang.hmcl.ui.LogWindow; import org.jackhuang.hmcl.ui.construct.DialogCloseEvent; -import org.jackhuang.hmcl.ui.construct.MessageBox; +import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType; import org.jackhuang.hmcl.ui.construct.TaskExecutorDialogPane; import org.jackhuang.hmcl.util.Log4jLevel; import org.jackhuang.hmcl.util.Logging; @@ -236,7 +236,7 @@ public final class LauncherHelper { } Controllers.dialog(message, scriptFile == null ? i18n("launch.failed") : i18n("version.launch_script.failed"), - MessageBox.ERROR_MESSAGE); + MessageType.ERROR); } } }); @@ -263,7 +263,7 @@ public final class LauncherHelper { VersionNumber gameVersion = VersionNumber.asVersion(GameVersion.minecraftVersion(profile.getRepository().getVersionJar(version)).orElse("Unknown")); JavaVersion java = setting.getJavaVersion(); if (java == null) { - Controllers.dialog(i18n("launch.wrong_javadir"), i18n("message.warning"), MessageBox.WARNING_MESSAGE, onAccept); + Controllers.dialog(i18n("launch.wrong_javadir"), i18n("message.warning"), MessageType.WARNING, onAccept); setting.setJava(null); setting.setDefaultJavaPath(null); java = JavaVersion.fromCurrentEnvironment(); @@ -282,10 +282,10 @@ public final class LauncherHelper { if (gameVersion.compareTo(VersionNumber.asVersion("1.13")) >= 0) { // Minecraft 1.13 and later versions only support Java 8 or later. // Terminate launching operation. - Controllers.dialog(i18n("launch.advice.java8_1_13"), i18n("message.error"), MessageBox.ERROR_MESSAGE, null); + Controllers.dialog(i18n("launch.advice.java8_1_13"), i18n("message.error"), MessageType.ERROR, null); } else { // Most mods require Java 8 or later version. - Controllers.dialog(i18n("launch.advice.newer_java"), i18n("message.warning"), MessageBox.WARNING_MESSAGE, onAccept); + Controllers.dialog(i18n("launch.advice.newer_java"), i18n("message.warning"), MessageType.WARNING, onAccept); } flag = true; } @@ -301,10 +301,10 @@ public final class LauncherHelper { if (java8.isPresent()) { java8required = true; setting.setJavaVersion(java8.get()); - Controllers.dialog(i18n("launch.advice.java9") + "\n" + i18n("launch.advice.corrected"), i18n("message.info"), MessageBox.INFORMATION_MESSAGE, onAccept); + Controllers.dialog(i18n("launch.advice.java9") + "\n" + i18n("launch.advice.corrected"), i18n("message.info"), MessageType.INFORMATION, onAccept); flag = true; } else { - Controllers.dialog(i18n("launch.advice.java9") + "\n" + i18n("launch.advice.uncorrected"), i18n("message.error"), MessageBox.ERROR_MESSAGE, null); + Controllers.dialog(i18n("launch.advice.java9") + "\n" + i18n("launch.advice.uncorrected"), i18n("message.error"), MessageType.ERROR, null); flag = true; } } @@ -319,7 +319,7 @@ public final class LauncherHelper { newJavaRequired = true; setting.setJavaVersion(java8.get()); } else { - Controllers.dialog(i18n("launch.advice.java8_51_1_13"), i18n("message.warning"), MessageBox.WARNING_MESSAGE, onAccept); + Controllers.dialog(i18n("launch.advice.java8_51_1_13"), i18n("message.warning"), MessageType.WARNING, onAccept); flag = true; } } @@ -351,7 +351,7 @@ public final class LauncherHelper { if (java64.isPresent()) { setting.setJavaVersion(java64.get()); } else { - Controllers.dialog(i18n("launch.advice.different_platform"), i18n("message.error"), MessageBox.ERROR_MESSAGE, onAccept); + Controllers.dialog(i18n("launch.advice.different_platform"), i18n("message.error"), MessageType.ERROR, onAccept); flag = true; } } @@ -361,13 +361,13 @@ public final class LauncherHelper { setting.getMaxMemory() > 1.5 * 1024) { // 1.5 * 1024 is an inaccurate number. // Actual memory limit depends on operating system and memory. - Controllers.dialog(i18n("launch.advice.too_large_memory_for_32bit"), i18n("message.error"), MessageBox.ERROR_MESSAGE, onAccept); + Controllers.dialog(i18n("launch.advice.too_large_memory_for_32bit"), i18n("message.error"), MessageType.ERROR, onAccept); flag = true; } // Cannot allocate too much memory exceeding free space. if (!flag && OperatingSystem.TOTAL_MEMORY > 0 && OperatingSystem.TOTAL_MEMORY < setting.getMaxMemory()) { - Controllers.dialog(i18n("launch.advice.not_enough_space", OperatingSystem.TOTAL_MEMORY), i18n("message.error"), MessageBox.ERROR_MESSAGE, onAccept); + Controllers.dialog(i18n("launch.advice.not_enough_space", OperatingSystem.TOTAL_MEMORY), i18n("message.error"), MessageType.ERROR, onAccept); flag = true; } @@ -379,7 +379,7 @@ public final class LauncherHelper { VersionNumber.VERSION_COMPARATOR.compare(it.getVersion(), "1.12.2-14.23.5.2773") < 0); boolean hasLiteLoader = version.getLibraries().stream().anyMatch(it -> it.is("com.mumfrey", "liteloader")); if (hasForge2760 && hasLiteLoader && gameVersion.compareTo(VersionNumber.asVersion("1.12.2")) == 0) { - Controllers.dialog(i18n("launch.advice.forge2760_liteloader"), i18n("message.error"), MessageBox.ERROR_MESSAGE, onAccept); + Controllers.dialog(i18n("launch.advice.forge2760_liteloader"), i18n("message.error"), MessageType.ERROR, onAccept); flag = true; } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Profile.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Profile.java index 8b12ff90d..29f87fea9 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Profile.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Profile.java @@ -33,8 +33,6 @@ import org.jackhuang.hmcl.game.HMCLGameRepository; import org.jackhuang.hmcl.game.Version; import org.jackhuang.hmcl.ui.WeakListenerHolder; import org.jackhuang.hmcl.util.*; -import org.jackhuang.hmcl.util.javafx.ImmediateObjectProperty; -import org.jackhuang.hmcl.util.javafx.ImmediateStringProperty; import org.jackhuang.hmcl.util.javafx.ObservableHelper; import java.io.File; @@ -90,9 +88,9 @@ public final class Profile implements Observable { return global.get(); } - private final ImmediateStringProperty name; + private final SimpleStringProperty name; - public ImmediateStringProperty nameProperty() { + public StringProperty nameProperty() { return name; } @@ -131,8 +129,8 @@ public final class Profile implements Observable { } public Profile(String name, File initialGameDir, VersionSetting global, String selectedVersion, boolean useRelativePath) { - this.name = new ImmediateStringProperty(this, "name", name); - gameDir = new ImmediateObjectProperty<>(this, "gameDir", initialGameDir); + this.name = new SimpleStringProperty(this, "name", name); + gameDir = new SimpleObjectProperty<>(this, "gameDir", initialGameDir); repository = new HMCLGameRepository(this, initialGameDir); this.global.set(global == null ? new VersionSetting() : global); this.selectedVersion.set(selectedVersion); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/VersionSetting.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/VersionSetting.java index 8d2a44c50..9fc8a766e 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/VersionSetting.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/VersionSetting.java @@ -21,13 +21,18 @@ import com.google.gson.*; import com.google.gson.annotations.JsonAdapter; import javafx.beans.InvalidationListener; +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.IntegerProperty; +import javafx.beans.property.ObjectProperty; +import javafx.beans.property.SimpleBooleanProperty; +import javafx.beans.property.SimpleIntegerProperty; +import javafx.beans.property.SimpleObjectProperty; +import javafx.beans.property.SimpleStringProperty; +import javafx.beans.property.StringProperty; + import org.jackhuang.hmcl.Metadata; import org.jackhuang.hmcl.game.LaunchOptions; import org.jackhuang.hmcl.util.*; -import org.jackhuang.hmcl.util.javafx.ImmediateBooleanProperty; -import org.jackhuang.hmcl.util.javafx.ImmediateIntegerProperty; -import org.jackhuang.hmcl.util.javafx.ImmediateObjectProperty; -import org.jackhuang.hmcl.util.javafx.ImmediateStringProperty; import org.jackhuang.hmcl.util.platform.JavaVersion; import org.jackhuang.hmcl.util.platform.OperatingSystem; @@ -60,9 +65,9 @@ public final class VersionSetting { this.global = global; } - private final ImmediateBooleanProperty usesGlobalProperty = new ImmediateBooleanProperty(this, "usesGlobal", false); + private final BooleanProperty usesGlobalProperty = new SimpleBooleanProperty(this, "usesGlobal", false); - public ImmediateBooleanProperty usesGlobalProperty() { + public BooleanProperty usesGlobalProperty() { return usesGlobalProperty; } @@ -84,9 +89,9 @@ public final class VersionSetting { // java - private final ImmediateStringProperty javaProperty = new ImmediateStringProperty(this, "java", ""); + private final StringProperty javaProperty = new SimpleStringProperty(this, "java", ""); - public ImmediateStringProperty javaProperty() { + public StringProperty javaProperty() { return javaProperty; } @@ -110,7 +115,7 @@ public final class VersionSetting { setDefaultJavaPath(null); } - private final ImmediateStringProperty defaultJavaPathProperty = new ImmediateStringProperty(this, "defaultJavaPath", ""); + private final StringProperty defaultJavaPathProperty = new SimpleStringProperty(this, "defaultJavaPath", ""); /** * Path to Java executable, or null if user customizes java directory. @@ -124,9 +129,9 @@ public final class VersionSetting { defaultJavaPathProperty.set(defaultJavaPath); } - private final ImmediateStringProperty javaDirProperty = new ImmediateStringProperty(this, "javaDir", ""); + private final StringProperty javaDirProperty = new SimpleStringProperty(this, "javaDir", ""); - public ImmediateStringProperty javaDirProperty() { + public StringProperty javaDirProperty() { return javaDirProperty; } @@ -141,9 +146,9 @@ public final class VersionSetting { javaDirProperty.set(javaDir); } - private final ImmediateStringProperty wrapperProperty = new ImmediateStringProperty(this, "wrapper", ""); + private final StringProperty wrapperProperty = new SimpleStringProperty(this, "wrapper", ""); - public ImmediateStringProperty wrapperProperty() { + public StringProperty wrapperProperty() { return wrapperProperty; } @@ -158,9 +163,9 @@ public final class VersionSetting { wrapperProperty.set(wrapper); } - private final ImmediateStringProperty permSizeProperty = new ImmediateStringProperty(this, "permSize", ""); + private final StringProperty permSizeProperty = new SimpleStringProperty(this, "permSize", ""); - public ImmediateStringProperty permSizeProperty() { + public StringProperty permSizeProperty() { return permSizeProperty; } @@ -175,9 +180,9 @@ public final class VersionSetting { permSizeProperty.set(permSize); } - private final ImmediateIntegerProperty maxMemoryProperty = new ImmediateIntegerProperty(this, "maxMemory", OperatingSystem.SUGGESTED_MEMORY); + private final IntegerProperty maxMemoryProperty = new SimpleIntegerProperty(this, "maxMemory", OperatingSystem.SUGGESTED_MEMORY); - public ImmediateIntegerProperty maxMemoryProperty() { + public IntegerProperty maxMemoryProperty() { return maxMemoryProperty; } @@ -195,9 +200,9 @@ public final class VersionSetting { /** * The minimum memory that JVM can allocate for heap. */ - private final ImmediateObjectProperty minMemoryProperty = new ImmediateObjectProperty<>(this, "minMemory", null); + private final ObjectProperty minMemoryProperty = new SimpleObjectProperty<>(this, "minMemory", null); - public ImmediateObjectProperty minMemoryProperty() { + public ObjectProperty minMemoryProperty() { return minMemoryProperty; } @@ -209,9 +214,9 @@ public final class VersionSetting { minMemoryProperty.set(minMemory); } - private final ImmediateStringProperty preLaunchCommandProperty = new ImmediateStringProperty(this, "precalledCommand", ""); + private final StringProperty preLaunchCommandProperty = new SimpleStringProperty(this, "precalledCommand", ""); - public ImmediateStringProperty preLaunchCommandProperty() { + public StringProperty preLaunchCommandProperty() { return preLaunchCommandProperty; } @@ -229,9 +234,9 @@ public final class VersionSetting { // options - private final ImmediateStringProperty javaArgsProperty = new ImmediateStringProperty(this, "javaArgs", ""); + private final StringProperty javaArgsProperty = new SimpleStringProperty(this, "javaArgs", ""); - public ImmediateStringProperty javaArgsProperty() { + public StringProperty javaArgsProperty() { return javaArgsProperty; } @@ -246,9 +251,9 @@ public final class VersionSetting { javaArgsProperty.set(javaArgs); } - private final ImmediateStringProperty minecraftArgsProperty = new ImmediateStringProperty(this, "minecraftArgs", ""); + private final StringProperty minecraftArgsProperty = new SimpleStringProperty(this, "minecraftArgs", ""); - public ImmediateStringProperty minecraftArgsProperty() { + public StringProperty minecraftArgsProperty() { return minecraftArgsProperty; } @@ -263,9 +268,9 @@ public final class VersionSetting { minecraftArgsProperty.set(minecraftArgs); } - private final ImmediateBooleanProperty noJVMArgsProperty = new ImmediateBooleanProperty(this, "noJVMArgs", false); + private final BooleanProperty noJVMArgsProperty = new SimpleBooleanProperty(this, "noJVMArgs", false); - public ImmediateBooleanProperty noJVMArgsProperty() { + public BooleanProperty noJVMArgsProperty() { return noJVMArgsProperty; } @@ -280,9 +285,9 @@ public final class VersionSetting { noJVMArgsProperty.set(noJVMArgs); } - private final ImmediateBooleanProperty notCheckJVMProperty = new ImmediateBooleanProperty(this, "notCheckJVM", false); + private final BooleanProperty notCheckJVMProperty = new SimpleBooleanProperty(this, "notCheckJVM", false); - public ImmediateBooleanProperty notCheckJVMProperty() { + public BooleanProperty notCheckJVMProperty() { return notCheckJVMProperty; } @@ -297,9 +302,9 @@ public final class VersionSetting { notCheckJVMProperty.set(notCheckJVM); } - private final ImmediateBooleanProperty notCheckGameProperty = new ImmediateBooleanProperty(this, "notCheckGame", false); + private final BooleanProperty notCheckGameProperty = new SimpleBooleanProperty(this, "notCheckGame", false); - public ImmediateBooleanProperty notCheckGameProperty() { + public BooleanProperty notCheckGameProperty() { return notCheckGameProperty; } @@ -314,9 +319,9 @@ public final class VersionSetting { notCheckGameProperty.set(notCheckGame); } - private final ImmediateBooleanProperty showLogsProperty = new ImmediateBooleanProperty(this, "showLogs", false); + private final BooleanProperty showLogsProperty = new SimpleBooleanProperty(this, "showLogs", false); - public ImmediateBooleanProperty showLogsProperty() { + public BooleanProperty showLogsProperty() { return showLogsProperty; } @@ -333,14 +338,14 @@ public final class VersionSetting { // Minecraft settings. - private final ImmediateStringProperty serverIpProperty = new ImmediateStringProperty(this, "serverIp", ""); + private final StringProperty serverIpProperty = new SimpleStringProperty(this, "serverIp", ""); - public ImmediateStringProperty serverIpProperty() { + public StringProperty serverIpProperty() { return serverIpProperty; } /** - * The server ip that will be entered after Minecraft successfully loaded immediately. + * The server ip that will be entered after Minecraft successfully loaded ly. * * Format: ip:port or without port. */ @@ -353,9 +358,9 @@ public final class VersionSetting { } - private final ImmediateBooleanProperty fullscreenProperty = new ImmediateBooleanProperty(this, "fullscreen", false); + private final BooleanProperty fullscreenProperty = new SimpleBooleanProperty(this, "fullscreen", false); - public ImmediateBooleanProperty fullscreenProperty() { + public BooleanProperty fullscreenProperty() { return fullscreenProperty; } @@ -370,9 +375,9 @@ public final class VersionSetting { fullscreenProperty.set(fullscreen); } - private final ImmediateIntegerProperty widthProperty = new ImmediateIntegerProperty(this, "width", 854); + private final IntegerProperty widthProperty = new SimpleIntegerProperty(this, "width", 854); - public ImmediateIntegerProperty widthProperty() { + public IntegerProperty widthProperty() { return widthProperty; } @@ -392,9 +397,9 @@ public final class VersionSetting { } - private final ImmediateIntegerProperty heightProperty = new ImmediateIntegerProperty(this, "height", 480); + private final IntegerProperty heightProperty = new SimpleIntegerProperty(this, "height", 480); - public ImmediateIntegerProperty heightProperty() { + public IntegerProperty heightProperty() { return heightProperty; } @@ -417,9 +422,9 @@ public final class VersionSetting { * 0 - .minecraft
* 1 - .minecraft/versions/<version>/
*/ - private final ImmediateObjectProperty gameDirTypeProperty = new ImmediateObjectProperty<>(this, "gameDirType", EnumGameDirectory.ROOT_FOLDER); + private final ObjectProperty gameDirTypeProperty = new SimpleObjectProperty<>(this, "gameDirType", EnumGameDirectory.ROOT_FOLDER); - public ImmediateObjectProperty gameDirTypeProperty() { + public ObjectProperty gameDirTypeProperty() { return gameDirTypeProperty; } @@ -434,9 +439,9 @@ public final class VersionSetting { /** * Your custom gameDir */ - private final ImmediateStringProperty gameDirProperty = new ImmediateStringProperty(this, "gameDir", ""); + private final StringProperty gameDirProperty = new SimpleStringProperty(this, "gameDir", ""); - public ImmediateStringProperty gameDirProperty() { + public StringProperty gameDirProperty() { return gameDirProperty; } @@ -455,9 +460,9 @@ public final class VersionSetting { * 1 - Hide the launcher when the game starts.
* 2 - Keep the launcher open.
*/ - private final ImmediateObjectProperty launcherVisibilityProperty = new ImmediateObjectProperty<>(this, "launcherVisibility", LauncherVisibility.HIDE); + private final ObjectProperty launcherVisibilityProperty = new SimpleObjectProperty<>(this, "launcherVisibility", LauncherVisibility.HIDE); - public ImmediateObjectProperty launcherVisibilityProperty() { + public ObjectProperty launcherVisibilityProperty() { return launcherVisibilityProperty; } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java index 6439af6fa..66e462d51 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java @@ -35,6 +35,7 @@ import org.jackhuang.hmcl.task.TaskExecutor; import org.jackhuang.hmcl.ui.account.AccountList; import org.jackhuang.hmcl.ui.account.AuthlibInjectorServersPage; import org.jackhuang.hmcl.ui.construct.*; +import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType; import org.jackhuang.hmcl.ui.decorator.DecoratorController; import org.jackhuang.hmcl.ui.download.ModpackInstallWizardProvider; import org.jackhuang.hmcl.ui.profile.ProfileList; @@ -223,14 +224,14 @@ public final class Controllers { } public static void dialog(String text, String title) { - dialog(text, title, MessageBox.INFORMATION_MESSAGE); + dialog(text, title, MessageType.INFORMATION); } - public static void dialog(String text, String title, int type) { + public static void dialog(String text, String title, MessageType type) { dialog(text, title, type, null); } - public static void dialog(String text, String title, int type, Runnable onAccept) { + public static void dialog(String text, String title, MessageType type, Runnable onAccept) { dialog(new MessageDialogPane(text, title, type, onAccept)); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java index 901f2837c..4e3c00948 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LogWindow.java @@ -201,11 +201,11 @@ public final class LogWindow extends Stage { if (!flag) cboLines.getSelectionModel().select(0); - btnFatals.textProperty().bind(Bindings.createStringBinding(() -> Integer.toString(fatal.get()) + " fatals", fatal)); - btnErrors.textProperty().bind(Bindings.createStringBinding(() -> Integer.toString(error.get()) + " errors", error)); - btnWarns.textProperty().bind(Bindings.createStringBinding(() -> Integer.toString(warn.get()) + " warns", warn)); - btnInfos.textProperty().bind(Bindings.createStringBinding(() -> Integer.toString(info.get()) + " infos", info)); - btnDebugs.textProperty().bind(Bindings.createStringBinding(() -> Integer.toString(debug.get()) + " debugs", debug)); + btnFatals.textProperty().bind(Bindings.concat(fatal, " fatals")); + btnErrors.textProperty().bind(Bindings.concat(error, " errors")); + btnWarns.textProperty().bind(Bindings.concat(warn, " warns")); + btnInfos.textProperty().bind(Bindings.concat(info, " infos")); + btnDebugs.textProperty().bind(Bindings.concat(debug, " debugs")); btnFatals.selectedProperty().addListener(o -> specificChanged()); btnErrors.selectedProperty().addListener(o -> specificChanged()); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java index 7adb5bbc6..68bfddb85 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java @@ -31,7 +31,7 @@ import javafx.scene.paint.Color; import javafx.scene.text.Font; import org.jackhuang.hmcl.Metadata; import org.jackhuang.hmcl.setting.*; -import org.jackhuang.hmcl.ui.construct.MessageBox; +import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType; import org.jackhuang.hmcl.ui.construct.Validator; import org.jackhuang.hmcl.ui.decorator.DecoratorPage; import org.jackhuang.hmcl.upgrade.RemoteVersion; @@ -228,7 +228,7 @@ public final class SettingsPage extends SettingsView implements DecoratorPage { try { Files.write(logFile, Logging.getRawLogs()); } catch (IOException e) { - Platform.runLater(() -> Controllers.dialog(i18n("settings.launcher.launcher_log.export.failed") + "\n" + e, null, MessageBox.ERROR_MESSAGE)); + Platform.runLater(() -> Controllers.dialog(i18n("settings.launcher.launcher_log.export.failed") + "\n" + e, null, MessageType.ERROR)); LOG.log(Level.WARNING, "Failed to export logs", e); return; } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MessageBox.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MessageBox.java deleted file mode 100644 index 88c0e71ab..000000000 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MessageBox.java +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Hello Minecraft! Launcher - * Copyright (C) 2019 huangyuhui and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.jackhuang.hmcl.ui.construct; - -import javafx.scene.control.Alert; -import javafx.scene.control.ButtonType; -import javafx.scene.control.TextInputDialog; -import org.jackhuang.hmcl.ui.FXUtils; - -import javax.swing.*; -import java.util.Optional; - -import static org.jackhuang.hmcl.util.i18n.I18n.i18n; - -public final class MessageBox { - private MessageBox() { - } - - private static final String TITLE = i18n("message.info"); - - /** - * User Operation: Yes - */ - public static final int YES_OPTION = 0; - - /** - * User Operation: No - */ - public static final int NO_OPTION = 1; - - /** - * User Operation: Cancel - */ - public static final int CANCEL_OPTION = 2; - - /** - * User Operation: OK - */ - public static final int OK_OPTION = 0; - - /** - * User Operation: Closed Message Box - */ - public static final int CLOSED_OPTION = -1; - - /** - * Buttons: Yes No - */ - public static final int YES_NO_OPTION = 10; - /** - * Buttons: Yes No Cancel - */ - public static final int YES_NO_CANCEL_OPTION = 11; - /** - * Buttons: OK Cancel - */ - public static final int OK_CANCEL_OPTION = 12; - - /** - * Message Box Type: Error - */ - public static final int ERROR_MESSAGE = 0; - /** - * Message Box Type: Info - */ - public static final int INFORMATION_MESSAGE = 1; - /** - * Message Box Type: Warning - */ - public static final int WARNING_MESSAGE = 2; - /** - * Message Box Type: Question - */ - public static final int QUESTION_MESSAGE = 3; - /** - * Message Box Type: Fine - */ - public static final int FINE_MESSAGE = 4; - /** - * Message Box Type: Plain - */ - public static final int PLAIN_MESSAGE = -1; - - - public static void show(String message) { - show(message, TITLE); - } - - /** - * Show MsgBox with title and options - * - * @param message The Message - * @param title The title of MsgBox. - * @return user operation. - */ - public static Optional show(String message, String title) { - Alert alert = new Alert(Alert.AlertType.INFORMATION); - alert.setTitle(title); - alert.setHeaderText(title); - alert.setContentText(message); - return alert.showAndWait(); - } - - public static int confirm(String message, String title) { - return confirm(message, title, -1); - } - - public static int confirm(String message, int option) { - return confirm(message, TITLE, option); - } - - public static int confirm(String message, String title, int option) { - return FXUtils.runInUIThread(() -> { - Alert alert = new Alert(Alert.AlertType.CONFIRMATION); - alert.setTitle(title); - alert.setHeaderText(title); - alert.setContentText(message); - switch (option) { - case YES_NO_OPTION: - alert.getButtonTypes().setAll(ButtonType.YES, ButtonType.NO); - break; - case YES_NO_CANCEL_OPTION: - alert.getButtonTypes().setAll(ButtonType.YES, ButtonType.NO, ButtonType.CANCEL); - break; - case OK_CANCEL_OPTION: - alert.getButtonTypes().setAll(ButtonType.OK, ButtonType.CANCEL); - break; - default: - throw new IllegalArgumentException("Unrecognized message box option " + option); - } - Optional buttonType = alert.showAndWait(); - if (!buttonType.isPresent()) return CLOSED_OPTION; - else if (buttonType.get() == ButtonType.OK) return OK_OPTION; - else if (buttonType.get() == ButtonType.YES) return YES_OPTION; - else if (buttonType.get() == ButtonType.NO) return NO_OPTION; - else if (buttonType.get() == ButtonType.CANCEL) return CANCEL_OPTION; - else throw new IllegalStateException("Unexpected button type:" + buttonType.get()); - }); - } - - public static Optional input(String message) { - return input(message, UIManager.getString("OptionPane.inputDialogTitle")); - } - - public static Optional input(String message, String title) { - return input(message, title, ""); - } - - public static Optional input(String message, String title, String initialValue) { - TextInputDialog dialog = new TextInputDialog(initialValue); - dialog.setTitle(title); - dialog.setHeaderText(message); - dialog.setContentText(message); - - return dialog.showAndWait(); - } -} diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MessageDialogPane.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MessageDialogPane.java index f0b576da8..f39b757d5 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MessageDialogPane.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MessageDialogPane.java @@ -32,6 +32,15 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public final class MessageDialogPane extends StackPane { + public static enum MessageType { + ERROR, + INFORMATION, + WARNING, + QUESTION, + FINE, + PLAIN, + } + @FXML private JFXButton acceptButton; @FXML @@ -45,7 +54,7 @@ public final class MessageDialogPane extends StackPane { @FXML private HBox actions; - public MessageDialogPane(String text, String title, int type, Runnable onAccept) { + public MessageDialogPane(String text, String title, MessageType type, Runnable onAccept) { FXUtils.loadFXML(this, "/assets/fxml/message-dialog.fxml"); if (title != null) @@ -60,19 +69,19 @@ public final class MessageDialogPane extends StackPane { actions.getChildren().remove(cancelButton); switch (type) { - case MessageBox.INFORMATION_MESSAGE: + case INFORMATION: graphic.setGraphic(SVG.infoCircle(Theme.blackFillBinding(), 40, 40)); break; - case MessageBox.ERROR_MESSAGE: + case ERROR: graphic.setGraphic(SVG.closeCircle(Theme.blackFillBinding(), 40, 40)); break; - case MessageBox.FINE_MESSAGE: + case FINE: graphic.setGraphic(SVG.checkCircle(Theme.blackFillBinding(), 40, 40)); break; - case MessageBox.WARNING_MESSAGE: + case WARNING: graphic.setGraphic(SVG.alert(Theme.blackFillBinding(), 40, 40)); break; - case MessageBox.QUESTION_MESSAGE: + case QUESTION: graphic.setGraphic(SVG.helpCircle(Theme.blackFillBinding(), 40, 40)); break; default: @@ -81,7 +90,7 @@ public final class MessageDialogPane extends StackPane { } public MessageDialogPane(String text, String title, Runnable onAccept, Runnable onCancel) { - this(text, title, MessageBox.QUESTION_MESSAGE, onAccept); + this(text, title, MessageType.QUESTION, onAccept); cancelButton.setVisible(true); cancelButton.setOnMouseClicked(e -> { diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallerWizardProvider.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallerWizardProvider.java index 87f1360f5..b245aac4c 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallerWizardProvider.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/InstallerWizardProvider.java @@ -28,7 +28,7 @@ import org.jackhuang.hmcl.setting.Profile; import org.jackhuang.hmcl.task.DownloadException; import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.ui.Controllers; -import org.jackhuang.hmcl.ui.construct.MessageBox; +import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType; import org.jackhuang.hmcl.ui.wizard.WizardController; import org.jackhuang.hmcl.ui.wizard.WizardProvider; import org.jackhuang.hmcl.util.StringUtils; @@ -121,11 +121,11 @@ public final class InstallerWizardProvider implements WizardProvider { public static void alertFailureMessage(Exception exception, Runnable next) { if (exception instanceof LibraryDownloadException) { - Controllers.dialog(i18n("launch.failed.download_library", ((LibraryDownloadException) exception).getLibrary().getName()) + "\n" + StringUtils.getStackTrace(exception.getCause()), i18n("install.failed.downloading"), MessageBox.ERROR_MESSAGE, next); + Controllers.dialog(i18n("launch.failed.download_library", ((LibraryDownloadException) exception).getLibrary().getName()) + "\n" + StringUtils.getStackTrace(exception.getCause()), i18n("install.failed.downloading"), MessageType.ERROR, next); } else if (exception instanceof DownloadException) { - Controllers.dialog(i18n("install.failed.downloading.detail", ((DownloadException) exception).getUrl()) + "\n" + StringUtils.getStackTrace(exception.getCause()), i18n("install.failed.downloading"), MessageBox.ERROR_MESSAGE, next); + Controllers.dialog(i18n("install.failed.downloading.detail", ((DownloadException) exception).getUrl()) + "\n" + StringUtils.getStackTrace(exception.getCause()), i18n("install.failed.downloading"), MessageType.ERROR, next); } else { - Controllers.dialog(StringUtils.getStackTrace(exception), i18n("install.failed"), MessageBox.ERROR_MESSAGE, next); + Controllers.dialog(StringUtils.getStackTrace(exception), i18n("install.failed"), MessageType.ERROR, next); } } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/ModpackInstallWizardProvider.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/ModpackInstallWizardProvider.java index 5536940ab..614055ae7 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/ModpackInstallWizardProvider.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/download/ModpackInstallWizardProvider.java @@ -27,7 +27,7 @@ import org.jackhuang.hmcl.setting.Profile; import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.ui.Controllers; -import org.jackhuang.hmcl.ui.construct.MessageBox; +import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType; import org.jackhuang.hmcl.ui.wizard.WizardController; import org.jackhuang.hmcl.ui.wizard.WizardProvider; @@ -84,11 +84,11 @@ public class ModpackInstallWizardProvider implements WizardProvider { try { return ModpackHelper.getUpdateTask(profile, selected, modpack.getEncoding(), name, ModpackHelper.readModpackConfiguration(profile.getRepository().getModpackConfiguration(name))); } catch (UnsupportedModpackException e) { - Controllers.dialog(i18n("modpack.unsupported"), i18n("message.error"), MessageBox.ERROR_MESSAGE); + Controllers.dialog(i18n("modpack.unsupported"), i18n("message.error"), MessageType.ERROR); } catch (MismatchedModpackTypeException e) { - Controllers.dialog(i18n("modpack.mismatched_type"), i18n("message.error"), MessageBox.ERROR_MESSAGE); + Controllers.dialog(i18n("modpack.mismatched_type"), i18n("message.error"), MessageType.ERROR); } catch (IOException e) { - Controllers.dialog(i18n("modpack.invalid"), i18n("message.error"), MessageBox.ERROR_MESSAGE); + Controllers.dialog(i18n("modpack.invalid"), i18n("message.error"), MessageType.ERROR); } return null; } else { @@ -105,9 +105,9 @@ public class ModpackInstallWizardProvider implements WizardProvider { public void onFail(Map settings, Exception exception, Runnable next) { if (exception instanceof CurseCompletionException) { if (exception.getCause() instanceof FileNotFoundException) { - Controllers.dialog(i18n("modpack.type.curse.not_found"), i18n("install.failed"), MessageBox.ERROR_MESSAGE, next); + Controllers.dialog(i18n("modpack.type.curse.not_found"), i18n("install.failed"), MessageType.ERROR, next); } else { - Controllers.dialog(i18n("modpack.type.curse.tolerable_error"), i18n("install.success"), MessageBox.INFORMATION_MESSAGE, next); + Controllers.dialog(i18n("modpack.type.curse.tolerable_error"), i18n("install.success"), MessageType.INFORMATION, next); } } else { InstallerWizardProvider.alertFailureMessage(exception, next); 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 4efc6f38b..82ee5b12b 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 @@ -33,7 +33,7 @@ import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.WebStage; -import org.jackhuang.hmcl.ui.construct.MessageBox; +import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType; import org.jackhuang.hmcl.ui.construct.SpinnerPane; import org.jackhuang.hmcl.ui.construct.Validator; import org.jackhuang.hmcl.ui.wizard.WizardController; @@ -129,7 +129,7 @@ public final class ModpackPage extends StackPane implements WizardPage { txtModpackName.textProperty().addListener(e -> btnInstall.setDisable(!txtModpackName.validate())); } }, e -> { - Controllers.dialog(i18n("modpack.task.install.error"), i18n("message.error"), MessageBox.ERROR_MESSAGE); + Controllers.dialog(i18n("modpack.task.install.error"), i18n("message.error"), MessageType.ERROR); Platform.runLater(controller::onEnd); }).start(); } 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 b5b0b45e7..dc2fbad09 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 @@ -57,7 +57,6 @@ import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Arrays; -import java.util.List; import java.util.logging.Level; import java.util.stream.Collectors; @@ -71,7 +70,6 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag private Profile profile; private String versionId; private boolean javaItemsLoaded; - private InvalidationListener specificSettingsListener; @FXML private VBox rootPane; @FXML private ScrollPane scroll; @@ -100,6 +98,12 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag @FXML private JFXCheckBox chkEnableSpecificSettings; @FXML private BorderPane settingsTypePane; + private InvalidationListener specificSettingsListener = any -> { + chkEnableSpecificSettings.setSelected(!lastVersionSetting.isUsesGlobal()); + }; + + private InvalidationListener javaListener = any -> initJavaSubtitle(); + public VersionSettingsPage() { FXUtils.loadFXML(this, "/assets/fxml/version/version-settings.fxml"); @@ -148,10 +152,6 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag Platform.runLater(() -> loadVersion(profile, versionId)); }); - specificSettingsListener = o -> { - chkEnableSpecificSettings.setSelected(!lastVersionSetting.isUsesGlobal()); - }; - componentList.disableProperty().bind(chkEnableSpecificSettings.selectedProperty().not()); advancedSettingsPane.disableProperty().bind(chkEnableSpecificSettings.selectedProperty().not()); } @@ -193,6 +193,8 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag FXUtils.unbindEnum(cboLauncherVisibility); lastVersionSetting.usesGlobalProperty().removeListener(specificSettingsListener); + lastVersionSetting.javaDirProperty().removeListener(javaListener); + lastVersionSetting.javaProperty().removeListener(javaListener); gameDirItem.selectedDataProperty().unbindBidirectional(lastVersionSetting.gameDirTypeProperty()); gameDirItem.subtitleProperty().unbind(); @@ -232,9 +234,8 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag } }); - versionSetting.javaDirProperty().setChangedListener(it -> initJavaSubtitle(versionSetting)); - versionSetting.javaProperty().setChangedListener(it -> initJavaSubtitle(versionSetting)); - initJavaSubtitle(versionSetting); + versionSetting.javaDirProperty().addListener(javaListener); + versionSetting.javaProperty().addListener(javaListener); gameDirItem.selectedDataProperty().bindBidirectional(versionSetting.gameDirTypeProperty()); gameDirItem.subtitleProperty().bind(Bindings.createStringBinding(() -> Paths.get(profile.getRepository().getRunDirectory(versionId).getAbsolutePath()).normalize().toString(), @@ -243,6 +244,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag lastVersionSetting = versionSetting; initializeSelectedJava(); + initJavaSubtitle(); loadIcon(); } @@ -267,11 +269,14 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag } } - private void initJavaSubtitle(VersionSetting versionSetting) { + private void initJavaSubtitle() { + VersionSetting versionSetting = lastVersionSetting; + if (versionSetting == null) + return; Task.of(variables -> variables.set("java", versionSetting.getJavaVersion())) .subscribe(Task.of(Schedulers.javafx(), variables -> javaItem.setSubtitle(variables.getOptional("java") - .map(JavaVersion::getBinary).map(Path::toString).orElse("Invalid Java Directory")))); + .map(JavaVersion::getBinary).map(Path::toString).orElse("Invalid Java Path")))); } @FXML diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/wizard/TaskExecutorDialogWizardDisplayer.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/wizard/TaskExecutorDialogWizardDisplayer.java index 3fde14e65..48fb46f0a 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/wizard/TaskExecutorDialogWizardDisplayer.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/wizard/TaskExecutorDialogWizardDisplayer.java @@ -24,7 +24,7 @@ import org.jackhuang.hmcl.task.TaskExecutor; import org.jackhuang.hmcl.task.TaskListener; import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.construct.DialogCloseEvent; -import org.jackhuang.hmcl.ui.construct.MessageBox; +import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType; import org.jackhuang.hmcl.ui.construct.TaskExecutorDialogPane; import org.jackhuang.hmcl.util.StringUtils; @@ -67,9 +67,9 @@ public interface TaskExecutorDialogWizardDisplayer extends AbstractWizardDisplay pane.fireEvent(new DialogCloseEvent()); if (success) { if (settings.containsKey("success_message") && settings.get("success_message") instanceof String) - Controllers.dialog((String) settings.get("success_message"), null, MessageBox.FINE_MESSAGE, () -> onEnd()); + Controllers.dialog((String) settings.get("success_message"), null, MessageType.FINE, () -> onEnd()); else if (!settings.containsKey("forbid_success_message")) - Controllers.dialog(i18n("message.success"), null, MessageBox.FINE_MESSAGE, () -> onEnd()); + Controllers.dialog(i18n("message.success"), null, MessageType.FINE, () -> onEnd()); } else { if (executor.getLastException() == null) return; @@ -77,9 +77,9 @@ public interface TaskExecutorDialogWizardDisplayer extends AbstractWizardDisplay if (settings.get("failure_callback") instanceof WizardProvider.FailureCallback) ((WizardProvider.FailureCallback)settings.get("failure_callback")).onFail(settings, executor.getLastException(), () -> onEnd()); else if (settings.get("failure_message") instanceof String) - Controllers.dialog(appendix, (String) settings.get("failure_message"), MessageBox.ERROR_MESSAGE, () -> onEnd()); + Controllers.dialog(appendix, (String) settings.get("failure_message"), MessageType.ERROR, () -> onEnd()); else if (!settings.containsKey("forbid_failure_message")) - Controllers.dialog(appendix, i18n("wizard.failed"), MessageBox.ERROR_MESSAGE, () -> onEnd()); + Controllers.dialog(appendix, i18n("wizard.failed"), MessageType.ERROR, () -> onEnd()); } }); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/upgrade/UpdateHandler.java b/HMCL/src/main/java/org/jackhuang/hmcl/upgrade/UpdateHandler.java index c97f1cf4a..d2cacc977 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/upgrade/UpdateHandler.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/upgrade/UpdateHandler.java @@ -26,7 +26,7 @@ import org.jackhuang.hmcl.Metadata; import org.jackhuang.hmcl.task.Task; import org.jackhuang.hmcl.task.TaskExecutor; import org.jackhuang.hmcl.ui.Controllers; -import org.jackhuang.hmcl.ui.construct.MessageBox; +import org.jackhuang.hmcl.ui.construct.MessageDialogPane.MessageType; import org.jackhuang.hmcl.util.StringUtils; import org.jackhuang.hmcl.util.io.FileUtils; import org.jackhuang.hmcl.util.io.JarUtils; @@ -116,14 +116,14 @@ public final class UpdateHandler { System.exit(0); } catch (IOException e) { LOG.log(Level.WARNING, "Failed to update to " + version, e); - Platform.runLater(() -> Controllers.dialog(StringUtils.getStackTrace(e), i18n("update.failed"), MessageBox.ERROR_MESSAGE)); + Platform.runLater(() -> Controllers.dialog(StringUtils.getStackTrace(e), i18n("update.failed"), MessageType.ERROR)); return; } } else { Throwable e = executor.getLastException(); LOG.log(Level.WARNING, "Failed to update to " + version, e); - Platform.runLater(() -> Controllers.dialog(e.toString(), i18n("update.failed"), MessageBox.ERROR_MESSAGE)); + Platform.runLater(() -> Controllers.dialog(e.toString(), i18n("update.failed"), MessageType.ERROR)); } }); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/util/CrashReporter.java b/HMCL/src/main/java/org/jackhuang/hmcl/util/CrashReporter.java index f5f99e31f..dc0e90d60 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/util/CrashReporter.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/util/CrashReporter.java @@ -18,9 +18,11 @@ package org.jackhuang.hmcl.util; import javafx.application.Platform; +import javafx.scene.control.Alert; +import javafx.scene.control.Alert.AlertType; + import org.jackhuang.hmcl.Metadata; import org.jackhuang.hmcl.ui.CrashWindow; -import org.jackhuang.hmcl.ui.construct.MessageBox; import org.jackhuang.hmcl.upgrade.IntegrityChecker; import org.jackhuang.hmcl.upgrade.UpdateChecker; import org.jackhuang.hmcl.util.io.NetworkUtils; @@ -69,7 +71,10 @@ public class CrashReporter implements Thread.UncaughtExceptionHandler { String info = entry.getValue(); LOG.severe(info); try { - MessageBox.show(info); + Alert alert = new Alert(AlertType.INFORMATION, info); + alert.setTitle(i18n("message.info")); + alert.setHeaderText(i18n("message.info")); + alert.showAndWait(); } catch (Throwable t) { LOG.log(Level.SEVERE, "Unable to show message", t); } 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 a5363ca1a..d94f09f35 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 @@ -58,10 +58,6 @@ public final class Locales { public static final List LOCALES = Lang.immutableListOf(DEFAULT, EN, ZH_CN, ZH); - public static SupportedLocale getLocale(int index) { - return Lang.get(LOCALES, index).orElse(DEFAULT); - } - public static SupportedLocale getLocaleByName(String name) { if (name == null) return DEFAULT; switch (name.toLowerCase()) { diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/VersionJsonSaveTask.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/VersionJsonSaveTask.java index d1031742b..2cc57b3cb 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/VersionJsonSaveTask.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/game/VersionJsonSaveTask.java @@ -24,7 +24,6 @@ import org.jackhuang.hmcl.util.gson.JsonUtils; import org.jackhuang.hmcl.util.io.FileUtils; import java.io.File; -import java.io.IOException; /** * This task is to save the version json. @@ -52,8 +51,6 @@ public final class VersionJsonSaveTask extends Task { @Override public void execute() throws Exception { File json = repository.getVersionJson(version.getId()).getAbsoluteFile(); - if (!FileUtils.makeFile(json)) - throw new IOException("Cannot create file " + json); FileUtils.writeText(json, JsonUtils.GSON.toJson(version)); } } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/ModInfo.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/ModInfo.java index 290c7f6b3..b1dd33246 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/ModInfo.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/mod/ModInfo.java @@ -20,7 +20,9 @@ package org.jackhuang.hmcl.mod; import org.jackhuang.hmcl.util.Logging; import org.jackhuang.hmcl.util.StringUtils; import org.jackhuang.hmcl.util.io.FileUtils; -import org.jackhuang.hmcl.util.javafx.ImmediateBooleanProperty; + +import javafx.beans.property.BooleanProperty; +import javafx.beans.property.SimpleBooleanProperty; import java.io.File; import java.io.IOException; @@ -42,7 +44,7 @@ public final class ModInfo implements Comparable { private final String gameVersion; private final String url; private final String fileName; - private final ImmediateBooleanProperty activeProperty; + private final BooleanProperty activeProperty; public ModInfo(ModManager modManager, File file, String name, String description) { this(modManager, file, name, description, "", "", "", ""); @@ -57,7 +59,7 @@ public final class ModInfo implements Comparable { this.gameVersion = gameVersion; this.url = url; - activeProperty = new ImmediateBooleanProperty(this, "active", !modManager.isDisabled(file)) { + activeProperty = new SimpleBooleanProperty(this, "active", !modManager.isDisabled(file)) { @Override protected void invalidated() { Path path = ModInfo.this.file.toAbsolutePath(); @@ -104,7 +106,7 @@ public final class ModInfo implements Comparable { return url; } - public ImmediateBooleanProperty activeProperty() { + public BooleanProperty activeProperty() { return activeProperty; } diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/Lang.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/Lang.java index 01e55f007..ad6b50243 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/Lang.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/Lang.java @@ -17,7 +17,6 @@ */ package org.jackhuang.hmcl.util; -import org.jackhuang.hmcl.util.function.ExceptionalRunnable; import org.jackhuang.hmcl.util.function.ExceptionalSupplier; import java.util.*; @@ -76,13 +75,6 @@ public final class Lang { } } - public static void ignoringException(ExceptionalRunnable runnable) { - try { - runnable.run(); - } catch (Exception ignore) { - } - } - /** * Cast {@code obj} to V dynamically. * @param obj the object reference to be cast. @@ -98,20 +90,6 @@ public final class Lang { } } - /** - * Get the element at the specific position {@code index} in {@code list}. - * - * @param index the index of element to be return - * @param the type of elements in {@code list} - * @return the element at the specific position, null if index is out of bound. - */ - public static Optional get(List list, int index) { - if (index < 0 || index >= list.size()) - return Optional.empty(); - else - return Optional.ofNullable(list.get(index)); - } - /** * Join two collections into one list. * diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/javafx/ImmediateBooleanProperty.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/javafx/ImmediateBooleanProperty.java deleted file mode 100644 index b73966b1f..000000000 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/javafx/ImmediateBooleanProperty.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Hello Minecraft! Launcher - * Copyright (C) 2019 huangyuhui and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.jackhuang.hmcl.util.javafx; - -import javafx.beans.property.SimpleBooleanProperty; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; - -/** - * @author huangyuhui - * @deprecated Use SimpleBooleanProperty instead - */ -@Deprecated -public class ImmediateBooleanProperty extends SimpleBooleanProperty { - - @Override - public void set(boolean newValue) { - super.get(); - super.set(newValue); - } - - @Override - public void bind(ObservableValue newObservable) { - super.get(); - super.bind(newObservable); - } - - @Override - public void unbind() { - super.get(); - super.unbind(); - } - - public ImmediateBooleanProperty(Object bean, String name, boolean initialValue) { - super(bean, name, initialValue); - ChangeListener changeListener = (a, b, newValue) -> { - }; - addListener(changeListener); - } -} \ No newline at end of file diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/javafx/ImmediateIntegerProperty.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/javafx/ImmediateIntegerProperty.java deleted file mode 100644 index 682950a13..000000000 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/javafx/ImmediateIntegerProperty.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Hello Minecraft! Launcher - * Copyright (C) 2019 huangyuhui and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.jackhuang.hmcl.util.javafx; - -import javafx.beans.property.SimpleIntegerProperty; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; - -/** - * @author huangyuhui - * @deprecated Use SimpleIntegerProperty instead - */ -@Deprecated -public class ImmediateIntegerProperty extends SimpleIntegerProperty { - - @Override - public void set(int newValue) { - super.get(); - super.set(newValue); - } - - @Override - public void bind(ObservableValue newObservable) { - super.get(); - super.bind(newObservable); - } - - @Override - public void unbind() { - super.get(); - super.unbind(); - } - - public ImmediateIntegerProperty(Object bean, String name, int initialValue) { - super(bean, name, initialValue); - ChangeListener changeListener = (a, b, newValue) -> { - }; - addListener(changeListener); - } -} diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/javafx/ImmediateObjectProperty.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/javafx/ImmediateObjectProperty.java deleted file mode 100644 index ac1a5f856..000000000 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/javafx/ImmediateObjectProperty.java +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Hello Minecraft! Launcher - * Copyright (C) 2019 huangyuhui and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.jackhuang.hmcl.util.javafx; - -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; - -/** - * @author huangyuhui - * @deprecated Use SimpleObjectProperty instead - */ -@Deprecated -public class ImmediateObjectProperty extends SimpleObjectProperty { - - @Override - public void set(T newValue) { - super.get(); - super.set(newValue); - } - - @Override - public void bind(ObservableValue newObservable) { - super.get(); - super.bind(newObservable); - } - - @Override - public void unbind() { - super.get(); - super.unbind(); - } - - public ImmediateObjectProperty(Object bean, String name, T initialValue) { - super(bean, name, initialValue); - ChangeListener changeListener = (a, b, newValue) -> { - }; - addListener(changeListener); - } -} \ No newline at end of file diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/javafx/ImmediateStringProperty.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/util/javafx/ImmediateStringProperty.java deleted file mode 100644 index 867e6c216..000000000 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/util/javafx/ImmediateStringProperty.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Hello Minecraft! Launcher - * Copyright (C) 2019 huangyuhui and contributors - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ -package org.jackhuang.hmcl.util.javafx; - -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.value.ChangeListener; -import javafx.beans.value.ObservableValue; - -import java.util.Objects; -import java.util.function.Consumer; - -/** - * @author huangyuhui - * @deprecated Use SimpleStringProperty instead - */ -@Deprecated -public class ImmediateStringProperty extends SimpleStringProperty { - - @Override - public void set(String newValue) { - super.get(); - super.set(newValue); - } - - @Override - public void bind(ObservableValue newObservable) { - super.get(); - super.bind(newObservable); - } - - @Override - public void unbind() { - super.get(); - super.unbind(); - } - - private Consumer consumer = null; - private ChangeListener listener = null; - - public void setChangedListener(Consumer consumer) { - this.consumer = Objects.requireNonNull(consumer); - this.listener = null; - } - - public void setChangedListener(ChangeListener listener) { - this.consumer = null; - this.listener = Objects.requireNonNull(listener); - } - - public ImmediateStringProperty(Object bean, String name, String initialValue) { - super(bean, name, initialValue); - ChangeListener changeListener = (a, b, newValue) -> { - if (consumer != null) - consumer.accept(newValue); - if (listener != null) - listener.changed(a, b, newValue); - }; - addListener(changeListener); - } -}