aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/vaadin/ui/Button.java
diff options
context:
space:
mode:
authorJohn Alhroos <john.ahlroos@itmill.com>2011-03-10 08:36:33 +0000
committerJohn Alhroos <john.ahlroos@itmill.com>2011-03-10 08:36:33 +0000
commitce0d30552e4ac982ff590795ba5b6655453c20a0 (patch)
treecd233442b4ba4934d246eb15138f87d26c474b55 /src/com/vaadin/ui/Button.java
parent4f344999ea604aab6260c932023cb19c89813d97 (diff)
downloadvaadin-framework-ce0d30552e4ac982ff590795ba5b6655453c20a0.tar.gz
vaadin-framework-ce0d30552e4ac982ff590795ba5b6655453c20a0.zip
Adds mouse event details to Button.ClickEvent #6605
svn changeset:17697/svn branch:6.5
Diffstat (limited to 'src/com/vaadin/ui/Button.java')
-rw-r--r--src/com/vaadin/ui/Button.java80
1 files changed, 78 insertions, 2 deletions
diff --git a/src/com/vaadin/ui/Button.java b/src/com/vaadin/ui/Button.java
index cf354750a8..22ab0a62a3 100644
--- a/src/com/vaadin/ui/Button.java
+++ b/src/com/vaadin/ui/Button.java
@@ -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.
*
@@ -311,6 +323,19 @@ public class Button extends AbstractField implements FieldEvents.BlurNotifier,
}
/**
+ * 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.
*
* @return the Source of the event.
@@ -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