001: /* Event.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Sat Jun 11 10:41:14 2005, Created by tomyeh
010: }}IS_NOTE
011:
012: Copyright (C) 2004 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019: package org.zkoss.zk.ui.event;
020:
021: import org.zkoss.zk.ui.Component;
022: import org.zkoss.zk.ui.Page;
023:
024: /**
025: * An event sent to the event handler of a component.
026: *
027: * @author tomyeh
028: * @see Component
029: */
030: public class Event {
031: private final String _name;
032: private final Component _target;
033: private final Object _data;
034: private boolean _propagatable = true;
035:
036: /** Constructs a simple event.
037: * @param target the component to receive this event,
038: * or null to indicate broadcasting the event to all root components.
039: */
040: public Event(String name, Component target) {
041: if (name == null)
042: throw new NullPointerException();
043: _name = name;
044: _target = target;
045: _data = null;
046: }
047:
048: /** Constructs a simple event.
049: * @param target the component to receive this event,
050: * or null to indicate broadcasting the event to all root components.
051: * @param data an arbitary data
052: */
053: public Event(String name, Component target, Object data) {
054: if (name == null)
055: throw new NullPointerException();
056: _name = name;
057: _target = target;
058: _data = data;
059: }
060:
061: /** Returns the event name.
062: */
063: public final String getName() {
064: return _name;
065: }
066:
067: /** Returns the target component that receives this event,
068: * or null if broadcast.
069: */
070: public final Component getTarget() {
071: return _target;
072: }
073:
074: /** Returns the page owning this event, or null if broadcast.
075: */
076: public final Page getPage() {
077: return _target != null ? _target.getPage() : null;
078: }
079:
080: /** Returns the data accompanies with this event, or null if not available.
081: */
082: public Object getData() {
083: return _data;
084: }
085:
086: /** Returns whether this event is propagatable.
087: * <p>Default: true.
088: * <p>It becomes false if {@link #stopPropagation} is called.
089: * If true, the event will be sent to the following event listener
090: * ({@link EventListener}) being registered by {@link Component#addEventListener}
091: * and {@link Page#addEventListener}.
092: */
093: public boolean isPropagatable() {
094: return _propagatable;
095: }
096:
097: /** Stops the propagation for this event.
098: */
099: public void stopPropagation() {
100: _propagatable = false;
101: }
102:
103: //-- Object --//
104: public String toString() {
105: final String clsnm = getClass().getName();
106: final int j = clsnm.lastIndexOf('.');
107: return "[" + clsnm.substring(j + 1) + ' ' + _name + ' '
108: + _target + ']';
109: }
110: }
|