Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

MouseEvents.java 7.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.event;
  5. import java.lang.reflect.Method;
  6. import com.vaadin.event.MouseEvents.ClickListener;
  7. import com.vaadin.terminal.gwt.client.MouseEventDetails;
  8. import com.vaadin.tools.ReflectTools;
  9. import com.vaadin.ui.Component;
  10. /**
  11. * Interface that serves as a wrapper for mouse related events.
  12. *
  13. * @author IT Mill Ltd.
  14. * @see ClickListener
  15. * @version
  16. * @VERSION@
  17. * @since 6.2
  18. */
  19. public interface MouseEvents {
  20. /**
  21. * Class for holding information about a mouse click event. A
  22. * {@link ClickEvent} is fired when the user clicks on a
  23. * <code>Component</code>.
  24. *
  25. * The information available for click events are terminal dependent.
  26. * Correct values for all event details cannot be guaranteed.
  27. *
  28. * @author IT Mill Ltd.
  29. * @see ClickListener
  30. * @version
  31. * @VERSION@
  32. * @since 6.2
  33. */
  34. public class ClickEvent extends Component.Event {
  35. public static final int BUTTON_LEFT = MouseEventDetails.BUTTON_LEFT;
  36. public static final int BUTTON_MIDDLE = MouseEventDetails.BUTTON_MIDDLE;
  37. public static final int BUTTON_RIGHT = MouseEventDetails.BUTTON_RIGHT;
  38. private MouseEventDetails details;
  39. public ClickEvent(Component source, MouseEventDetails mouseEventDetails) {
  40. super(source);
  41. details = mouseEventDetails;
  42. }
  43. /**
  44. * Returns an identifier describing which mouse button the user pushed.
  45. * Compare with {@link #BUTTON_LEFT},{@link #BUTTON_MIDDLE},
  46. * {@link #BUTTON_RIGHT} to find out which butten it is.
  47. *
  48. * @return one of {@link #BUTTON_LEFT}, {@link #BUTTON_MIDDLE},
  49. * {@link #BUTTON_RIGHT}.
  50. */
  51. public int getButton() {
  52. return details.getButton();
  53. }
  54. /**
  55. * Returns the mouse position (x coordinate) when the click took place.
  56. * The position is relative to the browser client area.
  57. *
  58. * @return The mouse cursor x position
  59. */
  60. public int getClientX() {
  61. return details.getClientX();
  62. }
  63. /**
  64. * Returns the mouse position (y coordinate) when the click took place.
  65. * The position is relative to the browser client area.
  66. *
  67. * @return The mouse cursor y position
  68. */
  69. public int getClientY() {
  70. return details.getClientY();
  71. }
  72. /**
  73. * Returns the relative mouse position (x coordinate) when the click
  74. * took place. The position is relative to the clicked component.
  75. *
  76. * @return The mouse cursor x position relative to the clicked layout
  77. * component or -1 if no x coordinate available
  78. */
  79. public int getRelativeX() {
  80. return details.getRelativeX();
  81. }
  82. /**
  83. * Returns the relative mouse position (y coordinate) when the click
  84. * took place. The position is relative to the clicked component.
  85. *
  86. * @return The mouse cursor y position relative to the clicked layout
  87. * component or -1 if no y coordinate available
  88. */
  89. public int getRelativeY() {
  90. return details.getRelativeY();
  91. }
  92. /**
  93. * Checks if the event is a double click event.
  94. *
  95. * @return true if the event is a double click event, false otherwise
  96. */
  97. public boolean isDoubleClick() {
  98. return details.isDoubleClick();
  99. }
  100. /**
  101. * Checks if the Alt key was down when the mouse event took place.
  102. *
  103. * @return true if Alt was down when the event occured, false otherwise
  104. */
  105. public boolean isAltKey() {
  106. return details.isAltKey();
  107. }
  108. /**
  109. * Checks if the Ctrl key was down when the mouse event took place.
  110. *
  111. * @return true if Ctrl was pressed when the event occured, false
  112. * otherwise
  113. */
  114. public boolean isCtrlKey() {
  115. return details.isCtrlKey();
  116. }
  117. /**
  118. * Checks if the Meta key was down when the mouse event took place.
  119. *
  120. * @return true if Meta was pressed when the event occured, false
  121. * otherwise
  122. */
  123. public boolean isMetaKey() {
  124. return details.isMetaKey();
  125. }
  126. /**
  127. * Checks if the Shift key was down when the mouse event took place.
  128. *
  129. * @return true if Shift was pressed when the event occured, false
  130. * otherwise
  131. */
  132. public boolean isShiftKey() {
  133. return details.isShiftKey();
  134. }
  135. /**
  136. * Returns a human readable string representing which button has been
  137. * pushed. This is meant for debug purposes only and the string returned
  138. * could change. Use {@link #getButton()} to check which button was
  139. * pressed.
  140. *
  141. * @since 6.3
  142. * @return A string representation of which button was pushed.
  143. */
  144. public String getButtonName() {
  145. return details.getButtonName();
  146. }
  147. }
  148. /**
  149. * Interface for listening for a {@link ClickEvent} fired by a
  150. * {@link Component}.
  151. *
  152. * @see ClickEvent
  153. * @author IT Mill Ltd.
  154. * @version
  155. * @VERSION@
  156. * @since 6.2
  157. */
  158. public interface ClickListener extends ComponentEventListener {
  159. public static final Method clickMethod = ReflectTools.findMethod(
  160. ClickListener.class, "click", ClickEvent.class);
  161. /**
  162. * Called when a {@link Component} has been clicked. A reference to the
  163. * component is given by {@link ClickEvent#getComponent()}.
  164. *
  165. * @param event
  166. * An event containing information about the click.
  167. */
  168. public void click(ClickEvent event);
  169. }
  170. /**
  171. * Class for holding additional event information for DoubleClick events.
  172. * Fired when the user double-clicks on a <code>Component</code>.
  173. *
  174. * @see ClickEvent
  175. * @author IT Mill Ltd.
  176. * @version
  177. * @VERSION@
  178. * @since 6.2
  179. */
  180. public class DoubleClickEvent extends Component.Event {
  181. public DoubleClickEvent(Component source) {
  182. super(source);
  183. }
  184. }
  185. /**
  186. * Interface for listening for a {@link DoubleClickEvent} fired by a
  187. * {@link Component}.
  188. *
  189. * @see DoubleClickEvent
  190. * @author IT Mill Ltd.
  191. * @version
  192. * @VERSION@
  193. * @since 6.2
  194. */
  195. public interface DoubleClickListener extends ComponentEventListener {
  196. public static final Method doubleClickMethod = ReflectTools.findMethod(
  197. DoubleClickListener.class, "doubleClick",
  198. DoubleClickEvent.class);
  199. /**
  200. * Called when a {@link Component} has been double clicked. A reference
  201. * to the component is given by {@link DoubleClickEvent#getComponent()}.
  202. *
  203. * @param event
  204. * An event containing information about the double click.
  205. */
  206. public void doubleClick(DoubleClickEvent event);
  207. }
  208. }