diff --git a/designer-base/src/main/java/com/fr/design/dialog/FineJOptionPane.java b/designer-base/src/main/java/com/fr/design/dialog/FineJOptionPane.java index c70fff5a56..f92f6bc0d8 100644 --- a/designer-base/src/main/java/com/fr/design/dialog/FineJOptionPane.java +++ b/designer-base/src/main/java/com/fr/design/dialog/FineJOptionPane.java @@ -4,6 +4,8 @@ import javax.swing.Icon; import javax.swing.JOptionPane; import java.awt.Component; import java.awt.HeadlessException; +import java.util.HashMap; +import java.util.Map; /** * @author Joe @@ -12,42 +14,82 @@ import java.awt.HeadlessException; */ public class FineJOptionPane extends JOptionPane { - private final static String[] OPTION_DEFAULT = { com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Button_OK") }; - private final static String[] OPTION_YES_NO = { com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Yes"), + public final static String[] OPTION_DEFAULT = { com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Button_OK") }; + public final static String[] OPTION_YES_NO = { com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Yes"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_No") }; - private final static String[] OPTION_YES_NO_CANCEL = { com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Yes"), + public final static String[] OPTION_YES_NO_CANCEL = { com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Yes"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_No"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Button_Cancel") }; - private final static String[] OPTION_OK_CANCEL = { com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Button_OK"), + public final static String[] OPTION_OK_CANCEL = { com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Button_OK"), com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Button_Cancel") }; - //这里用一个二维数组,根据optionType为具体的按钮建立索引 - private final static String[][] OPTIONS_ARRAY = {OPTION_DEFAULT, OPTION_YES_NO, OPTION_YES_NO_CANCEL, OPTION_OK_CANCEL}; + //选项类型optionType 和 选项字符串数组 一一对应 + private final static Map OPTION_MAP = new HashMap<>(); + + static { + OPTION_MAP.put(DEFAULT_OPTION, OPTION_DEFAULT); + OPTION_MAP.put(YES_NO_OPTION, OPTION_YES_NO); + OPTION_MAP.put(YES_NO_CANCEL_OPTION, OPTION_YES_NO_CANCEL); + OPTION_MAP.put(OK_CANCEL_OPTION, OPTION_OK_CANCEL); + } - //默认标题 private final static String MESSAGE_DIALOG_TITLE = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Message"); private final static String CONFIRM_DIALOG_TITLE = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Confirm"); - //重写所有showMessageDialog方法 + /** + * 使用默认 标题 和 消息类型 的消息提示弹出框 + * @param parentComponent 父容器 + * @param message 具体的提示消息 + * @throws HeadlessException + */ public static void showMessageDialog(Component parentComponent, Object message) throws HeadlessException { showMessageDialog(parentComponent, message, MESSAGE_DIALOG_TITLE, INFORMATION_MESSAGE); } + /** + * 使用默认 Icon 的消息提示弹出框 + * @param parentComponent 父容器 + * @param message 具体的提示消息 + * @param title 标题 + * @param messageType 消息类型 + * @throws HeadlessException + */ public static void showMessageDialog(Component parentComponent, Object message, String title, int messageType) throws HeadlessException { showMessageDialog(parentComponent, message, title, messageType, null); } + /** + * 使用默认 选项类型、选项 和 初始选项 的消息提示弹出框 + * @param parentComponent 父容器 + * @param message 具体的提示消息 + * @param title 标题 + * @param messageType 消息类型 + * @param icon 图标 + * @throws HeadlessException + */ public static void showMessageDialog(Component parentComponent, Object message, String title, int messageType, Icon icon) throws HeadlessException { showMessageDialog(parentComponent, message, title, DEFAULT_OPTION, - messageType, icon, OPTIONS_ARRAY[0], null); + messageType, icon, OPTION_DEFAULT, null); } + /** + * 完全自定义的消息提示弹出框 + * @param parentComponent 父容器 + * @param message 具体的提示消息 + * @param title 标题 + * @param optionType 选项类型 + * @param messageType 消息类型 + * @param icon 图标 + * @param options 选项 + * @param initialValue 初始选项 + * @throws HeadlessException + */ public static void showMessageDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, Object[] options, Object initialValue) @@ -56,8 +98,12 @@ public class FineJOptionPane extends JOptionPane { messageType, icon, options, initialValue); } - - //重写所有showConfirmDialog方法 + /** + * 使用默认 标题 和 选项类型 的确认弹出框 + * @param parentComponent 父容器 + * @param message 具体的提示消息 + * @throws HeadlessException + */ public static int showConfirmDialog(Component parentComponent, Object message) throws HeadlessException { return showConfirmDialog(parentComponent, message, @@ -65,12 +111,29 @@ public class FineJOptionPane extends JOptionPane { YES_NO_CANCEL_OPTION); } + /** + * 使用默认 消息类型 的确认弹出框 + * @param parentComponent 父容器 + * @param message 具体的提示消息 + * @param title 标题 + * @param optionType 选项类型 + * @throws HeadlessException + */ public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType) throws HeadlessException { return showConfirmDialog(parentComponent, message, title, optionType, QUESTION_MESSAGE); } + /** + * 使用默认 Icon 的确认弹出框 + * @param parentComponent 父容器 + * @param message 具体的提示消息 + * @param title 标题 + * @param optionType 选项类型 + * @param messageType 消息类型 + * @throws HeadlessException + */ public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType) throws HeadlessException { @@ -78,20 +141,41 @@ public class FineJOptionPane extends JOptionPane { messageType, null); } - //第一个方法,可以根据提供的optionType找到对应的国际化字符串;第二个方法,给使用者提供灵活性 + /** + * 根据 选项类型 获取对应 选项 ,且使用默认 初始选项 的确认弹出框 + * @param parentComponent 父容器 + * @param message 具体的提示消息 + * @param title 标题 + * @param optionType 选项类型 + * @param messageType 消息类型 + * @param icon 图标 + * @throws HeadlessException + */ public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon) throws HeadlessException { return showConfirmDialog(parentComponent, message, title, optionType, - messageType, icon, OPTIONS_ARRAY[optionType + 1], null); + messageType, icon, OPTION_MAP.get(optionType), null); } + /** + * 完全自定义的确认弹出框 + * @param parentComponent 父容器 + * @param message 具体的提示消息 + * @param title 标题 + * @param optionType 选项类型 + * @param messageType 消息类型 + * @param icon 图标 + * @param options 选项 + * @param initialValue 初始选项 + * @throws HeadlessException + */ public static int showConfirmDialog(Component parentComponent, Object message, String title, int optionType, int messageType, Icon icon, - Object[] objects, Object initialValue) + Object[] options, Object initialValue) throws HeadlessException { return showOptionDialog(parentComponent, message, title, optionType, - messageType, icon, objects, initialValue); + messageType, icon, options, initialValue); } diff --git a/designer-base/src/main/java/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java b/designer-base/src/main/java/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java index d5071423ac..19bd89ef10 100644 --- a/designer-base/src/main/java/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java +++ b/designer-base/src/main/java/com/fr/design/extra/exe/callback/InstallFromDiskCallback.java @@ -51,7 +51,7 @@ public class InstallFromDiskCallback extends AbstractPluginTaskCallback { JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, - null, + FineJOptionPane.OPTION_YES_NO_CANCEL, null ); if (rv == JOptionPane.NO_OPTION || rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { @@ -71,7 +71,7 @@ public class InstallFromDiskCallback extends AbstractPluginTaskCallback { JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, - null, + FineJOptionPane.OPTION_YES_NO_CANCEL, null ); if (rv == JOptionPane.NO_OPTION || rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { diff --git a/designer-base/src/main/java/com/fr/design/extra/exe/callback/InstallOnlineCallback.java b/designer-base/src/main/java/com/fr/design/extra/exe/callback/InstallOnlineCallback.java index 35f3387871..f597180e87 100644 --- a/designer-base/src/main/java/com/fr/design/extra/exe/callback/InstallOnlineCallback.java +++ b/designer-base/src/main/java/com/fr/design/extra/exe/callback/InstallOnlineCallback.java @@ -48,7 +48,7 @@ public class InstallOnlineCallback extends AbstractDealPreTaskCallback { JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, - null, + FineJOptionPane.OPTION_YES_NO_CANCEL, null ); if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { diff --git a/designer-base/src/main/java/com/fr/design/extra/exe/callback/UninstallPluginCallback.java b/designer-base/src/main/java/com/fr/design/extra/exe/callback/UninstallPluginCallback.java index 5914aadfe8..b3773ef6f9 100644 --- a/designer-base/src/main/java/com/fr/design/extra/exe/callback/UninstallPluginCallback.java +++ b/designer-base/src/main/java/com/fr/design/extra/exe/callback/UninstallPluginCallback.java @@ -37,7 +37,7 @@ public class UninstallPluginCallback extends AbstractPluginTaskCallback { JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, - null, + FineJOptionPane.OPTION_YES_NO_CANCEL, null ); if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { diff --git a/designer-base/src/main/java/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java b/designer-base/src/main/java/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java index 8ceea887dc..7cced40f0b 100644 --- a/designer-base/src/main/java/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java +++ b/designer-base/src/main/java/com/fr/design/extra/exe/callback/UpdateFromDiskCallback.java @@ -49,7 +49,7 @@ public class UpdateFromDiskCallback extends AbstractPluginTaskCallback { JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, - null, + FineJOptionPane.OPTION_YES_NO_CANCEL, null ); if (rv == JOptionPane.NO_OPTION || rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { @@ -69,7 +69,7 @@ public class UpdateFromDiskCallback extends AbstractPluginTaskCallback { JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, - null, + FineJOptionPane.OPTION_YES_NO_CANCEL, null ); if (rv == JOptionPane.NO_OPTION || rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) { diff --git a/designer-base/src/main/java/com/fr/design/extra/tradition/callback/UpdateOnlineCallback.java b/designer-base/src/main/java/com/fr/design/extra/tradition/callback/UpdateOnlineCallback.java index ef4c846b22..97a2ae0063 100644 --- a/designer-base/src/main/java/com/fr/design/extra/tradition/callback/UpdateOnlineCallback.java +++ b/designer-base/src/main/java/com/fr/design/extra/tradition/callback/UpdateOnlineCallback.java @@ -42,7 +42,7 @@ public class UpdateOnlineCallback implements ProgressCallback { JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE, null, - null, + FineJOptionPane.OPTION_YES_NO_CANCEL, null ); if (rv == JOptionPane.CANCEL_OPTION || rv == JOptionPane.CLOSED_OPTION) {