diff --git a/src/main/java/org/jcnc/jnotepad/util/PopUpUtil.java b/src/main/java/org/jcnc/jnotepad/util/PopUpUtil.java index a120bb5..086c6b6 100644 --- a/src/main/java/org/jcnc/jnotepad/util/PopUpUtil.java +++ b/src/main/java/org/jcnc/jnotepad/util/PopUpUtil.java @@ -13,7 +13,7 @@ public class PopUpUtil { } /** - * 获取错误弹窗 + * 设置错误弹窗 * * @param title 弹窗标题 * @param headerText 头文本 @@ -23,9 +23,10 @@ public class PopUpUtil { * @apiNote * @since 2023/9/3 11:54 */ - public static void errorAlert(String title, String headerText, String message, AppDialog.ButtonAction leftBtnAction, AppDialog.ButtonAction rightBtnAction) { - AppDialog.AppDialogBuilder builder = new AppDialog.AppDialogBuilder(); - builder + public static void errorAlert( + String title, String headerText, String message, + AppDialog.ButtonAction leftBtnAction, AppDialog.ButtonAction rightBtnAction) { + getCustomDialog() .setDialogType(AppDialog.DialogType.ERROR) .setTitle(title) .setHeaderText(headerText) @@ -34,4 +35,86 @@ public class PopUpUtil { .setRightBtnAction(rightBtnAction) .build().showAndWait(); } + + /** + * 设置信息弹窗 + * + * @param title 弹窗标题 + * @param headerText 头文本 + * @param message 消息文本 + * @param leftBtnAction 左侧按钮点击事件 + * @param rightBtnAction 右侧按钮点击事件 + * @apiNote + * @since 2023/9/3 11:54 + */ + public static void infoAlert( + String title, String headerText, String message, + AppDialog.ButtonAction leftBtnAction, AppDialog.ButtonAction rightBtnAction) { + getCustomDialog() + .setDialogType(AppDialog.DialogType.INFO) + .setTitle(title) + .setHeaderText(headerText) + .setCustomText(message) + .setLeftBtnAction(leftBtnAction) + .setRightBtnAction(rightBtnAction) + .build().showAndWait(); + } + + /** + * 设置警告弹窗 + * + * @param title 弹窗标题 + * @param headerText 头文本 + * @param message 消息文本 + * @param leftBtnAction 左侧按钮点击事件 + * @param rightBtnAction 右侧按钮点击事件 + * @apiNote + * @since 2023/9/3 11:54 + */ + public static void warningAlert( + String title, String headerText, String message, + AppDialog.ButtonAction leftBtnAction, AppDialog.ButtonAction rightBtnAction) { + getCustomDialog() + .setDialogType(AppDialog.DialogType.WARNING) + .setTitle(title) + .setHeaderText(headerText) + .setCustomText(message) + .setLeftBtnAction(leftBtnAction) + .setRightBtnAction(rightBtnAction) + .build().showAndWait(); + } + + /** + * 设置疑问弹窗 + * + * @param title 弹窗标题 + * @param headerText 头文本 + * @param message 消息文本 + * @param leftBtnAction 左侧按钮点击事件 + * @param rightBtnAction 右侧按钮点击事件 + * @apiNote + * @since 2023/9/3 11:54 + */ + public static void questionAlert( + String title, String headerText, String message, + AppDialog.ButtonAction leftBtnAction, AppDialog.ButtonAction rightBtnAction) { + getCustomDialog() + .setDialogType(AppDialog.DialogType.QUESTION) + .setTitle(title) + .setHeaderText(headerText) + .setCustomText(message) + .setLeftBtnAction(leftBtnAction) + .setRightBtnAction(rightBtnAction) + .build().showAndWait(); + } + + /** + * 获取自定义弹窗 + * + * @apiNote 使用此方法会返回原始的应用对话框建造者类,以实现自定义弹窗 + * @since 2023/9/3 11:54 + */ + public static AppDialog.AppDialogBuilder getCustomDialog() { + return new AppDialog.AppDialogBuilder(); + } } diff --git a/src/main/java/org/jcnc/jnotepad/util/UiUtil.java b/src/main/java/org/jcnc/jnotepad/util/UiUtil.java index 808a66b..2c7f85f 100644 --- a/src/main/java/org/jcnc/jnotepad/util/UiUtil.java +++ b/src/main/java/org/jcnc/jnotepad/util/UiUtil.java @@ -1,7 +1,7 @@ package org.jcnc.jnotepad.util; +import atlantafx.base.theme.Styles; import javafx.scene.image.Image; -import javafx.scene.paint.Color; import javafx.stage.Window; import org.jcnc.jnotepad.LunchApp; import org.jcnc.jnotepad.common.constants.AppConstants; @@ -14,7 +14,7 @@ import static org.kordamp.ikonli.antdesignicons.AntDesignIconsFilled.*; /** * UI工具 * - *

封装了项目中所有的UI组件,以减少组件单例模式造成的代码复杂性。

+ *

封装了项目中需要引入的UI组件

* * @author gewuyou */ @@ -27,24 +27,34 @@ public class UiUtil { /** * 错误图标 */ - private static final FontIcon ERROR_ICON = FontIcon.of(EXCLAMATION_CIRCLE, 64, Color.RED); + private static final FontIcon ERROR_ICON = FontIcon.of(EXCLAMATION_CIRCLE); /** * 信息图标 */ - private static final FontIcon INFO_ICON = FontIcon.of(INFO_CIRCLE, 64, Color.BLUE); + private static final FontIcon INFO_ICON = FontIcon.of(INFO_CIRCLE); /** * 警告图标 */ - private static final FontIcon WARNING_ICON = FontIcon.of(WARNING, 64, Color.ORANGE); + private static final FontIcon WARNING_ICON = FontIcon.of(WARNING); /** * 问题图标 */ - private static final FontIcon QUESTION_ICON = FontIcon.of(QUESTION_CIRCLE, 64, Color.YELLOW); + private static final FontIcon QUESTION_ICON = FontIcon.of(QUESTION_CIRCLE); + + private static final FontIcon SUCCEED_ICON = FontIcon.of(CHECK_CIRCLE); private UiUtil() { } + static { + // 暂时设置颜色 + ERROR_ICON.getStyleClass().addAll(Styles.DANGER); + INFO_ICON.getStyleClass().addAll(Styles.ACCENT); + QUESTION_ICON.getStyleClass().addAll(Styles.ACCENT); + WARNING_ICON.getStyleClass().addAll(Styles.WARNING); + SUCCEED_ICON.getStyleClass().addAll(Styles.SUCCESS); + } /** * 获取应用程序图标。