From 13e227851f26151bbeeb730af918bebf315dbeb2 Mon Sep 17 00:00:00 2001 From: yushijinhun Date: Sun, 29 Jul 2018 21:10:04 +0800 Subject: [PATCH] Refactor IconedItem --- .../jackhuang/hmcl/ui/LeftPaneController.java | 4 ++-- .../hmcl/ui/construct/IconedItem.java | 23 +++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java index 343041dd1..5addd5a91 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/LeftPaneController.java @@ -229,8 +229,8 @@ public final class LeftPaneController { } public void showUpdate() { - launcherSettingsItem.setText(i18n("update.found")); - launcherSettingsItem.setTextFill(Color.RED); + launcherSettingsItem.getLabel().setText(i18n("update.found")); + launcherSettingsItem.getLabel().setTextFill(Color.RED); } private boolean checkedModpack = false; diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/IconedItem.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/IconedItem.java index 38ecd9933..7a35595c0 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/IconedItem.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/IconedItem.java @@ -21,18 +21,25 @@ import javafx.geometry.Pos; import javafx.scene.Node; import javafx.scene.control.Label; import javafx.scene.layout.HBox; -import javafx.scene.paint.Paint; public class IconedItem extends RipplerContainer { + private Label label; + public IconedItem(Node icon, String text) { - super(createHBox(icon, text)); + this(icon); + label.setText(text); } - private static HBox createHBox(Node icon, String text) { + public IconedItem(Node icon) { + super(createHBox(icon)); + label = ((Label) lookup("#label")); + } + + private static HBox createHBox(Node icon) { HBox hBox = new HBox(); icon.setMouseTransparent(true); - Label textLabel = new Label(text); + Label textLabel = new Label(); textLabel.setId("label"); textLabel.setAlignment(Pos.CENTER); textLabel.setMouseTransparent(true); @@ -42,11 +49,7 @@ public class IconedItem extends RipplerContainer { return hBox; } - public void setText(String text) { - ((Label) lookup("#label")).setText(text); - } - - public void setTextFill(Paint paint) { - ((Label) lookup("#label")).setTextFill(paint); + public Label getLabel() { + return label; } }