ludc
2024-09-14 36c2449aec5b51e5ed4e5c6841154b746060e09a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
package com.vci.client.ui.swing;
 
import java.awt.Component;
import java.awt.Frame;
import java.awt.HeadlessException;
import java.util.Locale;
 
import javax.swing.JOptionPane;
 
import com.vci.client.ui.exception.VCIException;
import com.vci.client.ui.locale.LocaleDisplay;
import com.vci.corba.common.VCIError;
 
public class VCIOptionPane extends JOptionPane{
 
    /** 
     * 
     */
    private static final long serialVersionUID = 3800121423347621658L;
 
    public VCIOptionPane() {
        
    }
    
    public static void showMessageDialog(Frame frame, Component parentComponent, Object message,
            String title, int messageType) throws HeadlessException {
        if (parentComponent != null) {
            showMessageDialog(parentComponent, message, title, messageType, null);
        } else {
            showMessageDialog(frame, message, title, messageType, null);
        }
    }
    
    public static int showConfirmDialog(Frame frame, Component parentComponent,
              Object message, String title, int optionType, int messageType)
              throws HeadlessException {
        if(parentComponent != null) {
            return showConfirmDialog(parentComponent, message, title, optionType, messageType, null);
        } else {
            return showConfirmDialog(frame, message, title, optionType, messageType, null);
        }
    }
    
    /**
     * 消息提示
     * @param parentComponent 父容器
     * @param message 消息内容
     */
    public static void showMessage(Component parentComponent, String message){
        String title = LocaleDisplay.getI18nString("rmip.framework.info.message.dialog.title", "RMIPFramework", parentComponent.getLocale());
        VCIOptionPane.showMessageDialog(parentComponent, message, title, VCIOptionPane.INFORMATION_MESSAGE);
    }
    /**
     * 消息提示
     * @param parentComponent 父容器
     * @param message 消息内容
     */
    public static void showMessage(Component parentComponent, VCIError e){
        String title = LocaleDisplay.getI18nString("rmip.framework.info.message.dialog.title", "RMIPFramework", parentComponent.getLocale());
        String message = getCustomErrorMessage(e);
        VCIOptionPane.showMessageDialog(parentComponent, message, title, VCIOptionPane.INFORMATION_MESSAGE);
    }
    
    /**
     * 错误消息提示
     * @param parentComponent 父容器
     * @param message 消息内容
     */
    public static void showError(Component parentComponent, String message){
        String title = LocaleDisplay.getI18nString("rmip.framework.error.message.dialog.title", "RMIPFramework", parentComponent.getLocale());
        VCIOptionPane.showMessageDialog(parentComponent, message, title, VCIOptionPane.ERROR_MESSAGE);
    }
    
    /**
     * 错误消息提示
     * @param parentComponent 父容器
     * @param message 消息内容
     */
    public static void showError(Component parentComponent, VCIError e){
        String title = LocaleDisplay.getI18nString("rmip.framework.error.message.dialog.title", "RMIPFramework", parentComponent.getLocale());
        String message = getCustomErrorMessage(e);
        VCIOptionPane.showMessageDialog(parentComponent, message, title, VCIOptionPane.ERROR_MESSAGE);
    }
    
    /**
     * 
     * <p>Description: 更加错误异常信息显示提示对话框</p>
     * 
     * @author Administrator
     * @time 2011-7-13
     * @param parentComponent 父容器
     * @param fileName 国际化文件名称
     * @param exp 错误异常信息
     */
    public static void showError(Component parentComponent, String fileName, VCIException exp) {
        String title = LocaleDisplay.getI18nString("rmip.framework.error.message.dialog.title", "RMIPFramework", parentComponent.getLocale());
        String message = LocaleDisplay.getI18nString(exp, fileName, Locale.getDefault());
        VCIOptionPane.showMessageDialog(parentComponent, message, title, VCIOptionPane.ERROR_MESSAGE);
    }
    
    /**
     * 警告消息提示
     * @param parentComponent 父容器
     * @param message 消息内容
     */
    public static void showWarning(Component parentComponent, String message){
        String title = LocaleDisplay.getI18nString("rmip.framework.warn.message.dialog.title", "RMIPFramework", parentComponent.getLocale());
        VCIOptionPane.showMessageDialog(parentComponent, message, title, VCIOptionPane.WARNING_MESSAGE);
    }
    /**
     * 询问消息提示
     * @param parentComponent 父容器
     * @param message 消息内容
     */
    public static int showQuestion(Component parentComponent, String message){
        String title = LocaleDisplay.getI18nString("rmip.framework.friend.message.dialog.title", "RMIPFramework", parentComponent.getLocale());
        return VCIOptionPane.showConfirmDialog(parentComponent, message, title, VCIOptionPane.YES_NO_OPTION);
    }
    
    /***
     * 确认操作框
     */
    public static int showQuestion(Frame frame){
        String title = LocaleDisplay.getI18nString("rmip.framework.friend.message.dialog.title", "RMIPFramework", frame.getLocale());
        String msg = LocaleDisplay.getI18nString("rmip.framework.friend.message.dialog.title", "RMIPFramework", frame.getLocale());
        return VCIOptionPane.showConfirmDialog(frame, msg, title, VCIOptionPane.YES_NO_OPTION);
    }
    
    private static String getCustomErrorMessage(VCIError e){
        String message = LocaleDisplay.getI18nString(String.valueOf(e.code), "RMIPCode", Locale.getDefault());
        Object[] messages = (Object[])e.messages;
        if(messages.length != 0){
            message = String.format(message, messages);
        }
        return message;
    }
}