Class JStandardGUIApplication
- All Implemented Interfaces:
ActionListener
,ComponentListener
,WindowListener
,ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
,RootPaneContainer
,WindowConstants
- Direct Known Subclasses:
JDerivedGUIApplication
JStandardGUIApplication
class provides a standard Swing based GUI framework.
By default, the JStandardGUIApplication
class will result in the following GUI:
Typically, this JStandardGUIApplication
is subclassed, with several methods overridden.
These methods control the application's settings, the visual layout of its GUI, and the actions that need to be
taken upon user input.
The overridable methods that setup the GUI's form and behaviour are:
- Command-line parameter parsing
parseApplicationParameter(int,String)
- -locale=dutch|ukenglish|usenglish (default is ukenglish)
- -developmode
- -width=autosize|fullscreen|<number> (default is autosize)
- -height=autosize|fullscreen|<number> (default is autosize)
- -silent
- -help
- Custom initialisation and clean-up
getApplicationResourceArchiveFilename()
getApplicationLocalePrefix()
loadApplicationRegistry()
initialiseApplication(Object[])
shutdownApplication()
- Splash screen during startup
getGUISplashScreen()
getGUISplashScreenContent()
getGUISplashScreenSound()
[see alsoJSplashScreen
andMP3Player
]- Sound set selection
- Visual layout (window related)
getGUIInitialLookAndFeel()
guiLookAndFeelChanged()
getGUIInitialSize()
isGUIResizable()
isGUIRepaintedWhenResizing()
getGUIIcon()
getGUITitle()
isGUIMinimiseToSystemTrayAllowed()
setGUIDynamicLayout(boolean)
- Visual layout (content related)
getGUIContentPane(JPanel)
getGUIToolBarTitle()
isGUIToolBarFloatable()
createGUIToolBar()
addGUIToolBarButton(AbstractButton,String,String,ActionListener)
addGUIToolBarSeparator()
showGUIToolBar()
hideGUIToolBar()
getGUIToolBarInputMap()
getGUIToolBarActionMap()
getGUIMenus()
getGUIRightHandMenu()
constructGUIMenuItem(String,boolean)
constructGUIMenuItem(String)
constructGUIRadioButtonMenuItem(String,boolean)
constructGUIRadioButtonMenuItem(String)
constructGUICheckBoxMenuItem(String,boolean)
constructGUICheckBoxMenuItem(String)
getGUIStatusBarCustomLabels()
isGUIStatusBarEnabled()
getGUIStatusBar()
getGUIGlassPane()
isGUIClockEnabled()
hasGUIAboutBox()
[see alsoJAboutBox
]showGUIAboutBox()
[see alsoJAboutBox
]showGUIDefaultMouseCursor()
showGUIWaitMouseCursor()
hideGUIMouseCursor()
- Reacting to user input
Already built-in command-line parameters are:
Note that the application is sized to fullscreen if either width or height or set to reflect this. Fullscreen is this case this implies window-mode (which is maximised if the OS allows it).
Note that by default, a "General" menu is present, which looks as follows:
Note that if the underlying operating system allows for minimisation to the system tray, then this options becomes available in the menu.
As the application is ran, the global system Registry
is read from the file registry.ser
(and stored back to file at the end).
When the user wants to quit the application, a confirmation dialog is shown:
Note that this confirmation can be skipped if DevelopMode.isActivated()
is true
.
- Version:
- 09/05/2024
- Author:
- Sven Maerivoet
- See Also:
-
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, Window.Type
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
Modifier and TypeFieldDescriptionprotected JARResources
Access point to the application's own resources.protected static final int
Useful constant to specify that the GUI should fit exactly around its components.protected static final int
Useful constant to specify that the GUI should have full screen size.protected static final String
Useful constant for specifying Java's Metal look-and-feel.protected static final String
Useful constant for specifying the Motif look-and-feel.protected static final String
Useful constant for specifying Java's Nimbus look-and-feel.protected static final String
Useful constant for specifying the current platform's look-and-feel.protected static final String
Useful constant for specifying the Microsoft Windows look-and-feel.protected static final String
Useful constant for specifying the Microsoft Windows Classic look-and-feel.Fields inherited from class javax.swing.JFrame
accessibleContext, rootPane, rootPaneCheckingEnabled
Fields inherited from class java.awt.Frame
ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, NORMAL
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
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, EXIT_ON_CLOSE, HIDE_ON_CLOSE
-
Constructor Summary
ConstructorDescriptionJStandardGUIApplication
(String[] argv, Object[] parameters) Constructs aJStandardGUIApplication
object. -
Method Summary
Modifier and TypeMethodDescriptionprotected final void
abortApplication
(String abortMessage, boolean... appendLocale) Immediately aborts the running application.void
The GUI's action listener.protected final void
addGUIToolBarButton
(AbstractButton button, String toolTipText, String actionCommand, ActionListener actionListener) Helper method to add a button to the GUI's tool bar.protected final void
addGUIToolBarComponent
(JComponent component, String toolTipText) Helper method to add an arbitrary component to the GUI's tool bar.protected final void
Helper method to add a separator to the GUI's tool bar.final void
beep()
Emits an audible beep.final void
This method does nothing.final void
This method does nothing.final void
This method calls the callback functionguiWindowResized()
.final void
This method does nothing.protected final JCheckBoxMenuItem
constructGUICheckBoxMenuItem
(String checkBoxMenuItemKey) Helper method for constructing a check box menu item object; a mnemonic is used if it is found.
Note that the I18NL10N database is automatically used.protected final JCheckBoxMenuItem
constructGUICheckBoxMenuItem
(String checkBoxMenuItemKey, boolean useMnemonic) Helper method for constructing a check box menu item object; an optional mnemonic can be used if it is found.
Note that the I18NL10N database is automatically used.protected final JMenuItem
constructGUIMenuItem
(String menuItemKey) Helper method constructing a menu item object; a mnemonic is used if it is found.
Note that the I18NL10N database is automatically used.protected final JMenuItem
constructGUIMenuItem
(String menuItemKey, boolean useMnemonic) Helper method for constructing a menu item object; an optional mnemonic can be used if it is found.
Note that the I18NL10N database is automatically used.protected final JRadioButtonMenuItem
constructGUIRadioButtonMenuItem
(String radioButtonMenuItemKey) Helper method for constructing a radio button menu item object; a mnemonic is used if it is found.
Note that the I18NL10N database is automatically used.protected final JRadioButtonMenuItem
constructGUIRadioButtonMenuItem
(String radioButtonMenuItemKey, boolean useMnemonic) Helper method for constructing a radio button menu item object; an optional mnemonic can be used if it is found.
Note that the I18NL10N database is automatically used.protected void
Sets up the GUI's tool bar.protected String
Sets up the path and prefix names to the application's locale databases, for example:protected String
Sets up the filename of the JAR or ZIP file containing the application's resources.protected void
getGUIContentPane
(JPanel contentPane) Sets up the GUI's content pane.protected JPanel
Sets up a constructed glass pane.protected Image
Sets up theImage
containing the GUI's icon.protected String
Sets up the application's initial look-and-feel.protected Dimension
Sets up the GUI's initial size on the screen.protected JGUISounds.EGUISoundSet
Sets up the application's initial GUI sound set.Sets up custom menus.protected JMenu
Sets up a custom right hand menu (e.g., a "Help" menu).final Insets
Returns the screen insets.final Dimension
Returns the screen size.protected final JSplashScreen
Returns a handle to the GUI's splash screen.protected JLabel
Sets up aJLabel
containing the splash screen's custom content.protected InputStream
Sets up the MP3 sound to play during the splash screen.protected final JStatusBar
Getter method for the status bar.Sets up custom labels that are shown to the right hand side of the status bar.protected boolean
Specifies whether or not the GUI's system sounds should be enabled at startup.protected String
Sets up the GUI's window title.protected final ActionMap
Helper method to retrieve the GUI's tool bar's action map.protected final InputMap
Helper method to retrieve the GUI's tool bar's input map.protected String
Returns the GUI's tool bar's title.protected void
A callback method for when the look-and-feel has changed.protected void
A callback function for when the GUI's window is resized.protected boolean
Returns aboolean
indicating whether or not a custom about box is available.final void
Emulates hiding the mouse cursor.protected final void
Helper method to hide the GUI's tool bar.protected void
initialiseApplication
(Object[] parameters) Allows custom initialisation of the subclass's member fields.protected boolean
Sets up whether or not a clock (HH:MM:SS) should be shown at the right of the menubar.protected boolean
Sets up whether or not the application is allowed to minimise to the system tray (if supported by the host platform).protected boolean
Sets up whether or not the GUI should always be repainted when the window is resized.protected boolean
Sets up whether or not the GUI's window should be resizable.protected boolean
Sets up whether or not the status bar should be shown at the bottom of the application's window.protected boolean
Returns if the GUI's tool bar's can float freely.protected void
Allows loading of custom registry values.static void
The application'smain
method.protected boolean
parseApplicationParameter
(int paramNr, String parameter) Allows parsing of custom command-line parameters.final void
setGUIDynamicLayout
(boolean dynamicLayout) Sets the use of dynamic layout (i.e., real-time repainting of theJFrame
's components when resizing).protected final void
showApplicationParameterWarning
(int paramNr, String parameter, String message) Logs a textual warning message.protected void
Shows a custom about box.protected final void
Shows the default mouse cursor.protected final void
Helper method to show the GUI's tool bar.protected final void
Shows the wait mouse cursor.protected void
Allows custom clean-up when the application is shutting down.void
This method does nothing.void
This method does nothing.final void
Gracefully ends the application by running the shutdown sequence and saving the registry.void
This method does nothing.final void
Plays a sound.final void
Plays a sound and if necessary creates an icon in the system tray.void
This method does nothing.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, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setBackground, setExtendedState, setMaximizedBounds, setMenuBar, setOpacity, setResizable, setShape, setState, setTitle, setUndecorated
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, createBufferStrategy, createBufferStrategy, dispose, getBackground, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOpacity, getOwnedWindows, getOwner, getOwnerlessWindows, getShape, getToolkit, getType, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isAutoRequestFocus, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isOpaque, isShowing, isValidateRoot, pack, paint, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setAlwaysOnTop, setAutoRequestFocus, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocation, setLocation, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, setSize, setType, setVisible, toBack, toFront
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, list, list, paintComponents, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusDownCycle, validate, validateTree
Methods inherited from class java.awt.Component
add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, hasFocus, imageUpdate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isValid, isVisible, list, list, list, 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, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, requestFocusInWindow, revalidate, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setMaximumSize, setMixingCutoutShape, setName, setPreferredSize, toString, transferFocus, transferFocusBackward, 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
-
Field Details
-
kAutoSizeGUI
protected static final int kAutoSizeGUIUseful constant to specify that the GUI should fit exactly around its components.- See Also:
-
kFullScreenGUI
protected static final int kFullScreenGUIUseful constant to specify that the GUI should have full screen size.Note that the maximised state of a window is currently not yet supported due to Java lack thereof.
- See Also:
-
klafMetal
Useful constant for specifying Java's Metal look-and-feel.- See Also:
-
klafNimbus
Useful constant for specifying Java's Nimbus look-and-feel.- See Also:
-
klafMotif
Useful constant for specifying the Motif look-and-feel.- See Also:
-
klafWindows
Useful constant for specifying the Microsoft Windows look-and-feel.- See Also:
-
klafWindowsClassic
Useful constant for specifying the Microsoft Windows Classic look-and-feel.- See Also:
-
klafSystem
Useful constant for specifying the current platform's look-and-feel.- See Also:
-
fResources
Access point to the application's own resources.
-
-
Constructor Details
-
JStandardGUIApplication
Constructs aJStandardGUIApplication
object.During construction of the GUI, the following events take place:
- The system
JARResources
are loaded. - The GUI is set to auto-size by default (see
getGUIInitialSize()
andisGUIResizable()
). - British English is the default language used.
- The command-line parameters are parsed (see
parseApplicationParameter(int,String)
). - The system's locale
I18NL10N
database is loaded. - The application's
JARResources
and localeI18NL10N
database are loaded (if they are present) (seegetApplicationResourceArchiveFilename()
andgetApplicationLocalePrefix()
). - The global system
Registry
is read from file. - The look-and-feel of the operating system is used by default.
- A GUI sound set is selected (see
getGUIInitialSoundSet()
). - A optional splash screen is shown (see
getGUISplashScreenContent()
andgetGUISplashScreenSound()
). - Custom initialisation is performed (see
loadApplicationRegistry()
andinitialiseApplication(Object[])
). Note that the objects are specified asnew Object[] {object1,object2}
. - The window's icon and title are set (see
getGUIIcon()
andgetGUITitle()
). - The GUI's content pane is constructed (see
getGUIContentPane(JPanel)
). - The GUI's tool bar is constructed (see
getGUIToolBarTitle()
,isGUIToolBarFloatable()
,createGUIToolBar()
,addGUIToolBarButton(AbstractButton,String,String,ActionListener)
,addGUIToolBarSeparator()
,showGUIToolBar()
,hideGUIToolBar()
,getGUIToolBarInputMap()
andgetGUIToolBarActionMap()
). - The GUI's status bar is constructed (see
getGUIStatusBarCustomLabels()
,isGUIStatusBarEnabled()
, andgetGUIStatusBar()
). - The GUI's menu bar is constructed (see
getGUIMenus()
andgetGUIRightHandMenu()
). - The about box is shown (see
hasGUIAboutBox()
andshowGUIAboutBox()
). - The repainting behaviour when resizing is set to dynamic layout (see
setGUIDynamicLayout(boolean)
). - The application checks if minimisation to the system tray is allowed (see
isGUIMinimiseToSystemTrayAllowed()
). - The glass pane is constructed (see
getGUIGlassPane()
).
null
forparameters
.- Parameters:
argv
- an array of strings containing the command-line parametersparameters
- an array of objects containing the parameters to be passed to the GUI'sinitialiseApplication(Object[])
method
- The system
-
-
Method Details
-
actionPerformed
The GUI's action listener.Note that when overriding this method in a subclass, its parent should explicitly be called in order to guarantee the correct default processing of the user's input:
super.actionPerformed(e); // rest of method's code
- Specified by:
actionPerformed
in interfaceActionListener
- Parameters:
e
- theActionEvent
that is received
-
componentMoved
This method does nothing.Note that this method cannot be overridden!
- Specified by:
componentMoved
in interfaceComponentListener
- Parameters:
e
- theWindowEvent
that is received
-
componentShown
This method does nothing.Note that this method cannot be overridden!
- Specified by:
componentShown
in interfaceComponentListener
- Parameters:
e
- theWindowEvent
that is received
-
componentHidden
This method does nothing.Note that this method cannot be overridden!
- Specified by:
componentHidden
in interfaceComponentListener
- Parameters:
e
- theWindowEvent
that is received
-
componentResized
This method calls the callback functionguiWindowResized()
.Note that this method cannot be overridden!
- Specified by:
componentResized
in interfaceComponentListener
- Parameters:
e
- theWindowEvent
that is received
-
windowActivated
This method does nothing.- Specified by:
windowActivated
in interfaceWindowListener
- Parameters:
e
- theWindowEvent
that is received
-
windowClosed
This method does nothing.- Specified by:
windowClosed
in interfaceWindowListener
- Parameters:
e
- theWindowEvent
that is received
-
windowClosing
Gracefully ends the application by running the shutdown sequence and saving the registry.Note that this method cannot be overridden!
- Specified by:
windowClosing
in interfaceWindowListener
- Parameters:
e
- theWindowEvent
that is received
-
windowDeactivated
This method does nothing.- Specified by:
windowDeactivated
in interfaceWindowListener
- Parameters:
e
- theWindowEvent
that is received
-
windowDeiconified
Plays a sound.Note that this method cannot be overridden!
- Specified by:
windowDeiconified
in interfaceWindowListener
- Parameters:
e
- theWindowEvent
that is received
-
windowIconified
Plays a sound and if necessary creates an icon in the system tray.Note that this method cannot be overridden!
- Specified by:
windowIconified
in interfaceWindowListener
- Parameters:
e
- theWindowEvent
that is received
-
windowOpened
This method does nothing.- Specified by:
windowOpened
in interfaceWindowListener
- Parameters:
e
- theWindowEvent
that is received
-
main
The application'smain
method.Note that this method should be overridden by a derived subclass:
public static void main(String[] argv) { DerivedGUIApplication derivedGUIApplication = new DerivedGUIApplication(argv); }
- Parameters:
argv
- an array of strings containing the command-line parameters
-
beep
public final void beep()Emits an audible beep. -
showGUIDefaultMouseCursor
protected final void showGUIDefaultMouseCursor()Shows the default mouse cursor. -
showGUIWaitMouseCursor
protected final void showGUIWaitMouseCursor()Shows the wait mouse cursor. -
hideGUIMouseCursor
public final void hideGUIMouseCursor()Emulates hiding the mouse cursor. -
setGUIDynamicLayout
public final void setGUIDynamicLayout(boolean dynamicLayout) Sets the use of dynamic layout (i.e., real-time repainting of theJFrame
's components when resizing).- Parameters:
dynamicLayout
- aboolean
indicating whether or not dynamic layout should be activated
-
getGUIScreenSize
Returns the screen size.- Returns:
- the screen size
-
getGUIScreenInsets
Returns the screen insets.- Returns:
- the screen insets
-
getApplicationResourceArchiveFilename
Sets up the filename of the JAR or ZIP file containing the application's resources.If
null
is specified, then the system ignores loading the application's resources.- Returns:
- the filename of the archive (JAR or ZIP) containing the application's resources
- See Also:
-
getApplicationLocalePrefix
Sets up the path and prefix names to the application's locale databases, for example:
"application-resources/locales/locale-"
If
null
is specified, then the system ignores loading the application's locale databases.- Returns:
- the path to the location of the application's locale databases
- See Also:
-
loadApplicationRegistry
protected void loadApplicationRegistry()Allows loading of custom registry values. A typical code example looks like:(at)SuppressWarnings("unchecked") // obtain a local reference to the system registry Registry systemRegistry = Registry.kINSTANCE; // load last opened folder Object lastOpenedFolderEntry = systemRegistry.getObject("fLastOpenedFolder"); if (lastOpenedFolderEntry != null) { fLastOpenedFolder = (String) lastOpenedFolderEntry; } else { // setup and store default as the current folder fLastOpenedFolder = "."; systemRegistry.addObject("fLastOpenedFolder",fLastOpenedFolder); }
-
initialiseApplication
Allows custom initialisation of the subclass's member fields.The parameters in the
Object[]
array are passed through the class's constructor (seeJStandardGUIApplication(String[],Object[])
). They are typically specified asnew Object[] {object1,object2}
.- Parameters:
parameters
- an array ofObjects
-
shutdownApplication
protected void shutdownApplication()Allows custom clean-up when the application is shutting down. A typical code example could include:// obtain a local reference to the system registry Registry systemRegistry = Registry.kINSTANCE; // update registry systemRegistry.addObject("fLastOpenedFolder",fLastOpenedFolder);
Note that theshutdown()
sequence is not ran in case of a fatal error resulting in early abort.- See Also:
-
parseApplicationParameter
Allows parsing of custom command-line parameters.A derived subclass typically overrides this method to parse all its custom command-line parameters.
Note that if an error occurs during parsing, the
showApplicationParameterWarning(int,String,String)
method should be called with the appropriate parameters.The following example shows the parsing of one custom parameter (with a custom option):
final String kCustomParameter = "PARAMETER"; final String kCustomOption = "OPTION"; String upperCaseParameter = parameter.toUpperCase(); // parse parameter if (upperCaseParameter.startsWith(kCustomParameter + "=")) { String upperCaseOption = upperCaseParameter.substring(kCustomParameter.length() + 1); // parse option if (upperCaseOption.equalsIgnoreCase(kCustomOption)) { // take action as parameter is parsed } else { showParameterWarning(paramNr,parameter,"not a valid option"); } // indicate that parameter was valid return true; } else { // indicate that parameter is unknown return false; }
- Parameters:
paramNr
- the number of the parameter that is being parsedparameter
- the unmodified parameter as specified on the command-line- Returns:
true
if the parameter was parsed successfully,false
otherwise- See Also:
-
showApplicationParameterWarning
Logs a textual warning message.- Parameters:
paramNr
- the number of the parameter that failed to get parsedparameter
- the unmodified parameter as specified on the command-linemessage
- the warning message to log- See Also:
-
getGUISplashScreenContent
Sets up aJLabel
containing the splash screen's custom content.See
JSplashScreen
for more information regarding the splash screen.- Returns:
- a
JLabel
containing the splash screen's custom content - See Also:
-
getGUISplashScreenSound
Sets up the MP3 sound to play during the splash screen.See
JSplashScreen
for more information regarding the splash screen andMP3Player
for playing MP3 sounds.- Returns:
- the MP3 sound to play during the splash screen
- See Also:
-
getGUISplashScreen
Returns a handle to the GUI's splash screen.- Returns:
- a handle to the GUI's splash screen
- See Also:
-
getGUIInitialLookAndFeel
Sets up the application's initial look-and-feel.The possible values that can be returned are:
- Java's Metal look-and-feel (
klafMetal
) - Java's Nimbus look-and-feel (
klafNimbus
) - the Motif look-and-feel (
klafMotif
) - the Microsoft Windows look-and-feel (
klafWindows
) - the Microsoft Windows (classic) look-and-feel (
klafWindowsClassic
) - the current platform's look-and-feel (
klafSystem
)
Note that this method returns the current platform's look-and-feel by default.
- Returns:
- the application's initial look-and-feel
- Java's Metal look-and-feel (
-
getGUIInitialSoundSet
Sets up the application's initial GUI sound set.The possible values that can be returned are (see also
JGUISounds
):
- the LCARS sound set
- the Apple sound set
- the space sound set
Note that this method returns the LCARS GUI sound set by default.
- Returns:
- the application's initial GUI sound set
-
getGUISystemSoundsEnabledOnStartup
protected boolean getGUISystemSoundsEnabledOnStartup()Specifies whether or not the GUI's system sounds should be enabled at startup.This method returns
true
by default.- Returns:
- a
boolean
indicating whether or not the GUI's system sounds should be enabled at startup
-
guiLookAndFeelChanged
protected void guiLookAndFeelChanged()A callback method for when the look-and-feel has changed. -
getGUIInitialSize
Sets up the GUI's initial size on the screen.A derived subclass should return a
Dimension
object containing the initial width and height of the GUI's window. Their values are expressed in pixels, but the following two special values are also accepted:An example:
return (new Dimension(JStandardGUIApplication.kFullScreenGUI,250));
which specifies a GUI with full screen width and 250 pixels height.- Returns:
- the GUI's initial size on the screen as a
Dimension
object
-
isGUIResizable
protected boolean isGUIResizable()Sets up whether or not the GUI's window should be resizable.This method returns
true
by default.- Returns:
true
if the GUI's window should be resizable,false
if it should be fixed size
-
isGUIRepaintedWhenResizing
protected boolean isGUIRepaintedWhenResizing()Sets up whether or not the GUI should always be repainted when the window is resized. This only works if the host platform supports it.This method returns
true
by default.- Returns:
true
if the GUI should be repainted when the window is resized
-
guiWindowResized
protected void guiWindowResized()A callback function for when the GUI's window is resized. -
getGUIIcon
Sets up theImage
containing the GUI's icon.The
Image
should be a JPG-file, 32x32 pixels with 24-bit colourdepth (i.e., true colour).- Returns:
- the
Image
containing the GUI's icon
-
getGUITitle
Sets up the GUI's window title.- Returns:
- the GUI's window title
-
getGUIContentPane
Sets up the GUI's content pane.A derived subclass typically overrides this method. The subclass can operate on the given
contentPane
parameter (which is initialised, i.e., notnull
, by default).A subclass thus sets the content pane's layout managers, adds components to it, ...
- Parameters:
contentPane
- the GUI's main content pane to modify
-
getGUIToolBarTitle
Returns the GUI's tool bar's title.- Returns:
- the GUI's tool bar's title
-
isGUIToolBarFloatable
protected boolean isGUIToolBarFloatable()Returns if the GUI's tool bar's can float freely.By default, this method returns
true
.- Returns:
- a
boolean
indicating whether or not the GUI's tool bar can float freely
-
createGUIToolBar
protected void createGUIToolBar()Sets up the GUI's tool bar.A derived subclass typically overrides this method. The subclass can add buttons to the tool bar via the
addGUIToolBarButton(AbstractButton,String,String,ActionListener)
andaddGUIToolBarSeparator()
methods.This would typically look like the following:
String kActionCommandMenuItemXXX = "xxx"; String kActionCommandMenuItemYYY = "yyy"; JButton button1 = new JButton(new ImageIcon(fResources.getImage("application-resources/icons/load-parameters-icon.png"))); JButton button2 = new JButton("Button #2"); addToolBarButton( button1, I18NL10N.kINSTANCE.translate(kActionCommandMenuItemXXX), kActionCommandMenuItemXXX,this); addToolBarSeparator(); addToolBarButton( button2, I18NL10N.kINSTANCE.translate(kActionCommandMenuItemYYY), kActionCommandMenuItemYYY,this);
-
addGUIToolBarButton
protected final void addGUIToolBarButton(AbstractButton button, String toolTipText, String actionCommand, ActionListener actionListener) Helper method to add a button to the GUI's tool bar.- Parameters:
button
- the button to addtoolTipText
- the tool tip text associated with the buttonactionCommand
- the action command of the buttonactionListener
- the action listener for the button (usuallythis
)
-
addGUIToolBarComponent
Helper method to add an arbitrary component to the GUI's tool bar.- Parameters:
component
- the component to addtoolTipText
- the tool tip text associated with the component
-
addGUIToolBarSeparator
protected final void addGUIToolBarSeparator()Helper method to add a separator to the GUI's tool bar. -
showGUIToolBar
protected final void showGUIToolBar()Helper method to show the GUI's tool bar.Note that the GUI's tool bar is only shown if it contains any content.
-
hideGUIToolBar
protected final void hideGUIToolBar()Helper method to hide the GUI's tool bar. -
getGUIToolBarInputMap
Helper method to retrieve the GUI's tool bar's input map.- Returns:
- the GUI's tool bar's input map
-
getGUIToolBarActionMap
Helper method to retrieve the GUI's tool bar's action map.- Returns:
- the GUI's tool bar's action map
-
getGUIMenus
Sets up custom menus.By default, the application already contains a "General" menu containing access to the optional about box, setting the GUI's look and feel and getting confirmation when the user wants to quit the application.
Note that this method returns
null
by default.- Returns:
- an
ArrayList
of menus - See Also:
-
getGUIRightHandMenu
Sets up a custom right hand menu (e.g., a "Help" menu).Note that this method returns
null
by default.- Returns:
- a menu used in the right part of the menubar
- See Also:
-
constructGUIMenuItem
Helper method for constructing a menu item object; an optional mnemonic can be used if it is found.
Note that the I18NL10N database is automatically used.Note that this method cannot be overridden!
- Parameters:
menuItemKey
- the key of the menu itemuseMnemonic
- a flag indicating whether to use a mnemonic or not- Returns:
- a menu item object
-
constructGUIMenuItem
Helper method constructing a menu item object; a mnemonic is used if it is found.
Note that the I18NL10N database is automatically used.Note that this method cannot be overridden!
- Parameters:
menuItemKey
- the key of the menu item- Returns:
- a menu item object
-
constructGUIRadioButtonMenuItem
protected final JRadioButtonMenuItem constructGUIRadioButtonMenuItem(String radioButtonMenuItemKey, boolean useMnemonic) Helper method for constructing a radio button menu item object; an optional mnemonic can be used if it is found.
Note that the I18NL10N database is automatically used.Note that this method cannot be overridden!
- Parameters:
radioButtonMenuItemKey
- the key of the menu itemuseMnemonic
- a flag indicating whether to use a mnemonic or not- Returns:
- a radio button menu item object
-
constructGUIRadioButtonMenuItem
Helper method for constructing a radio button menu item object; a mnemonic is used if it is found.
Note that the I18NL10N database is automatically used.Note that this method cannot be overridden!
- Parameters:
radioButtonMenuItemKey
- the key of the menu item- Returns:
- a radio button menu item object
-
constructGUICheckBoxMenuItem
protected final JCheckBoxMenuItem constructGUICheckBoxMenuItem(String checkBoxMenuItemKey, boolean useMnemonic) Helper method for constructing a check box menu item object; an optional mnemonic can be used if it is found.
Note that the I18NL10N database is automatically used.Note that this method cannot be overridden!
- Parameters:
checkBoxMenuItemKey
- the key of the menu itemuseMnemonic
- a flag indicating whether to use a mnemonic or not- Returns:
- a check box menu item object
-
constructGUICheckBoxMenuItem
Helper method for constructing a check box menu item object; a mnemonic is used if it is found.
Note that the I18NL10N database is automatically used.Note that this method cannot be overridden!
- Parameters:
checkBoxMenuItemKey
- the key of the menu item- Returns:
- a check box menu item object
-
getGUIStatusBarCustomLabels
Sets up custom labels that are shown to the right hand side of the status bar.- Returns:
- an
ArrayList
of custom labels, ornull
if none are provided
-
isGUIStatusBarEnabled
protected boolean isGUIStatusBarEnabled()Sets up whether or not the status bar should be shown at the bottom of the application's window.Note that this method returns
true
by default.- Returns:
- whether or not the status bar should be shown at the bottom of the application's window
-
getGUIStatusBar
Getter method for the status bar.- Returns:
- the status bar
-
getGUIGlassPane
Sets up a constructed glass pane.An application will typically override this method and create its own glass pane object inside it after returning it.
- Returns:
- a constructed glass pane
-
isGUIClockEnabled
protected boolean isGUIClockEnabled()Sets up whether or not a clock (HH:MM:SS) should be shown at the right of the menubar.Note that this method returns
true
by default.- Returns:
- whether or not a clock (HH:MM:SS) should be shown at the right of the menubar
-
hasGUIAboutBox
protected boolean hasGUIAboutBox()Returns aboolean
indicating whether or not a custom about box is available.Note that this method returns
false
by default, indicating that no custom about box is available.- Returns:
- a
boolean
indicating whether or not a custom about box is available - See Also:
-
showGUIAboutBox
protected void showGUIAboutBox()Shows a custom about box.- See Also:
-
isGUIMinimiseToSystemTrayAllowed
protected boolean isGUIMinimiseToSystemTrayAllowed()Sets up whether or not the application is allowed to minimise to the system tray (if supported by the host platform).Note that this method returns
true
by default.- Returns:
- whether or not the application is allowed to minimise to the system tray
-
abortApplication
Immediately aborts the running application.- Parameters:
abortMessage
- the message to display when abortingappendLocale
- optional argument that, when set totrue
, appends a localised message that the application is aborted
-