PageRenderTime 44ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/Source/Wizard Wars/com/jgoodies/forms/factories/FormFactory.java

http://wizard-world-smc-cs56.googlecode.com/
Java | 346 lines | 60 code | 54 blank | 232 comment | 0 complexity | f231582a4c0f22b2c306ebc48581dcb6 MD5 | raw file
  1. /*
  2. * Copyright (c) 2002-2009 JGoodies Karsten Lentzsch. All Rights Reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * o Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. *
  10. * o Redistributions in binary form must reproduce the above copyright notice,
  11. * this list of conditions and the following disclaimer in the documentation
  12. * and/or other materials provided with the distribution.
  13. *
  14. * o Neither the name of JGoodies Karsten Lentzsch nor the names of
  15. * its contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  20. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  21. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
  25. * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  26. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
  27. * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  28. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. package com.jgoodies.forms.factories;
  31. import com.jgoodies.forms.layout.ColumnSpec;
  32. import com.jgoodies.forms.layout.ConstantSize;
  33. import com.jgoodies.forms.layout.RowSpec;
  34. import com.jgoodies.forms.layout.Sizes;
  35. import com.jgoodies.forms.util.LayoutStyle;
  36. /**
  37. * Provides frequently used column and row specifications.
  38. *
  39. * @author Karsten Lentzsch
  40. * @version $Revision: 1.13 $
  41. *
  42. * @see com.jgoodies.forms.layout.FormLayout
  43. * @see ColumnSpec
  44. */
  45. public final class FormFactory {
  46. private FormFactory() {
  47. // Suppresses default constructor, prevents instantiation.
  48. }
  49. // Frequently used Column Specifications ********************************
  50. /**
  51. * An unmodifiable <code>ColumnSpec</code> that determines its width by
  52. * computing the maximum of all column component minimum widths.
  53. *
  54. * @see #PREF_COLSPEC
  55. * @see #DEFAULT_COLSPEC
  56. */
  57. public static final ColumnSpec MIN_COLSPEC =
  58. new ColumnSpec(Sizes.MINIMUM);
  59. /**
  60. * An unmodifiable <code>ColumnSpec</code> that determines its width by
  61. * computing the maximum of all column component preferred widths.
  62. *
  63. * @see #MIN_COLSPEC
  64. * @see #DEFAULT_COLSPEC
  65. */
  66. public static final ColumnSpec PREF_COLSPEC =
  67. new ColumnSpec(Sizes.PREFERRED);
  68. /**
  69. * An unmodifiable <code>ColumnSpec</code> that determines its preferred
  70. * width by computing the maximum of all column component preferred widths
  71. * and its minimum width by computing all column component minimum widths.<p>
  72. *
  73. * Useful to let a column shrink from preferred width to minimum width
  74. * if the container space gets scarce.
  75. *
  76. * @see #MIN_COLSPEC
  77. * @see #PREF_COLSPEC
  78. */
  79. public static final ColumnSpec DEFAULT_COLSPEC =
  80. new ColumnSpec(Sizes.DEFAULT);
  81. /**
  82. * An unmodifiable <code>ColumnSpec</code> that has an initial width
  83. * of 0 pixels and that grows. Useful to describe <em>glue</em> columns
  84. * that fill the space between other columns.
  85. *
  86. * @see #GLUE_ROWSPEC
  87. */
  88. public static final ColumnSpec GLUE_COLSPEC =
  89. new ColumnSpec(ColumnSpec.DEFAULT, Sizes.ZERO, ColumnSpec.DEFAULT_GROW);
  90. // Layout Style Dependent Column Specs ***********************************
  91. /**
  92. * Describes a logical horizontal gap between a label and an associated
  93. * component. Useful for builders that automatically fill a grid with labels
  94. * and components.<p>
  95. *
  96. * <strong>Note:</strong> In a future version this constant will likely
  97. * be moved to a class <code>LogicalSize</code> or <code>StyledSize</code>.
  98. *
  99. * @since 1.0.3
  100. */
  101. public static final ColumnSpec LABEL_COMPONENT_GAP_COLSPEC =
  102. ColumnSpec.createGap(LayoutStyle.getCurrent().getLabelComponentPadX());
  103. /**
  104. * Describes a logical horizontal gap between two related components.
  105. * For example the <em>OK</em> and <em>Cancel</em> buttons are considered
  106. * related.<p>
  107. *
  108. * <strong>Note:</strong> In a future version this constant will likely
  109. * be moved to a class <code>LogicalSize</code> or <code>StyledSize</code>.
  110. *
  111. * @see #UNRELATED_GAP_COLSPEC
  112. */
  113. public static final ColumnSpec RELATED_GAP_COLSPEC =
  114. ColumnSpec.createGap(LayoutStyle.getCurrent().getRelatedComponentsPadX());
  115. /**
  116. * Describes a logical horizontal gap between two unrelated components.<p>
  117. *
  118. * <strong>Note:</strong> In a future version this constant will likely
  119. * be moved to a class <code>LogicalSize</code> or <code>StyledSize</code>.
  120. *
  121. * @see #RELATED_GAP_COLSPEC
  122. */
  123. public static final ColumnSpec UNRELATED_GAP_COLSPEC =
  124. ColumnSpec.createGap(LayoutStyle.getCurrent().getUnrelatedComponentsPadX());
  125. /**
  126. * Describes a logical horizontal column for a fixed size button. This spec
  127. * honors the current layout style's default button minimum width.<p>
  128. *
  129. * <strong>Note:</strong> In a future version this constant will likely
  130. * be moved to a class <code>LogicalSize</code> or <code>StyledSize</code>.
  131. *
  132. * @see #GROWING_BUTTON_COLSPEC
  133. */
  134. public static final ColumnSpec BUTTON_COLSPEC =
  135. new ColumnSpec(Sizes.bounded(Sizes.PREFERRED,
  136. LayoutStyle.getCurrent().getDefaultButtonWidth(),
  137. null));
  138. /**
  139. * Describes a logical horizontal column for a growing button. This spec
  140. * does <em>not</em> use the layout style's default button minimum width.<p>
  141. *
  142. * <strong>Note:</strong> In a future version this constant will likely
  143. * be moved to a class <code>LogicalSize</code> or <code>StyledSize</code>.
  144. *
  145. * @see #BUTTON_COLSPEC
  146. */
  147. public static final ColumnSpec GROWING_BUTTON_COLSPEC =
  148. new ColumnSpec(ColumnSpec.DEFAULT,
  149. BUTTON_COLSPEC.getSize(),
  150. ColumnSpec.DEFAULT_GROW);
  151. // Frequently used Row Specifications ***********************************
  152. /**
  153. * An unmodifiable <code>RowSpec</code> that determines its height by
  154. * computing the maximum of all column component minimum heights.
  155. *
  156. * @see #PREF_ROWSPEC
  157. * @see #DEFAULT_ROWSPEC
  158. */
  159. public static final RowSpec MIN_ROWSPEC =
  160. new RowSpec(Sizes.MINIMUM);
  161. /**
  162. * An unmodifiable <code>RowSpec</code> that determines its height by
  163. * computing the maximum of all column component preferred heights.
  164. *
  165. * @see #MIN_ROWSPEC
  166. * @see #DEFAULT_ROWSPEC
  167. */
  168. public static final RowSpec PREF_ROWSPEC =
  169. new RowSpec(Sizes.PREFERRED);
  170. /**
  171. * An unmodifiable <code>RowSpec</code> that determines its preferred
  172. * height by computing the maximum of all column component preferred heights
  173. * and its minimum height by computing all column component minimum heights.<p>
  174. *
  175. * Useful to let a column shrink from preferred height to minimum height
  176. * if the container space gets scarce.
  177. *
  178. * @see #MIN_COLSPEC
  179. * @see #PREF_COLSPEC
  180. */
  181. public static final RowSpec DEFAULT_ROWSPEC =
  182. new RowSpec(Sizes.DEFAULT);
  183. /**
  184. * An unmodifiable <code>RowSpec</code> that has an initial height
  185. * of 0 pixels and that grows. Useful to describe <em>glue</em> rows
  186. * that fill the space between other rows.
  187. *
  188. * @see #GLUE_COLSPEC
  189. */
  190. public static final RowSpec GLUE_ROWSPEC =
  191. new RowSpec(RowSpec.DEFAULT, Sizes.ZERO, RowSpec.DEFAULT_GROW);
  192. // Layout Style Dependent Row Specs *************************************
  193. /**
  194. * Describes a logical vertical gap between two related components.
  195. * For example the <em>OK</em> and <em>Cancel</em> buttons are considered
  196. * related.<p>
  197. *
  198. * <strong>Note:</strong> In a future version this constant will likely
  199. * be moved to a class <code>LogicalSize</code> or <code>StyledSize</code>.
  200. *
  201. * @see #UNRELATED_GAP_ROWSPEC
  202. */
  203. public static final RowSpec RELATED_GAP_ROWSPEC =
  204. RowSpec.createGap(LayoutStyle.getCurrent().getRelatedComponentsPadY());
  205. /**
  206. * Describes a logical vertical gap between two unrelated components.<p>
  207. *
  208. * <strong>Note:</strong> In a future version this constant will likely
  209. * be moved to a class <code>LogicalSize</code> or <code>StyledSize</code>.
  210. *
  211. * @see #RELATED_GAP_ROWSPEC
  212. */
  213. public static final RowSpec UNRELATED_GAP_ROWSPEC =
  214. RowSpec.createGap(LayoutStyle.getCurrent().getUnrelatedComponentsPadY());
  215. /**
  216. * Describes a logical vertical narrow gap between two rows in the grid.
  217. * Useful if the vertical space is scarce or if an individual vertical gap
  218. * shall be small than the default line gap.<p>
  219. *
  220. * <strong>Note:</strong> In a future version this constant will likely
  221. * be moved to a class <code>LogicalSize</code> or <code>StyledSize</code>.
  222. *
  223. * @see #LINE_GAP_ROWSPEC
  224. * @see #PARAGRAPH_GAP_ROWSPEC
  225. */
  226. public static final RowSpec NARROW_LINE_GAP_ROWSPEC =
  227. RowSpec.createGap(LayoutStyle.getCurrent().getNarrowLinePad());
  228. /**
  229. * Describes the logical vertical default gap between two rows in the grid.
  230. * A little bit larger than the narrow line gap.<p>
  231. *
  232. * <strong>Note:</strong> In a future version this constant will likely
  233. * be moved to a class <code>LogicalSize</code> or <code>StyledSize</code>.
  234. *
  235. * @see #NARROW_LINE_GAP_ROWSPEC
  236. * @see #PARAGRAPH_GAP_ROWSPEC
  237. */
  238. public static final RowSpec LINE_GAP_ROWSPEC =
  239. RowSpec.createGap(LayoutStyle.getCurrent().getLinePad());
  240. /**
  241. * Describes the logical vertical default gap between two paragraphs in
  242. * the layout grid. This gap is larger than the default line gap.<p>
  243. *
  244. * <strong>Note:</strong> In a future version this constant will likely
  245. * be moved to a class <code>LogicalSize</code> or <code>StyledSize</code>.
  246. *
  247. * @see #NARROW_LINE_GAP_ROWSPEC
  248. * @see #LINE_GAP_ROWSPEC
  249. */
  250. public static final RowSpec PARAGRAPH_GAP_ROWSPEC =
  251. RowSpec.createGap(LayoutStyle.getCurrent().getParagraphPad());
  252. /**
  253. * Describes a logical row for a fixed size button. This spec
  254. * honors the current layout style's default button minimum height.<p>
  255. *
  256. * <strong>Note:</strong> In a future version this constant will likely
  257. * be moved to a class <code>LogicalSize</code> or <code>StyledSize</code>.
  258. *
  259. * @since 1.2
  260. */
  261. public static final RowSpec BUTTON_ROWSPEC =
  262. new RowSpec(Sizes.bounded(Sizes.PREFERRED,
  263. LayoutStyle.getCurrent().getDefaultButtonHeight(),
  264. null));
  265. // Factory Methods ******************************************************
  266. /**
  267. * Creates and returns a {@link ColumnSpec} that represents a gap with the
  268. * specified {@link ConstantSize}.
  269. *
  270. * @param gapWidth a <code>ConstantSize</code> that specifies the gap
  271. * @return a <code>ColumnSpec</code> that describes a horizontal gap
  272. *
  273. * @deprecated Replaced by {@link ColumnSpec#createGap(ConstantSize)}.
  274. * This method will be removed from the next Forms version.
  275. */
  276. public static ColumnSpec createGapColumnSpec(ConstantSize gapWidth) {
  277. return ColumnSpec.createGap(gapWidth);
  278. }
  279. /**
  280. * Creates and returns a {@link RowSpec} that represents a gap with the
  281. * specified {@link ConstantSize}.
  282. *
  283. * @param gapHeight a <code>ConstantSize</code> that specifies the gap
  284. * @return a <code>RowSpec</code> that describes a vertical gap
  285. *
  286. * @deprecated Replaced by {@link RowSpec#createGap(ConstantSize)}.
  287. * This method will be removed from the next Forms version.
  288. */
  289. public static RowSpec createGapRowSpec(ConstantSize gapHeight) {
  290. return RowSpec.createGap(gapHeight);
  291. }
  292. }