net.lucidviews.util.gui.swing
Class WindowUtils

java.lang.Object
  extended by net.lucidviews.util.gui.swing.WindowUtils
All Implemented Interfaces:
WindowListener, EventListener

public class WindowUtils
extends Object
implements WindowListener

Utilities for setting window properties.

Since:
1.0
Version:
$Revision: 1.2 $
Author:
Stephen Battey

Field Summary
private  Properties _appnProperties
          The properties for the window.
private  String _appnPropertyPrefix
          The prefix for all property names (should include the name of the application).
private  JFrame _targetWindow
          A reference to the window that the properties are applicable to.
private static String WINDOW_HEIGHT_PROPERTY_NAME
          Suffix for window height property name.
private static String WINDOW_WIDTH_PROPERTY_NAME
          Suffix for window width property name.
private static String WINDOW_XPOS_PROPERTY_NAME
          Suffix for window x-position property name.
private static String WINDOW_YPOS_PROPERTY_NAME
          Suffix for window y-position property name.
 
Constructor Summary
WindowUtils(JFrame target)
          Create a utility suite for a given application window.
WindowUtils(JFrame target, Properties properties, String propertyPrefix)
          Create a utility suite for a given application window.
WindowUtils(JFrame target, String propertiesFileRef, String propertyPrefix)
          Create a utility suite for a given application window.
 
Method Summary
 void autoStoreWindowProperties()
          Automatically store the properties of this window when the window is closed.
 void setIcon(String iconImageURL)
          Set the icon for this window.
 void setWindowLocation()
          Set the position of the window.
 void setWindowSize()
          Set the size of the window.
 void storeWindowLocation()
          Store the position of the window.
private  void storeWindowLocation0()
           
 void storeWindowProperties()
          Store the size and position of the window.
 void storeWindowSize()
          Store the size of the window.
private  void storeWindowSize0()
           
 void windowActivated(WindowEvent e)
           
 void windowClosed(WindowEvent e)
           
 void windowClosing(WindowEvent e)
           
 void windowDeactivated(WindowEvent e)
           
 void windowDeiconified(WindowEvent e)
           
 void windowIconified(WindowEvent e)
           
 void windowOpened(WindowEvent e)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

WINDOW_WIDTH_PROPERTY_NAME

private static final String WINDOW_WIDTH_PROPERTY_NAME
Suffix for window width property name.

See Also:
Constant Field Values

WINDOW_HEIGHT_PROPERTY_NAME

private static final String WINDOW_HEIGHT_PROPERTY_NAME
Suffix for window height property name.

See Also:
Constant Field Values

WINDOW_XPOS_PROPERTY_NAME

private static final String WINDOW_XPOS_PROPERTY_NAME
Suffix for window x-position property name.

See Also:
Constant Field Values

WINDOW_YPOS_PROPERTY_NAME

private static final String WINDOW_YPOS_PROPERTY_NAME
Suffix for window y-position property name.

See Also:
Constant Field Values

_targetWindow

private JFrame _targetWindow
A reference to the window that the properties are applicable to.


_appnProperties

private Properties _appnProperties
The properties for the window.


_appnPropertyPrefix

private String _appnPropertyPrefix
The prefix for all property names (should include the name of the application).

Constructor Detail

WindowUtils

public WindowUtils(JFrame target)
Create a utility suite for a given application window.

Parameters:
target - the window to be controlled

WindowUtils

public WindowUtils(JFrame target,
                   Properties properties,
                   String propertyPrefix)
Create a utility suite for a given application window.

Parameters:
target - the window to be controlled
properties - data model containing the window's properties
propertyPrefix - the prefix to the names of all the window's properties

WindowUtils

public WindowUtils(JFrame target,
                   String propertiesFileRef,
                   String propertyPrefix)
            throws FileNotFoundException,
                   IOException
Create a utility suite for a given application window.

Parameters:
target - the window to be controlled
propertiesFileRef - URL of a file that stores the window's properties
propertyPrefix - the prefix to the names of all the window's properties
Throws:
FileNotFoundException - the file location specified by propertiesFileRef does not exist
IOException - the file at the specified location could not be read
Method Detail

storeWindowSize0

private void storeWindowSize0()
                       throws IOException
Throws:
IOException

storeWindowLocation0

private void storeWindowLocation0()
                           throws IOException
Throws:
IOException

setIcon

public void setIcon(String iconImageURL)
Set the icon for this window.
The icon will be displayed in the top left corner of the window.
This method will automatically load the image from the URL, waiting for the image data to load before returning. This ensure the icon is ready for display before you go on to make the window visible by calling setVisible.

Parameters:
iconImageURL - the URL to the image file

setWindowSize

public void setWindowSize()
Set the size of the window.
The size will be first taken from the application properties table. If there is no properties table or the properties do not contain a width and height, the window will take on the preferred size of the internal components of the window.


setWindowLocation

public void setWindowLocation()
Set the position of the window.
The (x and y) position will be first taken from the application properties table. If there is no properties table or the properties do not contain an x and y co-ordinate, the window will be placed in the centre of the screen.


storeWindowSize

public void storeWindowSize()
                     throws IOException
Store the size of the window.
If there is no properties table this operation is ignored. Otherwise, the current width and height of the window are saved to the file where the properties were originally read from.

Throws:
IOException - error writing the size properties to the properties file

storeWindowLocation

public void storeWindowLocation()
                         throws IOException
Store the position of the window.
If there is no properties table this operation is ignored. Otherwise, the current x and y co-ordinates of the window are saved to the file where the properties were originally read from.

Throws:
IOException - error writing the location properties to the properties file

storeWindowProperties

public void storeWindowProperties()
                           throws IOException
Store the size and position of the window.
If there is no properties table this operation is ignored. Otherwise, the current width, height, x co-ordinate and y co-ordinate of the window are saved to the file where the properties were originally read from.

Throws:
IOException - error writing the window properties to the properties file

autoStoreWindowProperties

public void autoStoreWindowProperties()
Automatically store the properties of this window when the window is closed.
The utils object will listen for the close-window event and save the window properties, ready for the next time the application is run.


windowOpened

public void windowOpened(WindowEvent e)
Specified by:
windowOpened in interface WindowListener

windowClosing

public void windowClosing(WindowEvent e)
Specified by:
windowClosing in interface WindowListener

windowClosed

public void windowClosed(WindowEvent e)
Specified by:
windowClosed in interface WindowListener

windowIconified

public void windowIconified(WindowEvent e)
Specified by:
windowIconified in interface WindowListener

windowDeiconified

public void windowDeiconified(WindowEvent e)
Specified by:
windowDeiconified in interface WindowListener

windowActivated

public void windowActivated(WindowEvent e)
Specified by:
windowActivated in interface WindowListener

windowDeactivated

public void windowDeactivated(WindowEvent e)
Specified by:
windowDeactivated in interface WindowListener