Package com.jgcomptech.tools.events
Class Event
- java.lang.Object
-
- com.jgcomptech.tools.events.Event
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
- Direct Known Subclasses:
ActionEvent
,PermissionEvent
,SessionEvent
public class Event extends java.lang.Object implements java.lang.Cloneable, java.io.Serializable
Base class for custom events. Each event has associated an event source, event target and an event type.- Since:
- 1.4.0
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description Event(EventTarget<? extends Event> target)
Construct a newEvent
with the specified event target.Event(EventTarget<? extends Event> target, EventType<? extends Event> eventType)
Construct a newEvent
with the specified event target and type.Event(EventTarget<? extends Event> target, EventType<? extends Event> eventType, java.util.List<java.lang.Object> args)
Construct a newEvent
with the specified event target, type and args.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Object
clone()
Creates and returns a copy of thisEvent
.void
consume()
Marks thisEvent
as consumed.Event
copyFor(java.lang.Object newSource, EventTarget<? extends Event> newTarget)
Creates and returns a copy of this event with the specified event source and target.boolean
equals(java.lang.Object o)
void
fireEvent(java.lang.Object source)
Fires the event with the specified source.void
fireEvent(java.lang.Object source, java.lang.Object... args)
Fires the event with the specified source and args.java.util.List<java.lang.Object>
getArgs()
Returns the Event arguments.EventType<? extends Event>
getEventType()
Gets the event type of this event.java.lang.Object
getSource()
The object on which the Event initially occurred.EventTarget<? extends Event>
getTarget()
Returns the event target of this event.int
hashCode()
boolean
isConsumed()
Indicates whether thisEvent
has been consumed by any filter or handler.protected void
setSource(java.lang.Object source)
Sets the event source, only available to other event objects.protected void
setTarget(EventTarget<? extends Event> target)
Sets the event target of this event, only available to other event objects.java.lang.String
toString()
-
-
-
Constructor Detail
-
Event
public Event(EventTarget<? extends Event> target)
Construct a newEvent
with the specified event target.- Parameters:
target
- the event target to associate with the event
-
Event
public Event(EventTarget<? extends Event> target, EventType<? extends Event> eventType)
Construct a newEvent
with the specified event target and type.- Parameters:
target
- the event target to associate with the eventeventType
- the event type
-
Event
public Event(EventTarget<? extends Event> target, EventType<? extends Event> eventType, java.util.List<java.lang.Object> args)
Construct a newEvent
with the specified event target, type and args.- Parameters:
target
- the event target to associate with the eventeventType
- the event typeargs
- arguments to make available to the EventHandler
-
-
Method Detail
-
getTarget
public final EventTarget<? extends Event> getTarget()
Returns the event target of this event. The event target specifies the path through which the event will travel when posted.- Returns:
- the event target
-
setTarget
protected final void setTarget(EventTarget<? extends Event> target)
Sets the event target of this event, only available to other event objects.- Parameters:
target
- the event target
-
getEventType
public EventType<? extends Event> getEventType()
Gets the event type of this event. Objects of the sameEvent
class can have different event types. These event types further specify what kind of event occurred.- Returns:
- the event type
-
copyFor
public Event copyFor(java.lang.Object newSource, EventTarget<? extends Event> newTarget)
Creates and returns a copy of this event with the specified event source and target.- Parameters:
newSource
- the new source of the copied eventnewTarget
- the new target of the copied event- Returns:
- the event copy with the new source and target
-
getSource
public final java.lang.Object getSource()
The object on which the Event initially occurred.- Returns:
- the object on which the Event initially occurred.
-
setSource
protected void setSource(java.lang.Object source)
Sets the event source, only available to other event objects.- Parameters:
source
- the source to set
-
isConsumed
public final boolean isConsumed()
Indicates whether thisEvent
has been consumed by any filter or handler.- Returns:
true
if thisEvent
has been consumed,false
otherwise
-
consume
public final void consume()
Marks thisEvent
as consumed. This stops its further propagation.
-
getArgs
public final java.util.List<java.lang.Object> getArgs()
Returns the Event arguments.- Returns:
- the Event arguments
-
clone
public final java.lang.Object clone()
Creates and returns a copy of thisEvent
.- Overrides:
clone
in classjava.lang.Object
- Returns:
- a new instance of
Event
with all values copied from thisEvent
.
-
fireEvent
public final void fireEvent(java.lang.Object source)
Fires the event with the specified source.- Parameters:
source
- the event source which sent the event
-
fireEvent
public final void fireEvent(java.lang.Object source, java.lang.Object... args)
Fires the event with the specified source and args.- Parameters:
source
- the event source which sent the eventargs
- a list of parameters to pass to the EventHandler
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-