简化 MessageDialogPane (#4918)

This commit is contained in:
Glavo
2025-12-06 21:18:58 +08:00
committed by GitHub
parent e455ce4c84
commit 04b300f453
2 changed files with 17 additions and 49 deletions

View File

@@ -28,7 +28,6 @@ import javafx.scene.text.Text;
import javafx.scene.text.TextFlow; import javafx.scene.text.TextFlow;
import org.jackhuang.hmcl.ui.Controllers; import org.jackhuang.hmcl.ui.Controllers;
import org.jackhuang.hmcl.ui.FXUtils; import org.jackhuang.hmcl.ui.FXUtils;
import org.jackhuang.hmcl.ui.SVG;
import java.util.Locale; import java.util.Locale;
@@ -45,28 +44,7 @@ public class HintPane extends VBox {
setFillWidth(true); setFillWidth(true);
getStyleClass().addAll("hint", type.name().toLowerCase(Locale.ROOT)); getStyleClass().addAll("hint", type.name().toLowerCase(Locale.ROOT));
SVG svg; HBox hbox = new HBox(type.getIcon().createIcon(16), new Text(type.getDisplayName()));
switch (type) {
case INFO:
svg = SVG.INFO;
break;
case ERROR:
svg = SVG.ERROR;
break;
case SUCCESS:
svg = SVG.CHECK_CIRCLE;
break;
case WARNING:
svg = SVG.WARNING;
break;
case QUESTION:
svg = SVG.HELP;
break;
default:
throw new IllegalArgumentException("Unrecognized message box message type " + type);
}
HBox hbox = new HBox(svg.createIcon(16), new Text(type.getDisplayName()));
hbox.setAlignment(Pos.CENTER_LEFT); hbox.setAlignment(Pos.CENTER_LEFT);
hbox.setSpacing(2); hbox.setSpacing(2);
flow.getChildren().setAll(label); flow.getChildren().setAll(label);

View File

@@ -46,11 +46,21 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
public final class MessageDialogPane extends HBox { public final class MessageDialogPane extends HBox {
public enum MessageType { public enum MessageType {
ERROR, ERROR(SVG.ERROR),
INFO, INFO(SVG.INFO),
WARNING, WARNING(SVG.WARNING),
QUESTION, QUESTION(SVG.HELP),
SUCCESS; SUCCESS(SVG.CHECK_CIRCLE);
private final SVG icon;
MessageType(SVG icon) {
this.icon = icon;
}
public SVG getIcon() {
return icon;
}
public String getDisplayName() { public String getDisplayName() {
return i18n("message." + name().toLowerCase(Locale.ROOT)); return i18n("message." + name().toLowerCase(Locale.ROOT));
@@ -70,27 +80,7 @@ public final class MessageDialogPane extends HBox {
graphic.setTranslateY(10); graphic.setTranslateY(10);
graphic.setMinSize(40, 40); graphic.setMinSize(40, 40);
graphic.setMaxSize(40, 40); graphic.setMaxSize(40, 40);
SVG svg; graphic.setGraphic(type.getIcon().createIcon(40));
switch (type) {
case INFO:
svg = SVG.INFO;
break;
case ERROR:
svg = SVG.ERROR;
break;
case SUCCESS:
svg = SVG.CHECK_CIRCLE;
break;
case WARNING:
svg = SVG.WARNING;
break;
case QUESTION:
svg = SVG.HELP;
break;
default:
throw new IllegalArgumentException("Unrecognized message box message type " + type);
}
graphic.setGraphic(svg.createIcon(40));
VBox vbox = new VBox(); VBox vbox = new VBox();
HBox.setHgrow(vbox, Priority.ALWAYS); HBox.setHgrow(vbox, Priority.ALWAYS);