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

http://mt4j.googlecode.com/ · Java · 232 lines · 74 code · 54 blank · 104 comment · 2 complexity · 0289f5825ca63ec267aff255d2df32d5 MD5 · raw file

  1. /***********************************************************************
  2. * mt4j Copyright (c) 2008 - 2009 C.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.inputSources.AbstractInputSource;
  21. import org.mt4j.util.math.Vector3D;
  22. /**
  23. * This event class is used for
  24. * input events that have position data associated with them. This applies
  25. * for mouse input, finger or fiducial input for example. Also associated
  26. * with this event is a InputMotion object, which contains information about the
  27. * input over time and is a container for all input events during this time.
  28. *
  29. * @author Christopher Ruff
  30. */
  31. public abstract class AbstractCursorInputEvt extends MTInputEvent {
  32. // public enum InputState{
  33. // INPUT_DETECTED,
  34. // INPUT_UPDATED,
  35. // INPUT_ENDED
  36. // }
  37. /** The Constant INPUT_DETECTED.
  38. * @deprecated use INPUT_STARTED instead
  39. * */
  40. public static final int INPUT_DETECTED = 0;
  41. public static final int INPUT_STARTED = 0;
  42. public static final int INPUT_UPDATED = 1;
  43. public static final int INPUT_ENDED = 2;
  44. /** The position x. */
  45. private float positionX;
  46. /** The position y. */
  47. private float positionY;
  48. /** The id. */
  49. private int id;
  50. /** The associated cursor. */
  51. private InputCursor associatedCursor;
  52. /**
  53. * Instantiates a new touch event.
  54. *
  55. * @param source the source
  56. * @param positionX the position x
  57. * @param positionY the position y
  58. * @param id the id
  59. * @param c the m
  60. */
  61. public AbstractCursorInputEvt(AbstractInputSource source, float positionX, float positionY, int id, InputCursor c) {
  62. super(source);
  63. this.id = id;
  64. this.positionX = positionX;
  65. this.positionY = positionY;
  66. this.associatedCursor = c;
  67. }
  68. /**
  69. * Instantiates a new touch event.
  70. *
  71. * @param source the source
  72. * @param positionX the position x
  73. * @param positionY the position y
  74. * @param id the id
  75. * @param m the m
  76. * @param target the target
  77. */
  78. public AbstractCursorInputEvt(AbstractInputSource source, IMTComponent3D target, float positionX, float positionY, int id, InputCursor m) {
  79. super(source, target);
  80. this.id = id;
  81. this.positionX = positionX;
  82. this.positionY = positionY;
  83. this.associatedCursor = m;
  84. }
  85. public void setId(int id){
  86. this.id = id;
  87. }
  88. /**
  89. * Gets the cursor.
  90. *
  91. * @return the cursor
  92. */
  93. public InputCursor getCursor() {
  94. return this.associatedCursor;
  95. }
  96. public void setCursor(InputCursor associatedcursor) {
  97. this.associatedCursor = associatedcursor;
  98. }
  99. /**
  100. * This method should be called before firing this event to the global input processors.
  101. * Here, the event is added to its cursor.
  102. */
  103. @Override
  104. public void onFired() {
  105. super.onFired();
  106. if (this.getCursor() != null){
  107. this.getCursor().addEvent(this);
  108. }else{
  109. // System.out.println("couldnt add event to cursor - cursor null");
  110. }
  111. }
  112. /**
  113. * Gets the position x.
  114. *
  115. * @return the position x
  116. * @deprecated use getScreenX()
  117. */
  118. public float getPosX() {
  119. return positionX;
  120. }
  121. /**
  122. * Gets the position y.
  123. *
  124. * @return the position y
  125. * @deprecated use getScreenY()
  126. */
  127. public float getPosY() {
  128. return positionY;
  129. }
  130. public float getX(){
  131. return this.positionX;
  132. }
  133. public float getY(){
  134. return this.positionY;
  135. }
  136. /**
  137. * Gets the position.
  138. *
  139. * @return the position
  140. */
  141. public Vector3D getPosition(){
  142. return new Vector3D(positionX, positionY, 0);
  143. }
  144. public void setScreenX(float positionX) {
  145. this.positionX = positionX;
  146. }
  147. public void setScreenY(float positionY) {
  148. this.positionY = positionY;
  149. }
  150. /**
  151. * Gets the id.
  152. *
  153. * @return the id
  154. */
  155. public int getId() {
  156. return id;
  157. }
  158. /* (non-Javadoc)
  159. * @see java.lang.Object#toString()
  160. */
  161. public String toString(){
  162. return super.toString() + "; " + " PosX: " + positionX + " PosY: " + positionY + " InputSource: " + this.getSource();
  163. }
  164. @Override
  165. abstract public Object clone() throws CloneNotSupportedException;
  166. /*
  167. abstract public Inputcursor<? extends MTConcretePositionEvt> getcursor();
  168. abstract public float getPositionX();
  169. abstract public float getPositionY();
  170. abstract public boolean isAddedTocursor();
  171. abstract public void setAddedTocursor(boolean addedTocursor);
  172. */
  173. }