components/visual-panels/core/src/java/util/com/oracle/solaris/vp/util/swing/ThrowableCollapsiblePane.java
changeset 3553 f1d133b09a8c
parent 3552 077ebe3d0d24
child 3554 ef58713bafc4
equal deleted inserted replaced
3552:077ebe3d0d24 3553:f1d133b09a8c
     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 /*
       
    23  * Copyright (c) 2010, 2012, Oracle and/or its affiliates. All rights reserved.
       
    24  */
       
    25 
       
    26 package com.oracle.solaris.vp.util.swing;
       
    27 
       
    28 import java.awt.*;
       
    29 import javax.swing.JScrollPane;
       
    30 import com.oracle.solaris.vp.util.misc.finder.Finder;
       
    31 
       
    32 /**
       
    33  * The {@code ThrowableCollapsiblePane} class displays a {@code Throwable}
       
    34  * within a {@link CollapsiblePane}.
       
    35  */
       
    36 @SuppressWarnings({"serial"})
       
    37 public class ThrowableCollapsiblePane extends LinkCollapsiblePane {
       
    38     //
       
    39     // Instance data
       
    40     //
       
    41 
       
    42     private ThrowableEditorPane tPane;
       
    43 
       
    44     //
       
    45     // Constructors
       
    46     //
       
    47 
       
    48     public ThrowableCollapsiblePane() {
       
    49 	tPane = new ThrowableEditorPane() {
       
    50 	    @Override
       
    51 	    public Dimension getPreferredScrollableViewportSize() {
       
    52 		FontMetrics metrics = getFontMetrics(
       
    53 		    getFont().deriveFont(Font.BOLD));
       
    54 		Dimension d = super.getPreferredScrollableViewportSize();
       
    55 
       
    56 		// Set scroll pane size (3 lines heigh, 20 characters wide)
       
    57 		d.height = Math.min(3 * metrics.getHeight(), d.height);
       
    58 		d.width = Math.min(20 * metrics.charWidth('e'), d.width);
       
    59 
       
    60 		return d;
       
    61 	    }
       
    62 
       
    63 	    @Override
       
    64 	    public boolean getScrollableTracksViewportWidth() {
       
    65 		return true;
       
    66 	    }
       
    67 	};
       
    68 	tPane.setOpaque(false);
       
    69 
       
    70 	JScrollPane scroll = new ExtScrollPane(tPane);
       
    71 	getContentPane().add(scroll);
       
    72     }
       
    73 
       
    74     public ThrowableCollapsiblePane(Throwable t) {
       
    75 	this();
       
    76 	tPane.setThrowable(t);
       
    77     }
       
    78 
       
    79     //
       
    80     // Component methods
       
    81     //
       
    82 
       
    83     @Override
       
    84     public void setVisible(boolean visible) {
       
    85 	super.setVisible(visible);
       
    86 	if (!visible) {
       
    87 	    setCollapsed(true);
       
    88 	}
       
    89     }
       
    90 
       
    91     //
       
    92     // LinkCollapsiblePane methods
       
    93     //
       
    94 
       
    95     @Override
       
    96     public String getLinkText(boolean collapsed) {
       
    97 	return Finder.getString(collapsed ?
       
    98 	    "error.details.show" : "error.details.hide");
       
    99     }
       
   100 
       
   101     //
       
   102     // ThrowableCollapsiblePane methods
       
   103     //
       
   104 
       
   105     public ThrowableEditorPane getThrowablePane() {
       
   106 	return tPane;
       
   107     }
       
   108 }