From 311dc682a13c1f35ce0ab9d723ea4ad5ede1d9ec Mon Sep 17 00:00:00 2001 From: "Joe.Jiang" Date: Thu, 5 Dec 2019 16:08:56 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-20516=20=E8=AF=AD=E8=A8=80=E5=88=87?= =?UTF-8?q?=E6=8D=A2=E8=87=B3=E8=8B=B1=E6=96=87=EF=BC=8C=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E5=B1=9E=E6=80=A7=E3=80=81=E8=B6=85=E7=BA=A7?= =?UTF-8?q?=E9=93=BE=E6=8E=A5=EF=BC=8C=E7=82=B9=E5=87=BB=E5=88=A0=E9=99=A4?= =?UTF-8?q?=EF=BC=8C=E5=AF=B9=E8=AF=9D=E6=A1=86=E7=9A=84=E2=80=9C=E7=A1=AE?= =?UTF-8?q?=E8=AE=A4=E2=80=9D=E5=92=8C=E2=80=9C=E5=8F=96=E6=B6=88=E2=80=9D?= =?UTF-8?q?=E6=98=BE=E7=A4=BA=E4=B8=BA=E4=B8=AD=E6=96=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/dialog/FineJOptionPane.java | 114 +++++++++++++++--- .../exe/callback/InstallFromDiskCallback.java | 4 +- .../exe/callback/InstallOnlineCallback.java | 2 +- .../exe/callback/UninstallPluginCallback.java | 2 +- .../exe/callback/UpdateFromDiskCallback.java | 4 +- .../callback/UpdateOnlineCallback.java | 2 +- 6 files changed, 106 insertions(+), 22 deletions(-) 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) {