]> source.dussan.org Git - vaadin-framework.git/commitdiff
Added a switch for hiding the popup on mouse out
authorRisto Yrjänä <risto.yrjana@itmill.com>
Wed, 12 Nov 2008 12:30:56 +0000 (12:30 +0000)
committerRisto Yrjänä <risto.yrjana@itmill.com>
Wed, 12 Nov 2008 12:30:56 +0000 (12:30 +0000)
svn changeset:5878/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/IPopupView.java
src/com/itmill/toolkit/ui/PopupView.java

index 633dc82a81dc010c6de2cd91f5e2534a650a9e63..640d4dafc65c9a9d33ee5f526cf096fd2cca19b9 100644 (file)
@@ -103,6 +103,10 @@ public class IPopupView extends HTML implements Paintable {
             setTitle(uidl.getStringAttribute("description"));
         }
 
+        if (uidl.hasAttribute("hideOnMouseOut")) {
+            popup.setHideOnMouseOut(uidl.getBooleanAttribute("hideOnMouseOut"));
+        }
+
         // Render the popup if visible and show it.
         if (hostPopupVisible) {
             UIDL popupUIDL = uidl.getChildUIDL(0);
@@ -171,30 +175,7 @@ public class IPopupView extends HTML implements Paintable {
      * @param host
      *            the widget to draw the popup on
      */
-    // private void showPopupOnTop(final CustomPopup popup, final Widget host) {
-    // popup.setPopupPositionAndShow(new PopupPanel.PositionCallback() {
-    // public void setPosition(int offsetWidth, int offsetHeight) {
-    // int hostHorizontalCenter = host.getAbsoluteLeft()
-    // + host.getOffsetWidth() / 2;
-    // int hostVerticalCenter = host.getAbsoluteTop()
-    // + host.getOffsetHeight() / 2;
-    //
-    // int left = hostHorizontalCenter - offsetWidth / 2;
-    // int top = hostVerticalCenter - offsetHeight / 2;
-    //
-    // // Superclass takes care of top and left
-    // if ((left + offsetWidth) > windowRight) {
-    // left -= (left + offsetWidth) - windowRight;
-    // }
-    //
-    // if ((top + offsetHeight) > windowBottom) {
-    // top -= (top + offsetHeight) - windowBottom;
-    // }
-    //
-    // popup.setPopupPosition(left, top);
-    // }
-    // });
-    // }
+
     public void updateWindowSize() {
         windowTop = RootPanel.get().getAbsoluteTop();
         windowLeft = RootPanel.get().getAbsoluteLeft();
@@ -216,6 +197,7 @@ public class IPopupView extends HTML implements Paintable {
         private ICaptionWrapper captionWrapper = null;
 
         private boolean hasHadMouseOver = false;
+        private boolean hideOnMouseOut = true;
         private final Set<Element> activeChildren;
 
         public CustomPopup() {
@@ -242,9 +224,9 @@ public class IPopupView extends HTML implements Paintable {
             }
 
             if (!eventTargetsPopup & type == Event.ONMOUSEMOVE) {
-                if (hasHadMouseOver) {
+
+                if (hasHadMouseOver && hideOnMouseOut) {
                     hide();
-                    hasHadMouseOver = false;
                     return true;
                 }
             }
@@ -265,6 +247,7 @@ public class IPopupView extends HTML implements Paintable {
             }
             activeChildren.clear();
             remove(popupComponentWidget);
+            hasHadMouseOver = false;
             super.hide();
         }
 
@@ -353,6 +336,14 @@ public class IPopupView extends HTML implements Paintable {
             return new RenderSpace(windowRight, windowBottom);
         }
 
+        public boolean isHideOnMouseOut() {
+            return hideOnMouseOut;
+        }
+
+        public void setHideOnMouseOut(boolean hideOnMouseOut) {
+            this.hideOnMouseOut = hideOnMouseOut;
+        }
+
     }// class CustomPopup
 
 }// class IPopupView
index 0eb4049c8606e6c23aa75719df2e8733111e75a8..99c29902d400a7f8b5bfb8ed8b24c985c12dbc9b 100644 (file)
@@ -20,6 +20,7 @@ public class PopupView extends AbstractComponentContainer {
 
     private Content content;
     private boolean popupVisible;
+    private boolean hideOnMouseOut;
     private final ArrayList<Component> componentList;
 
     /* Constructors */
@@ -57,6 +58,7 @@ public class PopupView extends AbstractComponentContainer {
     public PopupView(PopupView.Content content) {
         super();
         popupVisible = false;
+        hideOnMouseOut = true;
         componentList = new ArrayList<Component>(1);
         setContent(content);
     }
@@ -101,6 +103,28 @@ public class PopupView extends AbstractComponentContainer {
         return popupVisible;
     }
 
+    /**
+     * Check if this popup will be hidden when the user takes the mouse cursor
+     * out of the popup area.
+     * 
+     * @return true if the popup is hidden on mouse out, false otherwise
+     */
+    public boolean isHideOnMouseOut() {
+        return hideOnMouseOut;
+    }
+
+    /**
+     * Should the popup automaticly hide when the user takes the mouse cursor
+     * out of the popup area? If this is false, the user must click outside the
+     * popup to close it. The default is true.
+     * 
+     * @param hideOnMouseOut
+     * 
+     */
+    public void setHideOnMouseOut(boolean hideOnMouseOut) {
+        this.hideOnMouseOut = hideOnMouseOut;
+    }
+
     /*
      * Methods inherited from AbstractComponentContainer. These are unnecessary
      * (but mandatory). Most of them are not supported in this implementation.
@@ -199,6 +223,7 @@ public class PopupView extends AbstractComponentContainer {
                     "Recieved null when trying to paint minimized value.");
         }
         target.addAttribute("html", content.getMinimizedValueAsHTML());
+        target.addAttribute("hideOnMouseOut", hideOnMouseOut);
 
         // Only paint component to client if we know that the popup is showing
         if (popupVisible) {