|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjavax.swing.AbstractAction
org.bushe.swing.event.EventServiceAction
public abstract class EventServiceAction
Abstract class that publishes a Swing ActionEvent (or another object) to an EventService.
getTopicName(ActionEvent) and
setTopicName(String) for ways to customize the topic used. Override getTopicValue(ActionEvent) to
publish an object other than the ActionEvent.
Instead of publishing on a topic, the ActionEvent can be published using class-based publication, use setPublishesOnTopic(boolean) to set this behavior. When using class-based publication, the ActionEvent is published
by default. Override getEventServiceEvent(ActionEvent) to publish an object other than the ActionEvent.
| Field Summary | |
|---|---|
static java.lang.String |
EVENT_BUS_EVENT_CLASS_NAME
|
static java.lang.String |
EVENT_SERVICE_TOPIC_NAME
|
| Fields inherited from class javax.swing.AbstractAction |
|---|
changeSupport, enabled |
| Fields inherited from interface javax.swing.Action |
|---|
ACCELERATOR_KEY, ACTION_COMMAND_KEY, DEFAULT, DISPLAYED_MNEMONIC_INDEX_KEY, LARGE_ICON_KEY, LONG_DESCRIPTION, MNEMONIC_KEY, NAME, SELECTED_KEY, SHORT_DESCRIPTION, SMALL_ICON |
| Constructor Summary | |
|---|---|
EventServiceAction()
|
|
EventServiceAction(java.lang.String actionName,
javax.swing.ImageIcon icon)
|
|
| Method Summary | |
|---|---|
void |
actionPerformed(java.awt.event.ActionEvent event)
Publishes the event on the EventService returned by getEventService(event) Gets the EventService from getEventService(java.awt.event.ActionEvent). |
protected abstract EventService |
getEventService(java.awt.event.ActionEvent event)
Override to return the EventService on which to publish. |
protected java.lang.Object |
getEventServiceEvent(java.awt.event.ActionEvent event)
If isPublishesOnTopic() returns false (i.e., when using class-based rather than topic-based publication), then override this method to publish an on object other than the ActionEvent. |
java.lang.Object |
getName()
|
boolean |
getThrowsExceptionOnNullEventService()
By default, exceptions are throw if getEventService() returns null. |
java.lang.String |
getTopicName(java.awt.event.ActionEvent event)
The topic name is the first non-null value out of: A topic name explicitly set via setTopicName(String) the action's getValue("event-service-topic") EVENT_SERVICE_TOPIC_NAME the
action's getValue("ID") (for compatibility with the SAM ActionManager's ID) the action's Action.ACTION_COMMAND_KEY the action event's Action.ACTION_COMMAND_KEY
the action's Action.NAME the value is used (if the value is not a String, the value's
toString() is used). |
protected java.lang.Object |
getTopicValue(java.awt.event.ActionEvent event)
By default, the ActionEvent is the object published on the topic. |
boolean |
isPublishesOnTopic()
|
void |
setPublishesOnTopic(boolean onTopic)
Sets whether this action publishes on a topic or uses class-based publication. |
void |
setThrowsExceptionOnNullEventService(boolean throwsExceptionOnNullEventService)
By default, exceptions are thrown if getEventService() returns null. |
void |
setTopicName(java.lang.String topicName)
Explicitly sets the topic name this action publishes on. |
| Methods inherited from class javax.swing.AbstractAction |
|---|
addPropertyChangeListener, clone, firePropertyChange, getKeys, getPropertyChangeListeners, getValue, isEnabled, putValue, removePropertyChangeListener, setEnabled |
| Methods inherited from class java.lang.Object |
|---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.lang.String EVENT_SERVICE_TOPIC_NAME
public static final java.lang.String EVENT_BUS_EVENT_CLASS_NAME
| Constructor Detail |
|---|
public EventServiceAction()
public EventServiceAction(java.lang.String actionName,
javax.swing.ImageIcon icon)
| Method Detail |
|---|
protected abstract EventService getEventService(java.awt.event.ActionEvent event)
event - the event passed to #execute(ActionEvent)
EventBusAction,
ContainerEventServiceActionpublic boolean isPublishesOnTopic()
public void setPublishesOnTopic(boolean onTopic)
onTopic - true if publishes on topic (the default), false if using class-based publication.public void setTopicName(java.lang.String topicName)
getTopicName(ActionEvent) to understand how the
topic name is determined implicitly.
public java.lang.String getTopicName(java.awt.event.ActionEvent event)
setTopicName(String) EVENT_SERVICE_TOPIC_NAME Action.ACTION_COMMAND_KEY Action.ACTION_COMMAND_KEY
Action.NAME the value is used (if the value is not a String, the value's
toString() is used).
To use a different name, override this method.
event - the event passed to #execute(ActionEvent)
protected java.lang.Object getTopicValue(java.awt.event.ActionEvent event)
event - the event passed to #execute(ActionEvent)
public java.lang.Object getName()
protected java.lang.Object getEventServiceEvent(java.awt.event.ActionEvent event)
public void actionPerformed(java.awt.event.ActionEvent event)
getEventService(java.awt.event.ActionEvent). Checks isPublishesOnTopic(). If true,
gets the topic name from getTopicName(java.awt.event.ActionEvent) and the topic value from getTopicValue(ActionEvent), and publishes the value on the topic on the EventService. If false, gets event from
getEventServiceEvent(java.awt.event.ActionEvent), and publishes the event on the EventService.
event - the action event to publish.
java.lang.RuntimeException - if getThrowsExceptionOnNullEventService() && getEventService(event) == nullpublic boolean getThrowsExceptionOnNullEventService()
public void setThrowsExceptionOnNullEventService(boolean throwsExceptionOnNullEventService)
throwsExceptionOnNullEventService - true to suppress the exception when there is no event service
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||