1 package net.miginfocom.layout;
8 * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 * Redistributions of source code must retain the above copyright notice, this list
14 * of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice, this
16 * list of conditions and the following disclaimer in the documentation and/or other
17 * materials provided with the distribution.
18 * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
19 * used to endorse or promote products derived from this software without specific
20 * prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
34 * @author Mikael Grev, MiG InfoCom AB
38 /** Contains the constraints for an instance of the {@link LC} layout manager.
40 public final class LC implements Externalizable
42 // See the corresponding set/get method for documentation of the property!
44 private int wrapAfter = LayoutUtil.INF;
46 private Boolean leftToRight = null;
48 private UnitValue[] insets = null; // Never null elements but if unset array is null
50 private UnitValue alignX = null, alignY = null;
52 private BoundSize gridGapX = null, gridGapY = null;
54 private BoundSize width = BoundSize.NULL_SIZE, height = BoundSize.NULL_SIZE;
56 private BoundSize packW = BoundSize.NULL_SIZE, packH = BoundSize.NULL_SIZE;
58 private float pwAlign = 0.5f, phAlign = 1.0f;
60 private int debugMillis = 0;
62 private int hideMode = 0;
64 private boolean noCache = false;
66 private boolean flowX = true;
68 private boolean fillX = false, fillY = false;
70 private boolean topToBottom = true;
72 private boolean noGrid = false;
74 private boolean visualPadding = true;
76 /** Empty constructor.
82 // ************************************************************************
83 // * JavaBean get/set methods.
84 // ************************************************************************
87 /** If components have sizes or positions linked to the bounds of the parent in some way (as for instance the <code>"%"</code> unit has) the cache
88 * must be turned off for the panel. If components does not get the correct or expected size or position try to set this property to <code>true</code>.
89 * @return <code>true</code> means no cache and slightly slower layout.
91 public boolean isNoCache()
96 /** If components have sizes or positions linked to the bounds of the parent in some way (as for instance the <code>"%"</code> unit has) the cache
97 * must be turned off for the panel. If components does not get the correct or expected size or position try to set this property to <code>true</code>.
98 * @param b <code>true</code> means no cache and slightly slower layout.
100 public void setNoCache(boolean b)
105 /** If the laid out components' bounds in total is less than the final size of the container these align values will be used to align the components
106 * in the parent. <code>null</code> is default and that means top/left alignment. The relative distances between the components will not be affected
108 * @return The current alignment.
110 public final UnitValue getAlignX()
115 /** If the laid out components' bounds in total is less than the final size of the container these align values will be used to align the components
116 * in the parent. <code>null</code> is default and that means top/left alignment. The relative distances between the components will not be affected
118 * @param uv The new alignment. Use {@link ConstraintParser#parseAlignKeywords(String, boolean)} to create the {@link UnitValue}. May be <code>null</code>.
120 public final void setAlignX(UnitValue uv)
125 /** If the laid out components' bounds in total is less than the final size of the container these align values will be used to align the components
126 * in the parent. <code>null</code> is default and that means top/left alignment. The relative distances between the components will not be affected
128 * @return The current alignment.
130 public final UnitValue getAlignY()
135 /** If the laid out components' bounds in total is less than the final size of the container these align values will be used to align the components
136 * in the parent. <code>null</code> is default and that means top/left alignment. The relative distances between the components will not be affected
138 * @param uv The new alignment. Use {@link ConstraintParser#parseAlignKeywords(String, boolean)} to create the {@link UnitValue}. May be <code>null</code>.
140 public final void setAlignY(UnitValue uv)
145 /** If <code>> 0</code> the debug decorations will be repainted every <code>millis</code>. No debug information if <code><= 0</code> (default).
146 * @return The current debug repaint interval.
148 public final int getDebugMillis()
153 /** If <code>> 0</code> the debug decorations will be repainted every <code>millis</code>. No debug information if <code><= 0</code> (default).
154 * @param millis The new debug repaint interval.
156 public final void setDebugMillis(int millis)
158 this.debugMillis = millis;
161 /** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller.
162 * @return <code>true</code> means fill. <code>false</code> is default.
164 public final boolean isFillX()
169 /** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller.
170 * @param b <code>true</code> means fill. <code>false</code> is default.
172 public final void setFillX(boolean b)
177 /** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller.
178 * @return <code>true</code> means fill. <code>false</code> is default.
180 public final boolean isFillY()
185 /** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller.
186 * @param b <code>true</code> means fill. <code>false</code> is default.
188 public final void setFillY(boolean b)
193 /** The default flow direction. Normally (which is <code>true</code>) this is horizontal and that means that the "next" component
194 * will be put in the cell to the right (or to the left if left-to-right is false).
195 * @return <code>true</code> is the default flow horizontally.
196 * @see #setLeftToRight(Boolean)
198 public final boolean isFlowX()
203 /** The default flow direction. Normally (which is <code>true</code>) this is horizontal and that means that the "next" component
204 * will be put in the cell to the right (or to the left if left-to-right is false).
205 * @param b <code>true</code> is the default flow horizontally.
206 * @see #setLeftToRight(Boolean)
208 public final void setFlowX(boolean b)
213 /** If non-<code>null</code> (<code>null</code> is default) these value will be used as the default gaps between the columns in the grid.
214 * @return The default grid gap between columns in the grid. <code>null</code> if the platform default is used.
216 public final BoundSize getGridGapX()
221 /** If non-<code>null</code> (<code>null</code> is default) these value will be used as the default gaps between the columns in the grid.
222 * @param x The default grid gap between columns in the grid. If <code>null</code> the platform default is used.
224 public final void setGridGapX(BoundSize x)
229 /** If non-<code>null</code> (<code>null</code> is default) these value will be used as the default gaps between the rows in the grid.
230 * @return The default grid gap between rows in the grid. <code>null</code> if the platform default is used.
232 public final BoundSize getGridGapY()
237 /** If non-<code>null</code> (<code>null</code> is default) these value will be used as the default gaps between the rows in the grid.
238 * @param y The default grid gap between rows in the grid. If <code>null</code> the platform default is used.
240 public final void setGridGapY(BoundSize y)
245 /** How a component that is hidden (not visible) should be treated by default.
246 * @return The mode:<br>
247 * 0 == Normal. Bounds will be calculated as if the component was visible.<br>
248 * 1 == If hidden the size will be 0, 0 but the gaps remain.<br>
249 * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br>
250 * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
252 public final int getHideMode()
257 /** How a component that is hidden (not visible) should be treated.
258 * @param mode The mode:<br>
259 * 0 == Normal. Bounds will be calculated as if the component was visible.<br>
260 * 1 == If hidden the size will be 0, 0 but the gaps remain.<br>
261 * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br>
262 * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
264 public final void setHideMode(int mode)
266 if (mode < 0 || mode > 3)
267 throw new IllegalArgumentException("Wrong hideMode: " + mode);
269 this.hideMode = mode;
272 /** The insets for the layed out panel. The insets will be an empty space around the components in the panel. <code>null</code> values
273 * means that the default panel insets for the platform is used. See {@link PlatformDefaults#setDialogInsets(net.miginfocom.layout.UnitValue, net.miginfocom.layout.UnitValue, net.miginfocom.layout.UnitValue, net.miginfocom.layout.UnitValue)}.
274 * @return The insets. Of length 4 (top, left, bottom, right) or <code>null</code>. The elements (1 to 4) may be <code>null</code>. The array is a copy and can be used freely.
275 * @see net.miginfocom.layout.ConstraintParser#parseInsets(String, boolean)
277 public final UnitValue[] getInsets()
279 return insets != null ? new UnitValue[] {insets[0], insets[1], insets[2], insets[3]} : null;
282 /** The insets for the layed out panel. The insets will be an empty space around the components in the panel. <code>null</code> values
283 * means that the default panel insets for the platform is used. See {@link PlatformDefaults#setDialogInsets(net.miginfocom.layout.UnitValue, net.miginfocom.layout.UnitValue, net.miginfocom.layout.UnitValue, net.miginfocom.layout.UnitValue)}.
284 * @param ins The new insets. Must be of length 4 (top, left, bottom, right) or <code>null</code>. The elements (1 to 4) may be <code>null</code> to use
285 * the platform default for that side. The array is copied for storage.
286 * @see net.miginfocom.layout.ConstraintParser#parseInsets(String, boolean)
288 public final void setInsets(UnitValue[] ins)
290 this.insets = ins != null ? new UnitValue[] {ins[0], ins[1], ins[2], ins[3]} : null;
293 /** If the layout should be forced to be left-to-right or right-to-left. A value of <code>null</code> is default and
294 * means that this will be picked up from the {@link java.util.Locale} that the container being layed out is reporting.
295 * @return <code>Boolean.TRUE</code> if force left-to-right. <code>Boolean.FALSE</code> if force tight-to-left. <code>null</code>
296 * for the default "let the current Locale decide".
298 public final Boolean getLeftToRight()
303 /** If the layout should be forced to be left-to-right or right-to-left. A value of <code>null</code> is default and
304 * means that this will be picked up from the {@link java.util.Locale} that the container being layed out is reporting.
305 * @param b <code>Boolean.TRUE</code> to force left-to-right. <code>Boolean.FALSE</code> to force tight-to-left. <code>null</code>
306 * for the default "let the current Locale decide".
308 public final void setLeftToRight(Boolean b)
310 this.leftToRight = b;
313 /** If the whole layout should be non grid based. It is the same as setting the "nogrid" property on every row/column in the grid.
314 * @return <code>true</code> means not grid based. <code>false</code> is default.
316 public final boolean isNoGrid()
321 /** If the whole layout should be non grid based. It is the same as setting the "nogrid" property on every row/column in the grid.
322 * @param b <code>true</code> means no grid. <code>false</code> is default.
324 public final void setNoGrid(boolean b)
329 /** If the layout should go from the default top-to-bottom in the grid instead of the optional bottom-to-top.
330 * @return <code>true</code> for the default top-to-bottom.
332 public final boolean isTopToBottom()
337 /** If the layout should go from the default top-to-bottom in the grid instead of the optional bottom-to-top.
338 * @param b <code>true</code> for the default top-to-bottom.
340 public final void setTopToBottom(boolean b)
342 this.topToBottom = b;
345 /** If visual padding should be automatically used and compensated for by this layout instance.
346 * @return <code>true</code> if visual padding.
348 public final boolean isVisualPadding()
350 return visualPadding;
353 /** If visual padding should be automatically used and compensated for by this layout instance.
354 * @param b <code>true</code> turns on visual padding.
356 public final void setVisualPadding(boolean b)
358 this.visualPadding = b;
361 /** Returns after what cell the grid should always auto wrap.
362 * @return After what cell the grid should always auto wrap. If <code>0</code> the number of columns/rows in the
363 * {@link net.miginfocom.layout.AC} is used. <code>LayoutUtil.INF</code> is used for no auto wrap.
365 public final int getWrapAfter()
370 /** Sets after what cell the grid should always auto wrap.
371 * @param count After what cell the grid should always auto wrap. If <code>0</code> the number of columns/rows in the
372 * {@link net.miginfocom.layout.AC} is used. <code>LayoutUtil.INF</code> is used for no auto wrap.
374 public final void setWrapAfter(int count)
376 this.wrapAfter = count;
379 /** Returns the "pack width" for the <b>window</b> that this container is located in. When the size of this container changes
380 * the size of the window will be corrected to be within this BoundsSize. It can be used to set the minimum and/or maximum size of the window
381 * as well as the size window should optimally get. This optimal size is normally its "preferred" size which is why "preferred"
382 * is the normal value to set here.
384 * ":push" can be appended to the bound size to only push the size bigger and never shrink it if the preferred size gets smaller.
386 * E.g. "pref", "100:pref", "pref:700", "300::700", "pref:push"
387 * @return The current value. Never <code>null</code>. Check if not set with <code>.isUnset()</code>.
390 public final BoundSize getPackWidth()
395 /** Sets the "pack width" for the <b>window</b> that this container is located in. When the size of this container changes
396 * the size of the window will be corrected to be within this BoundsSize. It can be used to set the minimum and/or maximum size of the window
397 * as well as the size window should optimally get. This optimal size is normally its "preferred" size which is why "preferred"
398 * is the normal value to set here.
400 * ":push" can be appended to the bound size to only push the size bigger and never shrink it if the preferred size gets smaller.
402 * E.g. "pref", "100:pref", "pref:700", "300::700", "pref:push"
403 * @param size The new pack size. If <code>null</code> it will be corrected to an "unset" BoundSize.
406 public final void setPackWidth(BoundSize size)
408 packW = size != null ? size : BoundSize.NULL_SIZE;
411 /** Returns the "pack height" for the <b>window</b> that this container is located in. When the size of this container changes
412 * the size of the window will be corrected to be within this BoundsSize. It can be used to set the minimum and/or maximum size of the window
413 * as well as the size window should optimally get. This optimal size is normally its "preferred" size which is why "preferred"
414 * is the normal value to set here.
416 * ":push" can be appended to the bound size to only push the size bigger and never shrink it if the preferred size gets smaller.
418 * E.g. "pref", "100:pref", "pref:700", "300::700", "pref:push"
419 * @return The current value. Never <code>null</code>. Check if not set with <code>.isUnset()</code>.
422 public final BoundSize getPackHeight()
427 /** Sets the "pack height" for the <b>window</b> that this container is located in. When the size of this container changes
428 * the size of the window will be corrected to be within this BoundsSize. It can be used to set the minimum and/or maximum size of the window
429 * as well as the size window should optimally get. This optimal size is normally its "preferred" size which is why "preferred"
430 * is the normal value to set here.
432 * ":push" can be appended to the bound size to only push the size bigger and never shrink it if the preferred size gets smaller.
434 * E.g. "pref", "100:pref", "pref:700", "300::700", "pref:push"
435 * @param size The new pack size. If <code>null</code> it will be corrected to an "unset" BoundSize.
438 public final void setPackHeight(BoundSize size)
440 packH = size != null ? size : BoundSize.NULL_SIZE;
444 /** If there is a resize of the window due to packing (see {@link #setPackHeight(BoundSize)} this value, which is between 0f and 1f,
445 * decides where the extra/superfluous size is placed. 0f means that the window will resize so that the upper part moves up and the
446 * lower side stays in the same place. 0.5f will expand/reduce the window equally upwards and downwards. 1f will do the opposite of 0f
448 * @return The pack alignment. Always between 0f and 1f, inclusive.
451 public final float getPackHeightAlign()
456 /** If there is a resize of the window due to packing (see {@link #setPackHeight(BoundSize)} this value, which is between 0f and 1f,
457 * decides where the extra/superfluous size is placed. 0f means that the window will resize so that the upper part moves up and the
458 * lower side stays in the same place. 0.5f will expand/reduce the window equally upwards and downwards. 1f will do the opposite of 0f
460 * @param align The pack alignment. Always between 0f and 1f, inclusive. Values outside this will be truncated.
463 public final void setPackHeightAlign(float align)
465 phAlign = Math.max(0f, Math.min(1f, align));
468 /** If there is a resize of the window due to packing (see {@link #setPackHeight(BoundSize)} this value, which is between 0f and 1f,
469 * decides where the extra/superfluous size is placed. 0f means that the window will resize so that the left part moves left and the
470 * right side stays in the same place. 0.5f will expand/reduce the window equally to the right and lefts. 1f will do the opposite of 0f
472 * @return The pack alignment. Always between 0f and 1f, inclusive.
475 public final float getPackWidthAlign()
480 /** If there is a resize of the window due to packing (see {@link #setPackHeight(BoundSize)} this value, which is between 0f and 1f,
481 * decides where the extra/superfluous size is placed. 0f means that the window will resize so that the left part moves left and the
482 * right side stays in the same place. 0.5f will expand/reduce the window equally to the right and lefts. 1f will do the opposite of 0f
484 * @param align The pack alignment. Always between 0f and 1f, inclusive. Values outside this will be truncated.
487 public final void setPackWidthAlign(float align)
489 pwAlign = Math.max(0f, Math.min(1f, align));
492 /** Returns the minimum/preferred/maximum size for the container that this layout constraint is set for. Any of these
493 * sizes that is not <code>null</code> will be returned directly instead of determining the corresponding size through
494 * asking the components in this container.
495 * @return The width for the container that this layout constraint is set for. Not <code>null</code> but
496 * all sizes can be <code>null</code>.
499 public final BoundSize getWidth()
504 /** Sets the minimum/preferred/maximum size for the container that this layout constraint is set for. Any of these
505 * sizes that is not <code>null</code> will be returned directly instead of determining the corresponding size through
506 * asking the components in this container.
507 * @param size The width for the container that this layout constraint is set for. <code>null</code> is translated to
508 * a bound size containing only null sizes.
511 public final void setWidth(BoundSize size)
513 this.width = size != null ? size : BoundSize.NULL_SIZE;
516 /** Returns the minimum/preferred/maximum size for the container that this layout constraint is set for. Any of these
517 * sizes that is not <code>null</code> will be returned directly instead of determining the corresponding size through
518 * asking the components in this container.
519 * @return The height for the container that this layout constraint is set for. Not <code>null</code> but
520 * all sizes can be <code>null</code>.
523 public final BoundSize getHeight()
528 /** Sets the minimum/preferred/maximum size for the container that this layout constraint is set for. Any of these
529 * sizes that is not <code>null</code> will be returned directly instead of determining the corresponding size through
530 * asking the components in this container.
531 * @param size The height for the container that this layout constraint is set for. <code>null</code> is translated to
532 * a bound size containing only null sizes.
535 public final void setHeight(BoundSize size)
537 this.height = size != null ? size : BoundSize.NULL_SIZE;
540 // ************************************************************************
541 // * Builder methods.
542 // ************************************************************************
544 /** Short for, and thus same as, <code>.pack("pref", "pref")</code>.
546 * Same functionality as {@link #setPackHeight(BoundSize)} and {@link #setPackWidth(net.miginfocom.layout.BoundSize)}
547 * only this method returns <code>this</code> for chaining multiple calls.
549 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
550 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
553 public final LC pack()
555 return pack("pref", "pref");
558 /** Sets the pack width and height.
560 * Same functionality as {@link #setPackHeight(BoundSize)} and {@link #setPackWidth(net.miginfocom.layout.BoundSize)}
561 * only this method returns <code>this</code> for chaining multiple calls.
563 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
564 * @param width The pack width. May be <code>null</code>.
565 * @param height The pack height. May be <code>null</code>.
566 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
569 public final LC pack(String width, String height)
571 setPackWidth(width != null ? ConstraintParser.parseBoundSize(width, false, true) : BoundSize.NULL_SIZE);
572 setPackHeight(height != null ? ConstraintParser.parseBoundSize(height, false, false) : BoundSize.NULL_SIZE);
576 /** Sets the pack width and height alignment.
578 * Same functionality as {@link #setPackHeightAlign(float)} and {@link #setPackWidthAlign(float)}
579 * only this method returns <code>this</code> for chaining multiple calls.
581 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
582 * @param alignX The pack width alignment. 0.5f is default.
583 * @param alignY The pack height alignment. 0.5f is default.
584 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
587 public final LC packAlign(float alignX, float alignY)
589 setPackWidthAlign(alignX);
590 setPackHeightAlign(alignY);
594 /** Sets a wrap after the number of columns/rows that is defined in the {@link net.miginfocom.layout.AC}.
596 * Same functionality as calling {@link #setWrapAfter(int)} with <code>0</code> only this method returns <code>this</code> for chaining multiple calls.
598 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
599 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
601 public final LC wrap()
607 /** Same functionality as {@link #setWrapAfter(int)} only this method returns <code>this</code> for chaining multiple calls.
609 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
610 * @param count After what cell the grid should always auto wrap. If <code>0</code> the number of columns/rows in the
611 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
613 public final LC wrapAfter(int count)
619 /** Same functionality as calling {@link #setNoCache(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
621 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
622 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
624 public final LC noCache()
630 /** Same functionality as calling {@link #setFlowX(boolean)} with <code>false</code> only this method returns <code>this</code> for chaining multiple calls.
632 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
633 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
635 public final LC flowY()
641 /** Same functionality as calling {@link #setFlowX(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
643 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
644 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
646 public final LC flowX()
652 /** Same functionality as calling {@link #setFillX(boolean)} with <code>true</code> and {@link #setFillY(boolean)} with <code>true</code> conmbined.T his method returns
653 * <code>this</code> for chaining multiple calls.
655 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
656 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
658 public final LC fill()
665 /** Same functionality as calling {@link #setFillX(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
667 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
668 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
670 public final LC fillX()
676 /** Same functionality as calling {@link #setFillY(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
678 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
679 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
681 public final LC fillY()
687 /** Same functionality as {@link #setLeftToRight(Boolean)} only this method returns <code>this</code> for chaining multiple calls.
689 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
690 * @param b <code>true</code> for forcing left-to-right. <code>false</code> for forcing right-to-left.
691 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
693 public final LC leftToRight(boolean b)
695 setLeftToRight(b ? Boolean.TRUE : Boolean.FALSE);
699 /** Same functionality as setLeftToRight(false) only this method returns <code>this</code> for chaining multiple calls.
701 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
702 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
705 public final LC rightToLeft()
707 setLeftToRight(Boolean.FALSE);
711 /** Same functionality as calling {@link #setTopToBottom(boolean)} with <code>false</code> only this method returns <code>this</code> for chaining multiple calls.
713 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
714 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
716 public final LC bottomToTop()
718 setTopToBottom(false);
722 /** Same functionality as calling {@link #setTopToBottom(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
724 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
725 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
728 public final LC topToBottom()
730 setTopToBottom(true);
734 /** Same functionality as calling {@link #setNoGrid(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
736 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
737 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
739 public final LC noGrid()
745 /** Same functionality as calling {@link #setVisualPadding(boolean)} with <code>false</code> only this method returns <code>this</code> for chaining multiple calls.
747 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
748 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
750 public final LC noVisualPadding()
752 setVisualPadding(false);
756 /** Sets the same inset (expressed as a <code>UnitValue</code>, e.g. "10px" or "20mm") all around.
758 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
759 * @param allSides The unit value to set for all sides. May be <code>null</code> which means that the default panel insets
760 * for the platform is used.
761 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
762 * @see #setInsets(UnitValue[])
764 public final LC insetsAll(String allSides)
766 UnitValue insH = ConstraintParser.parseUnitValue(allSides, true);
767 UnitValue insV = ConstraintParser.parseUnitValue(allSides, false);
768 insets = new UnitValue[] {insV, insH, insV, insH}; // No setter to avoid copy again
772 /** Same functionality as <code>setInsets(ConstraintParser.parseInsets(s, true))</code>. This method returns <code>this</code>
773 * for chaining multiple calls.
775 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
776 * @param s The string to parse. E.g. "10 10 10 10" or "20". If less than 4 groups the last will be used for the missing.
777 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
778 * @see #setInsets(UnitValue[])
780 public final LC insets(String s)
782 insets = ConstraintParser.parseInsets(s, true);
786 /** Sets the different insets (expressed as a <code>UnitValue</code>s, e.g. "10px" or "20mm") for the corresponding sides.
788 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
789 * @param top The top inset. E.g. "10px" or "10mm" or "related". May be <code>null</code> in which case the default inset for this
790 * side for the platform will be used.
791 * @param left The left inset. E.g. "10px" or "10mm" or "related". May be <code>null</code> in which case the default inset for this
792 * side for the platform will be used.
793 * @param bottom The bottom inset. E.g. "10px" or "10mm" or "related". May be <code>null</code> in which case the default inset for this
794 * side for the platform will be used.
795 * @param right The right inset. E.g. "10px" or "10mm" or "related". May be <code>null</code> in which case the default inset for this
796 * side for the platform will be used.
797 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
798 * @see #setInsets(UnitValue[])
800 public final LC insets(String top, String left, String bottom, String right)
802 insets = new UnitValue[] { // No setter to avoid copy again
803 ConstraintParser.parseUnitValue(top, false),
804 ConstraintParser.parseUnitValue(left, true),
805 ConstraintParser.parseUnitValue(bottom, false),
806 ConstraintParser.parseUnitValue(right, true)};
810 /** Same functionality as <code>setAlignX(ConstraintParser.parseUnitValueOrAlign(unitValue, true))</code> only this method returns <code>this</code>
811 * for chaining multiple calls.
813 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
814 * @param align The align keyword or for instance "100px". E.g "left", "right", "leading" or "trailing".
815 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
816 * @see #setAlignX(UnitValue)
818 public final LC alignX(String align)
820 setAlignX(ConstraintParser.parseUnitValueOrAlign(align, true, null));
824 /** Same functionality as <code>setAlignY(ConstraintParser.parseUnitValueOrAlign(align, false))</code> only this method returns <code>this</code> for chaining multiple calls.
826 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
827 * @param align The align keyword or for instance "100px". E.g "top" or "bottom".
828 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
829 * @see #setAlignY(UnitValue)
831 public final LC alignY(String align)
833 setAlignY(ConstraintParser.parseUnitValueOrAlign(align, false, null));
837 /** Sets both the alignX and alignY as the same time.
839 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
840 * @param ax The align keyword or for instance "100px". E.g "left", "right", "leading" or "trailing".
841 * @param ay The align keyword or for instance "100px". E.g "top" or "bottom".
842 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
843 * @see #alignX(String)
844 * @see #alignY(String)
846 public final LC align(String ax, String ay)
857 /** Same functionality as <code>setGridGapX(ConstraintParser.parseBoundSize(boundsSize, true, true))</code> only this method
858 * returns <code>this</code> for chaining multiple calls.
860 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
861 * @param boundsSize The <code>BoundSize</code> of the gap. This is a minimum and/or preferred and/or maximum size. E.g.
862 * <code>"50:100:200"</code> or <code>"100px"</code>.
863 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
864 * @see #setGridGapX(BoundSize)
866 public final LC gridGapX(String boundsSize)
868 setGridGapX(ConstraintParser.parseBoundSize(boundsSize, true, true));
872 /** Same functionality as <code>setGridGapY(ConstraintParser.parseBoundSize(boundsSize, true, false))</code> only this method
873 * returns <code>this</code> for chaining multiple calls.
875 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
876 * @param boundsSize The <code>BoundSize</code> of the gap. This is a minimum and/or preferred and/or maximum size. E.g.
877 * <code>"50:100:200"</code> or <code>"100px"</code>.
878 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
879 * @see #setGridGapY(BoundSize)
881 public final LC gridGapY(String boundsSize)
883 setGridGapY(ConstraintParser.parseBoundSize(boundsSize, true, false));
887 /** Sets both grid gaps at the same time. see {@link #gridGapX(String)} and {@link #gridGapY(String)}.
889 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
890 * @param gapx The <code>BoundSize</code> of the gap. This is a minimum and/or preferred and/or maximum size. E.g.
891 * <code>"50:100:200"</code> or <code>"100px"</code>.
892 * @param gapy The <code>BoundSize</code> of the gap. This is a minimum and/or preferred and/or maximum size. E.g.
893 * <code>"50:100:200"</code> or <code>"100px"</code>.
894 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
895 * @see #gridGapX(String)
896 * @see #gridGapY(String)
898 public final LC gridGap(String gapx, String gapy)
909 /** Calls {@link #debug(int)} with 300 as an argument.
910 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
911 * @see #setDebugMillis(int)
913 public final LC debug()
919 /** Same functionality as {@link #setDebugMillis(int repaintMillis)} only this method returns <code>this</code> for chaining multiple calls.
921 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
922 * @param repaintMillis The new debug repaint interval.
923 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
924 * @see #setDebugMillis(int)
926 public final LC debug(int repaintMillis)
928 setDebugMillis(repaintMillis);
932 /** Same functionality as {@link #setHideMode(int mode)} only this method returns <code>this</code> for chaining multiple calls.
934 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
935 * @param mode The mode:<br>
936 * 0 == Normal. Bounds will be calculated as if the component was visible.<br>
937 * 1 == If hidden the size will be 0, 0 but the gaps remain.<br>
938 * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br>
939 * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
940 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
941 * @see #setHideMode(int)
943 public final LC hideMode(int mode)
949 /** The minimum width for the container. The value will override any value that is set on the container itself.
951 * For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com.
952 * @param width The width expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm".
953 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
955 public final LC minWidth(String width)
957 setWidth(LayoutUtil.derive(getWidth(), ConstraintParser.parseUnitValue(width, true), null, null));
961 /** The width for the container as a min and/or preferred and/or maximum width. The value will override any value that is set on
962 * the container itself.
964 * For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com.
965 * @param width The width expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px".
966 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
968 public final LC width(String width)
970 setWidth(ConstraintParser.parseBoundSize(width, false, true));
974 /** The maximum width for the container. The value will override any value that is set on the container itself.
976 * For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com.
977 * @param width The width expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm".
978 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
980 public final LC maxWidth(String width)
982 setWidth(LayoutUtil.derive(getWidth(), null, null, ConstraintParser.parseUnitValue(width, true)));
986 /** The minimum height for the container. The value will override any value that is set on the container itself.
988 * For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com.
989 * @param height The height expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm".
990 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
992 public final LC minHeight(String height)
994 setHeight(LayoutUtil.derive(getHeight(), ConstraintParser.parseUnitValue(height, false), null, null));
998 /** The height for the container as a min and/or preferred and/or maximum height. The value will override any value that is set on
999 * the container itself.
1001 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcontainers.com.
1002 * @param height The height expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px".
1003 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
1005 public final LC height(String height)
1007 setHeight(ConstraintParser.parseBoundSize(height, false, false));
1011 /** The maximum height for the container. The value will override any value that is set on the container itself.
1013 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcontainers.com.
1014 * @param height The height expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm".
1015 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
1017 public final LC maxHeight(String height)
1019 setHeight(LayoutUtil.derive(getHeight(), null, null, ConstraintParser.parseUnitValue(height, false)));
1023 // ************************************************
1024 // Persistence Delegate and Serializable combined.
1025 // ************************************************
1027 private Object readResolve() throws ObjectStreamException
1029 return LayoutUtil.getSerializedObject(this);
1033 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
1035 LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
1039 public void writeExternal(ObjectOutput out) throws IOException
1041 if (getClass() == LC.class)
1042 LayoutUtil.writeAsXML(out, this);