org.jurvis.swing.app
Class JvApplication

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 org.jurvis.swing.app.JvApplication
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, RootPaneContainer, WindowConstants

public class JvApplication
extends JFrame

A class representing a Swing application. Each application is named and has a ResourceBundle containing localized text for all the components within the application.

Though it's possible, it isn't intended that this class be extended. The expected usage is for a main routine to create an NApplication. For example:

 class WebTail
 {
   public static void main(String[] args)
   {
      JvSwingFactory factory = JvSwingFactory.getInstance(WebTail.class.getName());
      JvApplication app = factory.createApplication("webTailApp");
      app.setActiveView(new WebTail(app));
      app.setVisible(true);
   }
 }
 
JvApplication creates and provides two Actions. The Action to exit the application is named "exitApp." The Action to display an about dialog is named "aboutApp."

Author:
Neil W. Weber
See Also:
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.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  JvView activeView
          The active view.
protected static Collection instances
          List of the applications running in the JVM.
protected  Preferences preferences
          The preferences associated with this application.
protected  PropertyChangeListener propertyChangeListener
          PropertyChangeListener for listening to changes in the active view.
protected  Collection views
          The views contained within this application.
 
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
JvApplication(String name, JvSwingFactory factory)
          Construct an JvApplication with the specified name and factory.
 
Method Summary
protected  void capturePreferences()
          Capture any preferences of this application that should be persisted across sessions.
protected  boolean closeViews(int status)
          Close the views of the application.
 void exit(int status)
          Requests terminatination of the application.
protected  void extractPreferences()
          Extract any apply saved preferences applicable for this application.
 JvView getActiveView()
          Return the application's active view.
 Action getExitAction()
          Return an Action that when invoked will exit the application.
 JvSwingFactory getFactory()
          Return the factory used to construct this application.
 boolean isBusy()
          Determine if the application is busy.
static boolean isBusy(Component child)
          Determine if the application containing child is busy and is unable to respond to user events.
 void setActiveView(JvView view)
          Set the application's active view to the specified view.
 void setBusy(boolean busy)
          Indicate if the application is busy and is unable to respond to user events.
static void setBusy(Component child, boolean busy)
          Indicate if the application containing child is busy and is unable to respond to user events.
protected  void setupWindowListener()
          Sets up a window listener for the application
 void setVisible(boolean visible)
          Makes the component visible or invisible.
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, processWindowEvent, remove, setContentPane, setDefaultCloseOperation, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setRootPane, setRootPaneCheckingEnabled, update
 
Methods inherited from class java.awt.Frame
addNotify, finalize, 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, getInputContext, getListeners, getLocale, getMostRecentFocusOwner, getOwnedWindows, getOwner, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setAlwaysOnTop, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setLocationByPlatform, setLocationRelativeTo, 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, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, 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, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

views

protected Collection views
The views contained within this application.


activeView

protected JvView activeView
The active view.


preferences

protected Preferences preferences
The preferences associated with this application.


instances

protected static Collection instances
List of the applications running in the JVM. Used to avoid terminating the JVM while there are still applications running. Use a Vector for thread safety.


propertyChangeListener

protected final PropertyChangeListener propertyChangeListener
PropertyChangeListener for listening to changes in the active view.

Constructor Detail

JvApplication

public JvApplication(String name,
                     JvSwingFactory factory)
Construct an JvApplication with the specified name and factory.

Parameters:
name - the name of the application
factory - the factory used to create all components in the application
Method Detail

setupWindowListener

protected void setupWindowListener()
Sets up a window listener for the application


setActiveView

public void setActiveView(JvView view)
Set the application's active view to the specified view. If the specified view isn't already in the collection of views for this application, it is added to the collection.

Parameters:
view - the view to be made active

getActiveView

public final JvView getActiveView()
Return the application's active view.

Returns:
the application's active view

getFactory

public final JvSwingFactory getFactory()
Return the factory used to construct this application.

Returns:
the factory used to construct this application

extractPreferences

protected void extractPreferences()
Extract any apply saved preferences applicable for this application. This method extracts and applys the applications location and size.


capturePreferences

protected void capturePreferences()
Capture any preferences of this application that should be persisted across sessions. The captured preferences are saved in preferences. This method captures the applications location and size. Each application view is requested to save its modifications.


setVisible

public void setVisible(boolean visible)
Makes the component visible or invisible. Overrides Component.setVisible in order to set a default location.

Overrides:
setVisible in class Component
Parameters:
visible - true to make the component visible

setBusy

public void setBusy(boolean busy)
Indicate if the application is busy and is unable to respond to user events.

Parameters:
busy - true if the application is busy

isBusy

public boolean isBusy()
Determine if the application is busy.

Returns:
true if the application is busy

setBusy

public static void setBusy(Component child,
                           boolean busy)
Indicate if the application containing child is busy and is unable to respond to user events.

Parameters:
child - the child of the application
busy - true if the application is busy

isBusy

public static boolean isBusy(Component child)
Determine if the application containing child is busy and is unable to respond to user events.

Parameters:
child - the child of the application
Returns:
true if the application is busy

exit

public void exit(int status)
Requests terminatination of the application. This method should be used rather than System.exit or Runtime.exit because both of those methods terminates the currently running Java Virtual Machine ignoring the possiblity that we may be running more than a single application in the JVM.

The argument serves as a status code; by convention, a nonzero status code indicates abnormal termination.

If the application contains views that have outstanding modifications, the user will be prompted to save the changes, discard the changes, or cancel the exit.

Any user preferences including the application's window size and location are saved on exit.

Parameters:
status - exit status

closeViews

protected boolean closeViews(int status)
Close the views of the application. If any view has outstanding changes, prompt the user to determine what they want done.

Parameters:
status - exit status
Returns:
true if the application should be closed

getExitAction

public Action getExitAction()
Return an Action that when invoked will exit the application. The action will query each of the application views to determine if they have any outstanding modifications. The user will be prompted to save the changes, discard the changes, or cancel the exit.

Returns:
an action for exiting the application


Copyright © 1999-2004 Neil W. Weber. All Rights Reserved.