From 26d228c3ba20d09cb38d14e6682fd2d00626cc7b Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Thu, 26 Nov 2009 15:20:11 +0000 Subject: [PATCH] Patch that fixes #3772 - Add notifier interfaces for focus and blur events svn changeset:10079/svn branch:6.2 --- src/com/vaadin/event/FieldEvents.java | 74 +++++++++++++++++++++++++++ src/com/vaadin/ui/TextField.java | 24 ++------- 2 files changed, 77 insertions(+), 21 deletions(-) diff --git a/src/com/vaadin/event/FieldEvents.java b/src/com/vaadin/event/FieldEvents.java index fc9f225b8f..b298590a8c 100644 --- a/src/com/vaadin/event/FieldEvents.java +++ b/src/com/vaadin/event/FieldEvents.java @@ -11,6 +11,80 @@ import com.vaadin.ui.Component; public interface FieldEvents { + /** + * The interface for adding and removing FocusEvent listeners. + * By implementing this interface a class explicitly announces that it will + * generate a FocusEvent when it receives keyboard focus. + *

+ * Note: The general Java convention is not to explicitly declare that a + * class generates events, but to directly define the + * addListener and removeListener methods. That + * way the caller of these methods has no real way of finding out if the + * class really will send the events, or if it just defines the methods to + * be able to implement an interface. + *

+ * @since 6.2 + * @see FocusListener + * @see FocusEvent + */ + public interface FocusNotifier { + /** + * Adds a FocusListener to the Component which gets fired + * when a Field receives keyboard focus. + * + * @param listener + * @see FocusListener + * @since 6.2 + */ + public void addListener(FocusListener listener); + + /** + * Removes a FocusListener from the Component. + * + * @param listener + * @see FocusListener + * @since 6.2 + */ + public void removeListener(FocusListener listener); + } + + /** + * The interface for adding and removing BlurEvent listeners. + * By implementing this interface a class explicitly announces that it will + * generate a BlurEvent when it loses keyboard focus. + *

+ * Note: The general Java convention is not to explicitly declare that a + * class generates events, but to directly define the + * addListener and removeListener methods. That + * way the caller of these methods has no real way of finding out if the + * class really will send the events, or if it just defines the methods to + * be able to implement an interface. + *

+ * @since 6.2 + * @see BlurListener + * @see BlurEvent + */ + public interface BlurNotifier { + /** + * Adds a BlurListener to the Component which gets fired + * when a Field loses keyboard focus. + * + * @param listener + * @see BlurListener + * @since 6.2 + */ + public void addListener(BlurListener listener); + + /** + * Removes a BlurListener from the Component. + * + * @param listener + * @see BlurListener + * @since 6.2 + */ + public void removeListener(BlurListener listener); + } + /** * FocusEvent class for holding additional event information. * Fired when a Field receives keyboard focus. diff --git a/src/com/vaadin/ui/TextField.java b/src/com/vaadin/ui/TextField.java index 59cf6640ce..aa7923ed8b 100644 --- a/src/com/vaadin/ui/TextField.java +++ b/src/com/vaadin/ui/TextField.java @@ -8,6 +8,7 @@ import java.text.Format; import java.util.Map; import com.vaadin.data.Property; +import com.vaadin.event.FieldEvents; import com.vaadin.event.FieldEvents.BlurEvent; import com.vaadin.event.FieldEvents.BlurListener; import com.vaadin.event.FieldEvents.FocusEvent; @@ -38,7 +39,8 @@ import com.vaadin.terminal.gwt.client.ui.VTextField; */ @SuppressWarnings("serial") @ClientWidget(VTextField.class) -public class TextField extends AbstractField { +public class TextField extends AbstractField implements + FieldEvents.BlurNotifier, FieldEvents.FocusNotifier { /* Private members */ @@ -624,40 +626,20 @@ public class TextField extends AbstractField { fireEvent(new BlurEvent(this)); } - /** - * TODO - * - * @param listener - */ public void addListener(FocusListener listener) { addListener(FOCUS_EVENT, FocusEvent.class, listener, FocusListener.focusMethod); } - /** - * TODO - * - * @param listener - */ public void removeListener(FocusListener listener) { removeListener(FOCUS_EVENT, FocusEvent.class, listener); } - /** - * TODO - * - * @param listener - */ public void addListener(BlurListener listener) { addListener(BLUR_EVENT, BlurEvent.class, listener, BlurListener.blurMethod); } - /** - * TODO - * - * @param listener - */ public void removeListener(BlurListener listener) { removeListener(BLUR_EVENT, BlurEvent.class, listener); } -- 2.39.5