com.jgoodies.uif
Class AbstractFrame

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by com.jgoodies.uif.AbstractFrame
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public abstract class AbstractFrame
extends JFrame

Provides convenience code that is frequently used in application frames:

AbstractFrame registers an ApplicationListener with the UIF's ApplicationContext. Currently the ApplicationContext class keeps an indirect (but hard) reference to AbstractFrames. And so AbstractFrame instances won't be garbage collected before the ApplicationContext closes. A future version of the UIF will register ApplicationContext listeners using a listener list based on WeakReferences.

TODO: Register the listener based on WeakReferences.

TODO: Remove the above note once the ApplicationContext uses WeakReferences.

Version:
$Revision: 1.16 $
Author:
Karsten Lentzsch
See Also:
ApplicationContext, WindowUtils, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JFrame
JFrame.AccessibleJFrame
 
Nested classes/interfaces inherited from class java.awt.Frame
Frame.AccessibleAWTFrame
 
Nested classes/interfaces inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
protected AbstractFrame(String title)
          Constructs an AbstractFrame using the given window title.
 
Method Summary
 void build()
          Builds the frame's content pane, packs it, locates it on the screen, sets the icon, restores the saved state, and registers listeners.
protected abstract  JComponent buildContentPane()
          Subclasses must override this method to build and return the content pane.
protected abstract  void configureCloseOperation()
          Configures the behavior that will happen when the user initiates a "close" on this frame.
protected  void configureWindowIcon()
          Sets this frame's icon that is fetched via the ResourceUtils.
 String getTitleSuffix()
          Returns the title's suffix, the part of the title that is appended to the prefix - if any.
protected  void initEventHandling()
          Initializes the event handling.
protected  void locateOnScreen()
          Locates this frame on the screen, by default centered on the screen.
 void open()
          Makes this frame visible.
protected  void resizeHook(JComponent component)
          Resizes the specified component.
protected  void restoreState()
          Restores this frame's state from the user preferences as provided by the ApplicationContext.
 void setTitlePrefix(String prefix)
          Sets this frame's title by means of a prefix.
 void setTitleSuffix(String newTitleSuffix)
          Sets this frame's title suffix, which is used to compose this frame's title together with the title prefix.
protected  void storeState()
          Stores this frame's state in the user preferences as provided by the ApplicationContext.
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, repaint, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, setTransferHandler, update
 
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setTitle, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, dispose, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setVisible, show, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Constructor Detail

AbstractFrame

protected AbstractFrame(String title)
Constructs an AbstractFrame using the given window title. Also sets the title suffix to the given title.

Parameters:
title - the window title to be used
Method Detail

build

public void build()
Builds the frame's content pane, packs it, locates it on the screen, sets the icon, restores the saved state, and registers listeners. It then is ready to be opened.

Subclasses should rarely override this method.


buildContentPane

protected abstract JComponent buildContentPane()
Subclasses must override this method to build and return the content pane.

Returns:
the built content pane

configureCloseOperation

protected abstract void configureCloseOperation()
Configures the behavior that will happen when the user initiates a "close" on this frame.

To properly shut down the application, you must invoke ApplicationContext#close. If you just want to shut down you can use a default handler from class ApplicationContext as follows:

 protected void configureCloseOperation() {
     setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
     addWindowListener(
         ApplicationContext.getApplicationCloseOnWindowClosingHandler());
 }
 

See Also:
JFrame.setDefaultCloseOperation(int), Application.getApplicationExitOnWindowClosingHandler()

setTitlePrefix

public void setTitlePrefix(String prefix)
Sets this frame's title by means of a prefix. The prefix is ensured to have a length less than 40 characters. The title is then composed of the prefix and the suffix. The suffix will often be the application's name.

Example: The suffix is "JDiskReport", if the prefix is empty, the title is just

JDiskReport
. If the prefix is "Scanning", the title is
Scanning - JDiskReport
.

Parameters:
prefix - the window title's prefix
See Also:
setTitleSuffix(String)

getTitleSuffix

public String getTitleSuffix()
Returns the title's suffix, the part of the title that is appended to the prefix - if any.

Returns:
the suffix of this frame's title

setTitleSuffix

public void setTitleSuffix(String newTitleSuffix)
Sets this frame's title suffix, which is used to compose this frame's title together with the title prefix.

Example: The suffix is "JDiskReport", if the prefix is empty, the title is just

JDiskReport
. If the prefix is "Scanning", the title is
Scanning - JDiskReport
.

Parameters:
newTitleSuffix - the suffix for this frame's title
See Also:
setTitlePrefix(String)

open

public void open()
Makes this frame visible. Allows subclasses to perform additional operations immediately before or after the frame is made visible.


resizeHook

protected void resizeHook(JComponent component)
Resizes the specified component. This is called during the #build process and enables subclasses to achieve a better aspect ratio, by applying a resizer, e.g. the Resizer.

Parameters:
component - the component to be resized

locateOnScreen

protected void locateOnScreen()
Locates this frame on the screen, by default centered on the screen.


initEventHandling

protected void initEventHandling()
Initializes the event handling. The default implementation listens to frame resize events to ensure a minimum size and to keep track of the stored bounds.

Subclasses that override this method will typically invoke this default implementation.


configureWindowIcon

protected void configureWindowIcon()
Sets this frame's icon that is fetched via the ResourceUtils. Uses a 12x12 or 16x16 pixel image.

See Also:
WindowUtils.setImageIcon(java.awt.Frame, Image, Image)

storeState

protected void storeState()
Stores this frame's state in the user preferences as provided by the ApplicationContext.

The default implementation does nothing. Since we may add behavior in future versions, subclasses that override this method shall call this super implementation before their added behavior.


restoreState

protected void restoreState()
Restores this frame's state from the user preferences as provided by the ApplicationContext.

The default implementation restores the window bounds and a maximized or normal state via the WindowUtils. Also the current bounds are put into this frame's client properties.

Subclasses that override this method will likely call this default behavior before adding custom actions.

See Also:
WindowUtils.restoreBounds(JFrame, Preferences), WindowUtils.restoreState(Frame, Preferences, boolean), Frame.getExtendedState()


Copyright © 2000-2008 JGoodies Karsten Lentzsch. All Rights Reserved.