edu.stanford.hci.r3.util
Class WindowUtils

java.lang.Object
  extended by edu.stanford.hci.r3.util.WindowUtils

public class WindowUtils
extends java.lang.Object

This class contains useful methods for positioning, sizing, and manipulating JFrames and other Window-like elements.

This software is distributed under the BSD License.


Field Summary
static int DESKTOP_CENTER
           
static int DESKTOP_EAST
           
static int DESKTOP_NORTH
           
static int DESKTOP_NORTHEAST
           
static int DESKTOP_NORTHWEST
           
static int DESKTOP_SOUTH
           
static int DESKTOP_SOUTHEAST
           
static int DESKTOP_SOUTHWEST
           
static int DESKTOP_WEST
           
static int INVALID_MAX
           
static int INVALID_MIN
           
static int SCREEN_CENTER
           
static int SCREEN_EAST
           
static int SCREEN_NORTH
           
static int SCREEN_NORTHEAST
           
static int SCREEN_NORTHWEST
           
static int SCREEN_SOUTH
           
static int SCREEN_SOUTHEAST
           
static int SCREEN_SOUTHWEST
           
static int SCREEN_WEST
           
 
Constructor Summary
WindowUtils()
           
 
Method Summary
static void centerWindow(javax.swing.JFrame frame)
          Plops the frame into the center of the desktop.
static void enterFullScreenIfPossible(javax.swing.JFrame mainAppFrame)
           
static void exitFullScreen(javax.swing.JFrame mainAppFrame)
           
static void fitToDesktop(javax.swing.JFrame frame)
           
static java.awt.Point getCachedWindowOrigin(int windowWidth, int windowHeight, int where)
          Determines where to put windows based on the cached state
static java.awt.Rectangle getDesktopBounds()
           
static java.awt.Dimension getDesktopSize()
           
static int getScreenHeight()
           
static java.awt.Dimension getScreenSize()
           
static int getScreenWidth()
           
static java.awt.Point getWindowOrigin(java.awt.Frame frame, int where)
           
static java.awt.Point getWindowOrigin(int windowWidth, int windowHeight, int where)
          Given a size (width, height) of a window, and an intended location on the desktop, it returns the x, y location of where the origin should reside.
static void initCachedWindowState()
          Call this before calling getCachedWindowOrigin(...) to get the current state of the user's screen and desktop size.
static void main(java.lang.String[] args)
           
static javax.swing.JFrame openInJFrame(java.awt.Container content, int width, int height)
          Opens a container inside a JFrame.
static javax.swing.JFrame openInJFrame(java.awt.Container content, int width, int height, java.lang.String title)
          Opens a container inside a JFrame.
static javax.swing.JFrame openInJFrame(java.awt.Container content, int width, int height, java.lang.String title, java.awt.Color bgColor)
           
static javax.swing.JFrame openInJFrame(java.awt.Container content, int width, int height, java.lang.String title, java.awt.Color bgColor, boolean exitOnClose)
          Opens a container inside a JFrame.
static void setJavaLookAndFeel()
          The pleasant-looking *cough* Java look and feel.
static void setMotifLookAndFeel()
          Old Skool Look and Feel.
static void setNativeLookAndFeel()
          Windows, Mac, or Unix look and feels
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DESKTOP_CENTER

public static final int DESKTOP_CENTER
See Also:
Constant Field Values

DESKTOP_EAST

public static final int DESKTOP_EAST
See Also:
Constant Field Values

DESKTOP_NORTH

public static final int DESKTOP_NORTH
See Also:
Constant Field Values

DESKTOP_NORTHEAST

public static final int DESKTOP_NORTHEAST
See Also:
Constant Field Values

DESKTOP_NORTHWEST

public static final int DESKTOP_NORTHWEST
See Also:
Constant Field Values

DESKTOP_SOUTH

public static final int DESKTOP_SOUTH
See Also:
Constant Field Values

DESKTOP_SOUTHEAST

public static final int DESKTOP_SOUTHEAST
See Also:
Constant Field Values

DESKTOP_SOUTHWEST

public static final int DESKTOP_SOUTHWEST
See Also:
Constant Field Values

DESKTOP_WEST

public static final int DESKTOP_WEST
See Also:
Constant Field Values

INVALID_MAX

public static final int INVALID_MAX
See Also:
Constant Field Values

INVALID_MIN

public static final int INVALID_MIN
See Also:
Constant Field Values

SCREEN_CENTER

public static final int SCREEN_CENTER
See Also:
Constant Field Values

SCREEN_EAST

public static final int SCREEN_EAST
See Also:
Constant Field Values

SCREEN_NORTH

public static final int SCREEN_NORTH
See Also:
Constant Field Values

SCREEN_NORTHEAST

public static final int SCREEN_NORTHEAST
See Also:
Constant Field Values

SCREEN_NORTHWEST

public static final int SCREEN_NORTHWEST
See Also:
Constant Field Values

SCREEN_SOUTH

public static final int SCREEN_SOUTH
See Also:
Constant Field Values

SCREEN_SOUTHEAST

public static final int SCREEN_SOUTHEAST
See Also:
Constant Field Values

SCREEN_SOUTHWEST

public static final int SCREEN_SOUTHWEST
See Also:
Constant Field Values

SCREEN_WEST

public static final int SCREEN_WEST
See Also:
Constant Field Values
Constructor Detail

WindowUtils

public WindowUtils()
Method Detail

centerWindow

public static void centerWindow(javax.swing.JFrame frame)
Plops the frame into the center of the desktop.

Parameters:
frame -

enterFullScreenIfPossible

public static void enterFullScreenIfPossible(javax.swing.JFrame mainAppFrame)
Parameters:
mainAppFrame - window to be made full screen.

exitFullScreen

public static void exitFullScreen(javax.swing.JFrame mainAppFrame)
Parameters:
mainAppFrame -

getCachedWindowOrigin

public static java.awt.Point getCachedWindowOrigin(int windowWidth,
                                                   int windowHeight,
                                                   int where)
Determines where to put windows based on the cached state

Parameters:
windowWidth -
windowHeight -
where -
See Also:
util.WindowUtilities.initCachedWindowState()

getDesktopBounds

public static java.awt.Rectangle getDesktopBounds()
Returns:
the rectangle describing the user's desktop

getDesktopSize

public static java.awt.Dimension getDesktopSize()
Returns:
the size of the user's desktop

getScreenHeight

public static int getScreenHeight()
Returns:

getScreenSize

public static java.awt.Dimension getScreenSize()
Returns:
the screen size of the last known monitor mode

getScreenWidth

public static int getScreenWidth()
Returns:

getWindowOrigin

public static java.awt.Point getWindowOrigin(int windowWidth,
                                             int windowHeight,
                                             int where)
Given a size (width, height) of a window, and an intended location on the desktop, it returns the x, y location of where the origin should reside. This method will be pretty resilient to the user changing his/her interface (taskbar locations, etc). If you want a faster method, but would sacrifice a (little) bit of assurances... then use getCachedWindowOrigin(...) directly (after calling initCachedWindowState() once)

Parameters:
windowWidth -
windowHeight -
where -
Returns:

getWindowOrigin

public static java.awt.Point getWindowOrigin(java.awt.Frame frame,
                                             int where)
Parameters:
frame -
where -
Returns:

initCachedWindowState

public static void initCachedWindowState()
Call this before calling getCachedWindowOrigin(...) to get the current state of the user's screen and desktop size. The user may have changed it since the last call. This is called once when WindowUtils is first accessed.


main

public static void main(java.lang.String[] args)
                 throws java.lang.InterruptedException
Parameters:
args -
Throws:
java.lang.InterruptedException

openInJFrame

public static javax.swing.JFrame openInJFrame(java.awt.Container content,
                                              int width,
                                              int height)
Opens a container inside a JFrame. Useful for quick testing.

Parameters:
content -
width -
height -
Returns:

openInJFrame

public static javax.swing.JFrame openInJFrame(java.awt.Container content,
                                              int width,
                                              int height,
                                              java.lang.String title)
Opens a container inside a JFrame. Useful for quick testing.

Parameters:
content -
width -
height -
title -
Returns:

openInJFrame

public static javax.swing.JFrame openInJFrame(java.awt.Container content,
                                              int width,
                                              int height,
                                              java.lang.String title,
                                              java.awt.Color bgColor)
Parameters:
content -
width -
height -
title -
bgColor -
Returns:

openInJFrame

public static javax.swing.JFrame openInJFrame(java.awt.Container content,
                                              int width,
                                              int height,
                                              java.lang.String title,
                                              java.awt.Color bgColor,
                                              boolean exitOnClose)
Opens a container inside a JFrame. Useful for quick testing.

Parameters:
content -
width -
height -
title -
bgColor -
exitOnClose -
Returns:

setJavaLookAndFeel

public static void setJavaLookAndFeel()
The pleasant-looking *cough* Java look and feel.


setMotifLookAndFeel

public static void setMotifLookAndFeel()
Old Skool Look and Feel.


setNativeLookAndFeel

public static void setNativeLookAndFeel()
Windows, Mac, or Unix look and feels


fitToDesktop

public static void fitToDesktop(javax.swing.JFrame frame)
Parameters:
frame -

Copyright 2006 Stanford University