|
|
|
@ -1,5 +1,6 @@
|
|
|
|
|
package com.fr.design.dialog; |
|
|
|
|
|
|
|
|
|
import com.fine.theme.icon.LazyIcon; |
|
|
|
|
import com.fr.invoke.Reflect; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
|
@ -31,6 +32,8 @@ public class FineJOptionPane extends JOptionPane {
|
|
|
|
|
//选项类型optionType 和 选项字符串数组 一一对应
|
|
|
|
|
private final static Map<Integer, String[]> OPTION_MAP = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
public Icon successMessageIcon; |
|
|
|
|
|
|
|
|
|
static { |
|
|
|
|
OPTION_MAP.put(DEFAULT_OPTION, OPTION_DEFAULT); |
|
|
|
|
OPTION_MAP.put(YES_NO_OPTION, OPTION_YES_NO); |
|
|
|
@ -42,6 +45,17 @@ public class FineJOptionPane extends JOptionPane {
|
|
|
|
|
private final static String CONFIRM_DIALOG_TITLE = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Dialog_Prompt"); |
|
|
|
|
private final static String INPUT_DIALOG_TITLE = com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Basic_Tool_Tips"); |
|
|
|
|
|
|
|
|
|
public FineJOptionPane(Object message, int messageType, int optionType, |
|
|
|
|
Icon icon, Object[] options, Object initialValue, |
|
|
|
|
boolean successMessage) { |
|
|
|
|
super(message, messageType, optionType, icon, options, initialValue); |
|
|
|
|
if (successMessage) { |
|
|
|
|
successMessageIcon = new LazyIcon("success", 20); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 使用默认 标题 和 消息类型 的消息提示弹出框 |
|
|
|
|
* @param parentComponent 父容器 |
|
|
|
@ -54,6 +68,34 @@ public class FineJOptionPane extends JOptionPane {
|
|
|
|
|
INFORMATION_MESSAGE); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 使用 success 图标、 默认 标题 和 消息类型 的消息提示弹出框 |
|
|
|
|
* @param parentComponent 父容器 |
|
|
|
|
* @param message 具体的提示消息 |
|
|
|
|
* @throws HeadlessException |
|
|
|
|
*/ |
|
|
|
|
public static void showSuccessMessageDialog(Component parentComponent, Object message) |
|
|
|
|
throws HeadlessException { |
|
|
|
|
showMessageDialog(parentComponent, message, MESSAGE_DIALOG_TITLE, INFORMATION_MESSAGE, true); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 使用默认 标题 和 消息类型 的消息提示弹出框 |
|
|
|
|
* @param parentComponent 父容器 |
|
|
|
|
* @param message 具体的提示消息 |
|
|
|
|
* @param title 标题 |
|
|
|
|
* @param messageType 消息类型 |
|
|
|
|
* @param isSuccessMessage 是否使用 success 图标,如果不是则根据消息类型生成图标 |
|
|
|
|
* @throws HeadlessException |
|
|
|
|
*/ |
|
|
|
|
public static void showMessageDialog(Component parentComponent, Object message, |
|
|
|
|
String title, int messageType, boolean isSuccessMessage) |
|
|
|
|
throws HeadlessException { |
|
|
|
|
showOptionDialog(parentComponent, message, title, DEFAULT_OPTION, |
|
|
|
|
messageType, null, OPTION_DEFAULT, null, isSuccessMessage); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 使用默认 Icon 的消息提示弹出框 |
|
|
|
|
* @param parentComponent 父容器 |
|
|
|
@ -101,7 +143,7 @@ public class FineJOptionPane extends JOptionPane {
|
|
|
|
|
Icon icon, Object[] options, Object initialValue) |
|
|
|
|
throws HeadlessException { |
|
|
|
|
showOptionDialog(parentComponent, message, title, optionType, |
|
|
|
|
messageType, icon, options, initialValue); |
|
|
|
|
messageType, icon, options, initialValue, false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -182,7 +224,7 @@ public class FineJOptionPane extends JOptionPane {
|
|
|
|
|
Object[] options, Object initialValue) |
|
|
|
|
throws HeadlessException { |
|
|
|
|
return showOptionDialog(parentComponent, message, title, optionType, |
|
|
|
|
messageType, icon, options, initialValue); |
|
|
|
|
messageType, icon, options, initialValue, false); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -199,7 +241,7 @@ public class FineJOptionPane extends JOptionPane {
|
|
|
|
|
String title, Icon icon, Object initialValue, ActionListener listener) |
|
|
|
|
throws HeadlessException { |
|
|
|
|
int val = showOptionDialog(parentComponent, message, title, JOptionPane.DEFAULT_OPTION, |
|
|
|
|
FineJOptionPane.WARNING_MESSAGE, icon, OPTION_OK_CANCEL, initialValue); |
|
|
|
|
FineJOptionPane.WARNING_MESSAGE, icon, OPTION_OK_CANCEL, initialValue, false); |
|
|
|
|
if (val == JOptionPane.OK_OPTION && listener!=null) { |
|
|
|
|
listener.actionPerformed(null); |
|
|
|
|
} |
|
|
|
@ -315,4 +357,71 @@ public class FineJOptionPane extends JOptionPane {
|
|
|
|
|
return value; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 根据 message type 生成 icon |
|
|
|
|
* @return |
|
|
|
|
*/ |
|
|
|
|
public Icon getIcon() { |
|
|
|
|
if (successMessageIcon != null) { |
|
|
|
|
return successMessageIcon; |
|
|
|
|
} |
|
|
|
|
switch (messageType) { |
|
|
|
|
case ERROR_MESSAGE: |
|
|
|
|
return new LazyIcon("error", 20); |
|
|
|
|
case WARNING_MESSAGE: |
|
|
|
|
return new LazyIcon("warning", 20); |
|
|
|
|
case INFORMATION_MESSAGE: |
|
|
|
|
return new LazyIcon("information", 20); |
|
|
|
|
case QUESTION_MESSAGE: |
|
|
|
|
return new LazyIcon("question", 20); |
|
|
|
|
default: |
|
|
|
|
return icon; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* 自定义的确认弹出框 |
|
|
|
|
* @param parentComponent 父容器 |
|
|
|
|
* @param message 具体的提示消息 |
|
|
|
|
* @param title 标题 |
|
|
|
|
* @param optionType 选项类型 |
|
|
|
|
* @param messageType 消息类型 |
|
|
|
|
* @param icon 图标 |
|
|
|
|
* @param options 选项 |
|
|
|
|
* @param initialValue 初始选项 |
|
|
|
|
* @param isSuccessMessage 是否使用 success 图标 |
|
|
|
|
*/ |
|
|
|
|
public static int showOptionDialog(Component parentComponent, Object message, |
|
|
|
|
String title, int optionType, int messageType, |
|
|
|
|
Icon icon, Object[] options, Object initialValue, |
|
|
|
|
boolean isSuccessMessage) { |
|
|
|
|
FineJOptionPane pane = new FineJOptionPane(message, messageType, optionType, icon, options, initialValue, isSuccessMessage); |
|
|
|
|
pane.setInitialValue(initialValue); |
|
|
|
|
pane.setComponentOrientation(((parentComponent == null) ? getRootFrame() : parentComponent).getComponentOrientation()); |
|
|
|
|
|
|
|
|
|
JDialog dialog = pane.createDialog(parentComponent, title); |
|
|
|
|
pane.selectInitialValue(); |
|
|
|
|
dialog.show(); |
|
|
|
|
dialog.dispose(); |
|
|
|
|
|
|
|
|
|
Object selectedValue = pane.getValue(); |
|
|
|
|
|
|
|
|
|
if (selectedValue == null){ |
|
|
|
|
return CLOSED_OPTION; |
|
|
|
|
} |
|
|
|
|
if (options == null) { |
|
|
|
|
if (selectedValue instanceof Integer) { |
|
|
|
|
return ((Integer) selectedValue).intValue(); |
|
|
|
|
} |
|
|
|
|
return CLOSED_OPTION; |
|
|
|
|
} |
|
|
|
|
for(int counter = 0, maxCounter = options.length; |
|
|
|
|
counter < maxCounter; counter++) { |
|
|
|
|
if (options[counter].equals(selectedValue)) { |
|
|
|
|
return counter; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return CLOSED_OPTION; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|