JIDE 3.5.15

com.jidesoft.action
Class CommandBar

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JMenuBar
                  extended by com.jidesoft.action.DockableBar
                      extended by com.jidesoft.action.CommandBar
All Implemented Interfaces:
Dockable, Alignable, TopLevelMenuContainer, ImageObserver, MenuContainer, Serializable, Accessible, MenuElement, SwingConstants
Direct Known Subclasses:
CommandMenuBar

public class CommandBar
extends DockableBar
implements SwingConstants, TopLevelMenuContainer

CommandBar is a special DockableBar which is used to implement components like toolbars and menu bars.

See Also:
Serialized Form

Nested Class Summary
protected  class CommandBar.CommandBarContainerListener
           
static class CommandBar.Expansion
          A filler component that can be added to CommandBar to push components after it to align to the other end.
 
Nested classes/interfaces inherited from class javax.swing.JMenuBar
JMenuBar.AccessibleJMenuBar
 
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  boolean _changingContainer
          Flag indicating that a batch of add-component or remove-component operations is taking place; so don't re-validate the window until the flag is reset, indicating that the batch is complete.
protected  CommandBar.CommandBarContainerListener _commandBarContainerListener
          Listener to re-validate window if components are added to or removed from a floating CommandBar.
 
Fields inherited from class com.jidesoft.action.DockableBar
_orientation, PROPERTY_ALLOWED_DOCK_SIDES, PROPERTY_AVAILABLE, PROPERTY_CHEVRON_ALWAYS_VISIBLE, PROPERTY_FLOATABLE, PROPERTY_FLOATED, PROPERTY_HIDABLE, PROPERTY_HIDDEN, PROPERTY_HORI_DOCKED, PROPERTY_INIT_INDEX, PROPERTY_INIT_MODE, PROPERTY_INIT_SIDE, PROPERTY_INIT_SUBINDEX, PROPERTY_KEY, PROPERTY_MENU_BAR, PROPERTY_PAINT_BACKGROUND, PROPERTY_REARRANGABLE, PROPERTY_STRETCH, PROPERTY_TITLE, PROPERTY_UNDOCKED_BOUNDS, PROPERTY_VERT_DOCKED
 
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 javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface com.jidesoft.swing.Alignable
PROPERTY_ORIENTATION
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
CommandBar()
          Creates a new CommandBar; orientation defaults to HORIZONTAL.
CommandBar(int orientation)
          Creates a new CommandBar with the specified orientation.
CommandBar(String key)
          Creates a new CommandBar with the specified key.
CommandBar(String key, String title)
          Creates a new CommandBar with the specified key and title.
CommandBar(String key, String title, int orientation)
          Creates a new CommandBar with a specified key and orientation.
 
Method Summary
 JComponent add(Action a)
          Adds a new JButton which dispatches the action.
 void addExpansion()
          adds a expansion component.
protected  void addImpl(Component comp, Object constraints, int index)
          Overrides superclass to handle special UIResources when they are added.
 void addSeparator()
          Appends a separator of default size to the end of the CommandBar.
 void addSeparator(Dimension size)
          Appends a separator of a specified size to the end of the CommandBar.
 void adjustChildrenOrientation(int orientation)
           
protected  PropertyChangeListener createActionChangeListener(JComponent component)
          Returns a properly configured PropertyChangeListener which updates the control as changes to the Action occur, or null if the default property change listener for the control is desired.
protected  JComponent createActionComponent(Action a)
          Factory method which creates the JButton for Actions added to the CommandBar.
 Component[] getHiddenComponents()
          Gets an array of all hidden components.
 Insets getMargin()
          Returns the margin between the CommandBar's border and its buttons.
 JMenu getMenu(int index)
          Returns the menu at the specified position in the menu bar.
 int getMenuCount()
          Returns the number of items in the menu bar.
 int getPreferredRowCount()
          Gets the preferred row count when the CommandBar is in floating mode.
 MenuBarUI getUI()
          Returns the CommandBar's current UI.
 String getUIClassID()
          Returns the name of the L&F class that renders this component.
 boolean isBorderPainted()
          Gets the borderPainted property.
static boolean isScreenMenuBar(JMenuBar jMenuBar)
          Checks if the menu bar is used as screen menu bar (on Mac OS X only).
protected  void paintBorder(Graphics g)
          Paints the CommandBar's border if the borderPainted property is true.
 void remove(Component comp)
          Overridden to remove the component from the hiddenComponents list if it isn't in the components list.
 void removeAll()
          Overridden to remove the clear the hiddenComponents list as well as the components list.
 void removeAllHiddenComponents()
          Removes all components from the hidden components list.
 void setBorderPainted(boolean b)
          Sets the borderPainted property, which is true if the border should be painted.
 void setChangingContainer(boolean newChangingContainer)
          Set flag indicating that a batch of add-component or remove-component operations is taking place.
 void setMargin(Insets m)
          Sets the margin between the CommandBar's border and its buttons.
 void setPreferredRowCount(int preferredRowCount)
          Sets the preferred row count when the CommandBar is in floating mode.
 void updateUI()
          Notification from the UIFactory that the L&F has changed.
 void validateWindowIfFloating()
           
 
Methods inherited from class com.jidesoft.action.DockableBar
addDockableBarListener, checkOrientation, fireDockableBarEvent, getAllowedDockSides, getContext, getDockableBarListeners, getDockableBarManager, getDockID, getInitIndex, getInitMode, getInitSide, getInitSubindex, getKey, getOrientation, getTitle, getUndockedBounds, isAvailable, isChevronAlwaysVisible, isFloatable, isFloating, isHidable, isHidden, isHoriDocked, isMenuBar, isPaintBackground, isRearrangable, isStretch, isVertDocked, readElement, removeDockableBarListener, resetDockID, setAllowedDockSides, setAvailable, setChevronAlwaysVisible, setContext, setDockableBarManager, setDockID, setFloatable, setFloating, setHidable, setHidden, setHoriDocked, setInitIndex, setInitMode, setInitSide, setInitSubindex, setKey, setLayout, setMenuBar, setOpaque, setOrientation, setPaintBackground, setRearrangable, setStretch, setTitle, setUndockedBounds, setVertDocked, supportHorizontalOrientation, supportVerticalOrientation
 
Methods inherited from class javax.swing.JMenuBar
add, addNotify, getAccessibleContext, getComponent, getComponentAtIndex, getComponentIndex, getHelpMenu, getSelectionModel, getSubElements, isSelected, menuSelectionChanged, paramString, processKeyBinding, processKeyEvent, processMouseEvent, removeNotify, setHelpMenu, setSelected, setSelectionModel, setUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, 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, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, 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, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, 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, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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
 
Methods inherited from interface com.jidesoft.swing.TopLevelMenuContainer
isMenuBar
 

Field Detail

_commandBarContainerListener

protected CommandBar.CommandBarContainerListener _commandBarContainerListener
Listener to re-validate window if components are added to or removed from a floating CommandBar.


_changingContainer

protected boolean _changingContainer
Flag indicating that a batch of add-component or remove-component operations is taking place; so don't re-validate the window until the flag is reset, indicating that the batch is complete.

Constructor Detail

CommandBar

public CommandBar()
Creates a new CommandBar; orientation defaults to HORIZONTAL.


CommandBar

public CommandBar(int orientation)
Creates a new CommandBar with the specified orientation. The orientation must be either HORIZONTAL or VERTICAL.

Parameters:
orientation - the orientation desired

CommandBar

public CommandBar(String key)
Creates a new CommandBar with the specified key.

Parameters:
key - the key of the CommandBar

CommandBar

public CommandBar(String key,
                  String title)
Creates a new CommandBar with the specified key and title. The key is used as the title of the undocked CommandBar. The default orientation is HORIZONTAL.

Parameters:
key - the key of the CommandBar
title - the title

CommandBar

public CommandBar(String key,
                  String title,
                  int orientation)
Creates a new CommandBar with a specified key and orientation. All other constructors call this constructor. If orientation is an invalid value, an exception will be thrown.

Parameters:
key - the key of the CommandBar
title - the title of the CommandBar
orientation - the initial orientation -- it must be either HORIZONTAL or VERTICAL
Method Detail

getUI

public MenuBarUI getUI()
Returns the CommandBar's current UI.

Overrides:
getUI in class JMenuBar
See Also:
JMenuBar.setUI(javax.swing.plaf.MenuBarUI)

updateUI

public void updateUI()
Notification from the UIFactory that the L&F has changed. Called to replace the UI with the latest version from the UIFactory.

Overrides:
updateUI in class JMenuBar
See Also:
JComponent.updateUI()

getUIClassID

public String getUIClassID()
Returns the name of the L&F class that renders this component.

Overrides:
getUIClassID in class JMenuBar
Returns:
the string "CommandBarUI"
See Also:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

setMargin

public void setMargin(Insets m)
Sets the margin between the CommandBar's border and its buttons. Setting to null causes the CommandBar to use the default margins. The CommandBar's default Border object uses this value to create the proper margin. However, if a non-default border is set on the CommandBar, it is that Border object's responsibility to create the appropriate margin space (otherwise this property will effectively be ignored).

Overrides:
setMargin in class JMenuBar
Parameters:
m - an Insets object that defines the space between the border and the buttons
See Also:
Insets

getMargin

public Insets getMargin()
Returns the margin between the CommandBar's border and its buttons.

Overrides:
getMargin in class JMenuBar
Returns:
an Insets object containing the margin values
See Also:
Insets

isBorderPainted

public boolean isBorderPainted()
Gets the borderPainted property.

Overrides:
isBorderPainted in class JMenuBar
Returns:
the value of the borderPainted property
See Also:
setBorderPainted(boolean)

setBorderPainted

public void setBorderPainted(boolean b)
Sets the borderPainted property, which is true if the border should be painted. The default value for this property is true. Some look and feels might not implement painted borders; they will ignore this property.

Overrides:
setBorderPainted in class JMenuBar
Parameters:
b - if true, the border is painted
See Also:
isBorderPainted()

paintBorder

protected void paintBorder(Graphics g)
Paints the CommandBar's border if the borderPainted property is true.

Overrides:
paintBorder in class JMenuBar
Parameters:
g - the Graphics context in which the painting is done
See Also:
JComponent.paint(java.awt.Graphics), JComponent.setBorder(javax.swing.border.Border)

setChangingContainer

public void setChangingContainer(boolean newChangingContainer)
Set flag indicating that a batch of add-component or remove-component operations is taking place. Re-validate the window when the flag is reset, indicating that the batch is complete.

Parameters:
newChangingContainer - true to indicate the container is being changed. False to indicate it stops changing.

validateWindowIfFloating

public void validateWindowIfFloating()

addSeparator

public void addSeparator()
Appends a separator of default size to the end of the CommandBar. The default size is determined by the current look and feel.


addSeparator

public void addSeparator(Dimension size)
Appends a separator of a specified size to the end of the CommandBar.

In current implementation, we don't support different size separator, so this method is the same as addSeparator().

Parameters:
size - the Dimension of the separator

add

public JComponent add(Action a)
Adds a new JButton which dispatches the action.

As of 1.3, this is no longer the preferred method for adding Actions to a container. Instead it is recommended to configure a control with an action using using setAction, and then add that control directly to the Container.

Parameters:
a - the Action object to add as a new menu item
Returns:
the new button which dispatches the action

createActionComponent

protected JComponent createActionComponent(Action a)
Factory method which creates the JButton for Actions added to the CommandBar. The default name is empty if a null action is passed.

As of 1.3, this is no longer the preferred method for adding Actions to a Container. Instead it is recommended to configure a control with an action using setAction, and then add that control directly to the Container.

Parameters:
a - the Action for the button to be added
Returns:
the newly created button
See Also:
Action

createActionChangeListener

protected PropertyChangeListener createActionChangeListener(JComponent component)
Returns a properly configured PropertyChangeListener which updates the control as changes to the Action occur, or null if the default property change listener for the control is desired.

As of 1.3, this is no longer the preferred method for adding Actions to a Container. Instead it is recommended to configure a control with an action using setAction, and then add that control directly to the Container.

Parameters:
component - the component
Returns:
null

addImpl

protected void addImpl(Component comp,
                       Object constraints,
                       int index)
Overrides superclass to handle special UIResources when they are added.

There are three UIResource (gripper, title bar and chevron) being added to CommandBar in BasicCommandBarUI. To keep it transparent to users, if the comp is an instance of UIResource, it will be added as usual. If it's not a UIResource, it will be added at index + 3. Corresponding methods are changed too. For example, getMenuCount() will return the actual getComponentCount() - 3. getMenu(int index) will return the actual component at index + 3.

Overrides:
addImpl in class DockableBar
Parameters:
comp - the component to be enhanced
constraints - the constraints to be enforced on the component
index - the index of the component

isScreenMenuBar

public static boolean isScreenMenuBar(JMenuBar jMenuBar)
Checks if the menu bar is used as screen menu bar (on Mac OS X only).

Parameters:
jMenuBar - the JMenuBar
Returns:
true if it will be used as screen menu bar. Otherwise, false.

getPreferredRowCount

public int getPreferredRowCount()
Gets the preferred row count when the CommandBar is in floating mode.

Returns:
the preferred row count.

setPreferredRowCount

public void setPreferredRowCount(int preferredRowCount)
Sets the preferred row count when the CommandBar is in floating mode.

Parameters:
preferredRowCount - the preferred row count

getHiddenComponents

public Component[] getHiddenComponents()
Gets an array of all hidden components.

Returns:
the array of all hidden components.

remove

public void remove(Component comp)
Overridden to remove the component from the hiddenComponents list if it isn't in the components list.

Overrides:
remove in class Container
Parameters:
comp - the component to be removed

removeAll

public void removeAll()
Overridden to remove the clear the hiddenComponents list as well as the components list.

Overrides:
removeAll in class Container

removeAllHiddenComponents

public void removeAllHiddenComponents()
Removes all components from the hidden components list.


getMenuCount

public int getMenuCount()
Returns the number of items in the menu bar. Since there are three UIResource (gripper, title bar and chevron) being added to CommandBar in BasicCommandBarUI to keep it transparent to users, this method return the actual component count - 3.

Overrides:
getMenuCount in class JMenuBar
Returns:
the number of items in the menu bar

getMenu

public JMenu getMenu(int index)
Returns the menu at the specified position in the menu bar. Since there are three UIResource (gripper, title bar and chevron) being added to CommandBar in BasicCommandBarUI to keep it transparent to users, this method return the component whose actual index is index + 3.

Overrides:
getMenu in class JMenuBar
Parameters:
index - an integer giving the position in the menu bar, where 0 is the first position
Returns:
the JMenu at that position, or null if if there is no JMenu at that position (ie. if it is a JMenuItem)

addExpansion

public void addExpansion()
adds a expansion component. Components added after the expansion will be aligned to the other end of command bar.

Expansion only has effect when the command bar is in stretched mode. A typical use case is for a menu bar. You can add several menus, add a filter, then add Help menu. All menus before the expansion will align to the left end. Help menu will be aligned to the right end.

By default, we treat CommandBar.Expansion, a JTextField, a JComboBox as expandable by default. However, you can use a client property called "CommandBar.expandable" to make any component expandable or not. If it is "true", we return false. If "false" , we return false. Otherwise we return true only if the component is an instance of CommandBar.Expansion, a JTextField, a JComboBox.

See Also:
DockableBar.setStretch(boolean)

adjustChildrenOrientation

public void adjustChildrenOrientation(int orientation)
Overrides:
adjustChildrenOrientation in class DockableBar

JIDE 3.5.15