diva.gui
Class DesktopContext

java.lang.Object
  extended by diva.gui.AppContextDelegate
      extended by diva.gui.DesktopContext
All Implemented Interfaces:
AppContext, MDIContext, javax.swing.RootPaneContainer

public class DesktopContext
extends AppContextDelegate
implements MDIContext

DesktopContext is an application context that displays multiple content panes in an instance of a JDesktopPane. It also contains a menubar, toolbar, and a status bar. When created, it is not visible, so the caller must call setVisible(true) to make it appear on the screen.

The implementation of JDesktopPane in Swing is not really quite what we want in a frame of this type, so there are various listeners attached to the JDesktopPane and the internal components that resize and reparent components in a more useful way.

Each "content pane" that is added to this frame is added by default to a JInternalFrame. However, the pane may be removed from the pane, either by the JDesktopPane when it is iconified, or by this class when the internal frame is maximized. Hence, users of this class should not rely on the content pane actually being contained by the internal frame that it is associated with.

MDI applications often contain multiple toolbars. This class implements a toolbar pane that contains the basic toolbar, along with any other toolbars in the application.

Version:
$Id: DesktopContext.java 47561 2007-12-16 07:29:50Z cxh $
Author:
Steve Neuendorffer, Michael Shilman, John Reekie

Nested Class Summary
private static class DesktopContext.DesktopInternalFrame
          A workaround for the busted JInternalFrame closing event handling in jdk1.2.
private  class DesktopContext.DesktopPseudoFrame
           
private  class DesktopContext.FrameManager
          FrameManager is a class that responds to UI events on the internal frames and generates other events and does useful stuff.
 
Field Summary
private  javax.swing.JComponent _currentPane
          The current content pane
private  javax.swing.JDesktopPane _desktopPane
          The desktop pane
private  javax.swing.Icon _frameIcon
          The icon that is given to the internal frames.
private  DesktopContext.FrameManager _frameManager
          The internal frame manager/listener object
private  java.util.HashMap _frames
          A mapping from content panes to internal frames.
private  int _layoutMode
          The current layout mode of this pane.
private  javax.swing.event.EventListenerList _listeners
          Store the view listeners.
private  boolean _maximizeMode
          The maximize mode.
private  javax.swing.JComponent _palettePane
          The shade pane
private  JPseudoFrame _pseudoFrame
          The psuedo-frame
private  javax.swing.JSplitPane _splitPane
          The split pane
private  JStatusBar _statusBar
          The status bar
private  javax.swing.JToolBar _toolBar
          The toolbar
private  javax.swing.JPanel _toolBarPane
          The toolbar pane
static int LAYOUT_CASCADED
          The layout mode in which internal frames are cascaded one above another.
static int LAYOUT_HORIZONTAL
          The layout mode in which internal frames are tiled horizontally.
static int LAYOUT_PLACED
          The layout mode in which internal frames are placed by the user.
static int LAYOUT_VERTICAL
          The layout mode in which internal frames are tiled vertically.
 
Constructor Summary
DesktopContext(AppContext context)
          Create an instance of this Frame with the application.
DesktopContext(AppContext context, javax.swing.JComponent palette)
          Create an instance of this Frame with the application.
 
Method Summary
 void addContentPane(java.lang.String title, javax.swing.JComponent pane)
          Add a content pane to this frame.
 void addViewListener(ViewListener listener)
          Add a view listener to this frame.
 javax.swing.JComponent getCurrentContentPane()
          Get the content pane that is displayed as the current content pane.
 javax.swing.Icon getFrameIcon()
          Return the icon that is displayed in the frame.
 javax.swing.JInternalFrame getInternalFrame(javax.swing.JComponent pane)
          Return the internal frame for a given component.
 javax.swing.JToolBar getJToolBar()
          Get the tool bar.
 int getLayoutMode()
          Get the layout mode
 javax.swing.JComponent getPalettePane()
          Get the component used for palettes and the like.
 javax.swing.JSplitPane getSplitPane()
          Get the split pane separating the shade pane and the desktop pane.
 JStatusBar getStatusBar()
          Get the status bar.
 javax.swing.JPanel getToolBarPane()
          Get the tool bar pane.
 boolean isMaximizeMode()
          Test if we are in maximize mode
 void refreshLayout()
          Refresh the layout of the internal frames.
 void removeContentPane(javax.swing.JComponent pane)
          Remove the given content pane from the display and close.
 void removeViewListener(ViewListener listener)
          Remove a view listener from this frame.
 void setCurrentContentPane(javax.swing.JComponent pane)
          Set the given content pane to be displayed as the current content pane.
 void setFrameIcon(javax.swing.Icon icon)
          Set the icon that is displayed in internal frames.
 void setLayoutMode(int mode)
          Set the layout mode.
 void setMaximizeMode(boolean mode)
          Set the maximize mode.
 void setPalettePane(javax.swing.JComponent pane)
          Set the palette pane of the context to the given component.
 void showStatus(java.lang.String status)
          Show the given status string in the context.
 
Methods inherited from class diva.gui.AppContextDelegate
getContentPane, getDelegate, getExitAction, getGlassPane, getIconImage, getJMenuBar, getLayeredPane, getRootPane, getTitle, isVisible, makeComponent, setContentPane, setExitAction, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setSize, setTitle, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface diva.gui.AppContext
getExitAction, getIconImage, getJMenuBar, getTitle, isVisible, makeComponent, setExitAction, setIconImage, setJMenuBar, setSize, setTitle, setVisible
 
Methods inherited from interface javax.swing.RootPaneContainer
getContentPane, getGlassPane, getLayeredPane, getRootPane, setContentPane, setGlassPane, setLayeredPane
 

Field Detail

_listeners

private transient javax.swing.event.EventListenerList _listeners
Store the view listeners.


_desktopPane

private transient javax.swing.JDesktopPane _desktopPane
The desktop pane


_splitPane

private transient javax.swing.JSplitPane _splitPane
The split pane


_palettePane

private transient javax.swing.JComponent _palettePane
The shade pane


_toolBarPane

private transient javax.swing.JPanel _toolBarPane
The toolbar pane


_statusBar

private transient JStatusBar _statusBar
The status bar


_toolBar

private transient javax.swing.JToolBar _toolBar
The toolbar


_frameManager

private transient DesktopContext.FrameManager _frameManager
The internal frame manager/listener object


_currentPane

private transient javax.swing.JComponent _currentPane
The current content pane


_frameIcon

private transient javax.swing.Icon _frameIcon
The icon that is given to the internal frames.


_pseudoFrame

private transient JPseudoFrame _pseudoFrame
The psuedo-frame


_layoutMode

private transient int _layoutMode
The current layout mode of this pane. This indicates whether the internal frames are placed by the user, tiled, or cascaded.


_maximizeMode

private transient boolean _maximizeMode
The maximize mode. If true, the current window is fully maximized in the display.


LAYOUT_PLACED

public static final int LAYOUT_PLACED
The layout mode in which internal frames are placed by the user.

See Also:
Constant Field Values

LAYOUT_HORIZONTAL

public static final int LAYOUT_HORIZONTAL
The layout mode in which internal frames are tiled horizontally.

See Also:
Constant Field Values

LAYOUT_VERTICAL

public static final int LAYOUT_VERTICAL
The layout mode in which internal frames are tiled vertically.

See Also:
Constant Field Values

LAYOUT_CASCADED

public static final int LAYOUT_CASCADED
The layout mode in which internal frames are cascaded one above another.

See Also:
Constant Field Values

_frames

private transient java.util.HashMap _frames
A mapping from content panes to internal frames. All panes except the current pane, if it is maximized, will be in this mapping.

Constructor Detail

DesktopContext

public DesktopContext(AppContext context)
Create an instance of this Frame with the application. The title will be obtained from the application. It will not be visible by default. The palette pane is set to be an instance of JShadePane. Create a tool bar pane, a toolbar in that pane, and a menu bar for the given context.


DesktopContext

public DesktopContext(AppContext context,
                      javax.swing.JComponent palette)
Create an instance of this Frame with the application. The title will be obtained from the application. It will not be visible by default. The palette pane is set to be the given pane. Create a tool bar pane, a toolbar in that pane, and a menu bar for the given context.

Method Detail

addContentPane

public void addContentPane(java.lang.String title,
                           javax.swing.JComponent pane)
Add a content pane to this frame. This pane will be put into a JInternalFrame inside the internal desktop pane. The name of the pane will be its title. Generally, a client should call setCurrentPane() after calling this method. The default close operation of frame will be set to DO_NOTHING_ON_CLOSE, and closing operations should be handled by adding a view listener instead.

Specified by:
addContentPane in interface MDIContext

addViewListener

public void addViewListener(ViewListener listener)
Add a view listener to this frame.

Specified by:
addViewListener in interface MDIContext

getCurrentContentPane

public javax.swing.JComponent getCurrentContentPane()
Get the content pane that is displayed as the current content pane. In this class, this will return the content of the topmost internal frame.

Specified by:
getCurrentContentPane in interface MDIContext

getFrameIcon

public javax.swing.Icon getFrameIcon()
Return the icon that is displayed in the frame.

Specified by:
getFrameIcon in interface MDIContext

getInternalFrame

public javax.swing.JInternalFrame getInternalFrame(javax.swing.JComponent pane)
Return the internal frame for a given component.


getLayoutMode

public int getLayoutMode()
Get the layout mode


getPalettePane

public javax.swing.JComponent getPalettePane()
Get the component used for palettes and the like.


getStatusBar

public JStatusBar getStatusBar()
Get the status bar.


getSplitPane

public javax.swing.JSplitPane getSplitPane()
Get the split pane separating the shade pane and the desktop pane. This will be null if there is no shade pane.


getJToolBar

public javax.swing.JToolBar getJToolBar()
Get the tool bar.


getToolBarPane

public javax.swing.JPanel getToolBarPane()
Get the tool bar pane.


isMaximizeMode

public boolean isMaximizeMode()
Test if we are in maximize mode


refreshLayout

public void refreshLayout()
Refresh the layout of the internal frames. This method attempts to be smart about how the internal frames are laid out. It attempts to place iconified frames along the bottom of the desktop pane, and places the other frames within the remaining space.


removeContentPane

public void removeContentPane(javax.swing.JComponent pane)
Remove the given content pane from the display and close. This assumes a subsequent call to setCurrentContentPane.

Specified by:
removeContentPane in interface MDIContext

removeViewListener

public void removeViewListener(ViewListener listener)
Remove a view listener from this frame.

Specified by:
removeViewListener in interface MDIContext

setCurrentContentPane

public void setCurrentContentPane(javax.swing.JComponent pane)
Set the given content pane to be displayed as the current content pane. If we are in maximize mode, set that pane to be displayed maximized. Otherwise, deiconify it if it is iconified, and raise it to the front.

Specified by:
setCurrentContentPane in interface MDIContext

setFrameIcon

public void setFrameIcon(javax.swing.Icon icon)
Set the icon that is displayed in internal frames.

Specified by:
setFrameIcon in interface MDIContext

setLayoutMode

public void setLayoutMode(int mode)
Set the layout mode. As long as we are not in maximize mode, refresh the layout accordingly.


setMaximizeMode

public void setMaximizeMode(boolean mode)
Set the maximize mode. If changed to true, the current pane is removed from its internal frame and placed into the split pane. If changed to false, the reverse happens and the desktop pane layout is refreshed.


setPalettePane

public void setPalettePane(javax.swing.JComponent pane)
Set the palette pane of the context to the given component.


showStatus

public void showStatus(java.lang.String status)
Show the given status string in the context. In this class, the status is shown in the status bar at the bottom of the frame.

Specified by:
showStatus in interface AppContext
Overrides:
showStatus in class AppContextDelegate