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 6.1KB

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