dsto.dfc.swing.panels
Class PanelManager

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by dsto.dfc.swing.panels.PanelManager
All Implemented Interfaces:
CommandSource, UndoableEditSource, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, UndoableEditListener

public class PanelManager
extends JPanel
implements CommandSource, UndoableEditSource, UndoableEditListener

Manages a set of panels similar to a Window Manager. Clients add a panel by passing in a component to be managed within PanelManager.Panel via addPanel (). The panel acts like a window that may exist in one of three states. The FIXED state displays the component within a tabbed pane, the FLOAT_INTERNAL state uses a lightweight java frame, while the FLOAT_EXTERNAL state uses a native window. The display state is controlled by setFloating (). Panels may also have child "tool" views which are shown in floated windows that are only visible when the panel is active (see Panel.addToolView ()).

Version:
$Revision$
Author:
Peter J Smet
See Also:
Serialized Form

Nested Class Summary
 class PanelManager.Panel
          A panel managed by the panel manager.
protected  class PanelManager.WindowEventListener
          Inner class to capture events generated by internal and external frames.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  PanelManager.Panel activePanel
           
protected  DynamicCommandViews commandViewJuggler
           
protected  EditPropagator editPropagator
           
static String FIXED
           
static String FLOAT_EXTERNAL
           
static String FLOAT_INTERNAL
           
protected  HidePolicy hidePolicy
           
static Icon NULL_ICON
           
static String NULL_NAME
           
protected  Vector panelManagerListeners
           
protected  List panels
           
protected static int TAB_HEIGHT
           
protected static int TAB_WIDTH
           
 RestrictedIndexTabbedPane tabPane
           
protected static Dimension tabPaneInsets
           
protected  PanelManager.WindowEventListener windowEventListener
           
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
PanelManager()
           
 
Method Summary
 PanelManager.Panel addPanel(Component component)
          Add a new panel to the manager, using default settings for all other options.
 PanelManager.Panel addPanel(Component component, int index)
          Add a new panel to the manager.
 PanelManager.Panel addPanel(Component component, int index, String name, Icon icon)
          Add a new panel to the manager.
 PanelManager.Panel addPanel(Component component, int index, String name, Icon icon, boolean showingName, boolean useScrollPane)
          Add a new panel to the manager.
 PanelManager.Panel addPanel(Component component, String name, Icon icon)
          Add a new panel to the manager.
 void addPanelManagerListener(PanelManagerListener l)
           
 void addUndoableEditListener(UndoableEditListener listener)
           
protected  void basicAddPanel(PanelManager.Panel panel, int index)
          Do the job of adding a new Panel instance, updating active view, firing panel added event, etc.
 boolean containsPanel(PanelManager.Panel managedPanel)
          True if a given panel is inside this manager.
protected  UndoableEdit createActivePanelEdit(int oldActiveIndex, int newActiveIndex)
          Create an UndoableEdit that represents a change in the currently active panel
protected  FloatStateEdit createNewFloatStateEdit(String oldFloatState, String newFloatState)
          Create an UndoableEdit that represents a change in the floating state of a panel
protected  boolean fireAboutToRemovePanel(PanelManager.Panel panel)
          Fire the aboutToRemovePanel event.
protected  void fireNewActivePanelEdit(int oldIndex, int newIndex)
          If the active panel has changed, let undoable edit listeners know.
protected  void firePanelAdded(PanelManagerEvent e)
           
protected  void firePanelFloated(PanelManagerEvent e)
           
protected  void firePanelRemoved(PanelManagerEvent e)
           
protected  void firePanelUnfloated(PanelManagerEvent e)
           
 PanelManager.Panel getActivePanel()
          Return the active panel.
 CommandView getCommandView(String viewName)
          Get the command view instance for a given view name.
 Dimension getMinimumSize()
           
protected  PanelManager.Panel getNextFixedPanel(PanelManager.Panel startPanel)
           
 PanelManager.Panel getNextPanel(PanelManager.Panel startPanel)
          Get the panel that is the logical next panel after a given panel.
 PanelManager.Panel getPanel(Component component)
          Get the panel that is hosting a given component.
 PanelManager.Panel getPanelAt(int index)
          Get the panel at a given index.
 int getPanelCount()
          The number of panels.
 Dimension getPreferredSize()
           
protected  void hideOldActivePanel()
           
 int indexOfActivePanel()
          The index of the currently active panel.
 int indexOfPanel(PanelManager.Panel panel)
          The index of a panel.
protected  boolean listenersRejectPanelRemoval(PanelManager.Panel panel)
           
 String nameForPanelAt(int index)
          The name for a panel at a given index.
protected  boolean panelDoesNotFireEdits(int index)
           
 void removeAllPanels()
          Remove all panels and dispose of any resources.
 boolean removePanel(PanelManager.Panel managedPanel)
          Remove a panel.
 void removePanelManagerListener(PanelManagerListener l)
           
 void removeUndoableEditListener(UndoableEditListener listener)
           
 PanelManager.Panel replacePanel(PanelManager.Panel oldPanel, Component newComponent)
          Replace an existing panel with a new one.
 PanelManager.Panel replacePanel(PanelManager.Panel oldPanel, Component newComponent, String name)
          Replace an existing panel with a new one.
 PanelManager.Panel replacePanel(PanelManager.Panel oldPanel, Component newComponent, String name, Icon icon)
          Replace an existing panel with a new one.
 void setActiveIndex(int index)
          Set the active panel to be the panel at a given index.
 void setActivePanel(PanelManager.Panel newActivePanel)
          Set the active panel.
 void setAutoHide(boolean hideWhenNoPanels)
          When autoHide is true, the PanelManager becomes invisible when it contains no panels
protected  void setUndoFlag()
          Workaround for avoiding ActivePanelEdits being fired while undoing previous ActivePanelEdits.
protected  void showActivePanel(boolean show)
           
protected  void showNewActivePanel()
           
 void undoableEditHappened(UndoableEditEvent evt)
           
protected  boolean undoFlagIsSet()
           
protected  void unsetUndoFlag()
           
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, 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, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NULL_ICON

public static final Icon NULL_ICON

NULL_NAME

public static final String NULL_NAME
See Also:
Constant Field Values

TAB_WIDTH

protected static final int TAB_WIDTH
See Also:
Constant Field Values

TAB_HEIGHT

protected static final int TAB_HEIGHT
See Also:
Constant Field Values

tabPaneInsets

protected static Dimension tabPaneInsets

FIXED

public static final String FIXED
See Also:
Constant Field Values

FLOAT_INTERNAL

public static final String FLOAT_INTERNAL
See Also:
Constant Field Values

FLOAT_EXTERNAL

public static final String FLOAT_EXTERNAL
See Also:
Constant Field Values

panels

protected List panels

activePanel

protected PanelManager.Panel activePanel

windowEventListener

protected PanelManager.WindowEventListener windowEventListener

editPropagator

protected EditPropagator editPropagator

hidePolicy

protected HidePolicy hidePolicy

tabPane

public RestrictedIndexTabbedPane tabPane

commandViewJuggler

protected DynamicCommandViews commandViewJuggler

panelManagerListeners

protected transient Vector panelManagerListeners
Constructor Detail

PanelManager

public PanelManager()
Method Detail

setAutoHide

public void setAutoHide(boolean hideWhenNoPanels)
When autoHide is true, the PanelManager becomes invisible when it contains no panels


getCommandView

public CommandView getCommandView(String viewName)
Description copied from interface: CommandSource
Get the command view instance for a given view name.

Specified by:
getCommandView in interface CommandSource
Parameters:
viewName - The name of the view to be retrieved. Usually one of CommandView.MAIN_MENU_VIEW, CommandView.CONTEXT_MENU_VIEW or CommandView.TOOLBAR_VIEW, but custom views may be supported also.
Returns:
The command view instance or null if view is not defined.

addPanel

public PanelManager.Panel addPanel(Component component,
                                   int index,
                                   String name,
                                   Icon icon)
Add a new panel to the manager. If the component implements javax.swing.Scrollable, then the component will be added inside a JScrollPane.

Parameters:
component - The component to be shown in the panel.
index - The positio of the panel within the panels list.
name - The name to display for the panel.
icon - The icon to display next to the panel (may be null).
Returns:
The new panel that is holding the component.

addPanel

public PanelManager.Panel addPanel(Component component,
                                   String name,
                                   Icon icon)
Add a new panel to the manager.

Parameters:
component - The component to be shown in the panel.
name - The name to display for the panel.
icon - The icon to display next to the panel (may be null).
Returns:
The new panel that is holding the component.

addPanel

public PanelManager.Panel addPanel(Component component,
                                   int index)
Add a new panel to the manager.

Parameters:
component - The component to be shown in the panel.
index - The positio of the panel within the panels list.
Returns:
The new panel that is holding the component.

addPanel

public PanelManager.Panel addPanel(Component component)
Add a new panel to the manager, using default settings for all other options.

Parameters:
component - The component to be shown in the panel.
Returns:
The new panel that is holding the component.

addPanel

public PanelManager.Panel addPanel(Component component,
                                   int index,
                                   String name,
                                   Icon icon,
                                   boolean showingName,
                                   boolean useScrollPane)
Add a new panel to the manager.

Parameters:
component - The component to be shown in the panel.
index - The positio of the panel within the panels list.
name - The name to display for the panel.
icon - The icon to display next to the panel (may be null).
showingName - True if name should be shown.
useScrollPane - True if panel should be hosted within a scroll pane.
Returns:
The new panel that is holding the component.

basicAddPanel

protected void basicAddPanel(PanelManager.Panel panel,
                             int index)
Do the job of adding a new Panel instance, updating active view, firing panel added event, etc.


removeAllPanels

public void removeAllPanels()
Remove all panels and dispose of any resources.


containsPanel

public boolean containsPanel(PanelManager.Panel managedPanel)
True if a given panel is inside this manager.


removePanel

public boolean removePanel(PanelManager.Panel managedPanel)
Remove a panel. If the active panel is removed, a suitable remaining panel is made the active panel.


replacePanel

public PanelManager.Panel replacePanel(PanelManager.Panel oldPanel,
                                       Component newComponent,
                                       String name,
                                       Icon icon)
Replace an existing panel with a new one.

Parameters:
oldPanel - The existing panel to replace.
newComponent - The new component to add.
name - The name of the new panel.
icon - The icon of the new panel.
Returns:
The replacement panel.

replacePanel

public PanelManager.Panel replacePanel(PanelManager.Panel oldPanel,
                                       Component newComponent,
                                       String name)
Replace an existing panel with a new one.

Parameters:
oldPanel - The existing panel to replace.
newComponent - The new component to add.
name - The name of the new panel.
Returns:
The replacement panel.

replacePanel

public PanelManager.Panel replacePanel(PanelManager.Panel oldPanel,
                                       Component newComponent)
Replace an existing panel with a new one.

Parameters:
oldPanel - The existing panel to replace.
newComponent - The new component to add.
Returns:
The replacement panel.

setActivePanel

public void setActivePanel(PanelManager.Panel newActivePanel)
Set the active panel. Only one panel may be active at any time.


setActiveIndex

public void setActiveIndex(int index)
Set the active panel to be the panel at a given index.

Parameters:
index - The index of the new active panel.
See Also:
setActivePanel(dsto.dfc.swing.panels.PanelManager.Panel)

getActivePanel

public PanelManager.Panel getActivePanel()
Return the active panel.

See Also:
setActivePanel(dsto.dfc.swing.panels.PanelManager.Panel)

getPanelCount

public int getPanelCount()
The number of panels.


indexOfPanel

public int indexOfPanel(PanelManager.Panel panel)
The index of a panel.

Parameters:
panel - The panel.
Returns:
The index of the panel, or -1 if not found.

indexOfActivePanel

public int indexOfActivePanel()
The index of the currently active panel.


getPanelAt

public PanelManager.Panel getPanelAt(int index)
Get the panel at a given index.


nameForPanelAt

public String nameForPanelAt(int index)
The name for a panel at a given index.


getPanel

public PanelManager.Panel getPanel(Component component)
Get the panel that is hosting a given component.

Parameters:
component - The component.
Returns:
The panel hosting component, or null if not found.

getNextPanel

public PanelManager.Panel getNextPanel(PanelManager.Panel startPanel)
Get the panel that is the logical next panel after a given panel. This is the panel to the left of the panel, or the last panel if the panel is first.


hideOldActivePanel

protected void hideOldActivePanel()

showNewActivePanel

protected void showNewActivePanel()

showActivePanel

protected void showActivePanel(boolean show)

getPreferredSize

public Dimension getPreferredSize()
Overrides:
getPreferredSize in class JComponent

getMinimumSize

public Dimension getMinimumSize()
Overrides:
getMinimumSize in class JComponent

getNextFixedPanel

protected PanelManager.Panel getNextFixedPanel(PanelManager.Panel startPanel)

listenersRejectPanelRemoval

protected boolean listenersRejectPanelRemoval(PanelManager.Panel panel)

createActivePanelEdit

protected UndoableEdit createActivePanelEdit(int oldActiveIndex,
                                             int newActiveIndex)
Create an UndoableEdit that represents a change in the currently active panel


fireNewActivePanelEdit

protected void fireNewActivePanelEdit(int oldIndex,
                                      int newIndex)
If the active panel has changed, let undoable edit listeners know. The MonitorPanel does not fire Edits - these get in the way of the user.


panelDoesNotFireEdits

protected boolean panelDoesNotFireEdits(int index)

createNewFloatStateEdit

protected FloatStateEdit createNewFloatStateEdit(String oldFloatState,
                                                 String newFloatState)
Create an UndoableEdit that represents a change in the floating state of a panel


setUndoFlag

protected void setUndoFlag()
Workaround for avoiding ActivePanelEdits being fired while undoing previous ActivePanelEdits. When invoking setActivePanel(dsto.dfc.swing.panels.PanelManager.Panel) make sure to invoke setUndoFlag before the call and unsetUndoFlag() after the call.


unsetUndoFlag

protected void unsetUndoFlag()

undoFlagIsSet

protected boolean undoFlagIsSet()

addUndoableEditListener

public void addUndoableEditListener(UndoableEditListener listener)
Specified by:
addUndoableEditListener in interface UndoableEditSource

removeUndoableEditListener

public void removeUndoableEditListener(UndoableEditListener listener)
Specified by:
removeUndoableEditListener in interface UndoableEditSource

undoableEditHappened

public void undoableEditHappened(UndoableEditEvent evt)
Specified by:
undoableEditHappened in interface UndoableEditListener

removePanelManagerListener

public void removePanelManagerListener(PanelManagerListener l)

addPanelManagerListener

public void addPanelManagerListener(PanelManagerListener l)

firePanelAdded

protected void firePanelAdded(PanelManagerEvent e)

firePanelRemoved

protected void firePanelRemoved(PanelManagerEvent e)

firePanelFloated

protected void firePanelFloated(PanelManagerEvent e)

firePanelUnfloated

protected void firePanelUnfloated(PanelManagerEvent e)

fireAboutToRemovePanel

protected boolean fireAboutToRemovePanel(PanelManager.Panel panel)
Fire the aboutToRemovePanel event.

Returns:
True if no listener vetoed the event (ie true if OK to remove the panel).


Copyright © 2008 Commonwealth of Australia