org.bs.mdi.swing
Class SwingMainWindow

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Window
              extended byjava.awt.Frame
                  extended byjavax.swing.JFrame
                      extended byorg.bs.mdi.swing.SwingMainWindow
All Implemented Interfaces:
Accessible, ImageObserver, MainWindow, MenuContainer, MessageProcessor, RootPaneContainer, Serializable, Window, WindowConstants

public class SwingMainWindow
extends JFrame
implements MainWindow, MessageProcessor

An implementation of a MainWindow using Swing technology.

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
protected  Application application
           
protected  SwingDefaultCommands commands
           
protected  JComponent desktop
           
protected  DataPageable docPrinter
           
protected  JMenu editMenu
           
protected  JMenu fileExportMenu
           
protected  JMenu fileMenu
           
protected  JMenuBar menuBar
           
protected  PrinterJob printerJob
           
protected  SwingProgressMonitor progressMonitor
           
protected  JMenu recentFilesMenu
           
protected  SwingStatusBar statusBar
           
protected  JToolBar toolBar
           
protected  MDIWindowManager windowManager
           
protected  JMenu windowMenu
           
 
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 org.bs.mdi.MainWindow
ERROR, INFO, QUESTION, WARNING
 
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
SwingMainWindow()
          Creates a new main window and adds a menu and a toolbar to it.
SwingMainWindow(boolean addMenu, boolean addStatusBar, boolean addToolBar)
          Creates a new main window.
 
Method Summary
protected  void addSpecialWindowCommands(SwingCommand[] commands)
           
 boolean close()
          Tries to close the window.
protected  SwingDefaultCommands createCommands()
          Creates a new set of commands to be used by the application.
 DocumentWindow createDocumentWindow()
          Creates a new document window.
protected  void createEditMenu()
          Creates the edit menu.
protected  void createFileMenu()
          Creates the file menu.
protected  void createToolBar()
          Creates the toolbar.
 SwingDefaultCommands getCommands()
          Gets the current set of commands.
 JComponent getDesktop()
          Returns the desktop component.
 List getDocumentWindows()
          Gets a list of all currently opened document windows.
 JMenu getEditMenu()
          Returns the edit menu.
 JMenu getFileMenu()
          Returns the file menu.
protected  Icon getMessageIcon(int type)
           
 ProgressMonitor getProgressMonitor()
          Gets the default progress monitor for this main window.
 SwingStatusBar getStatusBar()
          Gets the status bar.
 JToolBar getToolBar()
          Returns the toolbar.
 MDIWindowManager getWindowManager()
          Gets the current document window manager.
 JMenu getWindowMenu()
          Returns the window menu.
 void printDocument()
          Prints the current document.
 void processMessage(Object source, int type, Object argument)
          Called from the MessageDispatcher to indicate that an event has occurred which this object may be interested in.
protected  void removeAllSpecialWindowCommands()
           
 void setBusy(boolean busy)
          Sets the busy flag.
protected  void setDesktop(JComponent c)
          Sets the desktop component.
 void setStatus(String status)
          Sets the statusbar text.
 void setStatusBar(SwingStatusBar statusBar)
          Sets the status bar.
 void setWindowManager(MDIWindowManager manager)
          Sets another document window manager to be used.
 int showDialog(int type, Window window, String message, String[] choices, int defaultChoice)
          Displays a dialog box.
 String showFileOpenDialog(FileFormat[] formats)
          Shows a file open dialog for the given file formats.
 String showFileSaveDialog(FileFormat[] formats, String initialName)
          Shows a file save dialog for the given file formats.
 void showMessage(int type, Window window, String message)
          Displays a message box.
 void showPrintPreview()
          Shows a print preview dialog for the current document.
 void showPrintSetup()
          Shows a print setup dialog.
 
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 org.bs.mdi.Window
getTitle, hide, repaint, setTitle, show
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Field Detail

application

protected Application application

printerJob

protected PrinterJob printerJob

docPrinter

protected DataPageable docPrinter

commands

protected SwingDefaultCommands commands

menuBar

protected JMenuBar menuBar

toolBar

protected JToolBar toolBar

recentFilesMenu

protected JMenu recentFilesMenu

windowMenu

protected JMenu windowMenu

editMenu

protected JMenu editMenu

fileMenu

protected JMenu fileMenu

fileExportMenu

protected JMenu fileExportMenu

statusBar

protected SwingStatusBar statusBar

progressMonitor

protected SwingProgressMonitor progressMonitor

windowManager

protected MDIWindowManager windowManager

desktop

protected JComponent desktop
Constructor Detail

SwingMainWindow

public SwingMainWindow()
Creates a new main window and adds a menu and a toolbar to it. This constructor is equivalent to SwingMainWindow(true, true).


SwingMainWindow

public SwingMainWindow(boolean addMenu,
                       boolean addStatusBar,
                       boolean addToolBar)
Creates a new main window.

Parameters:
addMenu - true if the main menu should be added to this window
addStatusBar - true if a status bar should be added to the window
Method Detail

close

public boolean close()
Description copied from interface: Window
Tries to close the window.

Note that calling this method does not guarantee that the window is actually closed. The implementations of this interface can intercept close requests and decide if they are really carried out or not. For example, if you try to close a changed document,

Specified by:
close in interface Window
Returns:
true if the window was successfully closed, false otherwise

setStatus

public void setStatus(String status)
Description copied from interface: MainWindow
Sets the statusbar text.

Specified by:
setStatus in interface MainWindow
Parameters:
status - the statusbar text

createDocumentWindow

public DocumentWindow createDocumentWindow()
Description copied from interface: MainWindow
Creates a new document window.

Specified by:
createDocumentWindow in interface MainWindow
Returns:
a new document window

getDocumentWindows

public List getDocumentWindows()
Description copied from interface: MainWindow
Gets a list of all currently opened document windows.

Specified by:
getDocumentWindows in interface MainWindow
Returns:
a list of document windows

showFileOpenDialog

public String showFileOpenDialog(FileFormat[] formats)
Description copied from interface: MainWindow
Shows a file open dialog for the given file formats.

Specified by:
showFileOpenDialog in interface MainWindow
Parameters:
formats - the file formats which are used to setup the file filters
Returns:
the selected filename, or null in case of error

showFileSaveDialog

public String showFileSaveDialog(FileFormat[] formats,
                                 String initialName)
Description copied from interface: MainWindow
Shows a file save dialog for the given file formats.

Specified by:
showFileSaveDialog in interface MainWindow
Parameters:
formats - the file formats which are used to setup the file filters
initialName - the initial file name
Returns:
the selected filename, or null in case of error

getMessageIcon

protected Icon getMessageIcon(int type)

showMessage

public void showMessage(int type,
                        Window window,
                        String message)
Description copied from interface: MainWindow
Displays a message box. The given message is shown on the screen and the user has only the option to confirm the message (by clicking an "OK"-Button, for example).

Specified by:
showMessage in interface MainWindow
Parameters:
type - the type: QUESTION, INFO, WARNING or ERROR,
window - the window which this message concerns, or null if it concerns the entire application.
message - the message to be displayed (note: the message is not automatically translated by passing it to Application.tr(java.lang.String))

showDialog

public int showDialog(int type,
                      Window window,
                      String message,
                      String[] choices,
                      int defaultChoice)
Description copied from interface: MainWindow
Displays a dialog box. The given message is shown on the screen and the user can choose between several options to react on the event. The options may be displayed as clickable buttons, for example.

Specified by:
showDialog in interface MainWindow
Parameters:
type - the type: QUESTION, INFO, WARNING or ERROR,
window - the document window which this message concerns, or null if it concerns the entire application.
message - the message to be displayed (note: the message is not automatically translated by passing it to Application.tr(java.lang.String))
choices - the choices to be presented to the user (note: the options are - unlike the message - translated by passing it to Application.tr(java.lang.String))
defaultChoice - the index of the default choice
Returns:
the index of the chosen option

showPrintSetup

public void showPrintSetup()
Shows a print setup dialog. Using this dialog, the user can set the page format, orientation and margins to be used by further print jobs.

Specified by:
showPrintSetup in interface MainWindow

showPrintPreview

public void showPrintPreview()
Description copied from interface: MainWindow
Shows a print preview dialog for the current document.

Specified by:
showPrintPreview in interface MainWindow

printDocument

public void printDocument()
Description copied from interface: MainWindow
Prints the current document. The implementation may display a printing dialog before the print job is actually created.

Specified by:
printDocument in interface MainWindow

processMessage

public void processMessage(Object source,
                           int type,
                           Object argument)
Description copied from interface: MessageProcessor
Called from the MessageDispatcher to indicate that an event has occurred which this object may be interested in.

Specified by:
processMessage in interface MessageProcessor
Parameters:
source - the source where this message originated from
type - the message type
argument - an optional argument

getCommands

public SwingDefaultCommands getCommands()
Gets the current set of commands.

Returns:
the set of commands

getDesktop

public JComponent getDesktop()
Returns the desktop component.

Returns:
the desktop component

setDesktop

protected void setDesktop(JComponent c)
Sets the desktop component.

Parameters:
c - the desktop component

getWindowManager

public MDIWindowManager getWindowManager()
Gets the current document window manager.

Returns:
the current window manager

setWindowManager

public void setWindowManager(MDIWindowManager manager)
Sets another document window manager to be used.

Parameters:
manager - the new window manager

getToolBar

public JToolBar getToolBar()
Returns the toolbar.

Returns:
the tool bar

getFileMenu

public JMenu getFileMenu()
Returns the file menu.

Returns:
the file menu

getEditMenu

public JMenu getEditMenu()
Returns the edit menu.

Returns:
the edit menu

getWindowMenu

public JMenu getWindowMenu()
Returns the window menu. Warning! This items in this menu are automatically managed by the MDI framework. Don't mess around with this menu unless you know what you are doing!

Returns:
the window menu

setBusy

public void setBusy(boolean busy)
Description copied from interface: MainWindow
Sets the busy flag. The main window may for example show an hourglass mouse cursor to give the user the indication that the program is busy now.

Specified by:
setBusy in interface MainWindow
Parameters:
busy - true if the busy indication should be enabled, false otherwise

getStatusBar

public SwingStatusBar getStatusBar()
Gets the status bar.

Returns:
the status bar

setStatusBar

public void setStatusBar(SwingStatusBar statusBar)
Sets the status bar. The status bar is added to the bottom of the main window.

Parameters:
statusBar -

getProgressMonitor

public ProgressMonitor getProgressMonitor()
Description copied from interface: MainWindow
Gets the default progress monitor for this main window. This progress monitor is responsible for giving the user some feedback about the tasks which your application is currently performing.

Specified by:
getProgressMonitor in interface MainWindow
Returns:
the default progress monitor

createCommands

protected SwingDefaultCommands createCommands()
Creates a new set of commands to be used by the application. You can overwrite this method to make the application use your own set of commands instead.

Returns:
the set of commands to be used

createFileMenu

protected void createFileMenu()
Creates the file menu.


createEditMenu

protected void createEditMenu()
Creates the edit menu.


createToolBar

protected void createToolBar()
Creates the toolbar.


addSpecialWindowCommands

protected void addSpecialWindowCommands(SwingCommand[] commands)

removeAllSpecialWindowCommands

protected void removeAllSpecialWindowCommands()