001: /*
002: #IFNDEF ALT_LICENSE
003: ThinWire(R) RIA Ajax Framework
004: Copyright (C) 2003-2007 Custom Credit Systems
005:
006: This library is free software; you can redistribute it and/or modify it under
007: the terms of the GNU Lesser General Public License as published by the Free
008: Software Foundation; either version 2.1 of the License, or (at your option) any
009: later version.
010:
011: This library is distributed in the hope that it will be useful, but WITHOUT ANY
012: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
013: PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
014:
015: You should have received a copy of the GNU Lesser General Public License along
016: with this library; if not, write to the Free Software Foundation, Inc., 59
017: Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:
019: Users who would rather have a commercial license, warranty or support should
020: contact the following company who invented, built and supports the technology:
021:
022: Custom Credit Systems, Richardson, TX 75081, USA.
023: email: info@thinwire.com ph: +1 (888) 644-6405
024: http://www.thinwire.com
025: #ENDIF
026: [ v1.2_RC2 ]
027: */
028: package thinwire.ui.event;
029:
030: import java.util.EventObject;
031:
032: import thinwire.ui.Component;
033:
034: /**
035: * @author Joshua J. Gertzen
036: */
037: public final class ActionEvent extends EventObject {
038: private String stringValue;
039: private Component sourceComponent;
040: private String action;
041: private int sourceComponentX;
042: private int sourceComponentY;
043: private int sourceX;
044: private int sourceY;
045:
046: public ActionEvent(String action, Component sourceComponent) {
047: this (action, sourceComponent, null, -1, -1, -1, -1, true);
048: }
049:
050: public ActionEvent(String action, Component sourceComponent,
051: int sourceComponentX, int sourceComponentY) {
052: this (action, sourceComponent, null, sourceComponentX,
053: sourceComponentY, -1, -1, true);
054: }
055:
056: public ActionEvent(String action, Component sourceComponent,
057: Object source) {
058: this (action, sourceComponent, source, -1, -1, -1, -1, true);
059: }
060:
061: public ActionEvent(String action, Component sourceComponent,
062: Object source, int sourceComponentX, int sourceComponentY,
063: int sourceX, int sourceY) {
064: this (action, sourceComponent, source, sourceComponentX,
065: sourceComponentY, sourceX, sourceY, true);
066: }
067:
068: private ActionEvent(String action, Component sourceComponent,
069: Object source, int sourceComponentX, int sourceComponentY,
070: int sourceX, int sourceY, boolean init) {
071: super (source == null ? sourceComponent : source);
072: if (sourceComponent == null)
073: throw new IllegalArgumentException(
074: "sourceComponent == null");
075: if (init && sourceComponentX == -1)
076: sourceComponentX = 0;
077: if (init && sourceComponentY == -1)
078: sourceComponentY = 0;
079: if (sourceComponentX < 0)
080: throw new IllegalArgumentException("sourceComponentX{"
081: + sourceComponentX + "} < 0");
082: if (sourceComponentY < 0)
083: throw new IllegalArgumentException("sourceComponentY{"
084: + sourceComponentY + "} < 0");
085: if (init && sourceX == -1)
086: sourceX = sourceComponentX;
087: if (init && sourceY == -1)
088: sourceY = sourceComponentY;
089: if (sourceX < 0)
090: throw new IllegalArgumentException("sourceX{" + sourceX
091: + "} < 0");
092: if (sourceY < 0)
093: throw new IllegalArgumentException("sourceY{" + sourceY
094: + "} < 0");
095: if (action == null || !action.equals(Component.ACTION_CLICK)
096: && !action.equals(Component.ACTION_DOUBLE_CLICK))
097: throw new IllegalArgumentException(
098: "action == null || !action.equals(ActionEventComponent.ACTION_CLICK) && !action.equals(ActionEventComponent.ACTION_DOUBLE_CLICK)");
099:
100: this .action = action;
101: this .sourceComponent = sourceComponent;
102: this .sourceComponentX = sourceComponentX;
103: this .sourceComponentY = sourceComponentY;
104: this .sourceX = sourceX;
105: this .sourceY = sourceY;
106: }
107:
108: public String getAction() {
109: return action;
110: }
111:
112: public Component getSourceComponent() {
113: return sourceComponent;
114: }
115:
116: public int getSourceComponentX() {
117: return sourceComponentX;
118: }
119:
120: public int getSourceComponentY() {
121: return sourceComponentY;
122: }
123:
124: public int getSourceX() {
125: return sourceX;
126: }
127:
128: public int getSourceY() {
129: return sourceY;
130: }
131:
132: public boolean equals(Object o) {
133: return o instanceof ActionEvent
134: && toString().equals(o.toString());
135: }
136:
137: public int hashCode() {
138: return toString().hashCode();
139: }
140:
141: public String toString() {
142: if (stringValue == null)
143: stringValue = "ActionEvent{action:" + action
144: + ",sourceComponent:"
145: + sourceComponent.getClass().getName() + "@"
146: + System.identityHashCode(sourceComponent)
147: + ",source:" + source + "@"
148: + System.identityHashCode(source)
149: + ",sourceComponentX:" + sourceComponentX
150: + ",sourceComponentY:" + sourceComponentY
151: + ",sourceX:" + sourceX + ",sourceY:" + sourceY
152: + "}";
153: return stringValue;
154: }
155: }
|