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 15975 2014-05-08 21:08:33Z onoprien $
Author:
tonyj
See Also:
Serialized Form

Nested Class Summary
 class Application.ApplicationCommandProcessor
          Extends CommandProcessor to handle some standard Application commands.
 class Application.AppPrintPreview
           
static class Application.InitializationException
           
static interface Application.InitializationListener
           
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Component
Component.BaselineResizeBehavior
 
Field Summary
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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
 
Method Summary
 void about()
           
 void addApplicationListener(ApplicationListener l)
           
 JFrame createFrame(String[] argv)
          Creates a JFrame that holds the application.
 PrintPreview createPrintPreview()
           
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.
static int error(Component source, String message, Throwable detail, Object[] options)
          Show an error message in an error dialog, with optional supporting detail and user response options.
 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.
 int error(String message, Throwable detail, Object[] options)
          Show an error message in an error dialog, with optional supporting detail and user response options.
 void exit()
          Override this method to provide specialized application exit handling.
static Application getApplication()
           
 String getAppName()
           
 Properties getAppProperties()
           
 CommandLine getCommandLine()
           
 CommandProcessor getCommandProcessor()
           
 CommandTargetManager getCommandTargetManager()
           
 String getFullVersion()
           
 JMenuBar getMenuBar()
           
 RecentFileList getRecentFileList(String name)
           
 ServiceManager getServiceManager()
           
 boolean getShowStatusBar()
           
 boolean getShowToolBar()
           
 StatusBar getStatusBar()
           
 JPanel getToolBarHolder()
           
 Properties getUserProperties()
           
 String getVersion()
           
 XMLMenuBuilder getXMLMenuBuilder()
           
 void removeApplicationListener(ApplicationListener l)
           
 void restart()
          Restarts application.
 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, setUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, 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, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, 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, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, enableInputMethods, 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, 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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

getServiceManager

public ServiceManager getServiceManager()

getApplication

public static Application getApplication()

getRecentFileList

public RecentFileList getRecentFileList(String name)

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 CommandProcessor getCommandProcessor()

getCommandTargetManager

public CommandTargetManager getCommandTargetManager()

getCommandLine

public CommandLine getCommandLine()

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

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

error

public int error(String message,
                 Throwable detail,
                 Object[] options)
Show an error message in an error dialog, with optional supporting detail and user response options. Blocks until the user responds to the message. 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. See JOptionPane API documentation for the description of options treatment and return values.

Parameters:
message - The error message
detail - A throwable giving more details on the error.
options - An array of objects indicating the possible choices the user can make.
Returns:
an integer indicating the option chosen by the user, or CLOSED_OPTION if the user closed the dialog or the thread was interrupted while waiting for user's response.

error

public static int error(Component source,
                        String message,
                        Throwable detail,
                        Object[] options)
Show an error message in an error dialog, with optional supporting detail and user response options. Blocks until the user responds to the message. 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. See JOptionPane API documentation for the description of options treatment and return values.

Parameters:
source - The owner of the error dialog
message - The error message
detail - A throwable giving more details on the error.
options - An array of objects indicating the possible choices the user can make.
Returns:
an integer indicating the option chosen by the user, or CLOSED_OPTION if the user closed the dialog or the thread was interrupted while waiting for user's response.

getToolBarHolder

public JPanel getToolBarHolder()

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).


restart

public void restart()
Restarts application. This method performs the same pre-shutdown activities as the exit(), then attempts to restart the application. If the application cannot be restarted for any reason, it is shut down.


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

getUserProperties

public Properties getUserProperties()

getXMLMenuBuilder

public XMLMenuBuilder getXMLMenuBuilder()
                                 throws Application.InitializationException
Throws:
Application.InitializationException

getAppProperties

public final Properties getAppProperties()

getAppName

public String getAppName()

addApplicationListener

public void addApplicationListener(ApplicationListener l)

removeApplicationListener

public void removeApplicationListener(ApplicationListener l)

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-2014 FreeHEP. All Rights Reserved.