components/visual-panels/core/src/java/util/com/oracle/solaris/vp/util/swing/glass/SimpleGlassPane.java
changeset 827 0944d8c0158b
equal deleted inserted replaced
826:c6aad84d2493 827:0944d8c0158b
       
     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.glass;
       
    27 
       
    28 import java.awt.Component;
       
    29 import javax.swing.JPanel;
       
    30 import com.oracle.solaris.vp.util.swing.ShowingListener;
       
    31 
       
    32 @SuppressWarnings({"serial"})
       
    33 public class SimpleGlassPane extends JPanel {
       
    34     //
       
    35     // Instance data
       
    36     //
       
    37 
       
    38     private ShowingListener showingListener;
       
    39 
       
    40     //
       
    41     // Constructors
       
    42     //
       
    43 
       
    44     public SimpleGlassPane() {
       
    45 	setOpaque(false);
       
    46 
       
    47 	addHierarchyListener(
       
    48 	    new ShowingListener() {
       
    49 		@Override
       
    50 		public void componentHidden() {
       
    51 		    SimpleGlassPane.this.componentHidden();
       
    52 		}
       
    53 
       
    54 		@Override
       
    55 		public void componentShown() {
       
    56 		    SimpleGlassPane.this.componentShown();
       
    57 		}
       
    58 	    });
       
    59     }
       
    60 
       
    61     //
       
    62     // Component methods
       
    63     //
       
    64 
       
    65     /**
       
    66      * Calls {@link #componentToBeVisible} or {@link #componentToBeInvisible} as
       
    67      * appropriate, then forwards to superclass.
       
    68      */
       
    69     @Override
       
    70     public void setVisible(boolean visible) {
       
    71 	if (visible != isVisible()) {
       
    72 	    if (visible) {
       
    73 		componentToBeVisible();
       
    74 	    } else {
       
    75 		componentToBeInvisible();
       
    76 	    }
       
    77 	    super.setVisible(visible);
       
    78 	}
       
    79     }
       
    80 
       
    81     //
       
    82     // SimpleGlassPane methods
       
    83     //
       
    84 
       
    85     /**
       
    86      * Called when this {@code SimpleGlassPane}'s {@link #isShowing showing}
       
    87      * status changes to {@code false}.
       
    88      * </p>
       
    89      * This default implementation does nothing.
       
    90      */
       
    91     public void componentHidden() {
       
    92     }
       
    93 
       
    94     /**
       
    95      * Called when this {@code SimpleGlassPane}'s {@link #isShowing showing}
       
    96      * status changes to {@code true}.
       
    97      * </p>
       
    98      * This default implementation does nothing.
       
    99      */
       
   100     public void componentShown() {
       
   101     }
       
   102 
       
   103     /**
       
   104      * Called when this {@code SimpleGlassPane}'s {@link #isVisible visibility}
       
   105      * is about to be set to {@code true}.
       
   106      * </p>
       
   107      * This default implementation does nothing.
       
   108      */
       
   109     public void componentToBeVisible() {
       
   110     }
       
   111 
       
   112     /**
       
   113      * Called when this {@code SimpleGlassPane}'s {@link #isVisible visibility}
       
   114      * is about to be set to {@code false}.
       
   115      * </p>
       
   116      * This default implementation does nothing.
       
   117      */
       
   118     public void componentToBeInvisible() {
       
   119     }
       
   120 
       
   121     protected ShowingListener getShowingListener() {
       
   122 	return showingListener;
       
   123     }
       
   124 }