diff options
author | Pekka Hyvönen <pekka@vaadin.com> | 2012-09-10 22:12:47 +0300 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2012-09-11 12:19:02 +0300 |
commit | 0f5284bb827b5f04c6c064c851b851604293665a (patch) | |
tree | 4c9949ba7fa08dfae4f276f95c6928cae8b7760f /shared | |
parent | 8a904080835193e322e1f006aa65f490f2cd930a (diff) | |
download | vaadin-framework-0f5284bb827b5f04c6c064c851b851604293665a.tar.gz vaadin-framework-0f5284bb827b5f04c6c064c851b851604293665a.zip |
Constants -> enums (#9072)
Patch from Pekka with minor changes (ButtonCode -> MouseButton, FilteringMode -> ComboBox)
Diffstat (limited to 'shared')
6 files changed, 169 insertions, 22 deletions
diff --git a/shared/src/com/vaadin/shared/MouseEventDetails.java b/shared/src/com/vaadin/shared/MouseEventDetails.java index ccfaac3a00..733d4c08e7 100644 --- a/shared/src/com/vaadin/shared/MouseEventDetails.java +++ b/shared/src/com/vaadin/shared/MouseEventDetails.java @@ -21,16 +21,55 @@ import java.io.Serializable; * Helper class to store and transfer mouse event details. */ public class MouseEventDetails implements Serializable { - // From com.google.gwt.dom.client.NativeEvent - public static final int BUTTON_LEFT = 1; - public static final int BUTTON_MIDDLE = 4; - public static final int BUTTON_RIGHT = 2; + /** + * @deprecated use {@link MouseButton#LEFT} instead. + */ + @Deprecated + public static final MouseButton BUTTON_LEFT = MouseButton.LEFT; + /** + * @deprecated use {@link MouseButton#MIDDLE} instead. + */ + @Deprecated + public static final MouseButton BUTTON_MIDDLE = MouseButton.MIDDLE; + /** + * @deprecated use {@link MouseButton#RIGHT} instead. + */ + @Deprecated + public static final MouseButton BUTTON_RIGHT = MouseButton.RIGHT; + + /** + * Constants for mouse buttons. + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0 + * + */ + public enum MouseButton { + LEFT("left"), RIGHT("right"), MIDDLE("middle"); + + private String name; + + private MouseButton(String name) { + this.name = name; + } + + /** + * Returns a human readable text representing the button + * + * @return + */ + public String getName() { + return name; + } + + } private static final char DELIM = ','; // From com.google.gwt.user.client.Event private static final int ONDBLCLICK = 0x00002; - private int button; + private MouseButton button; private int clientX; private int clientY; private boolean altKey; @@ -41,7 +80,7 @@ public class MouseEventDetails implements Serializable { private int relativeX = -1; private int relativeY = -1; - public int getButton() { + public MouseButton getButton() { return button; } @@ -77,7 +116,7 @@ public class MouseEventDetails implements Serializable { return relativeY; } - public void setButton(int button) { + public void setButton(MouseButton button) { this.button = button; } @@ -126,16 +165,15 @@ public class MouseEventDetails implements Serializable { } public String serialize() { - return "" + button + DELIM + clientX + DELIM + clientY + DELIM + altKey - + DELIM + ctrlKey + DELIM + metaKey + DELIM + shiftKey + DELIM - + type + DELIM + relativeX + DELIM + relativeY; + return button.toString() + DELIM + clientX + DELIM + clientY + DELIM + + altKey + DELIM + ctrlKey + DELIM + metaKey + DELIM + shiftKey + + DELIM + type + DELIM + relativeX + DELIM + relativeY; } public static MouseEventDetails deSerialize(String serializedString) { MouseEventDetails instance = new MouseEventDetails(); String[] fields = serializedString.split(","); - - instance.button = Integer.parseInt(fields[0]); + instance.button = MouseButton.valueOf(fields[0]); instance.clientX = Integer.parseInt(fields[1]); instance.clientY = Integer.parseInt(fields[2]); instance.altKey = Boolean.valueOf(fields[3]).booleanValue(); @@ -149,15 +187,7 @@ public class MouseEventDetails implements Serializable { } public String getButtonName() { - if (button == BUTTON_LEFT) { - return "left"; - } else if (button == BUTTON_RIGHT) { - return "right"; - } else if (button == BUTTON_MIDDLE) { - return "middle"; - } - - return ""; + return button == null ? "" : button.getName(); } public int getType() { diff --git a/shared/src/com/vaadin/shared/ui/BorderStyle.java b/shared/src/com/vaadin/shared/ui/BorderStyle.java index 786d340f1c..8a48253a22 100755 --- a/shared/src/com/vaadin/shared/ui/BorderStyle.java +++ b/shared/src/com/vaadin/shared/ui/BorderStyle.java @@ -15,6 +15,28 @@ */ package com.vaadin.shared.ui; +/** + * Constants for border styles used on HTML elements. + * + * @author Vaadin Ltd + * @version @VERSION@ + * @since 7.0 + * + */ public enum BorderStyle { - NONE, MINIMAL, DEFAULT; + /** + * A border style used for using no border. + */ + NONE, + + /** + * A border style used for a minimal border. + */ + MINIMAL, + + /** + * A border style that indicates that the default border style should be + * used. + */ + DEFAULT; } diff --git a/shared/src/com/vaadin/shared/ui/MultiSelectMode.java b/shared/src/com/vaadin/shared/ui/MultiSelectMode.java new file mode 100644 index 0000000000..13eef452cd --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/MultiSelectMode.java @@ -0,0 +1,16 @@ +package com.vaadin.shared.ui; + +/** + * Multi select modes that controls how multi select behaves. + */ +public enum MultiSelectMode { + /** + * The default behavior of the multi select mode + */ + DEFAULT, + + /** + * The previous more simple behavior of the multi select + */ + SIMPLE +} diff --git a/shared/src/com/vaadin/shared/ui/Orientation.java b/shared/src/com/vaadin/shared/ui/Orientation.java new file mode 100644 index 0000000000..b055f078ae --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/Orientation.java @@ -0,0 +1,5 @@ +package com.vaadin.shared.ui; + +public enum Orientation { + HORIZONTAL, VERTICAL; +} diff --git a/shared/src/com/vaadin/shared/ui/combobox/FilteringMode.java b/shared/src/com/vaadin/shared/ui/combobox/FilteringMode.java new file mode 100644 index 0000000000..eaae85c156 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/combobox/FilteringMode.java @@ -0,0 +1,5 @@ +package com.vaadin.shared.ui.combobox; + +public enum FilteringMode { + OFF, STARTSWITH, CONTAINS; +} diff --git a/shared/src/com/vaadin/shared/ui/datefield/Resolution.java b/shared/src/com/vaadin/shared/ui/datefield/Resolution.java new file mode 100644 index 0000000000..a457c99de9 --- /dev/null +++ b/shared/src/com/vaadin/shared/ui/datefield/Resolution.java @@ -0,0 +1,69 @@ +package com.vaadin.shared.ui.datefield; + +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; + +/** + * Resolutions for DateFields + * + * @author Vaadin Ltd. + * @since 7.0 + */ +public enum Resolution { + SECOND(Calendar.SECOND), MINUTE(Calendar.MINUTE), HOUR(Calendar.HOUR_OF_DAY), DAY( + Calendar.DAY_OF_MONTH), MONTH(Calendar.MONTH), YEAR(Calendar.YEAR); + + private int calendarField; + + private Resolution(int calendarField) { + this.calendarField = calendarField; + } + + /** + * Returns the field in {@link Calendar} that corresponds to this + * resolution. + * + * @return one of the field numbers used by Calendar + */ + public int getCalendarField() { + return calendarField; + } + + /** + * Returns the resolutions that are higher or equal to the given resolution, + * starting from the given resolution. In other words passing DAY to this + * methods returns DAY,MONTH,YEAR + * + * @param r + * The resolution to start from + * @return An iterable for the resolutions higher or equal to r + */ + public static Iterable<Resolution> getResolutionsHigherOrEqualTo( + Resolution r) { + List<Resolution> resolutions = new ArrayList<Resolution>(); + Resolution[] values = Resolution.values(); + for (int i = r.ordinal(); i < values.length; i++) { + resolutions.add(values[i]); + } + return resolutions; + } + + /** + * Returns the resolutions that are lower than the given resolution, + * starting from the given resolution. In other words passing DAY to this + * methods returns HOUR,MINUTE,SECOND. + * + * @param r + * The resolution to start from + * @return An iterable for the resolutions lower than r + */ + public static List<Resolution> getResolutionsLowerThan(Resolution r) { + List<Resolution> resolutions = new ArrayList<Resolution>(); + Resolution[] values = Resolution.values(); + for (int i = r.ordinal() - 1; i >= 0; i--) { + resolutions.add(values[i]); + } + return resolutions; + } +}; |