ErrorDisplayDialogpublic class ErrorDisplayDialog extends Object Displays errors detected after Java Web Start has launched the
Java Web Start-aware ACC but before the developer's client has
launched. Such errors would normally go to the Java Web Start trace file
or the Java Console (if either is enabled) but by default neither of those
is turned on, with the result that the end-user has no information about
such errors. The client would simply never start. |
Fields Summary |
---|
private static final String | LINE_SEP | private static ResourceBundle | rb |
Methods Summary |
---|
private static java.lang.String | getString(java.lang.String key)
return rb.getString(key);
| private static boolean | showDialog(java.lang.String mainMessage, javax.swing.JScrollPane sp, javax.swing.JCheckBox copyToClipboardCB)Displays a dialog box with the specified main message and stack trace.
String close = getString("jwsacc.errorDialog.closeLabel");
Object [] displayElements = (copyToClipboardCB == null) ?
new Object[] {mainMessage, sp} :
new Object[] {mainMessage, sp, copyToClipboardCB};
JOptionPane pane = new JOptionPane(
displayElements,
JOptionPane.ERROR_MESSAGE,
JOptionPane.DEFAULT_OPTION,
null,
new String[] {close},
close);
JDialog dialog = pane.createDialog(null, getString("jwsacc.errorDialog.title"));
dialog.setResizable(true);
dialog.setVisible(true);
boolean result = (copyToClipboardCB == null ? false : copyToClipboardCB.isSelected());
dialog.dispose();
return result;
| public static void | showErrors(java.lang.Throwable t, java.util.ResourceBundle rb)Displays a dialog box reporting an error, listing the stack trace in
a text box and allowing the user to copy the stack trace to the platform's
clipboard before dismissing the dialog box.
ErrorDisplayDialog.rb = rb;
/*
*The JOptionPane class will accept other Components as elements of
*the dialog box. Build a JTextArea containing the stack trace. Do not
*let the user edit the text.
*/
JTextArea stackTraceArea = new JTextArea();
stackTraceArea.setEditable(false);
stackTraceArea.setRows(16);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream ps = new PrintStream(baos);
t.printStackTrace(ps);
stackTraceArea.setText(baos.toString());
/*
*Place the text area inside a scroll pane.
*/
JScrollPane sp = new JScrollPane(stackTraceArea);
/*
*Build a check box for the user to click to copy the error information
*to the platform's clipboard.
*/
JCheckBox copyToClipboardCB = new JCheckBox(getString("jwsacc.errorDialog.copyToClipboardLabel"));
/*
*Display the dialog box that also contains the text area's scroll
*pane and the checkbox and then wait for the user to close it.
*/
boolean copyToClipboard = showDialog(
getString("jwsacc.errorDialog.mainMessage.1") +
LINE_SEP +
getString("jwsacc.errorDialog.mainMessage.2"),
sp,
copyToClipboardCB
);
if (copyToClipboard) {
Clipboard cb = Toolkit.getDefaultToolkit().getSystemClipboard();
StringSelection ss = new StringSelection(stackTraceArea.getText());
try {
cb.setContents(ss, null);
}
catch (Throwable e) {
/*
*If we cannot copy the text to the clipboard, tell the user that
*and suggest that he or she manually copy it.
*/
showDialog(
getString("jwsacc.errorDialog.errorCopyingMessage.1") +
LINE_SEP +
getString("jwsacc.errorDialog.errorCopyingMessage.2"),
sp,
null /* no checkbox this time */
);
}
}
|
|