Skip to content

Commit 04b300f

Browse files
authored
简化 MessageDialogPane (#4918)
1 parent e455ce4 commit 04b300f

File tree

2 files changed

+17
-49
lines changed

2 files changed

+17
-49
lines changed

HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/HintPane.java

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import javafx.scene.text.TextFlow;
2929
import org.jackhuang.hmcl.ui.Controllers;
3030
import org.jackhuang.hmcl.ui.FXUtils;
31-
import org.jackhuang.hmcl.ui.SVG;
3231

3332
import java.util.Locale;
3433

@@ -45,28 +44,7 @@ public HintPane(MessageDialogPane.MessageType type) {
4544
setFillWidth(true);
4645
getStyleClass().addAll("hint", type.name().toLowerCase(Locale.ROOT));
4746

48-
SVG svg;
49-
switch (type) {
50-
case INFO:
51-
svg = SVG.INFO;
52-
break;
53-
case ERROR:
54-
svg = SVG.ERROR;
55-
break;
56-
case SUCCESS:
57-
svg = SVG.CHECK_CIRCLE;
58-
break;
59-
case WARNING:
60-
svg = SVG.WARNING;
61-
break;
62-
case QUESTION:
63-
svg = SVG.HELP;
64-
break;
65-
default:
66-
throw new IllegalArgumentException("Unrecognized message box message type " + type);
67-
}
68-
69-
HBox hbox = new HBox(svg.createIcon(16), new Text(type.getDisplayName()));
47+
HBox hbox = new HBox(type.getIcon().createIcon(16), new Text(type.getDisplayName()));
7048
hbox.setAlignment(Pos.CENTER_LEFT);
7149
hbox.setSpacing(2);
7250
flow.getChildren().setAll(label);

HMCL/src/main/java/org/jackhuang/hmcl/ui/construct/MessageDialogPane.java

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,21 @@
4646
public final class MessageDialogPane extends HBox {
4747

4848
public enum MessageType {
49-
ERROR,
50-
INFO,
51-
WARNING,
52-
QUESTION,
53-
SUCCESS;
49+
ERROR(SVG.ERROR),
50+
INFO(SVG.INFO),
51+
WARNING(SVG.WARNING),
52+
QUESTION(SVG.HELP),
53+
SUCCESS(SVG.CHECK_CIRCLE);
54+
55+
private final SVG icon;
56+
57+
MessageType(SVG icon) {
58+
this.icon = icon;
59+
}
60+
61+
public SVG getIcon() {
62+
return icon;
63+
}
5464

5565
public String getDisplayName() {
5666
return i18n("message." + name().toLowerCase(Locale.ROOT));
@@ -70,27 +80,7 @@ public MessageDialogPane(@NotNull String text, @Nullable String title, @NotNull
7080
graphic.setTranslateY(10);
7181
graphic.setMinSize(40, 40);
7282
graphic.setMaxSize(40, 40);
73-
SVG svg;
74-
switch (type) {
75-
case INFO:
76-
svg = SVG.INFO;
77-
break;
78-
case ERROR:
79-
svg = SVG.ERROR;
80-
break;
81-
case SUCCESS:
82-
svg = SVG.CHECK_CIRCLE;
83-
break;
84-
case WARNING:
85-
svg = SVG.WARNING;
86-
break;
87-
case QUESTION:
88-
svg = SVG.HELP;
89-
break;
90-
default:
91-
throw new IllegalArgumentException("Unrecognized message box message type " + type);
92-
}
93-
graphic.setGraphic(svg.createIcon(40));
83+
graphic.setGraphic(type.getIcon().createIcon(40));
9484

9585
VBox vbox = new VBox();
9686
HBox.setHgrow(vbox, Priority.ALWAYS);

0 commit comments

Comments
 (0)