From 61aee90c8dd1e5972ecd0c17971190c65b6937af Mon Sep 17 00:00:00 2001 From: huangyuhui Date: Wed, 5 Sep 2018 23:25:51 +0800 Subject: [PATCH] Refactor DecoratorPage --- .../src/main/java/org/jackhuang/hmcl/ui/MainPage.java | 10 +++++----- .../main/java/org/jackhuang/hmcl/ui/SettingsPage.java | 11 ++++------- .../org/jackhuang/hmcl/ui/account/AccountList.java | 6 +++--- .../hmcl/ui/account/AuthlibInjectorServersPage.java | 10 +++++----- .../jackhuang/hmcl/ui/decorator/DecoratorPage.java | 4 ++-- .../org/jackhuang/hmcl/ui/profile/ProfileList.java | 6 +++--- .../org/jackhuang/hmcl/ui/profile/ProfilePage.java | 10 ++++++---- .../java/org/jackhuang/hmcl/ui/versions/GameList.java | 6 +++--- .../org/jackhuang/hmcl/ui/versions/VersionPage.java | 10 +++++----- .../hmcl/ui/versions/VersionSettingsPage.java | 10 ++++++---- .../java/org/jackhuang/hmcl/ui/versions/Versions.java | 1 - 11 files changed, 42 insertions(+), 42 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/MainPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/MainPage.java index 4219c8cec..ddbdc4fc1 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/MainPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/MainPage.java @@ -17,8 +17,8 @@ */ package org.jackhuang.hmcl.ui; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; +import javafx.beans.property.ReadOnlyStringProperty; +import javafx.beans.property.ReadOnlyStringWrapper; import javafx.fxml.FXML; import javafx.scene.layout.StackPane; import org.jackhuang.hmcl.setting.ConfigHolder; @@ -31,7 +31,7 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public final class MainPage extends StackPane implements DecoratorPage { - private final StringProperty title = new SimpleStringProperty(this, "title", i18n("main_page")); + private final ReadOnlyStringWrapper title = new ReadOnlyStringWrapper(this, "title", i18n("main_page")); @FXML private StackPane main; @@ -58,8 +58,8 @@ public final class MainPage extends StackPane implements DecoratorPage { } @Override - public StringProperty titleProperty() { - return title; + public ReadOnlyStringProperty titleProperty() { + return title.getReadOnlyProperty(); } public void setTitle(String title) { 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 f395a18da..a660c125e 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/SettingsPage.java @@ -24,10 +24,7 @@ import javafx.beans.InvalidationListener; import javafx.beans.WeakInvalidationListener; import javafx.beans.binding.Bindings; import javafx.beans.binding.When; -import javafx.beans.property.ObjectProperty; -import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; +import javafx.beans.property.*; import javafx.collections.FXCollections; import javafx.collections.ObservableList; import javafx.scene.control.Label; @@ -54,7 +51,7 @@ import static org.jackhuang.hmcl.setting.ConfigHolder.config; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public final class SettingsPage extends SettingsView implements DecoratorPage { - private final StringProperty title = new SimpleStringProperty(this, "title", i18n("settings.launcher")); + private final ReadOnlyStringWrapper title = new ReadOnlyStringWrapper(this, "title", i18n("settings.launcher")); private ObjectProperty selectedProxyType; @@ -238,8 +235,8 @@ public final class SettingsPage extends SettingsView implements DecoratorPage { } @Override - public StringProperty titleProperty() { - return title; + public ReadOnlyStringProperty titleProperty() { + return title.getReadOnlyProperty(); } public void setTitle(String title) { diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountList.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountList.java index 441fe88a8..f3fa11fdd 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountList.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountList.java @@ -32,7 +32,7 @@ import static org.jackhuang.hmcl.ui.FXUtils.onInvalidating; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public class AccountList extends Control implements DecoratorPage { - private final StringProperty title = new SimpleStringProperty(i18n("account.manage")); + private final ReadOnlyStringWrapper title = new ReadOnlyStringWrapper(i18n("account.manage")); private final ListProperty items = new SimpleListProperty<>(FXCollections.observableArrayList()); private ObjectProperty selectedAccount = new SimpleObjectProperty() { { @@ -87,7 +87,7 @@ public class AccountList extends Control implements DecoratorPage { } @Override - public StringProperty titleProperty() { - return title; + public ReadOnlyStringProperty titleProperty() { + return title.getReadOnlyProperty(); } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AuthlibInjectorServersPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AuthlibInjectorServersPage.java index b792331a3..33715e060 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AuthlibInjectorServersPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AuthlibInjectorServersPage.java @@ -18,8 +18,8 @@ package org.jackhuang.hmcl.ui.account; import javafx.beans.binding.Bindings; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; +import javafx.beans.property.ReadOnlyStringProperty; +import javafx.beans.property.ReadOnlyStringWrapper; import javafx.collections.ObservableList; import javafx.fxml.FXML; import javafx.scene.control.ScrollPane; @@ -36,7 +36,7 @@ import static org.jackhuang.hmcl.ui.FXUtils.smoothScrolling; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public class AuthlibInjectorServersPage extends StackPane implements DecoratorPage { - private final StringProperty title = new SimpleStringProperty(this, "title", i18n("account.injector.manage.title")); + private final ReadOnlyStringWrapper title = new ReadOnlyStringWrapper(this, "title", i18n("account.injector.manage.title")); @FXML private ScrollPane scrollPane; @FXML private VBox listPane; @@ -67,8 +67,8 @@ public class AuthlibInjectorServersPage extends StackPane implements DecoratorPa } @Override - public StringProperty titleProperty() { - return title; + public ReadOnlyStringProperty titleProperty() { + return title.getReadOnlyProperty(); } public void setTitle(String title) { diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorPage.java index 658c73e3f..6830747bd 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/decorator/DecoratorPage.java @@ -17,10 +17,10 @@ */ package org.jackhuang.hmcl.ui.decorator; -import javafx.beans.property.StringProperty; +import javafx.beans.property.ReadOnlyStringProperty; public interface DecoratorPage { - StringProperty titleProperty(); + ReadOnlyStringProperty titleProperty(); default boolean canForceToClose() { return false; diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfileList.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfileList.java index 0ce8804c1..bf089248c 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfileList.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfileList.java @@ -32,7 +32,7 @@ import static org.jackhuang.hmcl.ui.FXUtils.onInvalidating; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public class ProfileList extends Control implements DecoratorPage { - private final StringProperty title = new SimpleStringProperty(i18n("profile.manage")); + private final ReadOnlyStringWrapper title = new ReadOnlyStringWrapper(i18n("profile.manage")); private final ListProperty items = new SimpleListProperty<>(FXCollections.observableArrayList()); private ObjectProperty selectedProfile = new SimpleObjectProperty() { { @@ -87,7 +87,7 @@ public class ProfileList extends Control implements DecoratorPage { } @Override - public StringProperty titleProperty() { - return title; + public ReadOnlyStringProperty titleProperty() { + return title.getReadOnlyProperty(); } } 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 9b9b921ae..1146bd35f 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 @@ -20,6 +20,8 @@ package org.jackhuang.hmcl.ui.profile; import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXCheckBox; import com.jfoenix.controls.JFXTextField; +import javafx.beans.property.ReadOnlyStringProperty; +import javafx.beans.property.ReadOnlyStringWrapper; import javafx.beans.property.SimpleStringProperty; import javafx.beans.property.StringProperty; import javafx.fxml.FXML; @@ -39,7 +41,7 @@ import java.util.Optional; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public final class ProfilePage extends StackPane implements DecoratorPage { - private final StringProperty title; + private final ReadOnlyStringWrapper title; private final StringProperty location; private final Profile profile; @@ -55,7 +57,7 @@ public final class ProfilePage extends StackPane implements DecoratorPage { this.profile = profile; String profileDisplayName = Optional.ofNullable(profile).map(Profiles::getProfileDisplayName).orElse(""); - title = new SimpleStringProperty(this, "title", + title = new ReadOnlyStringWrapper(this, "title", profile == null ? i18n("profile.new") : i18n("profile") + " - " + profileDisplayName); location = new SimpleStringProperty(this, "location", Optional.ofNullable(profile).map(Profile::getGameDir).map(File::getAbsolutePath).orElse("")); @@ -101,8 +103,8 @@ public final class ProfilePage extends StackPane implements DecoratorPage { } @Override - public StringProperty titleProperty() { - return title; + public ReadOnlyStringProperty titleProperty() { + return title.getReadOnlyProperty(); } public void setTitle(String title) { diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameList.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameList.java index fff5b55d3..fac2ab763 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameList.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameList.java @@ -41,7 +41,7 @@ import java.util.stream.Collectors; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public class GameList extends Control implements DecoratorPage { - private final StringProperty title = new SimpleStringProperty(I18n.i18n("version.manage")); + private final ReadOnlyStringWrapper title = new ReadOnlyStringWrapper(I18n.i18n("version.manage")); private final BooleanProperty loading = new SimpleBooleanProperty(true); private final ListProperty items = new SimpleListProperty<>(FXCollections.observableArrayList()); @@ -115,8 +115,8 @@ public class GameList extends Control implements DecoratorPage { } @Override - public StringProperty titleProperty() { - return title; + public ReadOnlyStringProperty titleProperty() { + return title.getReadOnlyProperty(); } public BooleanProperty loadingProperty() { diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionPage.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionPage.java index b8741055b..39dca326b 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionPage.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/VersionPage.java @@ -21,8 +21,8 @@ import com.jfoenix.controls.JFXButton; import com.jfoenix.controls.JFXListView; import com.jfoenix.controls.JFXPopup; import com.jfoenix.controls.JFXTabPane; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; +import javafx.beans.property.ReadOnlyStringProperty; +import javafx.beans.property.ReadOnlyStringWrapper; import javafx.fxml.FXML; import javafx.scene.control.Tab; import javafx.scene.layout.StackPane; @@ -37,7 +37,7 @@ import java.io.File; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public final class VersionPage extends StackPane implements DecoratorPage { - private final StringProperty title = new SimpleStringProperty(this, "title", null); + private final ReadOnlyStringWrapper title = new ReadOnlyStringWrapper(this, "title", null); @FXML private VersionSettingsPage versionSettings; @@ -167,8 +167,8 @@ public final class VersionPage extends StackPane implements DecoratorPage { } @Override - public StringProperty titleProperty() { - return title; + public ReadOnlyStringProperty titleProperty() { + return title.getReadOnlyProperty(); } public void setTitle(String title) { 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 24a0a1f8a..bdf8defde 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 @@ -24,8 +24,8 @@ import com.jfoenix.controls.JFXToggleButton; import javafx.application.Platform; import javafx.beans.InvalidationListener; import javafx.beans.binding.Bindings; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; +import javafx.beans.property.ReadOnlyStringProperty; +import javafx.beans.property.ReadOnlyStringWrapper; import javafx.fxml.FXML; import javafx.scene.control.Label; import javafx.scene.control.ScrollPane; @@ -36,6 +36,7 @@ import javafx.scene.layout.VBox; import javafx.stage.FileChooser; import org.jackhuang.hmcl.setting.EnumGameDirectory; import org.jackhuang.hmcl.setting.Profile; +import org.jackhuang.hmcl.setting.Profiles; import org.jackhuang.hmcl.setting.VersionSetting; import org.jackhuang.hmcl.task.Schedulers; import org.jackhuang.hmcl.task.Task; @@ -61,7 +62,7 @@ import java.util.stream.Collectors; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public final class VersionSettingsPage extends StackPane implements DecoratorPage { - private final StringProperty title = new SimpleStringProperty(); + private final ReadOnlyStringWrapper title = new ReadOnlyStringWrapper(); private VersionSetting lastVersionSetting = null; private Profile profile; @@ -156,6 +157,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag rootPane.getChildren().remove(iconPickerItemWrapper); rootPane.getChildren().remove(settingsTypePane); chkEnableSpecificSettings.setSelected(true); + title.set(Profiles.getProfileDisplayName(profile) + " - " + i18n("settings.type.global.manage")); } VersionSetting versionSetting = profile.getVersionSetting(versionId); @@ -310,7 +312,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag } @Override - public StringProperty titleProperty() { + public ReadOnlyStringProperty titleProperty() { return title; } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java index 82ddc9623..0ea9890ee 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/Versions.java @@ -135,7 +135,6 @@ public class Versions { public static void modifyGlobalSettings(Profile profile) { VersionSettingsPage page = new VersionSettingsPage(); page.loadVersionSetting(profile, null); - page.titleProperty().set(Profiles.getProfileDisplayName(profile) + " - " + i18n("settings.type.global.manage")); Controllers.navigate(page); } }