Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

MouseEvents.java 7.1KB

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