jwo.utils.gui
Class JWFrame

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Window
              extended byjava.awt.Frame
                  extended byjavax.swing.JFrame
                      extended byjwo.utils.gui.JWFrame
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, RootPaneContainer, Runnable, Serializable, WindowConstants
Direct Known Subclasses:
GUI3d, GUIFrame, RunTest

public class JWFrame
extends JFrame
implements Runnable

Creates a containing window with status, progress, menu and toolbar options. If this window contains any buttons on its toolbar, it must contain equivalent menu items. Menu items need not have equivalent toolbar buttons.

Menus are aligned with space for iconic representation. If icons are used they should be all the same size (16x16 recommended). Alignment is forced by inserting blank icons of the same size where necessary. This icon should be located at images/blank.gif in the classpath of the VM that uses this class.

Version:
2.2, 5th December, 2004.
Author:
Jo Wood.
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JFrame
JFrame.AccessibleJFrame
 
Nested classes inherited from class java.awt.Frame
Frame.AccessibleAWTFrame
 
Nested classes inherited from class java.awt.Window
Window.AccessibleAWTWindow
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, 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
JWFrame(String title)
          Creates a top-level window with a given title.
JWFrame(String title, String iconName, boolean showMenu, boolean showTools, boolean showStatus)
          Creates a top-level window with various decoration options.
 
Method Summary
 JMenuItem addActionItem(int type, JMenuItem menu, String name, String icon, int mnemonic, int accelerator, ActionListener listener)
          Adds a given menu and button item.
 JMenuItem addActionItem(int type, JMenuItem menu, String name, String icon, int mnemonic, int accelerator, ButtonGroup bg, ActionListener listener)
          Adds a given menu and button item.
 JMenuItem addActionItem(JMenuItem menu, String name, int mnemonic, ActionListener listener)
          Adds a given menu item to a given menu.
 JMenuItem addActionItem(JMenuItem menu, String name, String icon, int mnemonic, ActionListener listener)
          Adds given menu and button items.
 JMenuItem addActionItem(JMenuItem menu, String name, String icon, int mnemonic, int accelerator, ActionListener listener)
          Adds a given menu and button item.
 JMenuItem addBinActionItem(JMenuItem menu, String name, boolean isSelected, int mnemonic, ActionListener listener)
          Adds a given checkbox menu item to a given menu.
 JMenuItem addBinActionItem(JMenuItem menu, String name, boolean isSelected, int mnemonic, ButtonGroup bg, ActionListener listener)
          Adds given checkbox menu and toggle button items.
 JMenuItem addBinActionItem(JMenuItem menu, String name, boolean isSelected, String icon, int mnemonic, ActionListener listener)
          Adds given checkbox menu and toggle button items.
 JMenuItem addBinActionItem(JMenuItem menu, String name, boolean isSelected, String icon, int mnemonic, ButtonGroup bg, ActionListener listener)
          Adds given checkbox menu and toggle button items.
 JMenuItem addBinActionItem(JMenuItem menu, String name, int mnemonic, ActionListener listener)
          Adds a given checkbox menu item to a given menu.
 JMenuItem addBinActionItem(JMenuItem menu, String name, int mnemonic, ButtonGroup bg, ActionListener listener)
          Adds a given checkbox menu item to a given menu.
 JMenuItem addBinActionItem(JMenuItem menu, String name, String icon, int mnemonic, ActionListener listener)
          Adds given checkbox menu and toggle button items.
 JMenuItem addBinActionItem(JMenuItem menu, String name, String icon, int mnemonic, ButtonGroup bg, ActionListener listener)
          Adds given checkbox menu and toggle button items.
 void addButtonSeparator()
          Adds a separator to the tool bar.
 void addInterruptionListener(JWInterruptionListener interruptionListener)
          Adds the given interruption listener to this window.
 JMenu addMenu(JComponent parent, String name, int mnemonic)
          Adds a given menu with mnemonic to a component such as a menu bar or sub menu.
 JMenu addMenu(String name)
          Adds a given menu without mnenonic to menu bar.
 JMenu addMenu(String name, int mnemonic)
          Adds a given menu with mnemonic to menu bar.
 void addMenuSeparator(JMenu menu)
          Adds a separator to the given menu.
protected  void closeDown()
          Asks the user if they really want to quit, then closes.
 Action getAction(String name)
          Returns the action item (button or menu item) associated with the given name.
protected  void initWindow()
          Performs any window initialisation that is required after the frame has been displayed.
 boolean removeInterruptionListener(JWInterruptionListener interruptionListener)
          Removes the given interruption listener from this window.
 void run()
          Displays the frame as part of a threaded process.
 void setMaxProgress(int maxProgress)
          Displays the maximum progress value.
 void setMessage(String text)
          Displays the given message in the status bar.
 void setMinProgress(int minProgress)
          Displays the minimum progress value.
 void setProgress(int progress)
          Sets the current progress (should be between 0 and 100 unless minimum or maximum progress values have been changed.
 void showProgress(boolean visible)
          Shows or removes the progress bar from the frame.
 
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, 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, setIconImage, 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, isFocusableWindow, isFocusCycleRoot, isFocused, isShowing, pack, postEvent, processEvent, processWindowFocusEvent, processWindowStateEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, setCursor, setFocusableWindowState, setFocusCycleRoot, 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, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, preferredSize, print, printComponents, processContainerEvent, remove, removeAll, removeContainerListener, setFocusTraversalKeys, setFocusTraversalPolicy, 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, 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, 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, isOpaque, 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, setBounds, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, 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
 

Constructor Detail

JWFrame

public JWFrame(String title)
Creates a top-level window with a given title. Assumes that an icon file called Icon16.gif is located in he 'images' subdirectory.

Parameters:
title - Title of window.

JWFrame

public JWFrame(String title,
               String iconName,
               boolean showMenu,
               boolean showTools,
               boolean showStatus)
Creates a top-level window with various decoration options.

Parameters:
title - Title of window.
iconName - Name of file containing icon. File should be a .gif or .jpeg in the 'images' subdirectory.
showMenu - Menu will be displayed if true;
showTools - Toolbar will be displayed if true;
showStatus - Statusbar will be displayed if true;
Method Detail

addMenu

public JMenu addMenu(String name)
Adds a given menu without mnenonic to menu bar.

Parameters:
name - Name on menu to add.
Returns:
Reference to the menu just created. This is useful for adding menu items.

addMenu

public JMenu addMenu(String name,
                     int mnemonic)
Adds a given menu with mnemonic to menu bar.

Parameters:
name - Name on menu to add.
mnemonic - Keyboard mnemonic to use.
Returns:
Reference to the menu just created. This is useful for adding menu items.

addMenu

public JMenu addMenu(JComponent parent,
                     String name,
                     int mnemonic)
Adds a given menu with mnemonic to a component such as a menu bar or sub menu.

Parameters:
parent - Component onto which a menu is added.
name - Name on menu to add.
mnemonic - Keyboard mnemonic to use.
Returns:
Reference to the menu just created. This is useful for adding menu items.

addMenuSeparator

public void addMenuSeparator(JMenu menu)
Adds a separator to the given menu. This should be called in sequence between adding other menus/menu items to the menu.

Parameters:
menu - Menu onto which a separator.

addButtonSeparator

public void addButtonSeparator()
Adds a separator to the tool bar. This should be called in sequence between adding other items to the toolbar.


addActionItem

public JMenuItem addActionItem(JMenuItem menu,
                               String name,
                               int mnemonic,
                               ActionListener listener)
Adds a given menu item to a given menu.

Parameters:
menu - Menu onto which this menu item is added.
name - Name on the new menu item to add.
mnemonic - Keyboard mnemonic to use.
listener - Action listener to respond to menu selection.
Returns:
Reference to the menu item just created. This is useful for adding sub-menus.

addActionItem

public JMenuItem addActionItem(JMenuItem menu,
                               String name,
                               String icon,
                               int mnemonic,
                               ActionListener listener)
Adds given menu and button items.

Parameters:
menu - Menu onto which this menu item is added.
name - Name on the new menu item to add.
icon - Name of file containing icon or null if no icon.
mnemonic - Keyboard mnemonic to use.
listener - Action listener to respond to menu or button selection.
Returns:
Reference to the menu item just created. This is useful for adding sub-menus.

addActionItem

public JMenuItem addActionItem(JMenuItem menu,
                               String name,
                               String icon,
                               int mnemonic,
                               int accelerator,
                               ActionListener listener)
Adds a given menu and button item.

Parameters:
menu - Menu onto which this menu item is added.
name - Name on the new menu item to add.
icon - Name of file containing icon or null if no icon.
mnemonic - Keyboard mnemonic to use.
accelerator - Keyboard accelerator to use. Assumes this key is combined with 'ctrl'.
listener - Action listener to respond to menu or button selection.
Returns:
Reference to the menu item just created. This is useful for adding sub-menus.

addActionItem

public JMenuItem addActionItem(int type,
                               JMenuItem menu,
                               String name,
                               String icon,
                               int mnemonic,
                               int accelerator,
                               ActionListener listener)
Adds a given menu and button item.

Parameters:
type - Type of menu (NORMAL, CHECKBOX).
menu - Menu onto which this menu item is added.
name - Name on the new menu item to add.
icon - Name of file containing icon or null if no icon.
mnemonic - Keyboard mnemonic to use.
accelerator - Keyboard accelerator to use. Assumes this key is combined with 'ctrl'.
listener - Action listener to respond to menu or button selection.
Returns:
Reference to the menu item just created. This is useful for adding sub-menus.

addBinActionItem

public JMenuItem addBinActionItem(JMenuItem menu,
                                  String name,
                                  int mnemonic,
                                  ActionListener listener)
Adds a given checkbox menu item to a given menu.

Parameters:
menu - Menu onto which this menu item is added.
name - Name on the new menu item to add.
mnemonic - Keyboard mnemonic to use.
listener - Action listener to respond to menu selection.
Returns:
Reference to the menu item just created. This is useful for adding sub-menus.

addBinActionItem

public JMenuItem addBinActionItem(JMenuItem menu,
                                  String name,
                                  boolean isSelected,
                                  int mnemonic,
                                  ActionListener listener)
Adds a given checkbox menu item to a given menu.

Parameters:
menu - Menu onto which this menu item is added.
name - Name on the new menu item to add.
isSelected - Item will be selected if true.
mnemonic - Keyboard mnemonic to use.
listener - Action listener to respond to menu selection.
Returns:
Reference to the menu item just created. This is useful for adding sub-menus.

addBinActionItem

public JMenuItem addBinActionItem(JMenuItem menu,
                                  String name,
                                  int mnemonic,
                                  ButtonGroup bg,
                                  ActionListener listener)
Adds a given checkbox menu item to a given menu.

Parameters:
menu - Menu onto which this menu item is added.
name - Name on the new menu item to add.
mnemonic - Keyboard mnemonic to use.
bg - Button group for grouped toggle buttons/checkboxes.
listener - Action listener to respond to menu selection.
Returns:
Reference to the menu item just created. This is useful for adding sub-menus.

addBinActionItem

public JMenuItem addBinActionItem(JMenuItem menu,
                                  String name,
                                  String icon,
                                  int mnemonic,
                                  ActionListener listener)
Adds given checkbox menu and toggle button items. Assumes added item is not selected.

Parameters:
menu - Menu onto which this menu item is added.
name - Name on the new menu item to add.
icon - Name of file containing icon or null if no icon.
mnemonic - Keyboard mnemonic to use.
listener - Action listener to respond to menu or button selection.
Returns:
Reference to the menu item just created. This is useful for adding sub-menus.

addBinActionItem

public JMenuItem addBinActionItem(JMenuItem menu,
                                  String name,
                                  boolean isSelected,
                                  String icon,
                                  int mnemonic,
                                  ActionListener listener)
Adds given checkbox menu and toggle button items.

Parameters:
menu - Menu onto which this menu item is added.
name - Name on the new menu item to add.
isSelected - Item will be selected if true.
icon - Name of file containing icon or null if no icon.
mnemonic - Keyboard mnemonic to use.
listener - Action listener to respond to menu or button selection.
Returns:
Reference to the menu item just created. This is useful for adding sub-menus.

addBinActionItem

public JMenuItem addBinActionItem(JMenuItem menu,
                                  String name,
                                  String icon,
                                  int mnemonic,
                                  ButtonGroup bg,
                                  ActionListener listener)
Adds given checkbox menu and toggle button items.

Parameters:
menu - Menu onto which this menu item is added.
name - Name on the new menu item to add.
icon - Name of file containing icon or null if no icon.
mnemonic - Keyboard mnemonic to use.
bg - Button group for grouped toggle buttons/checkboxes.
listener - Action listener to respond to menu or button selection.
Returns:
Reference to the menu item just created. This is useful for adding sub-menus.

addBinActionItem

public JMenuItem addBinActionItem(JMenuItem menu,
                                  String name,
                                  boolean isSelected,
                                  int mnemonic,
                                  ButtonGroup bg,
                                  ActionListener listener)
Adds given checkbox menu and toggle button items.

Parameters:
menu - Menu onto which this menu item is added.
name - Name on the new menu item to add.
isSelected - Item will be selected if true.
mnemonic - Keyboard mnemonic to use.
bg - Button group for grouped toggle buttons/checkboxes.
listener - Action listener to respond to menu or button selection.
Returns:
Reference to the menu item just created. This is useful for adding sub-menus.

addBinActionItem

public JMenuItem addBinActionItem(JMenuItem menu,
                                  String name,
                                  boolean isSelected,
                                  String icon,
                                  int mnemonic,
                                  ButtonGroup bg,
                                  ActionListener listener)
Adds given checkbox menu and toggle button items.

Parameters:
menu - Menu onto which this menu item is added.
name - Name on the new menu item to add.
isSelected - Item will be selected if true.
icon - Name of file containing icon or null if no icon.
mnemonic - Keyboard mnemonic to use.
bg - Button group for grouped toggle buttons/checkboxes.
listener - Action listener to respond to menu or button selection.
Returns:
Reference to the menu item just created. This is useful for adding sub-menus.

addActionItem

public JMenuItem addActionItem(int type,
                               JMenuItem menu,
                               String name,
                               String icon,
                               int mnemonic,
                               int accelerator,
                               ButtonGroup bg,
                               ActionListener listener)
Adds a given menu and button item.

Parameters:
type - Type of menu (NORMAL, CHECKBOX).
menu - Menu onto which this menu item is added.
name - Name on the new menu item to add.
icon - Name of file containing icon or null if no icon.
mnemonic - Keyboard mnemonic to use.
accelerator - Keyboard accelerator to use. Assumes this key is combined with 'ctrl'.
bg - Button group for linking items together.
listener - Action listener to respond to menu or button selection.
Returns:
Reference to the menu item just created. This is useful for adding sub-menus.

getAction

public Action getAction(String name)
Returns the action item (button or menu item) associated with the given name.

Parameters:
name - Name of action item to search for. Should be lower case without elipsis.
Returns:
The first action item that has the given name, or null of nothing found. Should be all lower case and without elipsis.

setMessage

public void setMessage(String text)
Displays the given message in the status bar.

Parameters:
text - Message to display.

setMinProgress

public void setMinProgress(int minProgress)
Displays the minimum progress value.

Parameters:
minProgress - Minimum progress value.

setMaxProgress

public void setMaxProgress(int maxProgress)
Displays the maximum progress value.

Parameters:
maxProgress - Maximum progress value.

setProgress

public void setProgress(int progress)
Sets the current progress (should be between 0 and 100 unless minimum or maximum progress values have been changed.

Parameters:
progress - progress value.

showProgress

public void showProgress(boolean visible)
Shows or removes the progress bar from the frame.

Parameters:
visible - Progress bar will be visible if true;

addInterruptionListener

public void addInterruptionListener(JWInterruptionListener interruptionListener)
Adds the given interruption listener to this window. The listener will be informed whenever the progress bar is clicked.

Parameters:
interruptionListener - Object to be informed of an interuption request.

removeInterruptionListener

public boolean removeInterruptionListener(JWInterruptionListener interruptionListener)
Removes the given interruption listener from this window.

Parameters:
interruptionListener - Listener to be removed.
Returns:
True if listener was present and has been successfully removed.

run

public void run()
Displays the frame as part of a threaded process. This can be used when called with EventQueue.invokeLater() to ensure that the window is invoked in a thread-safe manner.

Specified by:
run in interface Runnable

initWindow

protected void initWindow()
Performs any window initialisation that is required after the frame has been displayed. Not usually required, but this can be overridden for subclasses that need to perform some dynamic display changes or need to capture the graphics context of this frame.


closeDown

protected void closeDown()
Asks the user if they really want to quit, then closes.



Copyright Jo Wood, 1996-2005, last modified, 11th March, 2005