kiwi.ui
Class WorkspaceManager

java.lang.Object
  extended bykiwi.ui.WorkspaceManager

public class WorkspaceManager
extends java.lang.Object

This class represents a workspace manager. The manager controls a set of WorkspaceEditors and their relationship to a JDesktopPane. Each WorkspaceEditor is associated with an arbitrary user object (the object that it is editing) and is represented by a JInternalFrame in the desktop. The manager's duties include saving unsaved changes in editors when their windows are closed and providing a high-level interface for retrieving information about the editors in the desktop.

Author:
Mark Lindner, PING Software Group
See Also:
WorkspaceEditor, JDesktopPane

Nested Class Summary
private  class WorkspaceManager._FrameListener
           
 
Field Summary
private  WorkspaceEditor activeEditor
           
private  javax.swing.JDesktopPane desktop
           
private  DialogSet dialogs
           
private  java.util.Vector editors
           
private  WorkspaceManager._FrameListener frameListener
           
private  java.util.Vector listeners
           
private  LocaleData loc
           
private  java.util.Hashtable menus
           
 
Constructor Summary
WorkspaceManager(javax.swing.JDesktopPane desktop)
          Construct a new WorkspaceManager.
 
Method Summary
 void activateEditor(WorkspaceEditor editor)
          Activate a specific editor.
 void addEditor(WorkspaceEditor editor)
          Add an editor to the workspace.
 void addWorkspaceListener(WorkspaceListener listener)
          Register a WorkspaceListener with this WorkspaceManager.
 boolean areUnsavedEditors()
          Determine if there are any editors in the workspace that have unsaved changes.
 boolean closeAllEditors()
          Close all of the editors in the workspace.
 boolean closeEditor(WorkspaceEditor editor)
          Close an editor.
protected  void fireEditorClosed(WorkspaceEditor editor)
          Notify listeners that an editor has been closed in the workspace.
protected  void fireEditorDeselected(WorkspaceEditor editor)
          Notify listeners that an editor has been deselected in the workspace.
protected  void fireEditorIconified(WorkspaceEditor editor)
          Notify listeners that an editor has been minimized (iconified) in the workspace.
protected  void fireEditorRestored(WorkspaceEditor editor)
          Notify listeners that an editor has been maximized in the workspace.
protected  void fireEditorSelected(WorkspaceEditor editor)
          Notify listeners that an editor has been selected in the workspace.
protected  void fireEditorStateChanged(WorkspaceEditor editor)
          Notify listeners that an editor's state has changed.
 WorkspaceEditor getActiveEditor()
          Get the currently active editor.
 java.util.Enumeration getAllEditors()
          Get an enumeration of all editors existing in this workspace.
 int getEditorCount()
          Count the editors in the workspace.
 WorkspaceEditor getEditorForObject(java.lang.Object object)
          Get the editor for a specific object.
 javax.swing.JMenu getMenu(java.lang.String name)
          Get a reference to a JMenu associated with this WorkspaceManager.
 void notifyStateChanged(WorkspaceEditor editor)
          Notify the manager that an editor's state has changed.
 void registerMenu(java.lang.String name, javax.swing.JMenu menu)
          Register a menu with this WorkspaceManager.
 void removeAllEditors()
          Remove all editors from the workspace.
 void removeEditor(WorkspaceEditor editor)
          Remove an editor from the workspace.
 void removeWorkspaceListener(WorkspaceListener listener)
          Unregister a WorkspaceListener from this WorkspaceManager.
private  void startEditing(WorkspaceEditor editor)
           
private  void stopEditing(WorkspaceEditor editor)
           
 void unregisterMenu(java.lang.String name)
          Unregister a menu from this WorkspaceManager.
 void updateLookAndFeel()
          Update the look and feel of all of the components being managed by this WorkspaceManager.
private  void updateMenuHooks(WorkspaceEditor editor, boolean unhook)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

editors

private java.util.Vector editors

listeners

private java.util.Vector listeners

desktop

private javax.swing.JDesktopPane desktop

activeEditor

private WorkspaceEditor activeEditor

frameListener

private WorkspaceManager._FrameListener frameListener

dialogs

private DialogSet dialogs

menus

private java.util.Hashtable menus

loc

private LocaleData loc
Constructor Detail

WorkspaceManager

public WorkspaceManager(javax.swing.JDesktopPane desktop)
Construct a new WorkspaceManager.

Parameters:
desktop - The JDesktopPane that is associated with this workspace. This JDesktopPane must have already been added to the application's component hierarchy before this constructor is called.
Method Detail

getAllEditors

public java.util.Enumeration getAllEditors()
Get an enumeration of all editors existing in this workspace.

Returns:
An Enumeration of the editors.

getActiveEditor

public WorkspaceEditor getActiveEditor()
Get the currently active editor.

Returns:
The currently active editor, or null if no editor is currently active.

addEditor

public void addEditor(WorkspaceEditor editor)
Add an editor to the workspace. The editor's window becomes visible in the workspace.

Parameters:
editor - The WorkspaceEditor to add to the workspace.
See Also:
removeEditor(kiwi.ui.WorkspaceEditor), closeEditor(kiwi.ui.WorkspaceEditor)

activateEditor

public void activateEditor(WorkspaceEditor editor)
Activate a specific editor. The editor is brought to the foreground in the desktop, deiconified if necessary, and given mouse focus. This method results in a call to the editor's startEditing() method.

Parameters:
editor - The editor to activate.
See Also:
WorkspaceEditor.startEditing()

removeEditor

public void removeEditor(WorkspaceEditor editor)
Remove an editor from the workspace. The editor's window becomes invisible. This method does not attempt a save on the editor. If the editor is currently active, its stopEditing() method is called before it is removed.

Parameters:
editor - The WorkspaceEditor to remove from the workspace.
See Also:
addEditor(kiwi.ui.WorkspaceEditor), closeEditor(kiwi.ui.WorkspaceEditor), removeAllEditors(), WorkspaceEditor.stopEditing()

areUnsavedEditors

public boolean areUnsavedEditors()
Determine if there are any editors in the workspace that have unsaved changes.

Returns:
true if there is at least one editor with unsaved changes, false otherwise.

getEditorForObject

public WorkspaceEditor getEditorForObject(java.lang.Object object)
Get the editor for a specific object. Each editor can be associated with an arbitrary user object (the object that it is editing). This method searches for an editor that is associated with the given object. Objects are compared by calling Object.equals(), not by comparing references.

Parameters:
object - The object whose editor is desired.
Returns:
The editor associated with object, or null if there is no editor for this object in the workspace.
See Also:
Object.equals(java.lang.Object)

addWorkspaceListener

public void addWorkspaceListener(WorkspaceListener listener)
Register a WorkspaceListener with this WorkspaceManager. Listeners are notified about events relating to the editors currently being managed by this manager.

Parameters:
listener - The listener to register.
See Also:
removeWorkspaceListener(WorkspaceListener)

removeWorkspaceListener

public void removeWorkspaceListener(WorkspaceListener listener)
Unregister a WorkspaceListener from this WorkspaceManager.

Parameters:
listener - The listener to unregister.
See Also:
addWorkspaceListener(WorkspaceListener)

fireEditorSelected

protected void fireEditorSelected(WorkspaceEditor editor)
Notify listeners that an editor has been selected in the workspace.

Parameters:
editor - The editor that was selected.

fireEditorDeselected

protected void fireEditorDeselected(WorkspaceEditor editor)
Notify listeners that an editor has been deselected in the workspace.

Parameters:
editor - The editor that was deselected.

fireEditorRestored

protected void fireEditorRestored(WorkspaceEditor editor)
Notify listeners that an editor has been maximized in the workspace.

Parameters:
editor - The editor that was maximized.

fireEditorIconified

protected void fireEditorIconified(WorkspaceEditor editor)
Notify listeners that an editor has been minimized (iconified) in the workspace.

Parameters:
editor - The editor that was minimized.

fireEditorClosed

protected void fireEditorClosed(WorkspaceEditor editor)
Notify listeners that an editor has been closed in the workspace.

Parameters:
editor - The editor that was closed.

fireEditorStateChanged

protected void fireEditorStateChanged(WorkspaceEditor editor)
Notify listeners that an editor's state has changed.

Parameters:
editor - The editor whose state has changed.

getEditorCount

public int getEditorCount()
Count the editors in the workspace.

Returns:
The number of editors currently in the workspace (and being managed by this WorkspaceManager).

closeEditor

public boolean closeEditor(WorkspaceEditor editor)
Close an editor. If the editor has unsaved changes, the user will be prompted with a dialog to that effect. If this editor is currently active, its stopEditing() method is called before it is closed.

Parameters:
editor - The editor to close.
See Also:
removeEditor(kiwi.ui.WorkspaceEditor), closeAllEditors(), WorkspaceEditor.stopEditing()

removeAllEditors

public void removeAllEditors()
Remove all editors from the workspace. Unconditionally removes each editor from the workspace, without attempting to save unsaved changes.

See Also:
closeAllEditors()

closeAllEditors

public boolean closeAllEditors()
Close all of the editors in the workspace. For each editor with unsaved changes, the user will be prompted with a dialog asking whether that editor should save its changes.

Returns:
true if all editors were closed successfully, false otherwise.
See Also:
removeAllEditors()

notifyStateChanged

public void notifyStateChanged(WorkspaceEditor editor)
Notify the manager that an editor's state has changed. A WorkspaceEditor uses this method to broadcast a change event to all WorkspaceListeners.

Parameters:
editor - The editor whose state has changed.

updateLookAndFeel

public void updateLookAndFeel()
Update the look and feel of all of the components being managed by this WorkspaceManager.


registerMenu

public void registerMenu(java.lang.String name,
                         javax.swing.JMenu menu)
Register a menu with this WorkspaceManager. This convenience method provides a means for a WorkspaceEditor to manipulate one or more menus in an external menubar (such as the main application's menubar).

Parameters:
name - A symbolic name for the menu.
menu - The JMenu to register.
See Also:
unregisterMenu(java.lang.String), getMenu(java.lang.String)

unregisterMenu

public void unregisterMenu(java.lang.String name)
Unregister a menu from this WorkspaceManager.

Parameters:
name - The name of the menu to unregister.
See Also:
registerMenu(java.lang.String, javax.swing.JMenu)

getMenu

public javax.swing.JMenu getMenu(java.lang.String name)
Get a reference to a JMenu associated with this WorkspaceManager.

Parameters:
name - The name under which the menu was registered.
Returns:
The JMenu reference, or null if there is no menu registered under the specified name.
See Also:
registerMenu(java.lang.String, javax.swing.JMenu), unregisterMenu(java.lang.String)

updateMenuHooks

private void updateMenuHooks(WorkspaceEditor editor,
                             boolean unhook)

stopEditing

private void stopEditing(WorkspaceEditor editor)

startEditing

private void startEditing(WorkspaceEditor editor)