org.pietschy.command
Class CommandGroup

java.lang.Object
  extended by org.pietschy.command.Command
      extended by org.pietschy.command.CommandGroup
All Implemented Interfaces:
java.util.EventListener, CommandManagerListener
Direct Known Subclasses:
AbstractRecentFileGroup, EnableCommandGroup, ToggleCommandGroup, VisibleCommandGroup

public class CommandGroup
extends Command
implements CommandManagerListener

GroupCommands provide collections of other ActionCommand and ToggleCommandGroups.


Field Summary
protected  org.pietschy.command.MemberList memberList
           
 
Fields inherited from class org.pietschy.command.Command
internalLog, listenerList, pcs
 
Constructor Summary
CommandGroup(CommandManager commandManager)
          Creates a new anonymous GroupCommand.
CommandGroup(CommandManager commandManager, java.lang.String groupId)
          Creates a new command groups with the specified id.
CommandGroup(java.lang.String id)
          Creates a group that is bound to CommandManager.defaultInstance.
 
Method Summary
 void acceptVisitor(GroupVisitor visitor)
          Deprecated. use visit(GroupVisitor) or visitChildren(GroupVisitor) instead.
 void add(Command command)
          Adds a command to the groups expansion point and rebuilds all dependant widgets.
 void add(Command command, boolean rebuild)
          Adds a command to the groups expansion point and optionally rebuilds all dependant widgets.
 void addGlue()
          Inserts a glue member into the group and rebuilds all dependant widgets.
 void addGlue(boolean rebuild)
          Inserts a glue member into the group and optionally rebuilds all dependant widgets.
 void addGroupListener(GroupListener l)
          Adds a GroupListener to the group.
 void addInline(CommandGroup group)
          Adds the specified group to this groups expansion point as an inline member.
 void addInline(CommandGroup group, boolean rebuild)
          Adds the specified group to this groups expansion point as an inline member.
 void addSeparator()
          Inserts a separator into the command list and rebuilds all the groups dependant widgets.
 void addSeparator(boolean rebuild)
          Inserts a separator into the command list and optionally rebuilds all the groups dependant widgets.
protected  void bindMembers(javax.swing.JComponent container, ButtonFactory factory, java.lang.String faceName)
          Binds this group to the specified container.
protected  void bindMembers(javax.swing.JComponent container, MenuFactory factory, java.lang.String faceName)
          Binds this group to the specified container.
 void commandRegistered(CommandManagerEvent event)
          CommandManagerListener implementation.
 boolean contains(Command c)
          Checks if this group contains the specified command.
 javax.swing.AbstractButton createButton(ButtonFactory factory, java.lang.String faceName)
          Create a new button for this command using the specified ButtonFactory and Face.
 javax.swing.AbstractButton createButton(ButtonFactory buttonFactory, java.lang.String buttonFaceName, MenuFactory menuFactory, java.lang.String menuFaceName)
          Creates a new button using the specified id's for the button and menu faces and the specified factories for the button and menu items.
 javax.swing.JMenuBar createMenuBar()
           
 javax.swing.JMenuBar createMenuBar(MenuFactory factory)
           
 javax.swing.JMenuBar createMenuBar(java.lang.String faceName)
           
 javax.swing.JMenuBar createMenuBar(java.lang.String faceName, MenuFactory factory)
           
 javax.swing.JMenuItem createMenuItem(MenuFactory factory, java.lang.String faceName)
          Creates a new menu item for this command.
 javax.swing.JPopupMenu createPopupMenu()
          Creates a popup menu using Face.MENU and the default MenuFactory.
 javax.swing.JPopupMenu createPopupMenu(java.lang.String faceName, MenuFactory factory)
          Creates a popup menu for this group using the specified Face id and MenuFactory.
 javax.swing.JToolBar createToolBar()
          Creates a new JToolBar bound to this GroupCommand.
 javax.swing.JToolBar createToolBar(java.lang.String faceName)
           
 javax.swing.JToolBar createToolBar(java.lang.String faceName, ToolbarFactory factory)
          Creates a toolbar using the specified facename for the toolbar and the specified toolbar factory for the buttons.
 javax.swing.JToolBar createToolBar(ToolbarFactory factory)
           
protected  void fireMembersChanged()
           
 int getMemberCount()
          Returns the number of members in this group.
protected  GroupMemberFactory getMemberFactory()
          Gets the groups GroupMemberFactory.
protected  org.pietschy.command.MemberList getMemberList()
           
 boolean isAllowableMember(Command prospectiveMember)
          Checks if the specified Command can be added to this group.
 boolean isInlineMember(CommandGroup group)
           
 boolean isMember(CommandGroup group)
           
protected  void rebuildAllPopups()
           
 void remove(Command command)
          Removes this specified command from the group and rebuilds all dependant widgets.
 void remove(Command command, boolean rebuild)
          Removes this specified command from the group and optionally rebuilds all dependant widgets.
 void removeGroupListener(GroupListener l)
          Removes a GroupListener from the group.
 void reset()
          Resest this group back to its original state before any commands were programatically added.
 void reset(boolean rebuild)
          Resest this group back to its original state before any commands were programatically added.
 void visit(GroupVisitor visitor)
          Visits this group.
 void visitChildren(GroupVisitor visitor)
          Accepts a GroupVisitor to this group.
 
Methods inherited from class org.pietschy.command.Command
addFace, addHoverListener, addNewFace, addNotify, addPropertyChangeListener, addPropertyChangeListener, attach, buttonIterator, configureButtonAppearance, configureButtonAppearances, configureButtonAppearances, configureButtonStates, createButton, createButton, createButton, createMenuItem, createMenuItem, createMenuItem, detach, export, faceExists, fireHoverEnded, fireHoverStarted, getAccelerator, getAlternativeFaceNames, getButtonFactory, getButtonIn, getCommandManager, getDefaultFace, getDefaultFace, getDescription, getFace, getFace, getIcon, getId, getLongDescription, getMenuFactory, getMnemonic, getMnemonicIndex, getProperty, getProperty, getPropertyNames, getSelectedIcon, getText, getTextPosition, getToolbarFactory, initCommandManager, installFace, isAnonymous, isAttachedTo, isEnabled, isVisible, putProperty, removeHoverListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, requestFocusIn, setAccelerator, setButtonFactory, setDescription, setEnabled, setIcon, setLongDescription, setMenuFactory, setMnemonic, setMnemonicIndex, setSelectedIcon, setText, setTextPosition, setToolbarFactory, setVisible, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

memberList

protected org.pietschy.command.MemberList memberList
Constructor Detail

CommandGroup

public CommandGroup(CommandManager commandManager)
Creates a new anonymous GroupCommand. Anonymous groups must be fully programatically generated and can't be automatically discovered by other groups.


CommandGroup

public CommandGroup(java.lang.String id)
Creates a group that is bound to CommandManager.defaultInstance.

Parameters:
id - the id of the group.

CommandGroup

public CommandGroup(CommandManager commandManager,
                    java.lang.String groupId)
Creates a new command groups with the specified id. CommandGroups are lazy loading in that they will store the only the command ids until they are asked to create a button or menu. The command will use the specifed CommandManager to obtain commands.

Parameters:
groupId - this groups unique id.
Method Detail

createMenuItem

public javax.swing.JMenuItem createMenuItem(MenuFactory factory,
                                            java.lang.String faceName)
Creates a new menu item for this command.

Overrides:
createMenuItem in class Command
Returns:
a new JMenuItem

createButton

public javax.swing.AbstractButton createButton(ButtonFactory factory,
                                               java.lang.String faceName)
Create a new button for this command using the specified ButtonFactory and Face.

Overrides:
createButton in class Command
Returns:
a new JButton

createButton

public javax.swing.AbstractButton createButton(ButtonFactory buttonFactory,
                                               java.lang.String buttonFaceName,
                                               MenuFactory menuFactory,
                                               java.lang.String menuFaceName)
Creates a new button using the specified id's for the button and menu faces and the specified factories for the button and menu items.

Returns:
a new JButton

createPopupMenu

public javax.swing.JPopupMenu createPopupMenu()
Creates a popup menu using Face.MENU and the default MenuFactory.

Returns:
a popup menu for the group.

createPopupMenu

public javax.swing.JPopupMenu createPopupMenu(java.lang.String faceName,
                                              MenuFactory factory)
Creates a popup menu for this group using the specified Face id and MenuFactory.

Parameters:
faceName - the id of the Face to use.
factory - the MenuFactory to use to generate the menu items.
Returns:
a new popup menu for this group.

createToolBar

public javax.swing.JToolBar createToolBar()
Creates a new JToolBar bound to this GroupCommand.


createToolBar

public javax.swing.JToolBar createToolBar(ToolbarFactory factory)

createToolBar

public javax.swing.JToolBar createToolBar(java.lang.String faceName)

createToolBar

public javax.swing.JToolBar createToolBar(java.lang.String faceName,
                                          ToolbarFactory factory)
Creates a toolbar using the specified facename for the toolbar and the specified toolbar factory for the buttons.

Parameters:
faceName - the face name to use for the toolbar name.
factory - the ButtonFactory to use to create the toolbar buttons.
Returns:
a new JToolbar bound to this GroupCommand.

createMenuBar

public javax.swing.JMenuBar createMenuBar()

createMenuBar

public javax.swing.JMenuBar createMenuBar(java.lang.String faceName)

createMenuBar

public javax.swing.JMenuBar createMenuBar(MenuFactory factory)

createMenuBar

public javax.swing.JMenuBar createMenuBar(java.lang.String faceName,
                                          MenuFactory factory)

bindMembers

protected void bindMembers(javax.swing.JComponent container,
                           MenuFactory factory,
                           java.lang.String faceName)
Binds this group to the specified container. The group will ensure the containers contents are aligned with this groups members. This binding will insert menu items into the container.

Parameters:
container - the container that will hold the members of the group.
factory - the MenuFactory used to create the menu items.
faceName - the face to use for the group members.

bindMembers

protected void bindMembers(javax.swing.JComponent container,
                           ButtonFactory factory,
                           java.lang.String faceName)
Binds this group to the specified container. The group will ensure the containers contents are aligned with this groups members. This binding will insert buttons into the container.

Parameters:
container - the container that will hold the members of the group.
factory - the ButtonFactory used to create the buttons.
faceName - the face to use for the group members.

getMemberCount

public int getMemberCount()
Returns the number of members in this group. This includes commands that have been registered with the group but may not as yet been exported, it also constains commands that have been programatically added. Thus this number may be higher than the actuall number of commands that are visible in the groups menus and popups.

Returns:
the number of registered members of this group.

acceptVisitor

public void acceptVisitor(GroupVisitor visitor)
Deprecated. use visit(GroupVisitor) or visitChildren(GroupVisitor) instead.

Parameters:
visitor - the visitor.

visit

public void visit(GroupVisitor visitor)
Visits this group. This method does not automatically traverse the children of the group, to do this the visitor can call visitChildren(GroupVisitor).

Parameters:
visitor - the visitior.

visitChildren

public void visitChildren(GroupVisitor visitor)
Accepts a GroupVisitor to this group. For each active member of this group the GroupVisitor.visit(org.pietschy.command.ActionCommand) will be called. Only active members will be visited, that is commands that have been exported or explicitly added to the group.

Parameters:
visitor - the visitor.

isMember

public boolean isMember(CommandGroup group)

isInlineMember

public boolean isInlineMember(CommandGroup group)

commandRegistered

public void commandRegistered(CommandManagerEvent event)
CommandManagerListener implementation.

Specified by:
commandRegistered in interface CommandManagerListener
Parameters:
event - the event detailing the registered command.

rebuildAllPopups

protected void rebuildAllPopups()

contains

public boolean contains(Command c)
Checks if this group contains the specified command. This method only checks the direct chidren, it will only recurse into ToggleCommandGroup children if they have been added inline.

Parameters:
c - the command to check
Returns:
true if this groups children contain the command, or if a child group specified as inline contains this command.

reset

public void reset()
Resest this group back to its original state before any commands were programatically added. This is only useful if the group contains an expansion point.


reset

public void reset(boolean rebuild)
Resest this group back to its original state before any commands were programatically added. This is only useful if the group contains an expansion point.


add

public void add(Command command)
Adds a command to the groups expansion point and rebuilds all dependant widgets. Each command is appended to the list in order of addition. Each command can only be added once.

Parameters:
command - the command to installFace.
See Also:
add(org.pietschy.command.Command, boolean)

add

public void add(Command command,
                boolean rebuild)
Adds a command to the groups expansion point and optionally rebuilds all dependant widgets. Each command is appended to the list in order of addition.

Parameters:
command - the command to installFace.
rebuild - true to rebuild all the groups widgets, false to postpone the rebuild to some later time.

addInline

public void addInline(CommandGroup group)
Adds the specified group to this groups expansion point as an inline member. The childen of the specified group will appears to the user as though they are direct members of the group. This method will rebuild all dependant widgets.

Parameters:
group - the group to installFace inline.

addInline

public void addInline(CommandGroup group,
                      boolean rebuild)
Adds the specified group to this groups expansion point as an inline member. The childen of the specified group will appears to the user as though they are direct members of the group. This method will optionally rebuild all dependant widgets.

Parameters:
group - the group to installFace inline.
rebuild - true to rebuild all the groups widgets, false to postpone the rebuild to some later time.

remove

public void remove(Command command)
Removes this specified command from the group and rebuilds all dependant widgets.

Parameters:
command - the command to remove.

remove

public void remove(Command command,
                   boolean rebuild)
Removes this specified command from the group and optionally rebuilds all dependant widgets.

Parameters:
command - the command to remove.
rebuild - true to rebuild all the groups widgets, false to postpone the rebuild to some later time.

addSeparator

public void addSeparator()
Inserts a separator into the command list and rebuilds all the groups dependant widgets.


addSeparator

public void addSeparator(boolean rebuild)
Inserts a separator into the command list and optionally rebuilds all the groups dependant widgets.

Parameters:
rebuild - true to rebuild all the groups widgets, false to postpone the rebuild to some later time.

addGlue

public void addGlue()
Inserts a glue member into the group and rebuilds all dependant widgets.


addGlue

public void addGlue(boolean rebuild)
Inserts a glue member into the group and optionally rebuilds all dependant widgets.

Parameters:
rebuild - true to rebuild all the groups widgets, false to postpone the rebuild to some later time.l

getMemberList

protected org.pietschy.command.MemberList getMemberList()

getMemberFactory

protected GroupMemberFactory getMemberFactory()
Gets the groups GroupMemberFactory. This is a convenience method that delegates directly to CommandManager.getGroupMemberFactory()

Returns:
the GroupMemberFactory this group is to use.
See Also:
CommandManager.getGroupMemberFactory()

addGroupListener

public void addGroupListener(GroupListener l)
Adds a GroupListener to the group.

Parameters:
l - the listener to installFace.

removeGroupListener

public void removeGroupListener(GroupListener l)
Removes a GroupListener from the group.

Parameters:
l - the listener to remove.

fireMembersChanged

protected void fireMembersChanged()

isAllowableMember

public boolean isAllowableMember(Command prospectiveMember)
Checks if the specified Command can be added to this group. By default this method returns true but can be overriden by subclasses to control the command types that are allowable.

Parameters:
prospectiveMember - the command that is to be added to the group.
Returns:
true if the command type is allowable for this group, false otherwise.
See Also:
ToggleCommandGroup.isAllowableMember(org.pietschy.command.Command)