author | Stephen Talley <stephen.talley@oracle.com> |
Mon, 28 Mar 2011 10:53:34 -0400 | |
changeset 685 | 767674b0a2fb |
parent 219 | 57841c113efe |
permissions | -rw-r--r-- |
0 | 1 |
/* |
2 |
* CDDL HEADER START |
|
3 |
* |
|
4 |
* The contents of this file are subject to the terms of the |
|
5 |
* Common Development and Distribution License (the "License"). |
|
6 |
* You may not use this file except in compliance with the License. |
|
7 |
* |
|
8 |
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 |
* or http://www.opensolaris.org/os/licensing. |
|
10 |
* See the License for the specific language governing permissions |
|
11 |
* and limitations under the License. |
|
12 |
* |
|
13 |
* When distributing Covered Code, include this CDDL HEADER in each |
|
14 |
* file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 |
* If applicable, add the following below this CDDL HEADER, with the |
|
16 |
* fields enclosed by brackets "[]" replaced with your own identifying |
|
17 |
* information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 |
* |
|
19 |
* CDDL HEADER END |
|
20 |
*/ |
|
21 |
||
22 |
/* |
|
685
767674b0a2fb
18094 s/StringBuffer/StringBuilder/g
Stephen Talley <stephen.talley@oracle.com>
parents:
219
diff
changeset
|
23 |
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
0 | 24 |
*/ |
25 |
||
219
57841c113efe
6788 package names should share o.o.o.vp prefix
Stephen Talley <stephen.talley@sun.com>
parents:
76
diff
changeset
|
26 |
package org.opensolaris.os.vp.util.swing; |
0 | 27 |
|
76
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
28 |
import javax.swing.JEditorPane; |
219
57841c113efe
6788 package names should share o.o.o.vp prefix
Stephen Talley <stephen.talley@sun.com>
parents:
76
diff
changeset
|
29 |
import org.opensolaris.os.vp.util.misc.*; |
0 | 30 |
|
31 |
@SuppressWarnings({"serial"}) |
|
76
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
32 |
public class ThrowableEditorPane extends JEditorPane { |
0 | 33 |
// |
34 |
// Instance data |
|
35 |
// |
|
36 |
||
37 |
private Throwable throwable; |
|
38 |
||
39 |
// |
|
40 |
// Constructors |
|
41 |
// |
|
42 |
||
76
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
43 |
public ThrowableEditorPane() { |
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
44 |
setContentType("text/html"); |
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
45 |
setEditable(false); |
0 | 46 |
} |
47 |
||
76
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
48 |
public ThrowableEditorPane(Throwable throwable) { |
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
49 |
this(); |
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
50 |
setThrowable(throwable); |
0 | 51 |
} |
52 |
||
53 |
// |
|
76
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
54 |
// JTextComponent methods |
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
55 |
// |
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
56 |
|
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
57 |
@Override |
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
58 |
public void setText(String text) { |
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
59 |
super.setText(text); |
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
60 |
|
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
61 |
// Scroll to top |
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
62 |
setCaretPosition(0); |
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
63 |
} |
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
64 |
|
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
65 |
// |
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
66 |
// ThrowableEditorPane methods |
0 | 67 |
// |
68 |
||
69 |
public Throwable getThrowable() { |
|
70 |
return throwable; |
|
71 |
} |
|
72 |
||
73 |
/** |
|
74 |
* Sets the {@code Throwable} to display in this {@code |
|
76
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
75 |
* ThrowableEditorPane}. |
0 | 76 |
* |
77 |
* @param throwable |
|
78 |
* the {@code Throwable} object to display in this {@code |
|
76
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
79 |
* ThrowableEditorPane} |
0 | 80 |
*/ |
81 |
public void setThrowable(Throwable throwable) { |
|
82 |
this.throwable = throwable; |
|
83 |
||
685
767674b0a2fb
18094 s/StringBuffer/StringBuilder/g
Stephen Talley <stephen.talley@oracle.com>
parents:
219
diff
changeset
|
84 |
StringBuilder buffer = new StringBuilder(); |
0 | 85 |
|
86 |
while (throwable != null) { |
|
87 |
buffer.append("<b>").append( |
|
88 |
TextUtil.escapeHTMLChars(throwable.getClass().getName())). |
|
89 |
append("</b><br/><table><tr><td>  </td><td>"); |
|
90 |
||
91 |
String m = ThrowableUtil.getTrueMessage(throwable); |
|
92 |
if (m != null) { |
|
93 |
buffer.append(TextUtil.escapeHTMLChars(m)); |
|
94 |
} |
|
95 |
||
96 |
buffer.append("</td></tr></table>"); |
|
97 |
||
98 |
throwable = throwable.getCause(); |
|
99 |
if (throwable != null) { |
|
100 |
buffer.append("<br/>"); |
|
101 |
} |
|
102 |
} |
|
103 |
||
76
af5a052967b0
3415 login panel error details shouldn't launch another window
Stephen Talley <stephen.talley@sun.com>
parents:
0
diff
changeset
|
104 |
setText(buffer.toString()); |
0 | 105 |
} |
106 |
} |