org.freehep.application
Class Application

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.freehep.application.Application
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
Direct Known Subclasses:
MDIApplication

public class Application
extends JPanel

A framework for a simple swing application. This framework assumes there will be only one top level window associated with the application, which can always be accessed using the static method Application.getApplication();

The framework provides the following facilities:

The easiest way to use the framework is to provide an application properties file. The following properies are supported:
mainClass
The main class (which must extend Application)
title
The initial title for the main frame
menus
The name of an XML file to load which defines menus
The framework basically ties together a number of features that are implemented elsewhere in the FreeHEP library. By using this framework you are able to easily use some or all of these features. The framework has been implemented in such a way as to ensure there is almost no overhead paid for features that are not used.

Version:
$Id: Application.java 8584 2006-08-10 23:06:37Z duns $
Author:
tonyj
See Also:
Serialized Form

Nested Class Summary
 class Application.ApplicationCommandProcessor
          Extends CommandProcessor to handle some standard Application commands.
protected  class Application.ApplicationCommandTargetManager
           
 class Application.AppPrintPreview
           
static class Application.InitializationException
           
static interface Application.InitializationListener
           
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
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
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
protected Application(String appName)
          Creates new Application
 
Method Summary
 void about()
           
 void addApplicationListener(ApplicationListener l)
           
protected  JDialog createAboutDialog()
           
protected  Properties createAppProperties()
           
protected  org.freehep.util.commandline.CommandLine createCommandLine()
           
protected  org.freehep.util.commanddispatcher.CommandProcessor createCommandProcessor()
           
protected  org.freehep.util.commanddispatcher.CommandTargetManager createCommandTargetManager()
           
 JFrame createFrame(String[] argv)
          Creates a JFrame that holds the application.
protected  HelpService createHelpService()
           
 PrintPreview createPrintPreview()
           
protected  ServiceManager createServiceManager()
          Override this method to provide a specialized ServiceManager.
protected  Application.InitializationListener createSplashScreen()
           
protected  StatusBar createStatusBar()
          Override this to provide an application specific status bar
protected  JPanel createToolBarHolder()
           
protected  Properties createUserProperties()
           
protected  org.freehep.xml.menus.XMLMenuBuilder createXMLMenuBuilder()
           
protected  XMLReader createXMLReader()
           
static void error(Component source, String message)
          Show an error message in an error dialog.
static void error(Component source, String message, Throwable detail)
          Show an error message in an error dialog, with optional supporting detail.
 void error(String message)
          Show an error dialog with a simple message This method is thread safe and can be called from any thread.
 void error(String message, Throwable detail)
          Show an error dialog with a message and supporting detail.
 void exit()
          Override this method to provide specialized application exit handling.
protected  void fireAboutToExit(ApplicationEvent event)
           
protected  void fireApplicationVisible(ApplicationEvent event)
           
protected  void fireInitializationComplete(ApplicationEvent event)
           
static Application getApplication()
           
 String getAppName()
           
 Properties getAppProperties()
           
 org.freehep.util.commandline.CommandLine getCommandLine()
           
 org.freehep.util.commanddispatcher.CommandProcessor getCommandProcessor()
           
 org.freehep.util.commanddispatcher.CommandTargetManager getCommandTargetManager()
           
 String getFullVersion()
           
 JMenuBar getMenuBar()
           
protected  Rectangle getPreferredBounds()
           
 org.freehep.swing.RecentFileList getRecentFileList(String name)
           
 ServiceManager getServiceManager()
           
 boolean getShowStatusBar()
           
 boolean getShowToolBar()
           
 StatusBar getStatusBar()
           
 JPanel getToolBarHolder()
           
 Properties getUserProperties()
           
 String getVersion()
           
 org.freehep.xml.menus.XMLMenuBuilder getXMLMenuBuilder()
           
protected  void init()
           
protected  void loadDefaultProperties(Properties app)
           
 void removeApplicationListener(ApplicationListener l)
           
protected  void saveUserProperties()
           
 void setLookAndFeel(String lookAndFeelName)
           
 void setShowStatusBar(boolean show)
          Show or Hide the status bar.
 void setShowToolBar(boolean show)
          Show or Hide the tool bar.
 void setStatusMessage(String message)
          Display a message in the applications status bar.
 void showDialog(JDialog dlg, String key)
          Shows a dialog and remembers its screen position (across sessions)
 void showHelpContents()
          Shows the table of contents for the help system.
 void showHelpIndex()
          Shows the index for the help system.
 void showHelpSearch()
          Opens a search window for the help system.
 void showHelpTopic(String helpTopicTarget)
           
 void showHelpTopic(String helpTopicTarget, Component owner)
           
static void updateComponentTreeUI(Component c)
          A simple minded look and feel change: ask each node in the tree to updateUI() -- that is, to initialize its UI property with the current look and feel.
 void updateUI()
           
static int versionNumberCompare(String v1, String v2)
          Compares two version numbers of the form 1.2.3.4
 void whenAvailable(String part, Runnable run)
          Run Runnable when part is downloaded and available.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Application

protected Application(String appName)
Creates new Application

Method Detail

createServiceManager

protected ServiceManager createServiceManager()
                                       throws Application.InitializationException
Override this method to provide a specialized ServiceManager. By default this method checks the System property org.freehep.application.ServiceManager, and uses its value as the name of the class to instantiate. If the property is undefined we use org.freehep.application.services.app.AppServiceManager

Throws:
Application.InitializationException
See Also:
AppServiceManager

getServiceManager

public ServiceManager getServiceManager()

getApplication

public static Application getApplication()

getRecentFileList

public org.freehep.swing.RecentFileList getRecentFileList(String name)

saveUserProperties

protected void saveUserProperties()

setLookAndFeel

public void setLookAndFeel(String lookAndFeelName)

getVersion

public String getVersion()

getFullVersion

public String getFullVersion()

versionNumberCompare

public static int versionNumberCompare(String v1,
                                       String v2)
                                throws NumberFormatException
Compares two version numbers of the form 1.2.3.4

Returns:
>0 if v1>v2, <0 if v1Throws:
NumberFormatException

createPrintPreview

public PrintPreview createPrintPreview()

showDialog

public void showDialog(JDialog dlg,
                       String key)
Shows a dialog and remembers its screen position (across sessions)


getCommandProcessor

public org.freehep.util.commanddispatcher.CommandProcessor getCommandProcessor()

createCommandProcessor

protected org.freehep.util.commanddispatcher.CommandProcessor createCommandProcessor()

getCommandTargetManager

public org.freehep.util.commanddispatcher.CommandTargetManager getCommandTargetManager()

createCommandLine

protected org.freehep.util.commandline.CommandLine createCommandLine()

getCommandLine

public org.freehep.util.commandline.CommandLine getCommandLine()

createCommandTargetManager

protected org.freehep.util.commanddispatcher.CommandTargetManager createCommandTargetManager()

showHelpTopic

public final void showHelpTopic(String helpTopicTarget)

showHelpTopic

public void showHelpTopic(String helpTopicTarget,
                          Component owner)

whenAvailable

public void whenAvailable(String part,
                          Runnable run)
Run Runnable when part is downloaded and available. Runnable is always run on the event dispatch thread.

Parameters:
part - The part will be downloaded (if necessary)
run - The Runnable that will be run

createHelpService

protected HelpService createHelpService()
                                 throws Application.InitializationException
Throws:
Application.InitializationException

showHelpContents

public final void showHelpContents()
Shows the table of contents for the help system.


showHelpIndex

public final void showHelpIndex()
Shows the index for the help system.


showHelpSearch

public final void showHelpSearch()
Opens a search window for the help system.


about

public void about()

error

public void error(String message)
Show an error dialog with a simple message This method is thread safe and can be called from any thread.

Parameters:
message - The message to display

error

public void error(String message,
                  Throwable detail)
Show an error dialog with a message and supporting detail. This method is thread safe and can be called from any thread.

Parameters:
message - The error message
detail - the nested exception

error

public static void error(Component source,
                         String message)
Show an error message in an error dialog. This method is thread safe and can be called from any thread.

Parameters:
source - The owner of the error dialog
message - The error message

error

public static void error(Component source,
                         String message,
                         Throwable detail)
Show an error message in an error dialog, with optional supporting detail. If the detail implements HasNestedException the nested exception(s) will also be shown. This method is thread safe and can be called from any thread.

Parameters:
source - The owner of the error dialog
message - The error message
detail - A throwable giving more details on the error.
See Also:
org.freehep.util.HasNestedException

createAboutDialog

protected JDialog createAboutDialog()

createToolBarHolder

protected JPanel createToolBarHolder()

getToolBarHolder

public JPanel getToolBarHolder()

createStatusBar

protected StatusBar createStatusBar()
Override this to provide an application specific status bar


getStatusBar

public StatusBar getStatusBar()

setStatusMessage

public void setStatusMessage(String message)
Display a message in the applications status bar. This method is thread safe and can be called from any thread.

Parameters:
message - The message to display

getShowStatusBar

public boolean getShowStatusBar()

setShowStatusBar

public void setShowStatusBar(boolean show)
Show or Hide the status bar. This setting presists between sessions.

Parameters:
show - true to display the status bar

getShowToolBar

public boolean getShowToolBar()

setShowToolBar

public void setShowToolBar(boolean show)
Show or Hide the tool bar. This setting presists between sessions.

Parameters:
show - true to display the tool bar

exit

public void exit()
Override this method to provide specialized application exit handling. For example to double check with the user before exiting. The default implementation saves the user preferences and then calls System.exit(0).


createSplashScreen

protected Application.InitializationListener createSplashScreen()

createFrame

public JFrame createFrame(String[] argv)
                   throws Application.InitializationException
Creates a JFrame that holds the application. If the application has been run before, and the user properties were saved, will attempt to restore the old window position/size.

Throws:
Application.InitializationException

init

protected void init()

getPreferredBounds

protected Rectangle getPreferredBounds()

getUserProperties

public Properties getUserProperties()

createUserProperties

protected Properties createUserProperties()

createXMLReader

protected XMLReader createXMLReader()

createXMLMenuBuilder

protected org.freehep.xml.menus.XMLMenuBuilder createXMLMenuBuilder()

getXMLMenuBuilder

public org.freehep.xml.menus.XMLMenuBuilder getXMLMenuBuilder()
                                                       throws Application.InitializationException
Throws:
Application.InitializationException

getAppProperties

public Properties getAppProperties()

createAppProperties

protected Properties createAppProperties()
                                  throws Application.InitializationException
Throws:
Application.InitializationException

loadDefaultProperties

protected void loadDefaultProperties(Properties app)
                              throws IOException
Throws:
IOException

getAppName

public String getAppName()

addApplicationListener

public void addApplicationListener(ApplicationListener l)

removeApplicationListener

public void removeApplicationListener(ApplicationListener l)

fireInitializationComplete

protected void fireInitializationComplete(ApplicationEvent event)

fireApplicationVisible

protected void fireApplicationVisible(ApplicationEvent event)

fireAboutToExit

protected void fireAboutToExit(ApplicationEvent event)

getMenuBar

public JMenuBar getMenuBar()

updateUI

public void updateUI()
Overrides:
updateUI in class JPanel

updateComponentTreeUI

public static void updateComponentTreeUI(Component c)
A simple minded look and feel change: ask each node in the tree to updateUI() -- that is, to initialize its UI property with the current look and feel. Unlike SwingUtilities.updateComponentTreeUI this method updates each component's children before updating the component itself, making it easier for components to fine tune their children's look and feel's.



Copyright © 2000-2006 FreeHEP. All Rights Reserved.