]> source.dussan.org Git - vaadin-framework.git/commitdiff
Adds mouse event details to Button.ClickEvent #6605
authorJohn Alhroos <john.ahlroos@itmill.com>
Thu, 10 Mar 2011 08:36:33 +0000 (08:36 +0000)
committerJohn Alhroos <john.ahlroos@itmill.com>
Thu, 10 Mar 2011 08:36:33 +0000 (08:36 +0000)
svn changeset:17697/svn branch:6.5

src/com/vaadin/terminal/gwt/client/ui/VButton.java
src/com/vaadin/ui/Button.java

index 5a5eb0eda6ebe254b1db93e1d47600cef7844834..49aa520df1a76fef4389cddf70c718db51b768ea 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
 @ITMillApache2LicenseForJavaFiles@
  */
 
@@ -23,6 +23,7 @@ import com.vaadin.terminal.gwt.client.ApplicationConnection;
 import com.vaadin.terminal.gwt.client.BrowserInfo;
 import com.vaadin.terminal.gwt.client.EventHelper;
 import com.vaadin.terminal.gwt.client.EventId;
+import com.vaadin.terminal.gwt.client.MouseEventDetails;
 import com.vaadin.terminal.gwt.client.Paintable;
 import com.vaadin.terminal.gwt.client.UIDL;
 import com.vaadin.terminal.gwt.client.Util;
@@ -353,7 +354,12 @@ public class VButton extends FocusWidget implements Paintable, ClickHandler,
         if (BrowserInfo.get().isSafari()) {
             VButton.this.setFocus(true);
         }
-        client.updateVariable(id, "state", true, true);
+        client.updateVariable(id, "state", true, false);
+
+        // Add mouse details
+        MouseEventDetails details = new MouseEventDetails(
+                event.getNativeEvent());
+        client.updateVariable(id, "mousedetails", details.serialize(), true);
 
         clickPending = false;
     }
index cf354750a8f98a042e264cdb1d22c66ed265c226..22ab0a62a3682028191cc3d0922a4cc38ee307bc 100644 (file)
@@ -1,4 +1,4 @@
-/* 
+/*
 @ITMillApache2LicenseForJavaFiles@
  */
 
@@ -21,6 +21,7 @@ import com.vaadin.event.ShortcutAction.ModifierKey;
 import com.vaadin.event.ShortcutListener;
 import com.vaadin.terminal.PaintException;
 import com.vaadin.terminal.PaintTarget;
+import com.vaadin.terminal.gwt.client.MouseEventDetails;
 import com.vaadin.terminal.gwt.client.ui.VButton;
 import com.vaadin.ui.ClientWidget.LoadStyle;
 import com.vaadin.ui.themes.BaseTheme;
@@ -42,6 +43,9 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier,
 
     boolean switchMode = false;
 
+    /* Last mouse details from the last click event */
+    private MouseEventDetails mouseDetails;
+
     /**
      * Creates a new push button. The value of the push button is false and it
      * is immediate by default.
@@ -168,6 +172,12 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier,
             final Boolean newValue = (Boolean) variables.get("state");
             final Boolean oldValue = (Boolean) getValue();
 
+            // Handle mouse details
+            if (variables.containsKey("mousedetails")) {
+                mouseDetails = MouseEventDetails.deSerialize((String) variables
+                        .get("mousedetails"));
+            }
+
             if (isSwitchMode()) {
 
                 // For switch button, the event is only sent if the
@@ -300,6 +310,8 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier,
      */
     public class ClickEvent extends Component.Event {
 
+        private MouseEventDetails details;
+
         /**
          * New instance of text change event.
          * 
@@ -310,6 +322,19 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier,
             super(source);
         }
 
+        /**
+         * Event which is trigged when the button was clicked
+         * 
+         * @param source
+         *      The Component that triggered the event
+         * @param details
+         *      Additional details about the mouse event
+         */
+        public ClickEvent(Component source, MouseEventDetails details) {
+            super(source);
+            this.details = details;
+        }
+
         /**
          * Gets the Button where the event occurred.
          * 
@@ -318,6 +343,57 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier,
         public Button getButton() {
             return (Button) getSource();
         }
+
+        /**
+         * Checks if the Alt key was down when the mouse event took place.
+         * 
+         * @return true if Alt was down when the event occured, false otherwise
+         */
+        public boolean isAltKey() {
+            if (details != null) {
+                return details.isAltKey();
+            }
+            return false;
+        }
+
+        /**
+         * Checks if the Ctrl key was down when the mouse event took place.
+         * 
+         * @return true if Ctrl was pressed when the event occured, false
+         *         otherwise
+         */
+        public boolean isCtrlKey() {
+            if (details != null) {
+                return details.isCtrlKey();
+            }
+            return false;
+        }
+
+        /**
+         * Checks if the Meta key was down when the mouse event took place.
+         * 
+         * @return true if Meta was pressed when the event occured, false
+         *         otherwise
+         */
+        public boolean isMetaKey() {
+            if (details != null) {
+                return details.isMetaKey();
+            }
+            return false;
+        }
+
+        /**
+         * Checks if the Shift key was down when the mouse event took place.
+         * 
+         * @return true if Shift was pressed when the event occured, false
+         *         otherwise
+         */
+        public boolean isShiftKey() {
+            if (details != null) {
+                return details.isShiftKey();
+            }
+            return false;
+        }
     }
 
     /**
@@ -365,7 +441,7 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier,
      * Emits the options change event.
      */
     protected void fireClick() {
-        fireEvent(new Button.ClickEvent(this));
+        fireEvent(new Button.ClickEvent(this, mouseDetails));
     }
 
     @Override