/src/org/mt4j/input/inputData/MTInputEvent.java

http://mt4j.googlecode.com/ · Java · 171 lines · 60 code · 30 blank · 81 comment · 1 complexity · d2ff4240b4091910af408258fb9f807b MD5 · raw file

  1. /***********************************************************************
  2. * mt4j Copyright (c) 2008 - 2009 Christopher Ruff, Fraunhofer-Gesellschaft All rights reserved.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. ***********************************************************************/
  18. package org.mt4j.input.inputData;
  19. import org.mt4j.components.interfaces.IMTComponent3D;
  20. import org.mt4j.input.MTEvent;
  21. /**
  22. * The Class MTInputEvent. The base class for all input events.
  23. *
  24. * @author Christopher Ruff
  25. */
  26. public class MTInputEvent extends MTEvent {
  27. /** The target component. */
  28. private IMTComponent3D target;
  29. /**
  30. * Instantiates a new mT input event.
  31. *
  32. * @param source the source
  33. */
  34. public MTInputEvent(Object source) {
  35. this(source, null);
  36. }
  37. public MTInputEvent(Object source, IMTComponent3D target) {
  38. this(source, target, true);//FIXME?
  39. }
  40. /**
  41. * Instantiates a new mT input event.
  42. *
  43. * @param source the source
  44. * @param target the target component
  45. */
  46. public MTInputEvent(Object source, IMTComponent3D target, boolean bubbles) {
  47. super(source);
  48. this.target = target;
  49. this.propatationStopped = false;
  50. this.bubbles = bubbles;
  51. this.eventPhase = CAPTURING_PHASE; //FIXME?
  52. }
  53. /**
  54. * Gets the target of this input event.
  55. * <br><strong>NOTE:</strong> Not every event has a target component! To check this
  56. * we can call <code>event.hasTarget()</code>.
  57. *
  58. * @return the target component
  59. * @deprecated use getTarget() instead
  60. * @see #getTarget()
  61. */
  62. public IMTComponent3D getTargetComponent() {
  63. return target;
  64. }
  65. /**
  66. * Gets the target of this input event.
  67. * <br><strong>NOTE:</strong> Not every event has a target component! To check this
  68. * we can call <code>event.hasTarget()</code>.
  69. *
  70. * @return the target component
  71. */
  72. public IMTComponent3D getTarget() {
  73. return target;
  74. }
  75. /**
  76. * Sets the target component of this input event.
  77. * <br>NOTE: This is supposed to be called internally by
  78. * MT4j and not by users.
  79. *
  80. * @param targetComponent the new target component
  81. */
  82. public void setTarget(IMTComponent3D targetComponent) {
  83. this.target = targetComponent;
  84. }
  85. /**
  86. * Checks if this input event has a target component.
  87. *
  88. * @return true, if successful
  89. */
  90. public boolean hasTarget(){
  91. return this.target != null;
  92. }
  93. /**
  94. * This method is invoked right before the event is fired.
  95. * This can be used to do event specific actions if needed before firing.
  96. * <br>NOTE: this is called internally and should not be called by users!
  97. */
  98. public void onFired(){ }
  99. private short eventPhase;
  100. public static final short CAPTURING_PHASE = 1; // The current event phase is the capturing phase.
  101. public static final short AT_TARGET = 2; // The event is currently being evaluated at the target EventTarget.
  102. public static final short BUBBLING_PHASE = 3;// The current event phase is the bubbling phase.
  103. private boolean propatationStopped;
  104. private boolean bubbles;
  105. /**
  106. * The <code>setEventPhase</code> method is used by the DOM implementation
  107. * to change the value of a <code>eventPhase</code> attribute on the
  108. * <code>Event</code> interface.
  109. * @param phase Specifies the <code>eventPahse</code> attribute on the
  110. * <code>Event</code> interface.
  111. */
  112. public void setEventPhase(short phase){
  113. this.eventPhase = phase;
  114. }
  115. public short getEventPhase(){
  116. return this.eventPhase; //TODO set in constructor?
  117. }
  118. public void stopPropagation(){
  119. this.propatationStopped = true;
  120. }
  121. public boolean isPropagationStopped(){
  122. return propatationStopped;
  123. }
  124. public boolean getBubbles(){
  125. return bubbles;
  126. }
  127. private IMTComponent3D currentTarget;
  128. /**
  129. * The <code>setCurrentTarget</code> method is used by the DOM
  130. * implementation to change the value of a <code>currentTarget</code>
  131. * attribute on the <code>Event</code> interface.
  132. * @param target Specifies the <code>currentTarget</code> attribute on
  133. * the <code>Event</code> interface.
  134. */
  135. public void setCurrentTarget(IMTComponent3D target){
  136. this.currentTarget = target;
  137. }
  138. public IMTComponent3D getCurrentTarget(){
  139. return this.currentTarget;
  140. }
  141. }