|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.pietschy.command.Command
com.pietschy.command.group.CommandGroup
public class CommandGroup
Groups allow commands to be grouped together and act as factories for menus, toolbars and the like. The following is an example group configuration for a simple file menu. The example places an expansion point before the exit command. The expansion point will automatically insert a separator at before any commands it cotains.
group!file-menu@face.text=_File
group!file-menu@members=\
new, \
open, \
save, \
save-as, \
expand(separatorBefore), \
separator, \
exit
To use this group in you code you simple create and bind it as the following example shows.
CommandGroup group = new CommandGroup("file-menu");
group.bind(commandContainer);
JMenuItem menu = group.createMenu();
AbstractButton button = group.createButton();
For more information on the binding options please refer to the CommandContainer documentation.
Expansion points allow the addition of new members at runtime to a predetermined position in the
group. The content of an expansion point is managed using getExpansionPointBuilder().
Groups can also be programatically generated from scratch using getBuilder().
| Field Summary |
|---|
| Fields inherited from class com.pietschy.command.Command |
|---|
internalLog, PROPERTY_ENABLED, PROPERTY_VISIBLE |
| Constructor Summary | |
|---|---|
|
CommandGroup()
Creates a new anonymous instance. |
protected |
CommandGroup(boolean loadConfiguration)
Creates a new anonymous instance that conditionally invokes Command.loadConfiguration() |
|
CommandGroup(java.lang.String id)
Creates a new instance with the specified id. |
protected |
CommandGroup(java.lang.String id,
boolean loadConfiguration)
Creates a new anonymous instance with the specified id that conditionally invokes Command.loadConfiguration() |
| Method Summary | |
|---|---|
void |
addGroupListener(GroupListener l)
Adds a GroupListener to the group. |
protected void |
bindToContainer(CommandContainer container)
Invoked to bind this instance to the specified command container. |
javax.swing.AbstractButton |
createButton(ButtonFactory factory,
java.lang.String context)
Creates a new button that displays a popup menu when clicked. |
javax.swing.AbstractButton |
createButton(ButtonFactory buttonFactory,
java.lang.String context,
MenuFactory menuFactory,
java.lang.String popupContext)
Creates a new button that displays a popup menu when clicked. |
protected MemberManager |
createMemberManager()
Creates the member manager. |
javax.swing.JMenuBar |
createMenuBar()
Creates a new menu bar. |
javax.swing.JMenuBar |
createMenuBar(MenuFactory factory)
Creates a new menu bar. |
javax.swing.JMenuBar |
createMenuBar(java.lang.String context)
Creates a new menu bar. |
javax.swing.JMenuBar |
createMenuBar(java.lang.String context,
MenuFactory factory)
Creates a new menu bar. |
javax.swing.JMenuItem |
createMenuItem(MenuFactory factory,
java.lang.String context)
Creates a new menu for the group that contains the group members. |
javax.swing.JMenuItem |
createMenuItem(MenuFactory factory,
java.lang.String context,
MenuFactory popupFactory,
java.lang.String popupContext)
Creates a new menu for the group that contains the group members. |
javax.swing.JPopupMenu |
createPopupMenu()
Creates a popup menu. |
javax.swing.JPopupMenu |
createPopupMenu(MenuFactory factory,
java.lang.String context)
Creates a popup menu. |
javax.swing.JPopupMenu |
createPopupMenu(java.lang.String context)
Creates a popup menu. |
javax.swing.JToolBar |
createToolBar()
Creates a new toolbar. |
javax.swing.JToolBar |
createToolBar(java.lang.String context)
Creates a new toolbar. |
javax.swing.JToolBar |
createToolBar(java.lang.String context,
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)
Creates a new toolbar. |
GroupBuilder |
getBuilder()
Gets the current builder for this group. |
ExpansionPointBuilder |
getExpansionPointBuilder()
Gets the current expansion point builder for this group. |
int |
getMemberCount()
Returns the number of realised members in this group. |
java.lang.String |
getMemberListSpec()
Gets the member specification used to populate this group. |
protected MemberManager |
getMemberManager()
Gets the member support for this group. |
protected java.lang.String |
getPopupContext(java.lang.String context)
Gets the context to use for popups menus whose activators (i.e. |
boolean |
isAllowableMember(Command prospectiveMember)
Checks if the specified Command can be added to this group. |
java.util.Iterator<GroupMember> |
memberIterator()
Returns an iterator over this groups GroupMember instances. |
protected void |
rebuildMembersFromSpec()
Rebuilds this groups members from the current member list specification. |
void |
removeGroupListener(GroupListener l)
Removes a GroupListener from the group. |
void |
setMemberListSpec(java.lang.String memberListSpec)
Sets this groups member list specification. |
protected void |
unbindFromContainer(CommandContainer container)
Invoked to unbind this instance from the specified command container. |
void |
visit(GroupVisitor visitor)
Visits this group. |
void |
visitMembers(GroupVisitor visitor)
Visits just the members of this group. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public CommandGroup()
public CommandGroup(java.lang.String id)
id - the group id.protected CommandGroup(boolean loadConfiguration)
Command.loadConfiguration()
loadConfiguration - true to invoke Command.loadConfiguration() during the constructor,
false otherwise.
protected CommandGroup(java.lang.String id,
boolean loadConfiguration)
Command.loadConfiguration()
id - the group id.loadConfiguration - true to invoke Command.loadConfiguration() during the constructor,
false otherwise.| Method Detail |
|---|
protected void bindToContainer(CommandContainer container)
Command
bindToContainer in class Commandcontainer - the container to bind to.protected void unbindFromContainer(CommandContainer container)
Command
unbindFromContainer in class Commandcontainer - the container to unbind from.
public void setMemberListSpec(java.lang.String memberListSpec)
throws ParseException
The specification string must be of the same editor as that used on the configuration files.
group.setMemberListSpec("new, open, save, save-as, separator, exit");
memberListSpec - the memberlist specification string
java.lang.NullPointerException - if the spec is null.
ParseException - if the specification string is invalid.
protected void rebuildMembersFromSpec()
throws ParseException
ParseExceptionpublic java.lang.String getMemberListSpec()
public javax.swing.JMenuItem createMenuItem(MenuFactory factory,
java.lang.String context)
Defaults.getPopupContext(String) to determine the face context
for the popup members.
createMenuItem in class Commandfactory - the factory to use.context - the face context to use.
public javax.swing.JMenuItem createMenuItem(MenuFactory factory,
java.lang.String context,
MenuFactory popupFactory,
java.lang.String popupContext)
factory - the factory to use.context - the face context to use.popupFactory - the factory to use when creating the popup menu.popupContext - the face context to use for the popup menu items.
public javax.swing.AbstractButton createButton(ButtonFactory factory,
java.lang.String context)
getPopupContext(String) to determine the face context
for the popup members.
createButton in class Commandfactory - the factory to use.context - the face context to use.
public javax.swing.AbstractButton createButton(ButtonFactory buttonFactory,
java.lang.String context,
MenuFactory menuFactory,
java.lang.String popupContext)
getPopupContext(String) to determine the face context
for the popup members.
buttonFactory - the factory to use when creating the button.context - the face context to use for the button.menuFactory - the factory to use when creating the popup menu.popupContext - the face context to use when creating the menu.
protected java.lang.String getPopupContext(java.lang.String context)
Defaults.getPopupContext(String).
For example this method will return Face.TOOLBAR_POPUP if the
parent context is Face.TOOLBAR.
context - the face context of the parent component.
public javax.swing.JPopupMenu createPopupMenu()
public javax.swing.JPopupMenu createPopupMenu(java.lang.String context)
context - the face context to use.
public javax.swing.JPopupMenu createPopupMenu(MenuFactory factory,
java.lang.String context)
factory - the factory to use when creating the menu items.context - the face context to use.
public javax.swing.JToolBar createToolBar()
public javax.swing.JToolBar createToolBar(ToolbarFactory factory)
factory - to factory to use.
public javax.swing.JToolBar createToolBar(java.lang.String context)
context - the face context to use.
public javax.swing.JToolBar createToolBar(java.lang.String context,
ToolbarFactory factory)
context - the face context to usefactory - the factory to use.
public javax.swing.JMenuBar createMenuBar()
public javax.swing.JMenuBar createMenuBar(java.lang.String context)
context - the face context to use.
public javax.swing.JMenuBar createMenuBar(MenuFactory factory)
factory - the factory to use.
public javax.swing.JMenuBar createMenuBar(java.lang.String context,
MenuFactory factory)
context - the face context to use.factory - the factory to use.
public int getMemberCount()
public void visit(GroupVisitor visitor)
visitMembers(GroupVisitor).
visitor - the visitior.public void visitMembers(GroupVisitor visitor)
visitor - the visitor.public GroupBuilder getBuilder()
GroupBuilder.applyChanges() or
GroupBuilder.discard() is called.
public ExpansionPointBuilder getExpansionPointBuilder()
ExpansionPointBuilder.applyChanges() or
ExpansionPointBuilder.discard() is called.
protected MemberManager getMemberManager()
protected MemberManager createMemberManager()
public java.util.Iterator<GroupMember> memberIterator()
GroupMember instances. This method is used for
internal group management and generally should not be used.
GroupMember instances.public void addGroupListener(GroupListener l)
GroupListener to the group.
l - the listener to installFace.public void removeGroupListener(GroupListener l)
GroupListener from the group.
l - the listener to remove.public boolean isAllowableMember(Command prospectiveMember)
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.
prospectiveMember - the command that is to be added to the group.
ToggleGroup.isAllowableMember(com.pietschy.command.Command)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||