package org.sfc.gui.windows;
import java.awt.Frame;
import java.awt.Image;
import java.awt.Window;
import javax.swing.JFrame;
import org.sfc.scoped.AlreadyDisposedException;
/**
* This is the stk implementation of <code>JFrame</code>, incorporating
* the <code>IWindow</code> interface.
*
* @author Thomas Weise
*/
public class SfcFrame extends JFrame implements IWindow
{
/**
* The serial version uid.
*/
private static final long serialVersionUID = 1;
/**
* <code>true</code> only as long as this window was not closed.
*/
private boolean m_living ;
/**
* Create a new <code>SfcFrame</code>.
*/
public SfcFrame ()
{
super();
this.m_living = true;
Windows.add_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 this.getIconImage();
}
/**
* Sets the icon of the window.
*
* @param p_icon The icon of the window.
*/
public final void set_icon (Image p_icon)
{
this.setIconImage(p_icon);
}
/**
* Returns the underlying os-window of the <code>IWindow</code>.
* @return The window-instance of this <code>IWindow</code>.
*/
public final Window get_window ()
{
return this;
}
/**
* Returns the underlying frame of the <code>IWindow</code>.
* @return The frame-instance of this <code>IWindow</code>.
*/
public final Frame get_frame ()
{
return this;
}
/**
* 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 window and exists the system. You might override
* it to alter behavior.
*/
public void close_by_user ()
{
this.close();
System.exit(0);
}
}