/*
 * @(#)DisplayWrapper.java    1.0.1  2 July 2001
 *
 * Copyright 2004
 * College of Computer and Information Science
 * Northeastern University
 * Boston, MA  02115
 *
 * The Java Power Tools software may be used for educational
 * purposes as long as this copyright notice is retained intact
 * at the top of all source files.
 *
 * To discuss possible commercial use of this software, 
 * contact Richard Rasala at Northeastern University, 
 * College of Computer and Information Science,
 * 617-373-2462 or rasala@ccs.neu.edu.
 *
 * The Java Power Tools software has been designed and built
 * in collaboration with Viera Proulx and Jeff Raab.
 *
 * Should this software be modified, the words "Modified from 
 * Original" must be included as a comment below this notice.
 *
 * All publication rights are retained.  This software or its 
 * documentation may not be published in any media either
 * in whole or in part without explicit permission.
 *
 * This software was created with support from Northeastern 
 * University and from NSF grant DUE-9950829.
 */

package edu.neu.ccs.gui;

import java.awt.*;
import javax.swing.*;

/**
 * <P>Wrapper for a single <CODE>Displayable</CODE> object
 * that uses a <CODE>CenterLayout</CODE>
 * and faithfully respects 
 * minimum, maximum, and preferred sizes.</P>
 *
 * @author  Jeff Raab
 * @version 2.2
 * @since   1.0
 * @see ComponentWrapper
 * @see TypedViewWrapper
 * @see GeneralViewWrapper
 */
public class DisplayWrapper extends ComponentWrapper {

    /**
     * Constructs a wrapper for the given
     * <CODE>Displayable</CODE> object.
     *
     * @param display the displayable object to be wrapped
     */
    public DisplayWrapper(Displayable display) {
        super((Component)display);
    }

    /////////////////
    // Displayable //
    /////////////////
    
    public void setViewState(String data) {
        getWrappedDisplay().setViewState(data);
    }
    
    public String getViewState() {
        return getWrappedDisplay().getViewState();
    }

    public void setDefaultViewState(String data) {
        getWrappedDisplay().setDefaultViewState(data);
    }
    
    public String getDefaultViewState() {
        return getWrappedDisplay().getDefaultViewState();
    }
    
    public void reset() {
        getWrappedDisplay().reset();
    }

    ////////////////
    // Public API //
    ////////////////
    
    /**
     * Sets the wrapped display to the given component.
     *
     * This method should not be called directly.
     *
     * Rather, <CODE>setWrappedDisplay</CODE> should be called
     * in order to set the wrapped <CODE>Displayable</CODE> object.
     *
     * If the given component is not <CODE>Displayable</CODE>,
     * the currently wrapped display is not changed.
     *
     * @param component the component to be wrapped
     * @throws NullPointerException
     *      if the given object is <CODE>null</CODE>
     * @see #setWrappedDisplay(Displayable)
     */
    public void setWrappedComponent(Component component) {
        if (component instanceof Displayable)
            super.setWrappedComponent(component);
    }

    /**
     * Sets the wrapped display 
     * to the given <CODE>Displayable</CODE> object.
     *
     * @param display the object to be wrapped
     * @throws NullPointerException
     *      if the given object is <CODE>null</CODE>
     * @see #getWrappedDisplay()
     */
    public void setWrappedDisplay(Displayable display) {
        setWrappedComponent((Component)display);
    }

    /**
     * Returns the wrapped display.
     *
     * @see #setWrappedDisplay(Displayable)
     */
    public Displayable getWrappedDisplay() {
        return (Displayable)getWrappedComponent();
    }
}
