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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
|
package org.apache.fop.viewer;
import javax.swing.*;
import java.beans.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import org.apache.fop.apps.*;
/**
* Die Klasse <code>MessagesDialog</code> dient der Anzeige von Meldungen.
* Die Klasse erweitert <code>JOptionPane</code> um die M�glichkeit, auf Knopfdruck
* eine Detailanzeige einzublenden, in der z.B. bei Fehlern der StackTrace ausgegeben
* werden kann.
*
* @author Juergen.Verwohlt@af-software.de
* @version 1.0 09.06.99
*/
public class MessagesDialog extends JOptionPane {
static Translator res;
public static void setTranslator(Translator aRes) {
res = aRes;
iniConstants();
}
static String DETAIL_OPTION;
static String YES_OPTION;
static String NO_OPTION;
static String CANCEL_OPTION;
static String OK_OPTION;
static String[] defaultDetailOption;
static String[] yesNoDetailOption;
static String[] yesNoCancelDetailOption;
static String[] okCancelDetailOption;
static String[] defaultOption;
static String[] yesNoOption;
static String[] yesNoCancelOption;
static String[] okCancelOption;
private static void iniConstants() {
DETAIL_OPTION = res.getString("Details");
YES_OPTION = res.getString("Yes");
NO_OPTION = res.getString("No");
CANCEL_OPTION = res.getString("Cancel");
OK_OPTION = res.getString("Ok");
defaultDetailOption = new String[] { OK_OPTION, DETAIL_OPTION };
yesNoDetailOption = new String[] { YES_OPTION, NO_OPTION, DETAIL_OPTION };
yesNoCancelDetailOption = new String[] { YES_OPTION, NO_OPTION, CANCEL_OPTION, DETAIL_OPTION };
okCancelDetailOption = new String[] { OK_OPTION, CANCEL_OPTION, DETAIL_OPTION };
defaultOption = new String[] { OK_OPTION };
yesNoOption = new String[] { YES_OPTION, NO_OPTION };
yesNoCancelOption = new String[] { YES_OPTION, NO_OPTION, CANCEL_OPTION };
okCancelOption = new String[] { OK_OPTION, CANCEL_OPTION };
}
protected String detailInformation = null;
protected JDialog dialog = null;
protected boolean showsDetails = false;
// MessagesDialog.showConfirmDialog(null,preparedMes,title,
// optionTypeIndex,messageTypeIndex);
public MessagesDialog(Object message, int messageType, int optionType,
Icon icon, Object[] options, Object initialValue) {
super(message, messageType, optionType, icon, options, initialValue);
setMinimumSize(new Dimension(240, 96));
}
public static int showConfirmDialog(Component parentComponent, Object message,
String title, int optionType, int messageType) {
Object[] options;
switch (optionType) {
case JOptionPane.YES_NO_OPTION:
options = yesNoOption; break;
case JOptionPane.YES_NO_CANCEL_OPTION:
options = yesNoCancelOption; break;
case JOptionPane.OK_CANCEL_OPTION:
options = okCancelOption; break;
default:
options = defaultOption;
}
MessagesDialog pane = new MessagesDialog(message, messageType,
JOptionPane.DEFAULT_OPTION, null,
options, options[0]);
pane.setInitialValue(options[0]);
JDialog dialog = pane.createDialog(parentComponent, title);
pane.setDialog(dialog);
pane.selectInitialValue();
dialog.show();
Object selectedValue = pane.getValue();
if(selectedValue == null)
return CLOSED_OPTION;
if (selectedValue.equals(OK_OPTION))
return JOptionPane.OK_OPTION;
if (selectedValue.equals(CANCEL_OPTION))
return JOptionPane.CANCEL_OPTION;
if (selectedValue.equals(YES_OPTION))
return JOptionPane.YES_OPTION;
if (selectedValue.equals(NO_OPTION))
return JOptionPane.NO_OPTION;
return CLOSED_OPTION;
}
/**
* �ffnet ein Dialogfenster, bei dem zus�tzlich zu den spez. Buttons noch ein
* 'Detail'-Button erscheint. Wird dieser Knopf vom Benutzer bet�tigt, erscheint
* die �bergebene Detailinformation in einem scrollbaren Bereich des Dialogs.
*/
public static int showDetailDialog(Component parentComponent, Object message, String title, int optionType,
int messageType, Icon icon, String newDetailInformation) {
Object[] options;
switch (optionType) {
case JOptionPane.YES_NO_OPTION:
options = yesNoDetailOption; break;
case JOptionPane.YES_NO_CANCEL_OPTION:
options = yesNoCancelDetailOption; break;
case JOptionPane.OK_CANCEL_OPTION:
options = okCancelDetailOption; break;
default:
options = defaultDetailOption;
}
MessagesDialog pane = new MessagesDialog(message, messageType,
JOptionPane.DEFAULT_OPTION, icon,
options, options[0]);
pane.setDetailInformation(newDetailInformation);
pane.setInitialValue(options[0]);
JDialog dialog = pane.createDialog(parentComponent, title);
pane.setDialog(dialog);
pane.selectInitialValue();
dialog.show();
Object selectedValue = pane.getValue();
if(selectedValue == null)
return CLOSED_OPTION;
if (((String)selectedValue).equals(DETAIL_OPTION))
return CLOSED_OPTION;
if (selectedValue.equals(OK_OPTION))
return JOptionPane.OK_OPTION;
if (selectedValue.equals(CANCEL_OPTION))
return JOptionPane.CANCEL_OPTION;
if (selectedValue.equals(YES_OPTION))
return JOptionPane.YES_OPTION;
if (selectedValue.equals(NO_OPTION))
return JOptionPane.NO_OPTION;
return CLOSED_OPTION;
}
/**
* Die Methode f�gt in den �bergebenen Dialog eine scrollbare Textkomponente ein,
* in der die Detailinformation angezeigt wird.
*
* @param JDialog dialog Der Dialog, in den die Textkomponente eingef�gt werden soll
*/
protected void displayDetails(JDialog dialog) {
if (getDetailInformation() != null && dialog != null && showsDetails == false) {
showsDetails = true;
JScrollPane aScrollPane = new JScrollPane();
JTextArea aTextArea = new JTextArea();
StringWriter aStringWriter = new StringWriter();
aTextArea.setText(getDetailInformation());
aTextArea.setEditable(false);
aScrollPane.getViewport().add(aTextArea, null);
dialog.getContentPane().add(aScrollPane, BorderLayout.SOUTH);
aScrollPane.setPreferredSize(new Dimension(320, 240));
dialog.pack();
}
}
// Zugriff
public void setValue(Object aValue) {
if (aValue != null && DETAIL_OPTION.equals(aValue))
displayDetails(getDialog());
else
super.setValue(aValue);
}
public String getDetailInformation() {
return detailInformation;
}
public void setDetailInformation(String aValue) {
detailInformation = aValue;
}
public JDialog getDialog() {
return dialog;
}
public void setDialog(JDialog aValue) {
dialog = aValue;
}
}
|