Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

TooltipConfiguration.java 6.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * Copyright 2000-2018 Vaadin Ltd.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5. * use this file except in compliance with the License. You may obtain a copy of
  6. * the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13. * License for the specific language governing permissions and limitations under
  14. * the License.
  15. */
  16. package com.vaadin.ui;
  17. import java.io.Serializable;
  18. import com.vaadin.shared.ui.ui.UIState.TooltipConfigurationState;
  19. /**
  20. * Provides method for configuring the tooltip.
  21. *
  22. * @author Vaadin Ltd
  23. * @since 7.1
  24. */
  25. public interface TooltipConfiguration extends Serializable {
  26. /**
  27. * Returns the time (in ms) the tooltip should be displayed after an event
  28. * that will cause it to be closed (e.g. mouse click outside the component,
  29. * key down).
  30. *
  31. * @return The close timeout
  32. */
  33. public int getCloseTimeout();
  34. /**
  35. * Sets the time (in ms) the tooltip should be displayed after an event that
  36. * will cause it to be closed (e.g. mouse click outside the component, key
  37. * down).
  38. *
  39. * @param closeTimeout
  40. * The close timeout
  41. */
  42. public void setCloseTimeout(int closeTimeout);
  43. /**
  44. * Returns the time (in ms) during which {@link #getQuickOpenDelay()} should
  45. * be used instead of {@link #getOpenDelay()}. The quick open delay is used
  46. * when the tooltip has very recently been shown, is currently hidden but
  47. * about to be shown again.
  48. *
  49. * @return The quick open timeout
  50. */
  51. public int getQuickOpenTimeout();
  52. /**
  53. * Sets the time (in ms) that determines when {@link #getQuickOpenDelay()}
  54. * should be used instead of {@link #getOpenDelay()}. The quick open delay
  55. * is used when the tooltip has very recently been shown, is currently
  56. * hidden but about to be shown again.
  57. *
  58. * @param quickOpenTimeout
  59. * The quick open timeout
  60. */
  61. public void setQuickOpenTimeout(int quickOpenTimeout);
  62. /**
  63. * Returns the time (in ms) that should elapse before a tooltip will be
  64. * shown, in the situation when a tooltip has very recently been shown
  65. * (within {@link #getQuickOpenDelay()} ms).
  66. *
  67. * @return The quick open delay
  68. */
  69. public int getQuickOpenDelay();
  70. /**
  71. * Sets the time (in ms) that should elapse before a tooltip will be shown,
  72. * in the situation when a tooltip has very recently been shown (within
  73. * {@link #getQuickOpenDelay()} ms).
  74. *
  75. * @param quickOpenDelay
  76. * The quick open delay
  77. */
  78. public void setQuickOpenDelay(int quickOpenDelay);
  79. /**
  80. * Returns the time (in ms) that should elapse after an event triggering
  81. * tooltip showing has occurred (e.g. mouse over) before the tooltip is
  82. * shown. If a tooltip has recently been shown, then
  83. * {@link #getQuickOpenDelay()} is used instead of this.
  84. *
  85. * @return The open delay
  86. */
  87. public int getOpenDelay();
  88. /**
  89. * Sets the time (in ms) that should elapse after an event triggering
  90. * tooltip showing has occurred (e.g. mouse over) before the tooltip is
  91. * shown. If a tooltip has recently been shown, then
  92. * {@link #getQuickOpenDelay()} is used instead of this.
  93. *
  94. * @param openDelay
  95. * The open delay
  96. */
  97. public void setOpenDelay(int openDelay);
  98. /**
  99. * Returns the maximum width of the tooltip popup.
  100. *
  101. * @return The maximum width the tooltip popup
  102. */
  103. public int getMaxWidth();
  104. /**
  105. * Sets the maximum width of the tooltip popup.
  106. *
  107. * @param maxWidth
  108. * The maximum width the tooltip popup
  109. */
  110. public void setMaxWidth(int maxWidth);
  111. }
  112. class TooltipConfigurationImpl implements TooltipConfiguration {
  113. private final UI ui;
  114. public TooltipConfigurationImpl(UI ui) {
  115. this.ui = ui;
  116. }
  117. /*
  118. * (non-Javadoc)
  119. *
  120. * @see com.vaadin.ui.UI.Tooltip#getCloseTimeout()
  121. */
  122. @Override
  123. public int getCloseTimeout() {
  124. return getState(false).closeTimeout;
  125. }
  126. /*
  127. * (non-Javadoc)
  128. *
  129. * @see com.vaadin.ui.Tooltip#setCloseTimeout(int)
  130. */
  131. @Override
  132. public void setCloseTimeout(int closeTimeout) {
  133. getState().closeTimeout = closeTimeout;
  134. }
  135. /*
  136. * (non-Javadoc)
  137. *
  138. * @see com.vaadin.ui.Tooltip#getQuickOpenTimeout()
  139. */
  140. @Override
  141. public int getQuickOpenTimeout() {
  142. return getState(false).quickOpenTimeout;
  143. }
  144. /*
  145. * (non-Javadoc)
  146. *
  147. * @see com.vaadin.ui.Tooltip#setQuickOpenTimeout(int)
  148. */
  149. @Override
  150. public void setQuickOpenTimeout(int quickOpenTimeout) {
  151. getState().quickOpenTimeout = quickOpenTimeout;
  152. }
  153. /*
  154. * (non-Javadoc)
  155. *
  156. * @see com.vaadin.ui.Tooltip#getQuickOpenDelay()
  157. */
  158. @Override
  159. public int getQuickOpenDelay() {
  160. return getState(false).quickOpenDelay;
  161. }
  162. /*
  163. * (non-Javadoc)
  164. *
  165. * @see com.vaadin.ui.Tooltip#setQuickOpenDelay(int)
  166. */
  167. @Override
  168. public void setQuickOpenDelay(int quickOpenDelay) {
  169. getState().quickOpenDelay = quickOpenDelay;
  170. }
  171. /*
  172. * (non-Javadoc)
  173. *
  174. * @see com.vaadin.ui.Tooltip#getOpenDelay()
  175. */
  176. @Override
  177. public int getOpenDelay() {
  178. return getState(false).openDelay;
  179. }
  180. /*
  181. * (non-Javadoc)
  182. *
  183. * @see com.vaadin.ui.Tooltip#setOpenDelay(int)
  184. */
  185. @Override
  186. public void setOpenDelay(int openDelay) {
  187. getState().openDelay = openDelay;
  188. }
  189. /*
  190. * (non-Javadoc)
  191. *
  192. * @see com.vaadin.ui.Tooltip#getMaxWidth()
  193. */
  194. @Override
  195. public int getMaxWidth() {
  196. return getState(false).maxWidth;
  197. }
  198. /*
  199. * (non-Javadoc)
  200. *
  201. * @see com.vaadin.ui.Tooltip#setMaxWidth(int)
  202. */
  203. @Override
  204. public void setMaxWidth(int maxWidth) {
  205. getState().maxWidth = maxWidth;
  206. }
  207. private TooltipConfigurationState getState() {
  208. return ui.getState().tooltipConfiguration;
  209. }
  210. private TooltipConfigurationState getState(boolean markAsDirty) {
  211. return ui.getState(markAsDirty).tooltipConfiguration;
  212. }
  213. }