com.evanmclean.evlib.swing
Class Screen

java.lang.Object
  extended by com.evanmclean.evlib.swing.Screen

public final class Screen
extends Object

Utilities for managing windows on screen and screen dimensions.

Author:
Evan McLean McLean Computer Services (see the overview for copyright and licensing.)

Method Summary
static void centreOn(Window window, Window parent)
          Centre the window over the parent window, ensuring that it is still entirely visible on the screen.
static void centreScreen(Window window)
          Centre the window on the primary display screen.
static void clearWindowSizePos(Class<?> cls)
          Clear the size position preferences for the window.
static void clearWindowSizePos(Class<?> cls, String key)
          Clear the size position preferences for the window.
static void clearWindowSizePos(Window window)
          Clear the size position preferences for the window.
static void clearWindowSizePos(Window window, String key)
          Clear the size position preferences for the window.
static Preferences getPref(Window window)
          Helper function that gets the default preferences node for a window.
static boolean getWindowPos(Preferences pref, String key, Point pos)
          Retrieve the saved position information from a preferences key.
static boolean getWindowPos(Window window)
          Position a window based on the saved position information from a preferences key, ensuring that the window is still entirely on the screen.
static boolean getWindowPos(Window window, String key)
          Position a window based on the saved position information from a preferences key, ensuring that the window is still entirely on the screen.
static boolean getWindowSize(Preferences pref, String key, Dimension size)
          Retrieve the saved size information from a preferences key.
static boolean getWindowSize(Window window)
          Position a window based on the saved size information from a preferences key, ensuring that the window is still entirely on the screen.
static boolean getWindowSize(Window window, String key)
          Position a window based on the saved size information from a preferences key, ensuring that the window is still entirely on the screen.
static boolean getWindowSizePos(Preferences pref, String key, Dimension size, Point pos)
          Retrieve the saved size and position information from a preferences key.
static boolean getWindowSizePos(Window window)
          Position a window based on the saved size and position information from a preferences key, ensuring that the window is still entirely on the screen.
static boolean getWindowSizePos(Window window, String key)
          Position a window based on the saved size and position information from a preferences key, ensuring that the window is still entirely on the screen.
static void main(String[] args)
           
static Point onScreen(int xpos, int ypos, Dimension size)
          Ensure that, given the specified size, the specified position will have the entire window on the screen (or failing that, in the top left corner).
static Point onScreen(int xpos, int ypos, int width, int height)
          Ensure that, given the specified size, the specified position will have the entire window on the screen (or failing that, in the top left corner).
static boolean onScreen(Point pos, Dimension size)
          Ensure that, given the specified size, the specified position will have the entire window on the screen (or failing that, in the top left corner).
static boolean onScreen(Point pos, int width, int height)
          Ensure that, given the specified size, the specified position will have the entire window on a screen (or failing that, in the top left corner).
static boolean onScreen(Window window)
          Ensure that the entire window is on the screen (or failing that, in the top left corner).
static boolean saveWindowPos(Preferences pref, String key, int xpos, int ypos)
          Save position information in a preferences key.
static boolean saveWindowPos(Window window)
          Save position information in the default preferences key for the window.
static boolean saveWindowPos(Window window, String key)
          Save position information in the default preferences key for the window.
static boolean saveWindowSize(Preferences pref, String key, int width, int height)
          Save size information in a preferences key.
static boolean saveWindowSize(Window window)
          Save size information in the default preferences key for the window.
static boolean saveWindowSize(Window window, String key)
          Save size information in the default preferences key for the window.
static boolean saveWindowSizePos(Preferences pref, String key, int width, int height, int xpos, int ypos)
          Save size and position information in a preferences key.
static boolean saveWindowSizePos(Window window)
          Save size and position information in the default preferences key for the window.
static boolean saveWindowSizePos(Window window, String key)
          Save size and position information in the default preferences key for the window.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

centreOn

public static void centreOn(Window window,
                            Window parent)
Centre the window over the parent window, ensuring that it is still entirely visible on the screen.

Parameters:
window - The window to position.
parent - The window to centre over.

centreScreen

public static void centreScreen(Window window)
Centre the window on the primary display screen. If it is bigger then the screen it will be positioned in the top left corner.

Parameters:
window - The window to position.

clearWindowSizePos

public static void clearWindowSizePos(Class<?> cls)
Clear the size position preferences for the window.

Parameters:
cls - The class to clear.

clearWindowSizePos

public static void clearWindowSizePos(Class<?> cls,
                                      String key)
Clear the size position preferences for the window.

Parameters:
cls - The class to clear.
key - The key to retrieve from.

clearWindowSizePos

public static void clearWindowSizePos(Window window)
Clear the size position preferences for the window.

Parameters:
window - The window to clear.

clearWindowSizePos

public static void clearWindowSizePos(Window window,
                                      String key)
Clear the size position preferences for the window.

Parameters:
window - The window to clear.
key - The key to retrieve from.

getPref

public static Preferences getPref(Window window)
Helper function that gets the default preferences node for a window. Based on the name of the class (not just the package).

Parameters:
window -
Returns:
The default preferences node for the window.

getWindowPos

public static boolean getWindowPos(Preferences pref,
                                   String key,
                                   Point pos)
Retrieve the saved position information from a preferences key.

Parameters:
pref - The preferences key to retrieve from.
key - The key to retrieve from.
pos - Store the position values here.
Returns:
Returns true if the position changed.

getWindowPos

public static boolean getWindowPos(Window window)
Position a window based on the saved position information from a preferences key, ensuring that the window is still entirely on the screen.

Parameters:
window - The window to size and position.
Returns:
Returns true if the size or position was changed.

getWindowPos

public static boolean getWindowPos(Window window,
                                   String key)
Position a window based on the saved position information from a preferences key, ensuring that the window is still entirely on the screen.

Parameters:
window - The window to size and position.
key - The key to retrieve from.
Returns:
Returns true if the size or position was changed.

getWindowSize

public static boolean getWindowSize(Preferences pref,
                                    String key,
                                    Dimension size)
Retrieve the saved size information from a preferences key.

Parameters:
pref - The preferences key to retrieve from.
key - The key to retrieve from.
size - Store the size values here.
Returns:
Returns true if the size changed.

getWindowSize

public static boolean getWindowSize(Window window)
Position a window based on the saved size information from a preferences key, ensuring that the window is still entirely on the screen.

Parameters:
window - The window to size and position.
Returns:
Returns true if the size or position was changed.

getWindowSize

public static boolean getWindowSize(Window window,
                                    String key)
Position a window based on the saved size information from a preferences key, ensuring that the window is still entirely on the screen.

Parameters:
window - The window to size and position.
key - The key to retrieve from.
Returns:
Returns true if the size or position was changed.

getWindowSizePos

public static boolean getWindowSizePos(Preferences pref,
                                       String key,
                                       Dimension size,
                                       Point pos)
Retrieve the saved size and position information from a preferences key.

Parameters:
pref - The preferences key to retrieve from.
key - The key to retrieve from.
size - Store the size values here (if not null).
pos - Store the position values here (if not null).
Returns:
Returns true if the size or position was changed.

getWindowSizePos

public static boolean getWindowSizePos(Window window)
Position a window based on the saved size and position information from a preferences key, ensuring that the window is still entirely on the screen.

Parameters:
window - The window to size and position.
Returns:
Returns true if the size or position was changed.

getWindowSizePos

public static boolean getWindowSizePos(Window window,
                                       String key)
Position a window based on the saved size and position information from a preferences key, ensuring that the window is still entirely on the screen.

Parameters:
window - The window to size and position.
key - The key to retrieve from.
Returns:
Returns true if the size or position was changed.

main

public static void main(String[] args)

onScreen

public static Point onScreen(int xpos,
                             int ypos,
                             Dimension size)
Ensure that, given the specified size, the specified position will have the entire window on the screen (or failing that, in the top left corner).

Parameters:
xpos - The current x coordinate of the window.
ypos - The current y coordinate of the window.
size - The size of the window.
Returns:
The position, modified if necessary.

onScreen

public static Point onScreen(int xpos,
                             int ypos,
                             int width,
                             int height)
Ensure that, given the specified size, the specified position will have the entire window on the screen (or failing that, in the top left corner).

Parameters:
xpos - The current x coordinate of the window.
ypos - The current y coordinate of the window.
width - The width of the window.
height - The size of the window.
Returns:
The position, modified if necessary.

onScreen

public static boolean onScreen(Point pos,
                               Dimension size)
Ensure that, given the specified size, the specified position will have the entire window on the screen (or failing that, in the top left corner).

Parameters:
pos - The current position, which will be modified if necessary.
size - The size of the window.
Returns:
Returns true if the position has changed.

onScreen

public static boolean onScreen(Point pos,
                               int width,
                               int height)
Ensure that, given the specified size, the specified position will have the entire window on a screen (or failing that, in the top left corner).

Parameters:
pos - The current position, which will be modified if necessary.
width - The width of the window.
height - The size of the window.
Returns:
Returns true if the position has changed.

onScreen

public static boolean onScreen(Window window)
Ensure that the entire window is on the screen (or failing that, in the top left corner).

Parameters:
window - The window to reposition if necessary.
Returns:
Returns true if the location was changed.

saveWindowPos

public static boolean saveWindowPos(Preferences pref,
                                    String key,
                                    int xpos,
                                    int ypos)
Save position information in a preferences key.

Parameters:
pref - The preference node to store in.
key - The key to store in.
xpos -
ypos -
Returns:
True if stored successfully.

saveWindowPos

public static boolean saveWindowPos(Window window)
Save position information in the default preferences key for the window.

Parameters:
window - The window to store the information for.
Returns:
True if stored successfully.

saveWindowPos

public static boolean saveWindowPos(Window window,
                                    String key)
Save position information in the default preferences key for the window.

Parameters:
window - The window to store the information for.
key - The key to store in.
Returns:
True if stored successfully.

saveWindowSize

public static boolean saveWindowSize(Preferences pref,
                                     String key,
                                     int width,
                                     int height)
Save size information in a preferences key.

Parameters:
pref - The preference node to store in.
key - The key to store in.
width -
height -
Returns:
True if stored successfully.

saveWindowSize

public static boolean saveWindowSize(Window window)
Save size information in the default preferences key for the window.

Parameters:
window - The window to store the information for.
Returns:
True if stored successfully.

saveWindowSize

public static boolean saveWindowSize(Window window,
                                     String key)
Save size information in the default preferences key for the window.

Parameters:
window - The window to store the information for.
key - The key to store in.
Returns:
True if stored successfully.

saveWindowSizePos

public static boolean saveWindowSizePos(Preferences pref,
                                        String key,
                                        int width,
                                        int height,
                                        int xpos,
                                        int ypos)
Save size and position information in a preferences key.

Parameters:
pref - The preference node to store in.
key - The key to store in.
width -
height -
xpos -
ypos -
Returns:
True if stored successfully.

saveWindowSizePos

public static boolean saveWindowSizePos(Window window)
Save size and position information in the default preferences key for the window.

Parameters:
window - The window to store the information for.
Returns:
True if stored successfully.

saveWindowSizePos

public static boolean saveWindowSizePos(Window window,
                                        String key)
Save size and position information in the default preferences key for the window.

Parameters:
window - The window to store the information for.
key - The key to store in.
Returns:
True if stored successfully.