summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2013-03-25 21:54:36 +0200
committerVaadin Code Review <review@vaadin.com>2013-04-03 06:42:36 +0000
commit9586a30b64bfd1e8645574d9d7b6568d52dc9e25 (patch)
treea26ec723ebac47fd78b6180bc41434029a502aaf /client
parent3cc90e37d8abfa53d127691ae0b7641298d64fa2 (diff)
downloadvaadin-framework-9586a30b64bfd1e8645574d9d7b6568d52dc9e25.tar.gz
vaadin-framework-9586a30b64bfd1e8645574d9d7b6568d52dc9e25.zip
Made is possible to configure tooltip on the server (#8065)
Change-Id: I35af6df1dfa75ef1de1268eb630fc0f4b9306170
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/VTooltip.java138
-rw-r--r--client/src/com/vaadin/client/ui/ui/UIConnector.java17
2 files changed, 145 insertions, 10 deletions
diff --git a/client/src/com/vaadin/client/VTooltip.java b/client/src/com/vaadin/client/VTooltip.java
index e6d9a79a5b..53770f4201 100644
--- a/client/src/com/vaadin/client/VTooltip.java
+++ b/client/src/com/vaadin/client/VTooltip.java
@@ -48,11 +48,6 @@ public class VTooltip extends VOverlay {
public static final int TOOLTIP_EVENTS = Event.ONKEYDOWN
| Event.ONMOUSEOVER | Event.ONMOUSEOUT | Event.ONMOUSEMOVE
| Event.ONCLICK;
- protected static final int MAX_WIDTH = 500;
- private static final int QUICK_OPEN_TIMEOUT = 1000;
- private static final int CLOSE_TIMEOUT = 300;
- private static final int OPEN_DELAY = 750;
- private static final int QUICK_OPEN_DELAY = 100;
VErrorMessage em = new VErrorMessage();
Element description = DOM.createDiv();
@@ -64,6 +59,13 @@ public class VTooltip extends VOverlay {
private String uniqueId = DOM.createUniqueId();
private Element layoutElement;
+ private int maxWidth;
+
+ // Delays for the tooltip, configurable on the server side
+ private int openDelay;
+ private int quickOpenDelay;
+ private int quickOpenTimeout;
+ private int closeTimeout;
/**
* Used to show tooltips; usually used via the singleton in
@@ -126,8 +128,8 @@ public class VTooltip extends VOverlay {
@Override
public void setPosition(int offsetWidth, int offsetHeight) {
- if (offsetWidth > MAX_WIDTH) {
- setWidth(MAX_WIDTH + "px");
+ if (offsetWidth > getMaxWidth()) {
+ setWidth(getMaxWidth() + "px");
// Check new height and width with reflowed content
offsetWidth = getOffsetWidth();
@@ -172,7 +174,7 @@ public class VTooltip extends VOverlay {
// Schedule timer for showing the tooltip according to if it was
// recently closed or not.
- int timeout = justClosed ? QUICK_OPEN_DELAY : OPEN_DELAY;
+ int timeout = justClosed ? getQuickOpenDelay() : getOpenDelay();
showTimer.schedule(timeout);
opening = true;
}
@@ -222,10 +224,10 @@ public class VTooltip extends VOverlay {
// already about to close
return;
}
- closeTimer.schedule(CLOSE_TIMEOUT);
+ closeTimer.schedule(getCloseTimeout());
closing = true;
justClosed = true;
- justClosedTimer.schedule(QUICK_OPEN_TIMEOUT);
+ justClosedTimer.schedule(getQuickOpenTimeout());
}
@Override
@@ -466,4 +468,120 @@ public class VTooltip extends VOverlay {
Roles.getTooltipRole().setAriaHiddenState(layoutElement, false);
}
+
+ /**
+ * Returns the time (in ms) the tooltip should be displayed after an event
+ * that will cause it to be closed (e.g. mouse click outside the component,
+ * key down).
+ *
+ * @return The close timeout (in ms)
+ */
+ public int getCloseTimeout() {
+ return closeTimeout;
+ }
+
+ /**
+ * Sets the time (in ms) the tooltip should be displayed after an event that
+ * will cause it to be closed (e.g. mouse click outside the component, key
+ * down).
+ *
+ * @param closeTimeout
+ * The close timeout (in ms)
+ */
+ public void setCloseTimeout(int closeTimeout) {
+ this.closeTimeout = closeTimeout;
+ }
+
+ /**
+ * Returns the time (in ms) during which {@link #getQuickOpenDelay()} should
+ * be used instead of {@link #getOpenDelay()}. The quick open delay is used
+ * when the tooltip has very recently been shown, is currently hidden but
+ * about to be shown again.
+ *
+ * @return The quick open timeout (in ms)
+ */
+ public int getQuickOpenTimeout() {
+ return quickOpenTimeout;
+ }
+
+ /**
+ * Sets the time (in ms) that determines when {@link #getQuickOpenDelay()}
+ * should be used instead of {@link #getOpenDelay()}. The quick open delay
+ * is used when the tooltip has very recently been shown, is currently
+ * hidden but about to be shown again.
+ *
+ * @param quickOpenTimeout
+ * The quick open timeout (in ms)
+ */
+ public void setQuickOpenTimeout(int quickOpenTimeout) {
+ this.quickOpenTimeout = quickOpenTimeout;
+ }
+
+ /**
+ * Returns the time (in ms) that should elapse before a tooltip will be
+ * shown, in the situation when a tooltip has very recently been shown
+ * (within {@link #getQuickOpenDelay()} ms).
+ *
+ * @return The quick open delay (in ms)
+ */
+ public int getQuickOpenDelay() {
+ return quickOpenDelay;
+ }
+
+ /**
+ * Sets the time (in ms) that should elapse before a tooltip will be shown,
+ * in the situation when a tooltip has very recently been shown (within
+ * {@link #getQuickOpenDelay()} ms).
+ *
+ * @param quickOpenDelay
+ * The quick open delay (in ms)
+ */
+ public void setQuickOpenDelay(int quickOpenDelay) {
+ this.quickOpenDelay = quickOpenDelay;
+ }
+
+ /**
+ * Returns the time (in ms) that should elapse after an event triggering
+ * tooltip showing has occurred (e.g. mouse over) before the tooltip is
+ * shown. If a tooltip has recently been shown, then
+ * {@link #getQuickOpenDelay()} is used instead of this.
+ *
+ * @return The open delay (in ms)
+ */
+ public int getOpenDelay() {
+ return openDelay;
+ }
+
+ /**
+ * Sets the time (in ms) that should elapse after an event triggering
+ * tooltip showing has occurred (e.g. mouse over) before the tooltip is
+ * shown. If a tooltip has recently been shown, then
+ * {@link #getQuickOpenDelay()} is used instead of this.
+ *
+ * @param openDelay
+ * The open delay (in ms)
+ */
+ public void setOpenDelay(int openDelay) {
+ this.openDelay = openDelay;
+ }
+
+ /**
+ * Sets the maximum width of the tooltip popup.
+ *
+ * @param maxWidth
+ * The maximum width the tooltip popup (in pixels)
+ */
+ public void setMaxWidth(int maxWidth) {
+ this.maxWidth = maxWidth;
+ }
+
+ /**
+ * Returns the maximum width of the tooltip popup.
+ *
+ * @return The maximum width the tooltip popup (in pixels)
+ */
+ public int getMaxWidth() {
+ return maxWidth;
+ }
+
}
diff --git a/client/src/com/vaadin/client/ui/ui/UIConnector.java b/client/src/com/vaadin/client/ui/ui/UIConnector.java
index 1df74afd2e..b8b7786d21 100644
--- a/client/src/com/vaadin/client/ui/ui/UIConnector.java
+++ b/client/src/com/vaadin/client/ui/ui/UIConnector.java
@@ -599,4 +599,21 @@ public class UIConnector extends AbstractSingleComponentContainerConnector
}
});
}
+
+ @Override
+ public void onStateChanged(StateChangeEvent stateChangeEvent) {
+ super.onStateChanged(stateChangeEvent);
+ if (stateChangeEvent.hasPropertyChanged("tooltipConfiguration")) {
+ getConnection().getVTooltip().setCloseTimeout(
+ getState().tooltipConfiguration.closeTimeout);
+ getConnection().getVTooltip().setOpenDelay(
+ getState().tooltipConfiguration.openDelay);
+ getConnection().getVTooltip().setQuickOpenDelay(
+ getState().tooltipConfiguration.quickOpenDelay);
+ getConnection().getVTooltip().setQuickOpenTimeout(
+ getState().tooltipConfiguration.quickOpenTimeout);
+ getConnection().getVTooltip().setMaxWidth(
+ getState().tooltipConfiguration.maxWidth);
+ }
+ }
}