001    /*
002     * This file is part of the Echo Point Project.  This project is a
003     * collection of Components that have extended the Echo Web Application
004     * Framework Version 3.
005     *
006     * Version: MPL 1.1
007     *
008     * The contents of this file are subject to the Mozilla Public License Version
009     * 1.1 (the "License"); you may not use this file except in compliance with
010     * the License. You may obtain a copy of the License at
011     * http://www.mozilla.org/MPL/
012     *
013     * Software distributed under the License is distributed on an "AS IS" basis,
014     * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
015     * for the specific language governing rights and limitations under the
016     * License.
017     */
018    
019    package echopoint;
020    
021    import nextapp.echo.app.Component;
022    import nextapp.echo.app.ImageReference;
023    import nextapp.echo.app.Pane;
024    import nextapp.echo.app.PaneContainer;
025    
026    /**
027     * The {@code LightBox} is a component that covers all visible content
028     * with a translucent image. This can be used to give a visual clue to the
029     * user that content cannot be interacted with.  {@code LightBox} supports
030     * child components that may be used to present visually modal content to
031     * the user.  {@code LightBox} components are designed to be added as the
032     * only child of {@link nextapp.echo.app.WindowPane} or {@link
033     * nextapp.echo.app.SplitPane} components.
034     *
035     * @author Brad Baker, Rakesh 2009-03-06
036     * @version $Id: LightBox.java 143 2009-03-28 03:11:59Z sptrakesh $
037     */
038    public class LightBox extends Component implements Pane
039    {
040      private static final long serialVersionUID = 1L;
041    
042      /** The property for the image to use as the translucent overlay. */
043      public static final String PROPERTY_TRANSLUCENT_IMAGE = "translucentImage";
044    
045      /** The property used to toggle the display status of the light box. */
046      public static final String PROPERTY_HIDDEN = "hidden";
047    
048      /**
049       * The property used to indicate whether the light box should cover the
050       * entire browser window or just the pane (windowpane, split pane...).
051       */
052      public static final String PROPERTY_PARENT_ONLY = "parentOnly";
053    
054      /**
055       * Return the image that is used as the overlay to hide content.
056       *
057       * @return The overlay image.
058       */
059      public ImageReference getTranslucentImage()
060      {
061        return (ImageReference) get( PROPERTY_TRANSLUCENT_IMAGE );
062      }
063    
064      /**
065       * Sets the image to be used as the background of the light box.
066       * This image should be a translucent image such as a PNG and it
067       * will be used to cover any current content on the client when the
068       * lightbox is shown.
069       *
070       * @param image The image to use as the over lay.
071       */
072      public void setTranslucentImage( final ImageReference image )
073      {
074        set( PROPERTY_TRANSLUCENT_IMAGE, image );
075      }
076    
077      /**
078       * Return the visiable status of the light box.
079       *
080       * @return Return {@code true} if the light box will be visible when
081       *   added to the component hierarchy.
082       */
083      public boolean getHidden()
084      {
085        return (Boolean) get( PROPERTY_HIDDEN );
086      }
087    
088      /**
089       * Set the visible status of the light box.  Use in event listeners to
090       * display or hide the light box.  The usual action is to hide the light
091       * box after some processing, but may also be used to re-display a
092       * previously hidden light box (reuse the same light box).
093       *
094       * @param hidden The visible status indicator to set.
095       */
096      public void setHidden( final boolean hidden )
097      {
098        set( PROPERTY_HIDDEN, hidden );
099      }
100    
101      /**
102       * Return the indicator that specifies whether the light box will cover
103       * the entire browser window or just its container pane.
104       *
105       * @return Return {@code true} if only the container pane is covered.
106       */
107      public boolean getParentOnly()
108      {
109        return (Boolean) get( PROPERTY_PARENT_ONLY );
110      }
111    
112      /**
113       * Set the indicator that specified whether the light box covers the
114       * entire browser window or just its parent container pane.
115       *
116       * @param parentOnly The indicator to set.
117       */
118      public void setParentOnly( final boolean parentOnly )
119      {
120        set( PROPERTY_PARENT_ONLY, parentOnly );
121      }
122    
123      /**
124       * Over-ridden to allow only {@link nextapp.echo.app.PaneContainer}s as
125       * parents.
126       *
127       * @param component The component to test.
128       * @return Return {@code true} if the component is a pane container.
129       */
130      @Override
131      public boolean isValidParent( final Component component )
132      {
133        return ( component instanceof PaneContainer );
134      }
135    }