/*
* Copyright (c) 2005 Thomas Weise
*
* E-Mail : tweise@gmx.de
* Creation Date : 2005-06-17 20:01:54
* Original Filename: org.sfc.gui.windows.SfcDialog.java
* Version : 2.0.1
* Last modification: 2006-03-07
* by: Thomas Weise
*
* License : GNU LESSER GENERAL PUBLIC LICENSE
* Version 2.1, February 1999
* You should have received a copy of this license along
* with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston,
* MA 02111-1307, USA or download the license under
* http://www.gnu.org/copyleft/lesser.html.
*
* Warranty : This software is provided "as is" without any
* warranty; without even the implied warranty of
* merchantability or fitness for a particular purpose.
* See the Gnu Lesser General Public License for more
* details.
*/
package org.sfc.gui.windows;
import java.awt.Container;
import java.awt.Frame;
import java.awt.Image;
import java.awt.Window;
import javax.swing.JDialog;
import org.sfc.scoped.AlreadyDisposedException;
/**
* This is the stk implementation of JDialog
, incorporating
* the IWindow
interface.
*
* @author Thomas Weise
*/
public class SfcDialog extends JDialog implements IWindow
{
/**
* The serial version uid.
*/
private static final long serialVersionUID = 1;
/**
* true
only as long as this window was not closed.
*/
private boolean m_living ;
/**
* Create a new SfcDialog
.
*
* @param p_owner The owning frame of the dialog.
*/
public SfcDialog (final Frame p_owner)
{
super(p_owner);
this.m_living = true;
Windows.remove_window(this);
this.addWindowListener(Windows.WINDOW_LISTENER);
}
/**
* Returns the icon associated to the window.
*
* @return The icon of the window or null if no icon is assigned.
*/
public final Image get_icon ()
{
return null;
}
/**
* Sets the icon of the window.
*
* @param p_icon The icon of the window.
*/
public final void set_icon (Image p_icon)
{
//
}
/**
* Returns the underlying os-window of the IWindow
.
* @return The window-instance of this IWindow
.
*/
public final Window get_window ()
{
return this;
}
/**
* Returns the underlying frame of the IWindow
.
* @return The frame-instance of this IWindow
.
*/
public final Frame get_frame ()
{
Window l_w;
Container l_c;
l_w = getOwner();
if((l_w != null) && (l_w instanceof Frame))
{
return ((Frame)l_w);
}
l_c = l_w.getParent();
while(l_c != null)
{
if(l_c instanceof Frame) return ((Frame)l_c);
l_c = l_c.getParent();
}
l_c = this;
while(l_c != null)
{
if(l_c instanceof Frame) return ((Frame)l_c);
l_c = l_c.getParent();
}
return null;
}
/**
* Close the object. You must not perform any operations with the object
* afterwards nor should you allow any reference to point on this object.
* Also you must not access any member variables of the object.
* Call this method when you don't need an object anymore, allowing it to
* perform some cleanup.
*/
public final void close ()
{
synchronized(this)
{
if(this.m_living)
{
Windows.remove_window(this);
this.m_living = false;
this.dispose();
}
else
{
throw new AlreadyDisposedException();
}
}
}
/**
* This method will be called when the user decided to close the window
* via some input like hitting the "close"-button in the system menu.
* You can emulate a user-close action by calling this method.
* This method closes the dialog.
* You may override it to provide alternative behavior.
*/
public void close_by_user ()
{
this.close();
}
}