org.scopemvc.controller.swing
Class SwingContext

java.lang.Object
  |
  +--org.scopemvc.controller.basic.ViewContext
        |
        +--org.scopemvc.controller.swing.SwingContext

public class SwingContext
extends ViewContext

Swing implementation of ViewContext to show views inside JFrames or JDialogs and show errors using JOptionPanes.
Also allows Views to take ownership of SMenuItems from their containing Window.

Version:
$Revision: 1.17 $ $Date: 2002/09/12 18:23:24 $
Author:
Steve Meyfroidt
See Also:
ViewContext

Field Summary
static java.lang.String PROGRESS_START_DELAY_PROPERTY
          The property in ScopeConfig for the delay before showing the wait cursor when startProgress once startProgress() has been called, value in milliseconds
 
Constructor Summary
SwingContext()
          Constructor for the SwingContext object
 
Method Summary
 boolean areAllViewsClosed()
          Are there any Views left open?
 void exit()
          Exit the application
protected  SMenuItem findMenuItem(SwingView inView, java.lang.String inControlID)
          Find the SMenuItem in the menu bar associated with the frame of the view.
protected static SMenuItem findMenuItemInMenu(javax.swing.JMenu inMenu, java.lang.String inControlID)
          Find the SMenuItem in the menu.
protected  javax.swing.JRootPane findRootPaneFor(View inView)
          Find the Rootpane that contains the SwingView or null if none can be found.
protected  java.awt.Window getDefaultParentWindow()
          For dialogs to be opened, find the currently focussed window, or if none, the last opened window or if none, the shared null Frame.
protected  java.awt.Image getDefaultWindowIcon()
          Get the default icon.
protected  javax.swing.JRootPane getFocussedRootPane()
          Find the rootpane that currently contains the focussed component, or null if none.
protected  java.awt.Frame getSharedNullFrame()
          Get the frame used as default parent for the views.
protected  java.awt.Container getTopmostContainer(SwingView inView)
          Finds the topmost Container, stopping before any Window structure.
 void hideAllViews()
          Hide all open Views.
protected  void hideRootPane(javax.swing.JRootPane inRootPane)
          Hide the root pane and dispose of the parent window.
 void hideView(View inView)
          Find the Window that is showing this View and then close it on Swing's event-handling thread.
protected  void hideWindow(java.awt.Window window)
          Hide the window safely from the Swing event thread.
 void hookMenuItem(SwingView inView, java.lang.String inControlID, boolean inEnabled)
          Hook a menu item to a view.
protected  boolean isFocusOwner(java.awt.Window inWindow)
           Returns true if the window owns the focus.
protected  void setupWindow(javax.swing.JRootPane inRootPane, SwingView inView, boolean inCentreWindow)
          Setup the window: insert the view in the window, setup the title and the menubar in the window and position the window on the screen.
 void showError(java.lang.String inErrorTitle, java.lang.String inErrorMessage)
          Show an error message in a JOptionPane
 void showMessage(java.lang.String inTitle, java.lang.String inMessage)
          Show a message in a JOptionPane
 void showView(View inView)
          Show the view.
protected  void showViewInDialog(SwingView inView)
          Make a dialog (modal or modeless determined by the display mode) parented to either currently focussed window, or last shown, or null shared frame.
protected  void showViewInPrimaryWindow(SwingView inView)
          Show the view in a new frame
 void startProgress()
          Start a progress indicator to notify the user that a long operation is running.
 void stopProgress()
          Stop the progress indicator
protected  void unhookMenuItemImpl(java.lang.String inControlID, SwingView inView)
          Unhook a menu item from a view.
 
Methods inherited from class org.scopemvc.controller.basic.ViewContext
addProperty, clearProperties, clearThreadContext, getProperty, getViewContext, removeProperty, setGlobalContext, setThreadContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROGRESS_START_DELAY_PROPERTY

public static final java.lang.String PROGRESS_START_DELAY_PROPERTY
The property in ScopeConfig for the delay before showing the wait cursor when startProgress once startProgress() has been called, value in milliseconds

See Also:
Constant Field Values
Constructor Detail

SwingContext

public SwingContext()
Constructor for the SwingContext object

Method Detail

findMenuItemInMenu

protected static SMenuItem findMenuItemInMenu(javax.swing.JMenu inMenu,
                                              java.lang.String inControlID)
Find the SMenuItem in the menu.

Parameters:
inMenu - A menu
inControlID - The control ID of the menu item to find
Returns:
The SMenuItem matching the control ID, or null if not found

showView

public void showView(View inView)
Show the view.
Depending on the display mode of the view, the view is displayed in a frame or a dialog.

Specified by:
showView in class ViewContext
Parameters:
inView - The view to show. Must be a subclass of SwingView

hideView

public void hideView(View inView)
Find the Window that is showing this View and then close it on Swing's event-handling thread. Does nothing if the passed View isn't showing.
This method disposes the Window from memory.

Specified by:
hideView in class ViewContext
Parameters:
inView - The view to hide. Must be a subclass of SwingView

hideAllViews

public void hideAllViews()
Hide all open Views.


areAllViewsClosed

public boolean areAllViewsClosed()
Are there any Views left open?

Returns:
true if all views are closed

showError

public void showError(java.lang.String inErrorTitle,
                      java.lang.String inErrorMessage)
Show an error message in a JOptionPane

Specified by:
showError in class ViewContext
Parameters:
inErrorTitle - The title for the error message
inErrorMessage - The error message

showMessage

public void showMessage(java.lang.String inTitle,
                        java.lang.String inMessage)
Show a message in a JOptionPane

Parameters:
inTitle - The title for the message
inMessage - The message

exit

public void exit()
Exit the application

Specified by:
exit in class ViewContext

startProgress

public void startProgress()
Start a progress indicator to notify the user that a long operation is running.
In the SwingContext, the progress indicator is a wait cursor, and it is displayed after a delay of n milliseconds defined in the Scope property 'org.scopemvc.controller.swing.SwingContext.progress_start_delay'

Specified by:
startProgress in class ViewContext

stopProgress

public void stopProgress()
Stop the progress indicator

Specified by:
stopProgress in class ViewContext

hookMenuItem

public void hookMenuItem(SwingView inView,
                         java.lang.String inControlID,
                         boolean inEnabled)
Hook a menu item to a view.
The view and its bound controller will receive the Controls issued by the menu item.

Parameters:
inView - the view to hook the menu item to.
inControlID - The control ID used to identity the menu item
inEnabled - Set to true to enable the menu item

getSharedNullFrame

protected java.awt.Frame getSharedNullFrame()
Get the frame used as default parent for the views.
This frame uses the default application icon.

Returns:
The sharedNullFrame value

getDefaultWindowIcon

protected java.awt.Image getDefaultWindowIcon()
Get the default icon.
The icon is initialised from the property 'org.scopemvc.controller.swing.SwingContext.window_icon' defined in the Scope configuration. This property should contain the location of the icon resource. The icon is loaded with the ResourceLoader.

Returns:
The defaultWindowIcon value
See Also:
ResourceLoader

getFocussedRootPane

protected javax.swing.JRootPane getFocussedRootPane()
Find the rootpane that currently contains the focussed component, or null if none.

Returns:
The focussedRootPane value

isFocusOwner

protected boolean isFocusOwner(java.awt.Window inWindow)

Returns true if the window owns the focus.

Swing loses focus from the current component when a menu is pulled down so for a Window to have focus we say it needs to either contain the focus owner OR parent a Window (not a Dialog/Frame) that owns the focus.

Parameters:
inWindow - The Window to test for focus
Returns:
True if the window or one of its child owns the focus

getDefaultParentWindow

protected java.awt.Window getDefaultParentWindow()
For dialogs to be opened, find the currently focussed window, or if none, the last opened window or if none, the shared null Frame.

Returns:
The defaultParentWindow value

getTopmostContainer

protected java.awt.Container getTopmostContainer(SwingView inView)
Finds the topmost Container, stopping before any Window structure.

Parameters:
inView - The View to get the topmost Container from
Returns:
The topmost Container

setupWindow

protected void setupWindow(javax.swing.JRootPane inRootPane,
                           SwingView inView,
                           boolean inCentreWindow)
Setup the window: insert the view in the window, setup the title and the menubar in the window and position the window on the screen.

Parameters:
inRootPane - The RootPane where to add the View
inView - The View to setup
inCentreWindow - If true, centre the window on the screen or on its parent window

findRootPaneFor

protected javax.swing.JRootPane findRootPaneFor(View inView)
Find the Rootpane that contains the SwingView or null if none can be found.

Parameters:
inView - The View to get the RootPane from
Returns:
The parent RootPane, or null

hideRootPane

protected void hideRootPane(javax.swing.JRootPane inRootPane)
Hide the root pane and dispose of the parent window.

Parameters:
inRootPane - The RootPane to hide

hideWindow

protected void hideWindow(java.awt.Window window)
Hide the window safely from the Swing event thread.

Parameters:
window - The window to close

showViewInDialog

protected void showViewInDialog(SwingView inView)
Make a dialog (modal or modeless determined by the display mode) parented to either currently focussed window, or last shown, or null shared frame.

Parameters:
inView - The View to show

showViewInPrimaryWindow

protected void showViewInPrimaryWindow(SwingView inView)
Show the view in a new frame

Parameters:
inView - The View to show

unhookMenuItemImpl

protected void unhookMenuItemImpl(java.lang.String inControlID,
                                  SwingView inView)
Unhook a menu item from a view.

Parameters:
inView - the view where the menu item was hooked to.
inControlID - The control ID used to identity the menu item

findMenuItem

protected SMenuItem findMenuItem(SwingView inView,
                                 java.lang.String inControlID)
Find the SMenuItem in the menu bar associated with the frame of the view.

Parameters:
inView - A view contained in a frame containing a menubar
inControlID - The control ID of the menu item to find
Returns:
The SMenuItem matching the control ID, or null


Copyright © 2000-2002 The Scope Team. All Rights Reserved.