usr/src/java/util/org/opensolaris/os/vp/util/swing/ThrowableEditorPane.java
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--
18094 s/StringBuffer/StringBuilder/g
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     1
/*
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     2
 * CDDL HEADER START
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     3
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     4
 * The contents of this file are subject to the terms of the
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     5
 * Common Development and Distribution License (the "License").
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     6
 * You may not use this file except in compliance with the License.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     7
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     8
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
     9
 * or http://www.opensolaris.org/os/licensing.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    10
 * See the License for the specific language governing permissions
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    11
 * and limitations under the License.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    12
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    13
 * When distributing Covered Code, include this CDDL HEADER in each
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    14
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    15
 * If applicable, add the following below this CDDL HEADER, with the
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    16
 * fields enclosed by brackets "[]" replaced with your own identifying
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    17
 * information: Portions Copyright [yyyy] [name of copyright owner]
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    18
 *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    19
 * CDDL HEADER END
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    20
 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    21
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    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
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    24
 */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    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
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    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
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    30
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    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
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    33
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    34
    // Instance data
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    35
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    36
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    37
    private Throwable throwable;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    38
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    39
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    40
    // Constructors
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    41
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    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
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    46
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    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
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    51
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    52
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    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
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    67
    //
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    68
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    69
    public Throwable getThrowable() {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    70
	return throwable;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    71
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    72
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    73
    /**
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    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
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    76
     *
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    77
     * @param	    throwable
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    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
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    80
     */
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    81
    public void setThrowable(Throwable throwable) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    82
	this.throwable = throwable;
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    83
685
767674b0a2fb 18094 s/StringBuffer/StringBuilder/g
Stephen Talley <stephen.talley@oracle.com>
parents: 219
diff changeset
    84
	StringBuilder buffer = new StringBuilder();
0
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    85
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    86
	while (throwable != null) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    87
	    buffer.append("<b>").append(
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    88
		TextUtil.escapeHTMLChars(throwable.getClass().getName())).
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    89
		append("</b><br/><table><tr><td>&nbsp;&nbsp</td><td>");
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    90
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    91
	    String m = ThrowableUtil.getTrueMessage(throwable);
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    92
	    if (m != null) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    93
		buffer.append(TextUtil.escapeHTMLChars(m));
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    94
	    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    95
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    96
	    buffer.append("</td></tr></table>");
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    97
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    98
	    throwable = throwable.getCause();
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
    99
	    if (throwable != null) {
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   100
		buffer.append("<br/>");
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   101
	    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   102
	}
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   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
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   105
    }
62ac12e07fc0 Initial integration.
David Powell <David.Powell@sun.com>
parents:
diff changeset
   106
}