diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/AdvancedListItem2.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/AdvancedListItem2.java deleted file mode 100644 index 8c660746f..000000000 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/AdvancedListItem2.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Hello Minecraft! Launcher. - * Copyright (C) 2017 huangyuhui - * - * 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 {http://www.gnu.org/licenses/}. - */ -package org.jackhuang.hmcl.ui; - -import javafx.beans.property.*; -import javafx.event.ActionEvent; -import javafx.event.EventHandler; -import javafx.geometry.Rectangle2D; -import javafx.scene.control.Control; -import javafx.scene.control.Skin; -import javafx.scene.image.Image; -import org.jackhuang.hmcl.game.AccountHelper; - -public class AdvancedListItem2 extends Control { - private final ObjectProperty image = new SimpleObjectProperty<>(); - private final ObjectProperty viewport = new SimpleObjectProperty<>(); - private final StringProperty title = new SimpleStringProperty(); - private final StringProperty subtitle = new SimpleStringProperty(); - - public ObjectProperty imageProperty() { - return image; - } - - public ObjectProperty viewportProperty() { - return viewport; - } - - public StringProperty titleProperty() { - return title; - } - - public StringProperty subtitleProperty() { - return subtitle; - } - - public final ObjectProperty> onActionProperty() { - return onAction; - } - - public final void setOnAction(EventHandler value) { - onActionProperty().set(value); - } - - public final EventHandler getOnAction() { - return onActionProperty().get(); - } - - private ObjectProperty> onAction = new SimpleObjectProperty>(this, "onAction") { - @Override - protected void invalidated() { - setEventHandler(ActionEvent.ACTION, get()); - } - }; - - @Override - protected Skin createDefaultSkin() { - return new AdvancedListItemSkin(this); - } -} diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountAdvancedListItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountAdvancedListItem.java index 4aaf5c32c..ce968e09b 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountAdvancedListItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/account/AccountAdvancedListItem.java @@ -19,23 +19,17 @@ package org.jackhuang.hmcl.ui.account; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; -import javafx.geometry.Rectangle2D; import javafx.scene.image.Image; import org.jackhuang.hmcl.auth.Account; import org.jackhuang.hmcl.auth.offline.OfflineAccount; import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount; import org.jackhuang.hmcl.game.AccountHelper; -import org.jackhuang.hmcl.setting.Accounts; import org.jackhuang.hmcl.task.Schedulers; -import org.jackhuang.hmcl.ui.AdvancedListItem2; -import org.jackhuang.hmcl.ui.FXUtils; +import org.jackhuang.hmcl.ui.construct.AdvancedListItem; -import static org.jackhuang.hmcl.ui.FXUtils.onInvalidating; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; -public class AccountAdvancedListItem extends AdvancedListItem2 { +public class AccountAdvancedListItem extends AdvancedListItem { private ObjectProperty account = new SimpleObjectProperty() { @Override diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AdvancedListBox.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AdvancedListBox.java index 3b1ea32a6..0695bc013 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AdvancedListBox.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AdvancedListBox.java @@ -23,7 +23,6 @@ import javafx.scene.control.ScrollPane; import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; -import org.jackhuang.hmcl.ui.AdvancedListItem2; import org.jackhuang.hmcl.ui.FXUtils; public class AdvancedListBox extends ScrollPane { @@ -43,7 +42,7 @@ public class AdvancedListBox extends ScrollPane { } public AdvancedListBox add(Node child) { - if (child instanceof Pane || child instanceof AdvancedListItem2) + if (child instanceof Pane || child instanceof AdvancedListItem) container.getChildren().add(child); else { StackPane pane = new StackPane(); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AdvancedListItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AdvancedListItem.java index e740fbce9..356d7d7cd 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AdvancedListItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AdvancedListItem.java @@ -1,7 +1,7 @@ /* * Hello Minecraft! Launcher. - * Copyright (C) 2018 huangyuhui - * + * Copyright (C) 2017 huangyuhui + * * 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 @@ -17,55 +17,57 @@ */ package org.jackhuang.hmcl.ui.construct; -import com.jfoenix.controls.JFXButton; +import javafx.beans.property.*; +import javafx.event.ActionEvent; import javafx.event.EventHandler; -import javafx.fxml.FXML; import javafx.geometry.Rectangle2D; -import javafx.scene.control.Label; +import javafx.scene.control.Control; +import javafx.scene.control.Skin; import javafx.scene.image.Image; -import javafx.scene.image.ImageView; -import javafx.scene.input.MouseEvent; -import javafx.scene.layout.StackPane; -import org.jackhuang.hmcl.ui.FXUtils; -public final class AdvancedListItem extends StackPane { - @FXML - private StackPane imageViewContainer; - @FXML - private Label lblTitle; - @FXML - private Label lblSubtitle; - @FXML - private ImageView imageView; - @FXML private JFXButton btnSettings; +public class AdvancedListItem extends Control { + private final ObjectProperty image = new SimpleObjectProperty<>(); + private final ObjectProperty viewport = new SimpleObjectProperty<>(); + private final StringProperty title = new SimpleStringProperty(); + private final StringProperty subtitle = new SimpleStringProperty(); - public AdvancedListItem(String title) { - this(title, ""); + public ObjectProperty imageProperty() { + return image; } - public AdvancedListItem(String title, String subtitle) { - FXUtils.loadFXML(this, "/assets/fxml/advanced-list-item.fxml"); - - lblTitle.setText(title); - lblSubtitle.setText(subtitle); - - FXUtils.limitSize(imageView, 32, 32); + public ObjectProperty viewportProperty() { + return viewport; } - public void setOnSettingsButtonClicked(EventHandler handler) { - btnSettings.setOnMouseClicked(handler); + public StringProperty titleProperty() { + return title; } - public void setTitle(String title) { - lblTitle.setText(title); + public StringProperty subtitleProperty() { + return subtitle; } - public void setSubtitle(String subtitle) { - lblSubtitle.setText(subtitle); + public final ObjectProperty> onActionProperty() { + return onAction; } - public void setImage(Image image, Rectangle2D viewport) { - imageView.setImage(image); - imageView.setViewport(viewport); + public final void setOnAction(EventHandler value) { + onActionProperty().set(value); + } + + public final EventHandler getOnAction() { + return onActionProperty().get(); + } + + private ObjectProperty> onAction = new SimpleObjectProperty>(this, "onAction") { + @Override + protected void invalidated() { + setEventHandler(ActionEvent.ACTION, get()); + } + }; + + @Override + protected Skin createDefaultSkin() { + return new AdvancedListItemSkin(this); } } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/AdvancedListItemSkin.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AdvancedListItemSkin.java similarity index 95% rename from HMCL/src/main/java/org/jackhuang/hmcl/ui/AdvancedListItemSkin.java rename to HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AdvancedListItemSkin.java index 1b94cf304..901693879 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/AdvancedListItemSkin.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/AdvancedListItemSkin.java @@ -15,7 +15,7 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see {http://www.gnu.org/licenses/}. */ -package org.jackhuang.hmcl.ui; +package org.jackhuang.hmcl.ui.construct; import com.jfoenix.controls.JFXButton; import javafx.geometry.Insets; @@ -29,12 +29,12 @@ import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.scene.text.TextAlignment; import org.jackhuang.hmcl.setting.Theme; +import org.jackhuang.hmcl.ui.FXUtils; +import org.jackhuang.hmcl.ui.SVG; -import java.util.Optional; +public class AdvancedListItemSkin extends SkinBase { -public class AdvancedListItemSkin extends SkinBase { - - public AdvancedListItemSkin(AdvancedListItem2 skinnable) { + public AdvancedListItemSkin(AdvancedListItem skinnable) { super(skinnable); StackPane stackPane = new StackPane(); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfileAdvancedListItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfileAdvancedListItem.java index 19d7b1ff9..47bd4b01a 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfileAdvancedListItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/profile/ProfileAdvancedListItem.java @@ -19,24 +19,14 @@ package org.jackhuang.hmcl.ui.profile; import javafx.beans.property.ObjectProperty; import javafx.beans.property.SimpleObjectProperty; -import javafx.beans.property.SimpleStringProperty; -import javafx.beans.property.StringProperty; -import javafx.geometry.Rectangle2D; import javafx.scene.image.Image; -import org.jackhuang.hmcl.auth.Account; -import org.jackhuang.hmcl.auth.offline.OfflineAccount; -import org.jackhuang.hmcl.auth.yggdrasil.YggdrasilAccount; -import org.jackhuang.hmcl.game.AccountHelper; -import org.jackhuang.hmcl.setting.Accounts; import org.jackhuang.hmcl.setting.Profile; import org.jackhuang.hmcl.setting.Profiles; -import org.jackhuang.hmcl.task.Schedulers; -import org.jackhuang.hmcl.ui.AdvancedListItem2; -import org.jackhuang.hmcl.ui.FXUtils; +import org.jackhuang.hmcl.ui.construct.AdvancedListItem; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; -public class ProfileAdvancedListItem extends AdvancedListItem2 { +public class ProfileAdvancedListItem extends AdvancedListItem { private ObjectProperty profile = new SimpleObjectProperty() { @Override diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameAdvancedListItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameAdvancedListItem.java index 34a359e2d..58fbb22c2 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameAdvancedListItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/versions/GameAdvancedListItem.java @@ -24,12 +24,12 @@ import org.jackhuang.hmcl.event.EventBus; import org.jackhuang.hmcl.event.RefreshedVersionsEvent; import org.jackhuang.hmcl.setting.Profile; import org.jackhuang.hmcl.setting.Profiles; -import org.jackhuang.hmcl.ui.AdvancedListItem2; +import org.jackhuang.hmcl.ui.construct.AdvancedListItem; import org.jackhuang.hmcl.ui.WeakListenerHelper; import java.io.File; -public class GameAdvancedListItem extends AdvancedListItem2 { +public class GameAdvancedListItem extends AdvancedListItem { private final WeakListenerHelper helper = new WeakListenerHelper(); private Profile profile;