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.SerializableBase 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 newEventwith the specified event target.Event(EventTarget<? extends Event> target, EventType<? extends Event> eventType)Construct a newEventwith the specified event target and type.Event(EventTarget<? extends Event> target, EventType<? extends Event> eventType, java.util.List<java.lang.Object> args)Construct a newEventwith the specified event target, type and args.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.Objectclone()Creates and returns a copy of thisEvent.voidconsume()Marks thisEventas consumed.EventcopyFor(java.lang.Object newSource, EventTarget<? extends Event> newTarget)Creates and returns a copy of this event with the specified event source and target.booleanequals(java.lang.Object o)voidfireEvent(java.lang.Object source)Fires the event with the specified source.voidfireEvent(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.ObjectgetSource()The object on which the Event initially occurred.EventTarget<? extends Event>getTarget()Returns the event target of this event.inthashCode()booleanisConsumed()Indicates whether thisEventhas been consumed by any filter or handler.protected voidsetSource(java.lang.Object source)Sets the event source, only available to other event objects.protected voidsetTarget(EventTarget<? extends Event> target)Sets the event target of this event, only available to other event objects.java.lang.StringtoString()
-
-
-
Constructor Detail
-
Event
public Event(EventTarget<? extends Event> target)
Construct a newEventwith 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 newEventwith 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 newEventwith 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 sameEventclass 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 thisEventhas been consumed by any filter or handler.- Returns:
trueif thisEventhas been consumed,falseotherwise
-
consume
public final void consume()
Marks thisEventas 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:
clonein classjava.lang.Object- Returns:
- a new instance of
Eventwith 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:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-