/src/org/mt4j/input/inputData/MTInputEvent.java
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 ***********************************************************************/ 18package org.mt4j.input.inputData; 19 20import org.mt4j.components.interfaces.IMTComponent3D; 21import org.mt4j.input.MTEvent; 22 23/** 24 * The Class MTInputEvent. The base class for all input events. 25 * 26 * @author Christopher Ruff 27 */ 28public class MTInputEvent extends MTEvent { 29 30 /** The target component. */ 31 private IMTComponent3D target; 32 33 34 /** 35 * Instantiates a new mT input event. 36 * 37 * @param source the source 38 */ 39 public MTInputEvent(Object source) { 40 this(source, null); 41 } 42 43 public MTInputEvent(Object source, IMTComponent3D target) { 44 this(source, target, true);//FIXME? 45 } 46 47 /** 48 * Instantiates a new mT input event. 49 * 50 * @param source the source 51 * @param target the target component 52 */ 53 public MTInputEvent(Object source, IMTComponent3D target, boolean bubbles) { 54 super(source); 55 this.target = target; 56 this.propatationStopped = false; 57 this.bubbles = bubbles; 58 this.eventPhase = CAPTURING_PHASE; //FIXME? 59 } 60 61 62 63 /** 64 * Gets the target of this input event. 65 * <br><strong>NOTE:</strong> Not every event has a target component! To check this 66 * we can call <code>event.hasTarget()</code>. 67 * 68 * @return the target component 69 * @deprecated use getTarget() instead 70 * @see #getTarget() 71 */ 72 public IMTComponent3D getTargetComponent() { 73 return target; 74 } 75 76 77 /** 78 * Gets the target of this input event. 79 * <br><strong>NOTE:</strong> Not every event has a target component! To check this 80 * we can call <code>event.hasTarget()</code>. 81 * 82 * @return the target component 83 */ 84 public IMTComponent3D getTarget() { 85 return target; 86 } 87 88 /** 89 * Sets the target component of this input event. 90 * <br>NOTE: This is supposed to be called internally by 91 * MT4j and not by users. 92 * 93 * @param targetComponent the new target component 94 */ 95 public void setTarget(IMTComponent3D targetComponent) { 96 this.target = targetComponent; 97 } 98 99 /** 100 * Checks if this input event has a target component. 101 * 102 * @return true, if successful 103 */ 104 public boolean hasTarget(){ 105 return this.target != null; 106 } 107 108 /** 109 * This method is invoked right before the event is fired. 110 * This can be used to do event specific actions if needed before firing. 111 * <br>NOTE: this is called internally and should not be called by users! 112 */ 113 public void onFired(){ } 114 115 116 117 private short eventPhase; 118 public static final short CAPTURING_PHASE = 1; // The current event phase is the capturing phase. 119 public static final short AT_TARGET = 2; // The event is currently being evaluated at the target EventTarget. 120 public static final short BUBBLING_PHASE = 3;// The current event phase is the bubbling phase. 121 122 123 private boolean propatationStopped; 124 private boolean bubbles; 125 /** 126 * The <code>setEventPhase</code> method is used by the DOM implementation 127 * to change the value of a <code>eventPhase</code> attribute on the 128 * <code>Event</code> interface. 129 * @param phase Specifies the <code>eventPahse</code> attribute on the 130 * <code>Event</code> interface. 131 */ 132 public void setEventPhase(short phase){ 133 this.eventPhase = phase; 134 } 135 136 public short getEventPhase(){ 137 return this.eventPhase; //TODO set in constructor? 138 } 139 140 141 public void stopPropagation(){ 142 this.propatationStopped = true; 143 } 144 145 public boolean isPropagationStopped(){ 146 return propatationStopped; 147 } 148 149 public boolean getBubbles(){ 150 return bubbles; 151 } 152 153 154 private IMTComponent3D currentTarget; 155 /** 156 * The <code>setCurrentTarget</code> method is used by the DOM 157 * implementation to change the value of a <code>currentTarget</code> 158 * attribute on the <code>Event</code> interface. 159 * @param target Specifies the <code>currentTarget</code> attribute on 160 * the <code>Event</code> interface. 161 */ 162 public void setCurrentTarget(IMTComponent3D target){ 163 this.currentTarget = target; 164 } 165 166 public IMTComponent3D getCurrentTarget(){ 167 return this.currentTarget; 168 } 169 170 171}