Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

Sizeable.java 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. /*
  2. * Copyright 2011 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. public static final float SIZE_UNDEFINED = -1;
  72. public enum Unit {
  73. /**
  74. * Unit code representing pixels.
  75. */
  76. PIXELS("px"),
  77. /**
  78. * Unit code representing points (1/72nd of an inch).
  79. */
  80. POINTS("pt"),
  81. /**
  82. * Unit code representing picas (12 points).
  83. */
  84. PICAS("pc"),
  85. /**
  86. * Unit code representing the font-size of the relevant font.
  87. */
  88. EM("em"),
  89. /**
  90. * Unit code representing the x-height of the relevant font.
  91. */
  92. EX("ex"),
  93. /**
  94. * Unit code representing millimeters.
  95. */
  96. MM("mm"),
  97. /**
  98. * Unit code representing centimeters.
  99. */
  100. CM("cm"),
  101. /**
  102. * Unit code representing inches.
  103. */
  104. INCH("in"),
  105. /**
  106. * Unit code representing in percentage of the containing element
  107. * defined by terminal.
  108. */
  109. PERCENTAGE("%");
  110. private String symbol;
  111. private Unit(String symbol) {
  112. this.symbol = symbol;
  113. }
  114. public String getSymbol() {
  115. return symbol;
  116. }
  117. @Override
  118. public String toString() {
  119. return symbol;
  120. }
  121. public static Unit getUnitFromSymbol(String symbol) {
  122. if (symbol == null) {
  123. return Unit.PIXELS; // Defaults to pixels
  124. }
  125. for (Unit unit : Unit.values()) {
  126. if (symbol.equals(unit.getSymbol())) {
  127. return unit;
  128. }
  129. }
  130. return Unit.PIXELS; // Defaults to pixels
  131. }
  132. }
  133. /**
  134. * Gets the width of the object. Negative number implies unspecified size
  135. * (terminal is free to set the size).
  136. *
  137. * @return width of the object in units specified by widthUnits property.
  138. */
  139. public float getWidth();
  140. /**
  141. * Gets the height of the object. Negative number implies unspecified size
  142. * (terminal is free to set the size).
  143. *
  144. * @return height of the object in units specified by heightUnits property.
  145. */
  146. public float getHeight();
  147. /**
  148. * Gets the width property units.
  149. *
  150. * @return units used in width property.
  151. */
  152. public Unit getWidthUnits();
  153. /**
  154. * Gets the height property units.
  155. *
  156. * @return units used in height property.
  157. */
  158. public Unit getHeightUnits();
  159. /**
  160. * Sets the height of the component using String presentation.
  161. *
  162. * String presentation is similar to what is used in Cascading Style Sheets.
  163. * Size can be length or percentage of available size.
  164. *
  165. * The empty string ("") or null will unset the height and set the units to
  166. * pixels.
  167. *
  168. * See <a
  169. * href="http://www.w3.org/TR/REC-CSS2/syndata.html#value-def-length">CSS
  170. * specification</a> for more details.
  171. *
  172. * @param height
  173. * in CSS style string representation
  174. */
  175. public void setHeight(String height);
  176. /**
  177. * Sets the width of the object. Negative number implies unspecified size
  178. * (terminal is free to set the size).
  179. *
  180. * @param width
  181. * the width of the object.
  182. * @param unit
  183. * the unit used for the width.
  184. */
  185. public void setWidth(float width, Unit unit);
  186. /**
  187. * Sets the height of the object. Negative number implies unspecified size
  188. * (terminal is free to set the size).
  189. *
  190. * @param height
  191. * the height of the object.
  192. * @param unit
  193. * the unit used for the width.
  194. */
  195. public void setHeight(float height, Unit unit);
  196. /**
  197. * Sets the width of the component using String presentation.
  198. *
  199. * String presentation is similar to what is used in Cascading Style Sheets.
  200. * Size can be length or percentage of available size.
  201. *
  202. * The empty string ("") or null will unset the width and set the units to
  203. * pixels.
  204. *
  205. * See <a
  206. * href="http://www.w3.org/TR/REC-CSS2/syndata.html#value-def-length">CSS
  207. * specification</a> for more details.
  208. *
  209. * @param width
  210. * in CSS style string representation, null or empty string to
  211. * reset
  212. */
  213. public void setWidth(String width);
  214. /**
  215. * Sets the size to 100% x 100%.
  216. */
  217. public void setSizeFull();
  218. /**
  219. * Clears any size settings.
  220. */
  221. public void setSizeUndefined();
  222. }