|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
com.sas.visuals.adapters.PopupMenuAdapter
public class PopupMenuAdapter
PopupMenuAdapter is a class to handle populating and displaying a PopupMenu on a java.awt.Component.
The menu items are populated based on a list of Commands. ContextCommandsInterface objects are
registered to create the Command list based on a context object. A CommandDispatcher object
is added as a listener on each MenuItem to execute the Command associated with that MenuItem.
Notes:
treeView.getDefaultNodeStyle().set(NodeStyle.EDITABLE, new Boolean(true));
treeView.setPopupMenuVisible(false);
PopupMenuAdapter popupMenuAdapter = new PopupMenuAdapter();
popupMenuAdapter.setComponent(treeView);
popupMenuAdapter.addContextCommandsProducer(treeView);
You can add more commands to the popup menu by creating you own list of commands and adding another
ContextCommandsProducer. See the code below in the TableView for an example of this. The rename command will
be separated from your list of commands by a separator.
PopupMenuAdapter popupMenuAdapter = new PopupMenuAdapter();
popupMenuAdapter.setComponent(tableView);
CommandList myCmdList = new CommandList();
myCmdList.add( new MyCommand("Command 1") );
myCmdList.add( new MyCommand("Command 2") );
popupMenuAdapter.addContextCommandsProducer( myCmdList );
...
class CommandList
extends OrderedCollection
implements ContextCommandsInterface
{
public Command[] getContextCommands( Object context, int x, int y )
{
Object[] array = toArray();
Command[] cmdArray = new Command[array.length];
System.arraycopy( array, 0, cmdArray, 0, array.length );
return cmdArray;
}
}
class MyCommand
extends AbstractCommand
{
public MyCommand( String txt )
{
setText(txt);
{
public Object clone() throws CloneNotSupportedException
{
return new MyCommand( getText() );
}
public void execute( Object arg )
{
System.out.println( " executed command " + getText() );
}
}
Field Summary | |
---|---|
protected com.sas.collection.OrderedCollectionInterface |
commandProducers
|
protected java.awt.Component |
component
|
protected java.lang.Object |
context
|
protected ErrorHandlerInterface |
errHandler
|
protected java.awt.PopupMenu |
popupMenu
|
protected boolean |
popupMenuEnabled
|
protected boolean |
separatorsAdded
|
Constructor Summary | |
---|---|
PopupMenuAdapter()
Default constructor. setComponent() must be called before the adapter can be used. |
|
PopupMenuAdapter(java.awt.Component comp)
Constructor that sets the component to control the popupMenu. |
|
PopupMenuAdapter(java.awt.Component comp,
ContextCommandsInterface[] producers)
Constructor that sets the component to control the PopupMenu and the ContextCommandsInterface objects to populate the PopupMenu with. |
Method Summary | |
---|---|
void |
addContextCommandsProducer(ContextCommandsInterface producer)
Register a new context commands producer. |
java.lang.Object |
clone()
Clone the PopupMenuAdapter instance. |
protected void |
connectPopupToComponent()
Called to connect the PopupMenu to the Component. |
java.awt.Component |
getComponent()
Get the component whose popup menu is being controlled. |
java.lang.Object |
getContext()
Get the context object used to get the Command list. |
com.sas.util.Command[] |
getContextCommands(java.lang.Object context,
int x,
int y)
Get the Command objects based on the specified context and position. |
ContextCommandsInterface[] |
getContextCommandsProducers()
Get an array of the registered ContextCommandsProducers. |
ErrorHandlerInterface |
getErrorHandler()
Get the error handler used by all commands that implement the SupportsErrorHandlerInterface. |
protected java.awt.PopupMenu |
getPopupMenu()
Get the PopupMenu to be shown. |
boolean |
isPopupMenuEnabled()
Get whether the popup menu is enabled for the component. |
boolean |
isSeparatorsAdded()
Get whether or not a separator is added between each producer's list of commands. |
void |
mouseClicked(java.awt.event.MouseEvent event)
MouseListener method invoked when the mouse has been clicked on the component. |
void |
mouseEntered(java.awt.event.MouseEvent event)
MouseListener method invoked when the mouse enters the component. |
void |
mouseExited(java.awt.event.MouseEvent event)
MouseListener method invoked when the mouse exits the component. |
void |
mousePressed(java.awt.event.MouseEvent event)
MouseEvent handler to listen for MouseEvents that are popupTriggers. |
void |
mouseReleased(java.awt.event.MouseEvent event)
MouseEvent handler to listen for MouseEvents that are popupTriggers. |
protected CommandDispatcher |
newCommandDispatcher(com.sas.util.Command command)
Factory method for creating a CommandDispatcher to execute the specified Command when the MenuItem is selected. |
protected com.sas.collection.OrderedCollectionInterface |
newCommandProducerList()
Factory method for creating the list to store the command producers in. |
protected java.awt.PopupMenu |
newPopupMenu()
Factory method for creating a PopupMenu for this adapter. |
protected java.awt.MenuItem |
newPopupMenuItem(com.sas.util.Command command)
Factory method for creating a MenuItem from a Command object. |
protected void |
populateMenu(java.awt.Menu menu,
com.sas.util.Command[] cmds)
Recursively creates the items to go on the menu. |
protected void |
populatePopupMenu(java.awt.PopupMenu popupMenu,
int x,
int y)
Helper method to populate the popupMenu with Items. |
void |
removeContextCommandsProducer(ContextCommandsInterface producer)
Unregister a context commands producer. |
void |
setComponent(java.awt.Component comp)
Set the component to listen to MouseEvents on and to add the PopupMenu to. |
void |
setContext(java.lang.Object cntxt)
Set the context object used to get the Command list. |
void |
setDefaultValues()
|
void |
setErrorHandler(ErrorHandlerInterface errorHandler)
Set the error handler used by all commands that implement the SupportsErrorHandlerInterface. |
void |
setPopupMenuEnabled(boolean enabled)
Sets whether the popup menu is enabled for the component. |
void |
setSeparatorsAdded(boolean addSeparators)
Set whether or not a separator is added between each producer's list of commands. |
void |
showPopupMenu(int x,
int y)
Display the popup menu for the component. |
Field Detail |
---|
protected java.awt.Component component
protected java.lang.Object context
protected boolean popupMenuEnabled
protected boolean separatorsAdded
protected ErrorHandlerInterface errHandler
protected java.awt.PopupMenu popupMenu
protected com.sas.collection.OrderedCollectionInterface commandProducers
Constructor Detail |
---|
public PopupMenuAdapter()
public PopupMenuAdapter(java.awt.Component comp)
component
- The component to control the popup menu of.setComponent(java.awt.Component)
public PopupMenuAdapter(java.awt.Component comp, ContextCommandsInterface[] producers)
component
- The component to control the popup menu of.producers
- An array of ContextCommandsInterface objects that will be used to generate the
popup menu for the component.Method Detail |
---|
public void setDefaultValues()
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
clone
in class java.lang.Object
java.lang.CloneNotSupportedException
- if the object's class does not support the Cloneable interface.public ContextCommandsInterface[] getContextCommandsProducers()
getContextCommandsProducers
in interface ContextCommandsConsumerInterface
ContextCommandsConsumerInterface.addContextCommandsProducer(com.sas.util.ContextCommandsInterface)
public void addContextCommandsProducer(ContextCommandsInterface producer)
addContextCommandsProducer
in interface ContextCommandsConsumerInterface
producer
- An object that implements ContextCommandsInterface
.getContextCommandsProducers()
public void removeContextCommandsProducer(ContextCommandsInterface producer)
removeContextCommandsProducer
in interface ContextCommandsConsumerInterface
producer
- An object previously passed to
addContextCommandsProducer()
.ContextCommandsConsumerInterface.addContextCommandsProducer(com.sas.util.ContextCommandsInterface)
public com.sas.util.Command[] getContextCommands(java.lang.Object context, int x, int y)
getContextCommands
in interface ContextCommandsInterface
context
- The context to return commands for. Each implemenation should
define the contexts it accepts.x
- The horizontal coordinate of the location within the visual
coordinate space of the context for which the caller
would like commands. For example, if this method is being called
in response to a mouse click, then x would be the
x-position of the click. If the caller doesn't have a location
in mind, -1
should be specified.
Note that some implementations will find that x is
not necessary, so are free to ignore it with appropriate
documentation.y
- The vertical coordinate of the location within the visual
coordinate space of the context for which the caller
would like commands. For example, if this method is being called
in response to a mouse click, then y would be the
y-position of the click. If the caller doesn't have a location
in mind, -1
should be specified.
Note that some implementations will find that y is
not necessary, so are free to ignore it with appropriate
documentation.
public boolean isSeparatorsAdded()
public void setSeparatorsAdded(boolean addSeparators)
addSeparators
- true if separators should be added, false otherwisepublic void mouseClicked(java.awt.event.MouseEvent event)
mouseClicked
in interface java.awt.event.MouseListener
public void mouseEntered(java.awt.event.MouseEvent event)
mouseEntered
in interface java.awt.event.MouseListener
public void mouseExited(java.awt.event.MouseEvent event)
mouseExited
in interface java.awt.event.MouseListener
public void mouseReleased(java.awt.event.MouseEvent event)
showPopupMenu(int,int)
is called.
mouseReleased
in interface java.awt.event.MouseListener
a
- MouseEvent to trigger the PopupMenu onpublic void mousePressed(java.awt.event.MouseEvent event)
showPopupMenu(int,int)
is called.
mousePressed
in interface java.awt.event.MouseListener
a
- MouseEvent to trigger the PopupMenu onpublic java.awt.Component getComponent()
public void setComponent(java.awt.Component comp)
comp
- The component to control the popup menu of. The previous component is
removed as a MouseListener and as parent of the popup menu.protected void connectPopupToComponent()
public void showPopupMenu(int x, int y)
x
- the x location relative to the component property.y
- the y location relative to the component property.public void setPopupMenuEnabled(boolean enabled)
public boolean isPopupMenuEnabled()
public java.lang.Object getContext()
public void setContext(java.lang.Object cntxt)
the
- context used to determine the list of Commands. If no
context is set, the component will be used as the context.protected void populatePopupMenu(java.awt.PopupMenu popupMenu, int x, int y)
protected void populateMenu(java.awt.Menu menu, com.sas.util.Command[] cmds)
menu
- the menu to populate based on the cmdcmds
- the Commands array to use to populate the Menu.protected java.awt.PopupMenu getPopupMenu()
protected java.awt.PopupMenu newPopupMenu()
protected CommandDispatcher newCommandDispatcher(com.sas.util.Command command)
command
- the Command for the CommandDispatcher to execute when the MenuItem associated
with the Command is selected.
protected com.sas.collection.OrderedCollectionInterface newCommandProducerList()
protected java.awt.MenuItem newPopupMenuItem(com.sas.util.Command command)
command
- the Command to determine what type of MenuItem to create
public void setErrorHandler(ErrorHandlerInterface errorHandler)
setErrorHandler
in interface SupportsErrorHandlerInterface
errorHandler
- The error handler.public ErrorHandlerInterface getErrorHandler()
getErrorHandler
in interface SupportsErrorHandlerInterface
errorHandler
- The error handler.
|
Components |
|
| |||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |