Java Statistical Classes

jsc.swt.mdi
Class MDIApplication

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Window
                    |
                    +--java.awt.Frame
                          |
                          +--javax.swing.JFrame
                                |
                                +--jsc.swt.mdi.MDIApplication
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, RootPaneContainer, Serializable, WindowConstants

public abstract class MDIApplication
extends JFrame

This is the base class for Multiple Document Interface (MDI) applications, and is used in conjunction with windows derived from the MDIWindow class. It provides a desktop, menubar with File, Edit, Window, Options and Help menus. A toolbar provides buttons for some of the more frequently used commands of the menus. The desktop, menubar, menus and toolbar can be accessed and modified using those objects' methods.

The File menu displays filer dialogues for opening and saving files.

The Edit menu provides the usual cut, copy, paste etc., which are implemented by overriding methods of the same name in the MDIWindow class.

The Window menu keeps a list of the current windows, and commands for activating, cascading and tiling them.

The Help menu provides a window for displaying HTML help pages, a calculator and an "About" box.

Version:
1.0
Author:
A. J. Bertie.
See Also:
jsc.swt.mdi, Serialized Form

Field Summary
static int CLOSE_CANCELLED
          Indicates closing of MDI window cancelled.
static int CLOSE_CONFIRMED
          Indicates closing of MDI window confirmed.
protected  JDesktopPane desktop
          The MDI application's desktop.
protected  JMenu editMenu
          The MDI application's Edit menu.
protected  JMenu fileMenu
          The MDI application's File menu.
protected  JMenu helpMenu
          The MDI application's Help menu.
protected  JMenuBar menuBar
          The MDI application's menu bar.
static int NO_WINDOW
          Indicates no MDI window exists.
protected  JMenu optionsMenu
          The MDI application's Options menu.
protected  JFrame parent
          Handle to the MDI application window.
protected  ToolBar toolBar
          The MDI application's tool bar.
protected  JMenu windowMenu
          The MDI application's Window menu.
 
Fields inherited from class javax.swing.JFrame
accessibleContext, EXIT_ON_CLOSE, rootPane, rootPaneCheckingEnabled
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
MDIApplication(String title, String appIconFilename, String windowIconFilename, String fileExt, String initialHelpPage, Object aboutMessage)
          Create the MDI application.
 
Method Summary
 void closeAllWindows()
          Closes all windows.
abstract  MDIWindow createWindow(File f)
          Given a file, creates a new window of a class derived from MDIWindow.
 void fileWriteErrorMessage(File f)
          Display file write error massage.
 MDIWindow getActiveWindow()
          Returns the active window, or returns null if no window is active.
protected  void processWindowEvent(WindowEvent e)
          Detect application is closing and give user the opportunity to save changed windows, or cancel the closing.
 boolean save(boolean saveAs, MDIWindow win)
          Save the specified window to a file.
protected  int saveQuery()
          Check whether windows have been changed and, if any have, give user the opportunity to save them.
 void setClearEnabled(boolean b)
          Enable/disable Clear menu item.
 void setCopyEnabled(boolean b)
          Enable/disable Copy menu item and toolbar button.
 void setCutEnabled(boolean b)
          Enable/disable Cut menu item and toolbar button.
 void setEditEnabled(boolean b)
          Enable/disable Copy, Clear & Cut menu items and toolbar buttons.
 void setPasteEnabled(boolean b)
          Enable/disable Paste menu item and toolbar button.
 void setTitle(String filename)
          Change title of application window to display file name after title.
 
Methods inherited from class javax.swing.JFrame
addImpl, createRootPane, frameInit, getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getJMenuBar, getLayeredPane, getRootPane, isDefaultLookAndFeelDecorated, isRootPaneCheckingEnabled, paramString, 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, 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
 

Field Detail

NO_WINDOW

public static final int NO_WINDOW
Indicates no MDI window exists.

See Also:
Constant Field Values

CLOSE_CANCELLED

public static final int CLOSE_CANCELLED
Indicates closing of MDI window cancelled.

See Also:
Constant Field Values

CLOSE_CONFIRMED

public static final int CLOSE_CONFIRMED
Indicates closing of MDI window confirmed.

See Also:
Constant Field Values

menuBar

protected JMenuBar menuBar
The MDI application's menu bar.


fileMenu

protected JMenu fileMenu
The MDI application's File menu.


editMenu

protected JMenu editMenu
The MDI application's Edit menu.


windowMenu

protected JMenu windowMenu
The MDI application's Window menu.


optionsMenu

protected JMenu optionsMenu
The MDI application's Options menu.


helpMenu

protected JMenu helpMenu
The MDI application's Help menu.


toolBar

protected ToolBar toolBar
The MDI application's tool bar.


desktop

protected JDesktopPane desktop
The MDI application's desktop.


parent

protected JFrame parent
Handle to the MDI application window.

Constructor Detail

MDIApplication

public MDIApplication(String title,
                      String appIconFilename,
                      String windowIconFilename,
                      String fileExt,
                      String initialHelpPage,
                      Object aboutMessage)
Create the MDI application. Icons for the application and child windows are in the specified files, whose format can be GIF, JPEG or PNG. Either filename argument can be null, in which case Java's default icon is used.

Parameters:
title - the application's title.
appIconFilename - the file path of the application's icon, or null.
windowIconFilename - the file path of the windows' icon, or null.
fileExt - the default file extension for files opened and saved by the application: e.g. "txt".
initialHelpPage - the pathname of the text file which is initially to be displayed in the Help window: e.g. "c:\\myapp\\help.html",
aboutMessage - the message that will be displayed in the About box. Typically this will be a simple String object, but it could be something much more complicated such as a panel containing several graphical and textual components.
Method Detail

closeAllWindows

public void closeAllWindows()
Closes all windows.


createWindow

public abstract MDIWindow createWindow(File f)
Given a file, creates a new window of a class derived from MDIWindow. This method is invoked when New or Open is chosen from the File menu. In the case of New, the parameter f is null. In the case of Open, typically the method will attempt to read the contents of the new window from the specified file and use these in the constructor of the subclass of MDIWindow. If the file cannot be read, an appropriate message should be displayed and the method should return null. If the window is created successfully, the method should return the reference to the new window.

Parameters:
f - the abstract representation of the file, or null.
Returns:
the window, or null.

fileWriteErrorMessage

public void fileWriteErrorMessage(File f)
Display file write error massage.

Parameters:
f - the abstract representation of the file.

getActiveWindow

public MDIWindow getActiveWindow()
Returns the active window, or returns null if no window is active.

Returns:
the active window, or null.

processWindowEvent

protected void processWindowEvent(WindowEvent e)
Detect application is closing and give user the opportunity to save changed windows, or cancel the closing.

Overrides:
processWindowEvent in class JFrame

save

public boolean save(boolean saveAs,
                    MDIWindow win)
Save the specified window to a file. If saveAs is true or the window does not have a file associated with it, get the file name from the user using a file chooser dialogue.

Parameters:
saveAs - if true, display file chooser dialogue.
win - the window to save.
Returns:
true if if window was successfully saved, false otherwise.

saveQuery

protected int saveQuery()
Check whether windows have been changed and, if any have, give user the opportunity to save them. It returns CLOSE_CANCELLED if the user cancels the close or fails to save the window. It returns CLOSE_CONFIRMED otherwise.

Returns:
CLOSE_CANCELLED or CLOSE_CONFIRMED.

setClearEnabled

public void setClearEnabled(boolean b)
Enable/disable Clear menu item.

Parameters:
b - if true (false), enable (disable) Clear menu item.

setCopyEnabled

public void setCopyEnabled(boolean b)
Enable/disable Copy menu item and toolbar button.

Parameters:
b - if true (false), enable (disable) Copy menu item.

setCutEnabled

public void setCutEnabled(boolean b)
Enable/disable Cut menu item and toolbar button.

Parameters:
b - if true (false), enable (disable) Cut menu item.

setEditEnabled

public void setEditEnabled(boolean b)
Enable/disable Copy, Clear & Cut menu items and toolbar buttons. That is, items that need something selected to be enabled.

Parameters:
b - if true (false), enable (disable) Copy, Clear & Cut menu items.

setPasteEnabled

public void setPasteEnabled(boolean b)
Enable/disable Paste menu item and toolbar button.

Parameters:
b - if true (false), enable (disable) Paste menu item.

setTitle

public void setTitle(String filename)
Change title of application window to display file name after title.

Overrides:
setTitle in class Frame
Parameters:
filename - new file name.

Java Statistical Classes

Copyright © Andrew James Bertie, 2005, all rights reserved. Updated 12th Aug 2005