1 package net.miginfocom.layout;
7 * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
10 * Redistribution and use in source and binary forms, with or without modification,
11 * are permitted provided that the following conditions are met:
12 * Redistributions of source code must retain the above copyright notice, this list
13 * of conditions and the following disclaimer.
14 * Redistributions in binary form must reproduce the above copyright notice, this
15 * list of conditions and the following disclaimer in the documentation and/or other
16 * materials provided with the distribution.
17 * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
18 * used to endorse or promote products derived from this software without specific
19 * prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
27 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
33 * @author Mikael Grev, MiG InfoCom AB
39 /** Contains the constraints for an instance of the {@link LC} layout manager.
41 public final class LC //implements Externalizable
43 // See the corresponding set/get method for documentation of the property!
45 private int wrapAfter = LayoutUtil.INF;
47 private Boolean leftToRight = null;
49 private UnitValue[] insets = null; // Never null elements but if unset array is null
51 private UnitValue alignX = null, alignY = null;
53 private BoundSize gridGapX = null, gridGapY = null;
55 private BoundSize width = BoundSize.NULL_SIZE, height = BoundSize.NULL_SIZE;
57 private BoundSize packW = BoundSize.NULL_SIZE, packH = BoundSize.NULL_SIZE;
59 private float pwAlign = 0.5f, phAlign = 1.0f;
61 private int debugMillis = 0;
63 private int hideMode = 0;
65 private boolean noCache = false;
67 private boolean flowX = true;
69 private boolean fillX = false, fillY = false;
71 private boolean topToBottom = true;
73 private boolean noGrid = false;
75 private boolean visualPadding = true;
77 /** Empty constructor.
83 // ************************************************************************
84 // * JavaBean get/set methods.
85 // ************************************************************************
88 /** 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
89 * 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>.
90 * @return <code>true</code> means no cache and slightly slower layout.
92 public boolean isNoCache()
97 /** 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
98 * 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>.
99 * @param b <code>true</code> means no cache and slightly slower layout.
101 public void setNoCache(boolean b)
106 /** 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
107 * in the parent. <code>null</code> is default and that means top/left alignment. The relative distances between the components will not be affected
109 * @return The current alignment.
111 public final UnitValue getAlignX()
116 /** 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
117 * in the parent. <code>null</code> is default and that means top/left alignment. The relative distances between the components will not be affected
119 * @param uv The new alignment. Use {@link ConstraintParser#parseAlignKeywords(String, boolean)} to create the {@link UnitValue}. May be <code>null</code>.
121 public final void setAlignX(UnitValue uv)
126 /** 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
127 * in the parent. <code>null</code> is default and that means top/left alignment. The relative distances between the components will not be affected
129 * @return The current alignment.
131 public final UnitValue getAlignY()
136 /** 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
137 * in the parent. <code>null</code> is default and that means top/left alignment. The relative distances between the components will not be affected
139 * @param uv The new alignment. Use {@link ConstraintParser#parseAlignKeywords(String, boolean)} to create the {@link UnitValue}. May be <code>null</code>.
141 public final void setAlignY(UnitValue uv)
146 /** If <code>> 0</code> the debug decorations will be repainted every <code>millis</code>. No debug information if <code><= 0</code> (default).
147 * @return The current debug repaint interval.
149 public final int getDebugMillis()
154 /** If <code>> 0</code> the debug decorations will be repainted every <code>millis</code>. No debug information if <code><= 0</code> (default).
155 * @param millis The new debug repaint interval.
157 public final void setDebugMillis(int millis)
159 this.debugMillis = millis;
162 /** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller.
163 * @return <code>true</code> means fill. <code>false</code> is default.
165 public final boolean isFillX()
170 /** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller.
171 * @param b <code>true</code> means fill. <code>false</code> is default.
173 public final void setFillX(boolean b)
178 /** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller.
179 * @return <code>true</code> means fill. <code>false</code> is default.
181 public final boolean isFillY()
186 /** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller.
187 * @param b <code>true</code> means fill. <code>false</code> is default.
189 public final void setFillY(boolean b)
194 /** The default flow direction. Normally (which is <code>true</code>) this is horizontal and that means that the "next" component
195 * will be put in the cell to the right (or to the left if left-to-right is false).
196 * @return <code>true</code> is the default flow horizontally.
197 * @see #setLeftToRight(Boolean)
199 public final boolean isFlowX()
204 /** The default flow direction. Normally (which is <code>true</code>) this is horizontal and that means that the "next" component
205 * will be put in the cell to the right (or to the left if left-to-right is false).
206 * @param b <code>true</code> is the default flow horizontally.
207 * @see #setLeftToRight(Boolean)
209 public final void setFlowX(boolean b)
214 /** 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.
215 * @return The default grid gap between columns in the grid. <code>null</code> if the platform default is used.
217 public final BoundSize getGridGapX()
222 /** 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.
223 * @param x The default grid gap between columns in the grid. If <code>null</code> the platform default is used.
225 public final void setGridGapX(BoundSize x)
230 /** 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.
231 * @return The default grid gap between rows in the grid. <code>null</code> if the platform default is used.
233 public final BoundSize getGridGapY()
238 /** 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.
239 * @param y The default grid gap between rows in the grid. If <code>null</code> the platform default is used.
241 public final void setGridGapY(BoundSize y)
246 /** How a component that is hidden (not visible) should be treated by default.
247 * @return The mode:<br>
248 * 0 == Normal. Bounds will be calculated as if the component was visible.<br>
249 * 1 == If hidden the size will be 0, 0 but the gaps remain.<br>
250 * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br>
251 * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
253 public final int getHideMode()
258 /** How a component that is hidden (not visible) should be treated.
259 * @param mode The mode:<br>
260 * 0 == Normal. Bounds will be calculated as if the component was visible.<br>
261 * 1 == If hidden the size will be 0, 0 but the gaps remain.<br>
262 * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br>
263 * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
265 public final void setHideMode(int mode)
267 if (mode < 0 || mode > 3)
268 throw new IllegalArgumentException("Wrong hideMode: " + mode);
270 this.hideMode = mode;
273 /** The insets for the layed out panel. The insets will be an empty space around the components in the panel. <code>null</code> values
274 * 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)}.
275 * @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.
276 * @see net.miginfocom.layout.ConstraintParser#parseInsets(String, boolean)
278 public final UnitValue[] getInsets()
280 return insets != null ? new UnitValue[] {insets[0], insets[1], insets[2], insets[3]} : null;
283 /** The insets for the layed out panel. The insets will be an empty space around the components in the panel. <code>null</code> values
284 * 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)}.
285 * @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
286 * the platform default for that side. The array is copied for storage.
287 * @see net.miginfocom.layout.ConstraintParser#parseInsets(String, boolean)
289 public final void setInsets(UnitValue[] ins)
291 this.insets = ins != null ? new UnitValue[] {ins[0], ins[1], ins[2], ins[3]} : null;
294 /** If the layout should be forced to be left-to-right or right-to-left. A value of <code>null</code> is default and
295 * means that this will be picked up from the {@link java.util.Locale} that the container being layed out is reporting.
296 * @return <code>Boolean.TRUE</code> if force left-to-right. <code>Boolean.FALSE</code> if force tight-to-left. <code>null</code>
297 * for the default "let the current Locale decide".
299 public final Boolean getLeftToRight()
304 /** If the layout should be forced to be left-to-right or right-to-left. A value of <code>null</code> is default and
305 * means that this will be picked up from the {@link java.util.Locale} that the container being layed out is reporting.
306 * @param b <code>Boolean.TRUE</code> to force left-to-right. <code>Boolean.FALSE</code> to force tight-to-left. <code>null</code>
307 * for the default "let the current Locale decide".
309 public final void setLeftToRight(Boolean b)
311 this.leftToRight = b;
314 /** 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.
315 * @return <code>true</code> means not grid based. <code>false</code> is default.
317 public final boolean isNoGrid()
322 /** 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.
323 * @param b <code>true</code> means no grid. <code>false</code> is default.
325 public final void setNoGrid(boolean b)
330 /** If the layout should go from the default top-to-bottom in the grid instead of the optional bottom-to-top.
331 * @return <code>true</code> for the default top-to-bottom.
333 public final boolean isTopToBottom()
338 /** If the layout should go from the default top-to-bottom in the grid instead of the optional bottom-to-top.
339 * @param b <code>true</code> for the default top-to-bottom.
341 public final void setTopToBottom(boolean b)
343 this.topToBottom = b;
346 /** If visual padding should be automatically used and compensated for by this layout instance.
347 * @return <code>true</code> if visual padding.
349 public final boolean isVisualPadding()
351 return visualPadding;
354 /** If visual padding should be automatically used and compensated for by this layout instance.
355 * @param b <code>true</code> turns on visual padding.
357 public final void setVisualPadding(boolean b)
359 this.visualPadding = b;
362 /** Returns after what cell the grid should always auto wrap.
363 * @return After what cell the grid should always auto wrap. If <code>0</code> the number of columns/rows in the
364 * {@link net.miginfocom.layout.AC} is used. <code>LayoutUtil.INF</code> is used for no auto wrap.
366 public final int getWrapAfter()
371 /** Sets after what cell the grid should always auto wrap.
372 * @param count After what cell the grid should always auto wrap. If <code>0</code> the number of columns/rows in the
373 * {@link net.miginfocom.layout.AC} is used. <code>LayoutUtil.INF</code> is used for no auto wrap.
375 public final void setWrapAfter(int count)
377 this.wrapAfter = count;
380 /** Returns the "pack width" for the <b>window</b> that this container is located in. When the size of this container changes
381 * 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
382 * as well as the size window should optimally get. This optimal size is normally its "preferred" size which is why "preferred"
383 * is the normal value to set here.
385 * ":push" can be appended to the bound size to only push the size bigger and never shrink it if the preferred size gets smaller.
387 * E.g. "pref", "100:pref", "pref:700", "300::700", "pref:push"
388 * @return The current value. Never <code>null</code>. Check if not set with <code>.isUnset()</code>.
391 public final BoundSize getPackWidth()
396 /** Sets the "pack width" for the <b>window</b> that this container is located in. When the size of this container changes
397 * 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
398 * as well as the size window should optimally get. This optimal size is normally its "preferred" size which is why "preferred"
399 * is the normal value to set here.
401 * ":push" can be appended to the bound size to only push the size bigger and never shrink it if the preferred size gets smaller.
403 * E.g. "pref", "100:pref", "pref:700", "300::700", "pref:push"
404 * @param size The new pack size. If <code>null</code> it will be corrected to an "unset" BoundSize.
407 public final void setPackWidth(BoundSize size)
409 packW = size != null ? size : BoundSize.NULL_SIZE;
412 /** Returns the "pack height" for the <b>window</b> that this container is located in. When the size of this container changes
413 * 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
414 * as well as the size window should optimally get. This optimal size is normally its "preferred" size which is why "preferred"
415 * is the normal value to set here.
417 * ":push" can be appended to the bound size to only push the size bigger and never shrink it if the preferred size gets smaller.
419 * E.g. "pref", "100:pref", "pref:700", "300::700", "pref:push"
420 * @return The current value. Never <code>null</code>. Check if not set with <code>.isUnset()</code>.
423 public final BoundSize getPackHeight()
428 /** Sets the "pack height" for the <b>window</b> that this container is located in. When the size of this container changes
429 * 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
430 * as well as the size window should optimally get. This optimal size is normally its "preferred" size which is why "preferred"
431 * is the normal value to set here.
433 * ":push" can be appended to the bound size to only push the size bigger and never shrink it if the preferred size gets smaller.
435 * E.g. "pref", "100:pref", "pref:700", "300::700", "pref:push"
436 * @param size The new pack size. If <code>null</code> it will be corrected to an "unset" BoundSize.
439 public final void setPackHeight(BoundSize size)
441 packH = size != null ? size : BoundSize.NULL_SIZE;
445 /** If there is a resize of the window due to packing (see {@link #setPackHeight(BoundSize)} this value, which is between 0f and 1f,
446 * decides where the extra/superfluous size is placed. 0f means that the window will resize so that the upper part moves up and the
447 * 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
449 * @return The pack alignment. Always between 0f and 1f, inclusive.
452 public final float getPackHeightAlign()
457 /** If there is a resize of the window due to packing (see {@link #setPackHeight(BoundSize)} this value, which is between 0f and 1f,
458 * decides where the extra/superfluous size is placed. 0f means that the window will resize so that the upper part moves up and the
459 * 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
461 * @param align The pack alignment. Always between 0f and 1f, inclusive. Values outside this will be truncated.
464 public final void setPackHeightAlign(float align)
466 phAlign = Math.max(0f, Math.min(1f, align));
469 /** If there is a resize of the window due to packing (see {@link #setPackHeight(BoundSize)} this value, which is between 0f and 1f,
470 * decides where the extra/superfluous size is placed. 0f means that the window will resize so that the left part moves left and the
471 * 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
473 * @return The pack alignment. Always between 0f and 1f, inclusive.
476 public final float getPackWidthAlign()
481 /** If there is a resize of the window due to packing (see {@link #setPackHeight(BoundSize)} this value, which is between 0f and 1f,
482 * decides where the extra/superfluous size is placed. 0f means that the window will resize so that the left part moves left and the
483 * 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
485 * @param align The pack alignment. Always between 0f and 1f, inclusive. Values outside this will be truncated.
488 public final void setPackWidthAlign(float align)
490 pwAlign = Math.max(0f, Math.min(1f, align));
493 /** Returns the minimum/preferred/maximum size for the container that this layout constraint is set for. Any of these
494 * sizes that is not <code>null</code> will be returned directly instead of determining the corresponding size through
495 * asking the components in this container.
496 * @return The width for the container that this layout constraint is set for. Not <code>null</code> but
497 * all sizes can be <code>null</code>.
500 public final BoundSize getWidth()
505 /** Sets the minimum/preferred/maximum size for the container that this layout constraint is set for. Any of these
506 * sizes that is not <code>null</code> will be returned directly instead of determining the corresponding size through
507 * asking the components in this container.
508 * @param size The width for the container that this layout constraint is set for. <code>null</code> is translated to
509 * a bound size containing only null sizes.
512 public final void setWidth(BoundSize size)
514 this.width = size != null ? size : BoundSize.NULL_SIZE;
517 /** Returns the minimum/preferred/maximum size for the container that this layout constraint is set for. Any of these
518 * sizes that is not <code>null</code> will be returned directly instead of determining the corresponding size through
519 * asking the components in this container.
520 * @return The height for the container that this layout constraint is set for. Not <code>null</code> but
521 * all sizes can be <code>null</code>.
524 public final BoundSize getHeight()
529 /** Sets the minimum/preferred/maximum size for the container that this layout constraint is set for. Any of these
530 * sizes that is not <code>null</code> will be returned directly instead of determining the corresponding size through
531 * asking the components in this container.
532 * @param size The height for the container that this layout constraint is set for. <code>null</code> is translated to
533 * a bound size containing only null sizes.
536 public final void setHeight(BoundSize size)
538 this.height = size != null ? size : BoundSize.NULL_SIZE;
541 // ************************************************************************
542 // * Builder methods.
543 // ************************************************************************
545 /** Short for, and thus same as, <code>.pack("pref", "pref")</code>.
547 * Same functionality as {@link #setPackHeight(BoundSize)} and {@link #setPackWidth(net.miginfocom.layout.BoundSize)}
548 * only this method returns <code>this</code> for chaining multiple calls.
550 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
551 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
554 public final LC pack()
556 return pack("pref", "pref");
559 /** Sets the pack width and height.
561 * Same functionality as {@link #setPackHeight(BoundSize)} and {@link #setPackWidth(net.miginfocom.layout.BoundSize)}
562 * only this method returns <code>this</code> for chaining multiple calls.
564 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
565 * @param width The pack width. May be <code>null</code>.
566 * @param height The pack height. May be <code>null</code>.
567 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
570 public final LC pack(String width, String height)
572 setPackWidth(width != null ? ConstraintParser.parseBoundSize(width, false, true) : BoundSize.NULL_SIZE);
573 setPackHeight(height != null ? ConstraintParser.parseBoundSize(height, false, false) : BoundSize.NULL_SIZE);
577 /** Sets the pack width and height alignment.
579 * Same functionality as {@link #setPackHeightAlign(float)} and {@link #setPackWidthAlign(float)}
580 * only this method returns <code>this</code> for chaining multiple calls.
582 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
583 * @param alignX The pack width alignment. 0.5f is default.
584 * @param alignY The pack height alignment. 0.5f is default.
585 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
588 public final LC packAlign(float alignX, float alignY)
590 setPackWidthAlign(alignX);
591 setPackHeightAlign(alignY);
595 /** Sets a wrap after the number of columns/rows that is defined in the {@link net.miginfocom.layout.AC}.
597 * Same functionality as calling {@link #setWrapAfter(int)} with <code>0</code> only this method returns <code>this</code> for chaining multiple calls.
599 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
600 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
602 public final LC wrap()
608 /** Same functionality as {@link #setWrapAfter(int)} only this method returns <code>this</code> for chaining multiple calls.
610 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
611 * @param count After what cell the grid should always auto wrap. If <code>0</code> the number of columns/rows in the
612 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
614 public final LC wrapAfter(int count)
620 /** Same functionality as calling {@link #setNoCache(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
622 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
623 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
625 public final LC noCache()
631 /** Same functionality as calling {@link #setFlowX(boolean)} with <code>false</code> only this method returns <code>this</code> for chaining multiple calls.
633 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
634 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
636 public final LC flowY()
642 /** Same functionality as calling {@link #setFlowX(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
644 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
645 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
647 public final LC flowX()
653 /** Same functionality as calling {@link #setFillX(boolean)} with <code>true</code> and {@link #setFillY(boolean)} with <code>true</code> conmbined.T his method returns
654 * <code>this</code> for chaining multiple calls.
656 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
657 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
659 public final LC fill()
666 /** Same functionality as calling {@link #setFillX(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
668 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
669 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
671 public final LC fillX()
677 /** Same functionality as calling {@link #setFillY(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
679 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
680 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
682 public final LC fillY()
688 /** Same functionality as {@link #setLeftToRight(Boolean)} only this method returns <code>this</code> for chaining multiple calls.
690 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
691 * @param b <code>true</code> for forcing left-to-right. <code>false</code> for forcing right-to-left.
692 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
694 public final LC leftToRight(boolean b)
696 setLeftToRight(b ? Boolean.TRUE : Boolean.FALSE);
700 /** Same functionality as setLeftToRight(false) only this method returns <code>this</code> for chaining multiple calls.
702 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
703 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
706 public final LC rightToLeft()
708 setLeftToRight(Boolean.FALSE);
712 /** Same functionality as calling {@link #setTopToBottom(boolean)} with <code>false</code> only this method returns <code>this</code> for chaining multiple calls.
714 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
715 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
717 public final LC bottomToTop()
719 setTopToBottom(false);
723 /** Same functionality as calling {@link #setTopToBottom(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
725 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
726 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
729 public final LC topToBottom()
731 setTopToBottom(true);
735 /** Same functionality as calling {@link #setNoGrid(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
737 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
738 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
740 public final LC noGrid()
746 /** Same functionality as calling {@link #setVisualPadding(boolean)} with <code>false</code> only this method returns <code>this</code> for chaining multiple calls.
748 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
749 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
751 public final LC noVisualPadding()
753 setVisualPadding(false);
757 /** Sets the same inset (expressed as a <code>UnitValue</code>, e.g. "10px" or "20mm") all around.
759 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
760 * @param allSides The unit value to set for all sides. May be <code>null</code> which means that the default panel insets
761 * for the platform is used.
762 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
763 * @see #setInsets(UnitValue[])
765 public final LC insetsAll(String allSides)
767 UnitValue insH = ConstraintParser.parseUnitValue(allSides, true);
768 UnitValue insV = ConstraintParser.parseUnitValue(allSides, false);
769 insets = new UnitValue[] {insV, insH, insV, insH}; // No setter to avoid copy again
773 /** Same functionality as <code>setInsets(ConstraintParser.parseInsets(s, true))</code>. This method returns <code>this</code>
774 * for chaining multiple calls.
776 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
777 * @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.
778 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
779 * @see #setInsets(UnitValue[])
781 public final LC insets(String s)
783 insets = ConstraintParser.parseInsets(s, true);
787 /** Sets the different insets (expressed as a <code>UnitValue</code>s, e.g. "10px" or "20mm") for the corresponding sides.
789 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
790 * @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
791 * side for the platform will be used.
792 * @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
793 * side for the platform will be used.
794 * @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
795 * side for the platform will be used.
796 * @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
797 * side for the platform will be used.
798 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
799 * @see #setInsets(UnitValue[])
801 public final LC insets(String top, String left, String bottom, String right)
803 insets = new UnitValue[] { // No setter to avoid copy again
804 ConstraintParser.parseUnitValue(top, false),
805 ConstraintParser.parseUnitValue(left, true),
806 ConstraintParser.parseUnitValue(bottom, false),
807 ConstraintParser.parseUnitValue(right, true)};
811 /** Same functionality as <code>setAlignX(ConstraintParser.parseUnitValueOrAlign(unitValue, true))</code> only this method returns <code>this</code>
812 * for chaining multiple calls.
814 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
815 * @param align The align keyword or for instance "100px". E.g "left", "right", "leading" or "trailing".
816 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
817 * @see #setAlignX(UnitValue)
819 public final LC alignX(String align)
821 setAlignX(ConstraintParser.parseUnitValueOrAlign(align, true, null));
825 /** Same functionality as <code>setAlignY(ConstraintParser.parseUnitValueOrAlign(align, false))</code> only this method returns <code>this</code> for chaining multiple calls.
827 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
828 * @param align The align keyword or for instance "100px". E.g "top" or "bottom".
829 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
830 * @see #setAlignY(UnitValue)
832 public final LC alignY(String align)
834 setAlignY(ConstraintParser.parseUnitValueOrAlign(align, false, null));
838 /** Sets both the alignX and alignY as the same time.
840 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
841 * @param ax The align keyword or for instance "100px". E.g "left", "right", "leading" or "trailing".
842 * @param ay The align keyword or for instance "100px". E.g "top" or "bottom".
843 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
844 * @see #alignX(String)
845 * @see #alignY(String)
847 public final LC align(String ax, String ay)
858 /** Same functionality as <code>setGridGapX(ConstraintParser.parseBoundSize(boundsSize, true, true))</code> only this method
859 * returns <code>this</code> for chaining multiple calls.
861 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
862 * @param boundsSize The <code>BoundSize</code> of the gap. This is a minimum and/or preferred and/or maximum size. E.g.
863 * <code>"50:100:200"</code> or <code>"100px"</code>.
864 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
865 * @see #setGridGapX(BoundSize)
867 public final LC gridGapX(String boundsSize)
869 setGridGapX(ConstraintParser.parseBoundSize(boundsSize, true, true));
873 /** Same functionality as <code>setGridGapY(ConstraintParser.parseBoundSize(boundsSize, true, false))</code> only this method
874 * returns <code>this</code> for chaining multiple calls.
876 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
877 * @param boundsSize The <code>BoundSize</code> of the gap. This is a minimum and/or preferred and/or maximum size. E.g.
878 * <code>"50:100:200"</code> or <code>"100px"</code>.
879 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
880 * @see #setGridGapY(BoundSize)
882 public final LC gridGapY(String boundsSize)
884 setGridGapY(ConstraintParser.parseBoundSize(boundsSize, true, false));
888 /** Sets both grid gaps at the same time. see {@link #gridGapX(String)} and {@link #gridGapY(String)}.
890 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
891 * @param gapx The <code>BoundSize</code> of the gap. This is a minimum and/or preferred and/or maximum size. E.g.
892 * <code>"50:100:200"</code> or <code>"100px"</code>.
893 * @param gapy The <code>BoundSize</code> of the gap. This is a minimum and/or preferred and/or maximum size. E.g.
894 * <code>"50:100:200"</code> or <code>"100px"</code>.
895 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
896 * @see #gridGapX(String)
897 * @see #gridGapY(String)
899 public final LC gridGap(String gapx, String gapy)
910 /** Calls {@link #debug(int)} with 300 as an argument.
911 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
912 * @see #setDebugMillis(int)
914 public final LC debug()
920 /** Same functionality as {@link #setDebugMillis(int repaintMillis)} only this method returns <code>this</code> for chaining multiple calls.
922 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
923 * @param repaintMillis The new debug repaint interval.
924 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
925 * @see #setDebugMillis(int)
927 public final LC debug(int repaintMillis)
929 setDebugMillis(repaintMillis);
933 /** Same functionality as {@link #setHideMode(int mode)} only this method returns <code>this</code> for chaining multiple calls.
935 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
936 * @param mode The mode:<br>
937 * 0 == Normal. Bounds will be calculated as if the component was visible.<br>
938 * 1 == If hidden the size will be 0, 0 but the gaps remain.<br>
939 * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br>
940 * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
941 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
942 * @see #setHideMode(int)
944 public final LC hideMode(int mode)
950 /** The minimum width for the container. The value will override any value that is set on the container itself.
952 * For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com.
953 * @param width The width expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm".
954 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
956 public final LC minWidth(String width)
958 setWidth(LayoutUtil.derive(getWidth(), ConstraintParser.parseUnitValue(width, true), null, null));
962 /** 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
963 * the container itself.
965 * For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com.
966 * @param width The width expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px".
967 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
969 public final LC width(String width)
971 setWidth(ConstraintParser.parseBoundSize(width, false, true));
975 /** The maximum width for the container. The value will override any value that is set on the container itself.
977 * For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com.
978 * @param width The width expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm".
979 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
981 public final LC maxWidth(String width)
983 setWidth(LayoutUtil.derive(getWidth(), null, null, ConstraintParser.parseUnitValue(width, true)));
987 /** The minimum height for the container. The value will override any value that is set on the container itself.
989 * For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com.
990 * @param height The height expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm".
991 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
993 public final LC minHeight(String height)
995 setHeight(LayoutUtil.derive(getHeight(), ConstraintParser.parseUnitValue(height, false), null, null));
999 /** 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
1000 * the container itself.
1002 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcontainers.com.
1003 * @param height The height expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px".
1004 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
1006 public final LC height(String height)
1008 setHeight(ConstraintParser.parseBoundSize(height, false, false));
1012 /** The maximum height for the container. The value will override any value that is set on the container itself.
1014 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcontainers.com.
1015 * @param height The height expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm".
1016 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
1018 public final LC maxHeight(String height)
1020 setHeight(LayoutUtil.derive(getHeight(), null, null, ConstraintParser.parseUnitValue(height, false)));
1024 // // ************************************************
1025 // // Persistence Delegate and Serializable combined.
1026 // // ************************************************
1028 // private Object readResolve() throws ObjectStreamException
1030 // return LayoutUtil.getSerializedObject(this);
1034 // public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
1036 // LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
1040 // public void writeExternal(ObjectOutput out) throws IOException
1042 // if (getClass() == LC.class)
1043 // LayoutUtil.writeAsXML(out, this);