
package uk.co.wingpath.gui;

import java.awt.*;
import javax.swing.*;

/**
* This class is just a {@link JDialog} that is declared as implementing the
* {@link WWindow} interface.
* <p>There are no constructors for this class. Use the
* {@link #createModal createModal} method or the
* {@link #createNonModal createNonModal} method to create instances.
*/
public class WDialog
    extends JDialog
    implements WWindow
{
    private WWindow owner;

    private WDialog (JFrame owner, boolean modal)
    {
        super (owner, modal);
        this.owner = (WWindow) owner;
    }

    private WDialog (JDialog owner, boolean modal)
    {
        super (owner, modal);
        this.owner = (WWindow) owner;
    }

    /**
    * Creates a modal {@code WDialog} with the specified owner.
    * If the owner is {@code null}, a shared hidden frame will be set as
    * the owner. If you use a {@code null} owner, it is advisable to call
    * {@link WWindow#setAlwaysOnTop} to stop the dialog getting lost behind
    * other windows.
    * @param owner the {@code WWindow} from which the dialog is
    * displayed.
    */
    public static WDialog createModal (WWindow owner)
    {
        if (owner instanceof JDialog)
            return new WDialog ((JDialog) owner, true);
        else
            return new WDialog ((JFrame) owner, true);
    }

    /**
    * Creates a non-modal {@code WDialog} with the specified owner.
    * If the owner is {@code null}, a shared hidden frame will be set as
    * the owner. If you use a {@code null} owner, it is advisable to call
    * {@link WWindow#setAlwaysOnTop} to stop the dialog getting lost behind
    * other windows.
    * @param owner the {@code WWindow} from which the dialog is
    * displayed.
    */
    public static WDialog createNonModal (WWindow owner)
    {
        if (owner instanceof JDialog)
            return new WDialog ((JDialog) owner, false);
        else
            return new WDialog ((JFrame) owner, false);
    }

    /**
    * Gets the extended state.
    * Since {@code JDialog}s don't have a state, this method always returns
    * {@code Frame.NORMAL}.
    * @return {@code Frame.NORMAL}.
    */
    public int getExtendedState ()
    {
        return Frame.NORMAL;
    }

    /**
    * Sets the extended state.
    * Since {@code JDialog}s don't have a state, this method does nothing.
    */
    public void setExtendedState (int state)
    {
    }
}

