package com.itmill.toolkit.ui;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Map;
private boolean hideOnMouseOut;
private final ArrayList<Component> componentList;
+ private static final Method POPUP_VISIBILITY_METHOD;
+ static {
+ try {
+ POPUP_VISIBILITY_METHOD = PopupVisibilityListener.class
+ .getDeclaredMethod("popupVisibilityChange",
+ new Class[] { PopupVisibilityEvent.class });
+ } catch (final java.lang.NoSuchMethodException e) {
+ // This should never happen
+ throw new java.lang.RuntimeException(
+ "Internal error finding methods in PopupView");
+ }
+ }
+
/* Constructors */
/**
public void changeVariables(Object source, Map variables) {
if (variables.containsKey("popupVisibility")) {
+ boolean oldVisibility = popupVisible;
popupVisible = ((Boolean) variables.get("popupVisibility"))
.booleanValue();
super.removeComponent(componentList.get(0));
componentList.clear();
}
+ if (oldVisibility != popupVisible) {
+ fireEvent(new PopupVisibilityEvent(this));
+ }
requestRepaint();
}
}
*/
public Component getPopupComponent();
}
+
+ /**
+ * Add a listener that is called whenever the visibility of the popup is
+ * changed.
+ *
+ * @param listener
+ * the listener to add
+ * @see PopupVisibilityListener
+ * @see PopupVisibilityEvent
+ * @see #removeListener(PopupVisibilityListener)
+ *
+ */
+ public void addListener(PopupVisibilityListener listener) {
+ addListener(PopupVisibilityEvent.class, listener,
+ POPUP_VISIBILITY_METHOD);
+ }
+
+ /**
+ * Removes a previously added listener, so that it no longer receives events
+ * when the visibility of the popup changes.
+ *
+ * @param listener
+ * the listener to remove
+ * @see PopupVisibilityListener
+ * @see #addListener(PopupVisibilityListener)
+ */
+ public void removeListener(PopupVisibilityListener listener) {
+ removeListener(PopupVisibilityEvent.class, listener,
+ POPUP_VISIBILITY_METHOD);
+ }
+
+ /**
+ * This event is received by the PopupVisibilityListeners when the
+ * visibility of the popup changes. You can get the new visibility directly
+ * with {@link #isPopupVisible()}, or get the PopupView that produced the
+ * event with {@link #getPopupView()}.
+ *
+ */
+ public class PopupVisibilityEvent extends Event {
+ /**
+ * Serial generated by eclipse.
+ */
+ private static final long serialVersionUID = -130167162207143457L;
+
+ public PopupVisibilityEvent(PopupView source) {
+ super(source);
+ }
+
+ /**
+ * Get the PopupView instance that is the source of this event.
+ *
+ * @return the source PopupView
+ */
+ public PopupView getPopupView() {
+ return (PopupView) getSource();
+ }
+
+ /**
+ * Returns the current visibility of the popup.
+ *
+ * @return true if the popup is visible
+ */
+ public boolean isPopupVisible() {
+ return getPopupView().isPopupVisible();
+ }
+ }
+
+ /**
+ * Defines a listener that can receive a PopupVisibilityEvent when the
+ * visibility of the popup changes.
+ *
+ */
+ public interface PopupVisibilityListener {
+ /**
+ * Pass to {@link PopupView#PopupVisibilityEvent} to start listening for
+ * popup visibility changes.
+ *
+ * @param event
+ * the event
+ *
+ * @see {@link PopupVisibilityEvent}
+ * @see {@link PopupView#addListener(PopupVisibilityListener)}
+ */
+ public void popupVisibilityChange(PopupVisibilityEvent event);
+ }
}