|
jAER project on SourceForge | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.jaer.util.WindowSaver
public class WindowSaver
adapted from O'Reilly book Swing Hacks by Marinacci and Adamson ISBN 0-596-00907-0.
Used to save and restore window positions.
Static methods allow explicit saving and restoring, or the user can do the
following in their main class:
Toolkit.getDefaultToolkit().addAWTEventListener(windowSaver,AWTEvent.WINDOW_EVENT_MASK);
.
Then (magically) global window opening events will result in callbacks to
eventDispatched which loads saved settings, keyed on the frame.
A class could add a ShutdownHook to save the last window settings:
Runtime.getRuntime().addShutdownHook(new Thread(){ public void run(){ if(windowSaver!=null){ try{ windowSaver.saveSettings(); }catch(IOException e){ e.printStackTrace(); } } } });
Unexpected behavior can result if the user application resizes its own windows after the window settings are loaded.
Nested Class Summary | |
---|---|
static interface |
WindowSaver.DontResize
This marker interface can be implemented to avoid resizing the window |
Field Summary | |
---|---|
int |
DEFAULT_HEIGHT
Default width and height values. |
int |
DEFAULT_WIDTH
Default width and height values. |
int |
OFFSET_FROM_SAME
Offset from last window with same name. |
int |
WINDOWS_TASK_BAR_HEIGHT
|
Constructor Summary | |
---|---|
WindowSaver(java.lang.Object o,
java.util.prefs.Preferences preferences)
Creates a new instance of WindowSaver. |
Method Summary | |
---|---|
void |
eventDispatched(java.awt.AWTEvent evt)
Called when event is dispatched. |
void |
loadSettings(javax.swing.JFrame frame)
The preferred settings are loaded based on window name. |
static void |
restoreWindowLocation(java.awt.Window window,
java.util.prefs.Preferences prefs)
This static method can be used to restore the window x,y, position (but not size) of a window based on the Window class name. |
void |
saveSettings()
Used to explicity save settings. |
static void |
saveWindowLocation(java.awt.Window window,
java.util.prefs.Preferences prefs)
This static method can be used to save the window x,y, position (but not size). |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public final int WINDOWS_TASK_BAR_HEIGHT
public final int OFFSET_FROM_SAME
public final int DEFAULT_WIDTH
public final int DEFAULT_HEIGHT
Constructor Detail |
---|
public WindowSaver(java.lang.Object o, java.util.prefs.Preferences preferences)
o
- the object for which to savepreferences
- the user preferences to save toMethod Detail |
---|
public void eventDispatched(java.awt.AWTEvent evt)
eventDispatched
in interface java.awt.event.AWTEventListener
evt
- the AWTEvent. Only WINDOW_OPENED events are processed to loadSettingsloadSettings(javax.swing.JFrame)
public void loadSettings(javax.swing.JFrame frame) throws java.io.IOException
frame
- JFrame to load settings for
java.io.IOException
public void saveSettings() throws java.io.IOException
java.io.IOException
public static void restoreWindowLocation(java.awt.Window window, java.util.prefs.Preferences prefs)
window
- the window to restoreprefs
- user preferences nodesaveWindowLocation(java.awt.Window, java.util.prefs.Preferences)
public static void saveWindowLocation(java.awt.Window window, java.util.prefs.Preferences prefs)
window
- the window to save forprefs
- user preferences noderestoreWindowLocation(java.awt.Window, java.util.prefs.Preferences)
|
jAER project on SourceForge | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |