You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Sizeable.java 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290
  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.server;
  17. import java.io.Serializable;
  18. /**
  19. * Interface to be implemented by components wishing to display some object that
  20. * may be dynamically resized during runtime.
  21. *
  22. * @author Vaadin Ltd.
  23. * @since 3.0
  24. */
  25. public interface Sizeable extends Serializable {
  26. /**
  27. * @deprecated As of 7.0, use {@link Unit#PIXELS} instead    
  28. */
  29. @Deprecated
  30. public static final Unit UNITS_PIXELS = Unit.PIXELS;
  31. /**
  32. * @deprecated As of 7.0, use {@link Unit#POINTS} instead    
  33. */
  34. @Deprecated
  35. public static final Unit UNITS_POINTS = Unit.POINTS;
  36. /**
  37. * @deprecated As of 7.0, use {@link Unit#PICAS} instead    
  38. */
  39. @Deprecated
  40. public static final Unit UNITS_PICAS = Unit.PICAS;
  41. /**
  42. * @deprecated As of 7.0, use {@link Unit#EM} instead    
  43. */
  44. @Deprecated
  45. public static final Unit UNITS_EM = Unit.EM;
  46. /**
  47. * @deprecated As of 7.0, use {@link Unit#EX} instead    
  48. */
  49. @Deprecated
  50. public static final Unit UNITS_EX = Unit.EX;
  51. /**
  52. * @deprecated As of 7.0, use {@link Unit#MM} instead    
  53. */
  54. @Deprecated
  55. public static final Unit UNITS_MM = Unit.MM;
  56. /**
  57. * @deprecated As of 7.0, use {@link Unit#CM} instead    
  58. */
  59. @Deprecated
  60. public static final Unit UNITS_CM = Unit.CM;
  61. /**
  62. * @deprecated As of 7.0, use {@link Unit#INCH} instead    
  63. */
  64. @Deprecated
  65. public static final Unit UNITS_INCH = Unit.INCH;
  66. /**
  67. * @deprecated As of 7.0, use {@link Unit#PERCENTAGE} instead    
  68. */
  69. @Deprecated
  70. public static final Unit UNITS_PERCENTAGE = Unit.PERCENTAGE;
  71. /**
  72. * @deprecated As of 7.3, use instead {@link #setSizeUndefined()},
  73. * {@link #setHeightUndefined()} and
  74. * {@link #setWidthUndefined()}
  75. */
  76. @Deprecated
  77. public static final float SIZE_UNDEFINED = -1;
  78. public enum Unit {
  79. /**
  80. * Unit code representing pixels.
  81. */
  82. PIXELS("px"),
  83. /**
  84. * Unit code representing points (1/72nd of an inch).
  85. */
  86. POINTS("pt"),
  87. /**
  88. * Unit code representing picas (12 points).
  89. */
  90. PICAS("pc"),
  91. /**
  92. * Unit code representing the font-size of the relevant font.
  93. */
  94. EM("em"),
  95. /**
  96. * Unit code representing the font-size of the root font.
  97. */
  98. REM("rem"),
  99. /**
  100. * Unit code representing the x-height of the relevant font.
  101. */
  102. EX("ex"),
  103. /**
  104. * Unit code representing millimeters.
  105. */
  106. MM("mm"),
  107. /**
  108. * Unit code representing centimeters.
  109. */
  110. CM("cm"),
  111. /**
  112. * Unit code representing inches.
  113. */
  114. INCH("in"),
  115. /**
  116. * Unit code representing in percentage of the containing element
  117. * defined by terminal.
  118. */
  119. PERCENTAGE("%");
  120. private final String symbol;
  121. private Unit(String symbol) {
  122. this.symbol = symbol;
  123. }
  124. public String getSymbol() {
  125. return symbol;
  126. }
  127. @Override
  128. public String toString() {
  129. return symbol;
  130. }
  131. public static Unit getUnitFromSymbol(String symbol) {
  132. if (symbol == null) {
  133. return Unit.PIXELS; // Defaults to pixels
  134. }
  135. for (Unit unit : Unit.values()) {
  136. if (symbol.equals(unit.getSymbol())) {
  137. return unit;
  138. }
  139. }
  140. return Unit.PIXELS; // Defaults to pixels
  141. }
  142. }
  143. /**
  144. * Gets the width of the object. Negative number implies unspecified size
  145. * (terminal is free to set the size).
  146. *
  147. * @return width of the object in units specified by widthUnits property.
  148. */
  149. public float getWidth();
  150. /**
  151. * Gets the height of the object. Negative number implies unspecified size
  152. * (terminal is free to set the size).
  153. *
  154. * @return height of the object in units specified by heightUnits property.
  155. */
  156. public float getHeight();
  157. /**
  158. * Gets the width property units.
  159. *
  160. * @return units used in width property.
  161. */
  162. public Unit getWidthUnits();
  163. /**
  164. * Gets the height property units.
  165. *
  166. * @return units used in height property.
  167. */
  168. public Unit getHeightUnits();
  169. /**
  170. * Sets the height of the component using String presentation.
  171. *
  172. * String presentation is similar to what is used in Cascading Style Sheets.
  173. * Size can be length or percentage of available size.
  174. *
  175. * The empty string ("") or null will unset the height and set the units to
  176. * pixels.
  177. *
  178. * See
  179. * <a href="http://www.w3.org/TR/REC-CSS2/syndata.html#value-def-length">CSS
  180. * specification</a> for more details.
  181. *
  182. * @param height
  183. * in CSS style string representation
  184. */
  185. public void setHeight(String height);
  186. /**
  187. * Sets the width of the object. Negative number implies unspecified size
  188. * (terminal is free to set the size).
  189. *
  190. * @param width
  191. * the width of the object.
  192. * @param unit
  193. * the unit used for the width.
  194. */
  195. public void setWidth(float width, Unit unit);
  196. /**
  197. * Sets the height of the object. Negative number implies unspecified size
  198. * (terminal is free to set the size).
  199. *
  200. * @param height
  201. * the height of the object.
  202. * @param unit
  203. * the unit used for the width.
  204. */
  205. public void setHeight(float height, Unit unit);
  206. /**
  207. * Sets the width of the component using String presentation.
  208. *
  209. * String presentation is similar to what is used in Cascading Style Sheets.
  210. * Size can be length or percentage of available size.
  211. *
  212. * The empty string ("") or null will unset the width and set the units to
  213. * pixels.
  214. *
  215. * See
  216. * <a href="http://www.w3.org/TR/REC-CSS2/syndata.html#value-def-length">CSS
  217. * specification</a> for more details.
  218. *
  219. * @param width
  220. * in CSS style string representation, null or empty string to
  221. * reset
  222. */
  223. public void setWidth(String width);
  224. /**
  225. * Sets the size to 100% x 100%.
  226. */
  227. public void setSizeFull();
  228. /**
  229. * Sets the width to 100%.
  230. *
  231. * @since
  232. */
  233. public void setWidthFull();
  234. /**
  235. * Sets the height to 100%.
  236. *
  237. * @since
  238. */
  239. public void setHeightFull();
  240. /**
  241. * Clears any size settings.
  242. */
  243. public void setSizeUndefined();
  244. /**
  245. * Clears any defined width.
  246. *
  247. * @since 7.3
  248. */
  249. public void setWidthUndefined();
  250. /**
  251. * Clears any defined height.
  252. *
  253. * @since 7.3
  254. */
  255. public void setHeightUndefined();
  256. }