You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FieldEvents.java 8.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. /*
  2. @VaadinApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.event;
  5. import java.io.Serializable;
  6. import java.lang.reflect.Method;
  7. import com.vaadin.terminal.gwt.client.EventId;
  8. import com.vaadin.tools.ReflectTools;
  9. import com.vaadin.ui.Component;
  10. import com.vaadin.ui.Field;
  11. import com.vaadin.ui.Field.ValueChangeEvent;
  12. import com.vaadin.ui.TextField;
  13. /**
  14. * Interface that serves as a wrapper for {@link Field} related events.
  15. */
  16. public interface FieldEvents {
  17. /**
  18. * The interface for adding and removing <code>FocusEvent</code> listeners.
  19. * By implementing this interface a class explicitly announces that it will
  20. * generate a <code>FocusEvent</code> when it receives keyboard focus.
  21. * <p>
  22. * Note: The general Java convention is not to explicitly declare that a
  23. * class generates events, but to directly define the
  24. * <code>addListener</code> and <code>removeListener</code> methods. That
  25. * way the caller of these methods has no real way of finding out if the
  26. * class really will send the events, or if it just defines the methods to
  27. * be able to implement an interface.
  28. * </p>
  29. *
  30. * @since 6.2
  31. * @see FocusListener
  32. * @see FocusEvent
  33. */
  34. public interface FocusNotifier extends Serializable {
  35. /**
  36. * Adds a <code>FocusListener</code> to the Component which gets fired
  37. * when a <code>Field</code> receives keyboard focus.
  38. *
  39. * @param listener
  40. * @see FocusListener
  41. * @since 6.2
  42. */
  43. public void addListener(FocusListener listener);
  44. /**
  45. * Removes a <code>FocusListener</code> from the Component.
  46. *
  47. * @param listener
  48. * @see FocusListener
  49. * @since 6.2
  50. */
  51. public void removeListener(FocusListener listener);
  52. }
  53. /**
  54. * The interface for adding and removing <code>BlurEvent</code> listeners.
  55. * By implementing this interface a class explicitly announces that it will
  56. * generate a <code>BlurEvent</code> when it loses keyboard focus.
  57. * <p>
  58. * Note: The general Java convention is not to explicitly declare that a
  59. * class generates events, but to directly define the
  60. * <code>addListener</code> and <code>removeListener</code> methods. That
  61. * way the caller of these methods has no real way of finding out if the
  62. * class really will send the events, or if it just defines the methods to
  63. * be able to implement an interface.
  64. * </p>
  65. *
  66. * @since 6.2
  67. * @see BlurListener
  68. * @see BlurEvent
  69. */
  70. public interface BlurNotifier extends Serializable {
  71. /**
  72. * Adds a <code>BlurListener</code> to the Component which gets fired
  73. * when a <code>Field</code> loses keyboard focus.
  74. *
  75. * @param listener
  76. * @see BlurListener
  77. * @since 6.2
  78. */
  79. public void addListener(BlurListener listener);
  80. /**
  81. * Removes a <code>BlurListener</code> from the Component.
  82. *
  83. * @param listener
  84. * @see BlurListener
  85. * @since 6.2
  86. */
  87. public void removeListener(BlurListener listener);
  88. }
  89. /**
  90. * <code>FocusEvent</code> class for holding additional event information.
  91. * Fired when a <code>Field</code> receives keyboard focus.
  92. *
  93. * @since 6.2
  94. */
  95. @SuppressWarnings("serial")
  96. public class FocusEvent extends Component.Event {
  97. /**
  98. * Identifier for event that can be used in {@link EventRouter}
  99. */
  100. public static final String EVENT_ID = EventId.FOCUS;
  101. public FocusEvent(Component source) {
  102. super(source);
  103. }
  104. }
  105. /**
  106. * <code>FocusListener</code> interface for listening for
  107. * <code>FocusEvent</code> fired by a <code>Field</code>.
  108. *
  109. * @see FocusEvent
  110. * @since 6.2
  111. */
  112. public interface FocusListener extends ComponentEventListener {
  113. public static final Method focusMethod = ReflectTools.findMethod(
  114. FocusListener.class, "focus", FocusEvent.class);
  115. /**
  116. * Component has been focused
  117. *
  118. * @param event
  119. * Component focus event.
  120. */
  121. public void focus(FocusEvent event);
  122. }
  123. /**
  124. * <code>BlurEvent</code> class for holding additional event information.
  125. * Fired when a <code>Field</code> loses keyboard focus.
  126. *
  127. * @since 6.2
  128. */
  129. @SuppressWarnings("serial")
  130. public class BlurEvent extends Component.Event {
  131. /**
  132. * Identifier for event that can be used in {@link EventRouter}
  133. */
  134. public static final String EVENT_ID = EventId.BLUR;
  135. public BlurEvent(Component source) {
  136. super(source);
  137. }
  138. }
  139. /**
  140. * <code>BlurListener</code> interface for listening for
  141. * <code>BlurEvent</code> fired by a <code>Field</code>.
  142. *
  143. * @see BlurEvent
  144. * @since 6.2
  145. */
  146. public interface BlurListener extends ComponentEventListener {
  147. public static final Method blurMethod = ReflectTools.findMethod(
  148. BlurListener.class, "blur", BlurEvent.class);
  149. /**
  150. * Component has been blurred
  151. *
  152. * @param event
  153. * Component blur event.
  154. */
  155. public void blur(BlurEvent event);
  156. }
  157. /**
  158. * TextChangeEvents are fired when the user is editing the text content of a
  159. * field. Most commonly text change events are triggered by typing text with
  160. * keyboard, but e.g. pasting content from clip board to a text field also
  161. * triggers an event.
  162. * <p>
  163. * TextChangeEvents differ from {@link ValueChangeEvent}s so that they are
  164. * triggered repeatedly while the end user is filling the field.
  165. * ValueChangeEvents are not fired until the user for example hits enter or
  166. * focuses another field. Also note the difference that TextChangeEvents are
  167. * only fired if the change is triggered from the user, while
  168. * ValueChangeEvents are also fired if the field value is set by the
  169. * application code.
  170. * <p>
  171. * The {@link TextChangeNotifier}s implementation may decide when exactly
  172. * TextChangeEvents are fired. TextChangeEvents are not necessary fire for
  173. * example on each key press, but buffered with a small delay. The
  174. * {@link TextField} component supports different modes for triggering
  175. * TextChangeEvents.
  176. *
  177. * @see TextChangeListener
  178. * @see TextChangeNotifier
  179. * @see TextField#setTextChangeEventMode(com.vaadin.ui.TextField.TextChangeEventMode)
  180. * @since 6.5
  181. */
  182. public static abstract class TextChangeEvent extends Component.Event {
  183. public TextChangeEvent(Component source) {
  184. super(source);
  185. }
  186. /**
  187. * @return the text content of the field after the
  188. * {@link TextChangeEvent}
  189. */
  190. public abstract String getText();
  191. /**
  192. * @return the cursor position during after the {@link TextChangeEvent}
  193. */
  194. public abstract int getCursorPosition();
  195. }
  196. /**
  197. * A listener for {@link TextChangeEvent}s.
  198. *
  199. * @since 6.5
  200. */
  201. public interface TextChangeListener extends ComponentEventListener {
  202. public static String EVENT_ID = "ie";
  203. public static Method EVENT_METHOD = ReflectTools.findMethod(
  204. TextChangeListener.class, "textChange", TextChangeEvent.class);
  205. /**
  206. * This method is called repeatedly while the text is edited by a user.
  207. *
  208. * @param event
  209. * the event providing details of the text change
  210. */
  211. public void textChange(TextChangeEvent event);
  212. }
  213. /**
  214. * An interface implemented by a {@link Field} supporting
  215. * {@link TextChangeEvent}s. An example a {@link TextField} supports
  216. * {@link TextChangeListener}s.
  217. */
  218. public interface TextChangeNotifier extends Serializable {
  219. public void addListener(TextChangeListener listener);
  220. public void removeListener(TextChangeListener listener);
  221. }
  222. }