Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Layout.java 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. /*
  2. @ITMillApache2LicenseForJavaFiles@
  3. */
  4. package com.vaadin.ui;
  5. import java.io.Serializable;
  6. import com.vaadin.terminal.gwt.client.ui.AlignmentInfo.Bits;
  7. import com.vaadin.terminal.gwt.client.ui.VMarginInfo;
  8. /**
  9. * Extension to the {@link ComponentContainer} interface which adds the
  10. * layouting control to the elements in the container. This is required by the
  11. * various layout components to enable them to place other components in
  12. * specific locations in the UI.
  13. *
  14. * @author IT Mill Ltd.
  15. * @version
  16. * @VERSION@
  17. * @since 3.0
  18. */
  19. public interface Layout extends ComponentContainer, Serializable {
  20. /**
  21. * Enable layout margins. Affects all four sides of the layout. This will
  22. * tell the client-side implementation to leave extra space around the
  23. * layout. The client-side implementation decides the actual amount, and it
  24. * can vary between themes.
  25. *
  26. * @param enabled
  27. */
  28. public void setMargin(boolean enabled);
  29. /**
  30. * Enable specific layout margins. This will tell the client-side
  31. * implementation to leave extra space around the layout in specified edges,
  32. * clockwise from top (top, right, bottom, left). The client-side
  33. * implementation decides the actual amount, and it can vary between themes.
  34. *
  35. * @param top
  36. * @param right
  37. * @param bottom
  38. * @param left
  39. */
  40. public void setMargin(boolean top, boolean right, boolean bottom,
  41. boolean left);
  42. /**
  43. * AlignmentHandler is most commonly an advanced {@link Layout} that can
  44. * align its components.
  45. */
  46. public interface AlignmentHandler extends Serializable {
  47. /**
  48. * Contained component should be aligned horizontally to the left.
  49. *
  50. * @deprecated Use of {@link Alignment} class and its constants
  51. */
  52. @Deprecated
  53. public static final int ALIGNMENT_LEFT = Bits.ALIGNMENT_LEFT;
  54. /**
  55. * Contained component should be aligned horizontally to the right.
  56. *
  57. * @deprecated Use of {@link Alignment} class and its constants
  58. */
  59. @Deprecated
  60. public static final int ALIGNMENT_RIGHT = Bits.ALIGNMENT_RIGHT;
  61. /**
  62. * Contained component should be aligned vertically to the top.
  63. *
  64. * @deprecated Use of {@link Alignment} class and its constants
  65. */
  66. @Deprecated
  67. public static final int ALIGNMENT_TOP = Bits.ALIGNMENT_TOP;
  68. /**
  69. * Contained component should be aligned vertically to the bottom.
  70. *
  71. * @deprecated Use of {@link Alignment} class and its constants
  72. */
  73. @Deprecated
  74. public static final int ALIGNMENT_BOTTOM = Bits.ALIGNMENT_BOTTOM;
  75. /**
  76. * Contained component should be horizontally aligned to center.
  77. *
  78. * @deprecated Use of {@link Alignment} class and its constants
  79. */
  80. @Deprecated
  81. public static final int ALIGNMENT_HORIZONTAL_CENTER = Bits.ALIGNMENT_HORIZONTAL_CENTER;
  82. /**
  83. * Contained component should be vertically aligned to center.
  84. *
  85. * @deprecated Use of {@link Alignment} class and its constants
  86. */
  87. @Deprecated
  88. public static final int ALIGNMENT_VERTICAL_CENTER = Bits.ALIGNMENT_VERTICAL_CENTER;
  89. /**
  90. * Set alignment for one contained component in this layout. Alignment
  91. * is calculated as a bit mask of the two passed values.
  92. *
  93. * @deprecated Use {@link #setComponentAlignment(Component, Alignment)}
  94. * instead
  95. *
  96. * @param childComponent
  97. * the component to align within it's layout cell.
  98. * @param horizontalAlignment
  99. * the horizontal alignment for the child component (left,
  100. * center, right). Use ALIGNMENT constants.
  101. * @param verticalAlignment
  102. * the vertical alignment for the child component (top,
  103. * center, bottom). Use ALIGNMENT constants.
  104. */
  105. @Deprecated
  106. public void setComponentAlignment(Component childComponent,
  107. int horizontalAlignment, int verticalAlignment);
  108. /**
  109. * Set alignment for one contained component in this layout. Use
  110. * predefined alignments from Alignment class.
  111. *
  112. * Example: <code>
  113. * layout.setComponentAlignment(myComponent, Alignment.TOP_RIGHT);
  114. * </code>
  115. *
  116. * @param childComponent
  117. * the component to align within it's layout cell.
  118. * @param alignment
  119. * the Alignment value to be set
  120. */
  121. public void setComponentAlignment(Component childComponent,
  122. Alignment alignment);
  123. /**
  124. * Returns the current Alignment of given component.
  125. *
  126. * @param childComponent
  127. * @return the {@link Alignment}
  128. */
  129. public Alignment getComponentAlignment(Component childComponent);
  130. }
  131. /**
  132. * This type of layout supports automatic addition of space between its
  133. * components.
  134. *
  135. */
  136. public interface SpacingHandler extends Serializable {
  137. /**
  138. * Enable spacing between child components within this layout.
  139. *
  140. * <p>
  141. * <strong>NOTE:</strong> This will only affect the space between
  142. * components, not the space around all the components in the layout
  143. * (i.e. do not confuse this with the cellspacing attribute of a HTML
  144. * Table). Use {@link #setMargin(boolean)} to add space around the
  145. * layout.
  146. * </p>
  147. *
  148. * <p>
  149. * See the reference manual for more information about CSS rules for
  150. * defining the amount of spacing to use.
  151. * </p>
  152. *
  153. * @param enabled
  154. * true if spacing should be turned on, false if it should be
  155. * turned off
  156. */
  157. public void setSpacing(boolean enabled);
  158. /**
  159. *
  160. * @return true if spacing between child components within this layout
  161. * is enabled, false otherwise
  162. * @deprecated Use {@link #isSpacing()} instead.
  163. */
  164. @Deprecated
  165. public boolean isSpacingEnabled();
  166. /**
  167. *
  168. * @return true if spacing between child components within this layout
  169. * is enabled, false otherwise
  170. */
  171. public boolean isSpacing();
  172. }
  173. /**
  174. * This type of layout supports automatic addition of margins (space around
  175. * its components).
  176. */
  177. public interface MarginHandler extends Serializable {
  178. /**
  179. * Enable margins for this layout.
  180. *
  181. * <p>
  182. * <strong>NOTE:</strong> This will only affect the space around the
  183. * components in the layout, not space between the components in the
  184. * layout. Use {@link #setSpacing(boolean)} to add space between the
  185. * components in the layout.
  186. * </p>
  187. *
  188. * <p>
  189. * See the reference manual for more information about CSS rules for
  190. * defining the size of the margin.
  191. * </p>
  192. *
  193. * @param marginInfo
  194. * MarginInfo object containing the new margins.
  195. */
  196. public void setMargin(MarginInfo marginInfo);
  197. /**
  198. *
  199. * @return MarginInfo containing the currently enabled margins.
  200. */
  201. public MarginInfo getMargin();
  202. }
  203. @SuppressWarnings("serial")
  204. public static class MarginInfo extends VMarginInfo implements Serializable {
  205. public MarginInfo(boolean enabled) {
  206. super(enabled, enabled, enabled, enabled);
  207. }
  208. public MarginInfo(boolean top, boolean right, boolean bottom,
  209. boolean left) {
  210. super(top, right, bottom, left);
  211. }
  212. }
  213. }