3c8fc693caba5e75c033531921fc17b2fc2e7c0e
[jalview.git] / src / net / miginfocom / layout / LC.java
1 package net.miginfocom.layout;
2
3 /*
4  * License (BSD):
5  * ==============
6  *
7  * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
8  * All rights reserved.
9  *
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.
20  *
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
30  * OF SUCH DAMAGE.
31  *
32  * @version 1.0
33  * @author Mikael Grev, MiG InfoCom AB
34  *         Date: 2006-sep-08
35  */
36
37
38
39 /** Contains the constraints for an instance of the {@link LC} layout manager.
40  */
41 public final class LC //implements Externalizable
42 {
43         // See the corresponding set/get method for documentation of the property!
44
45         private int wrapAfter = LayoutUtil.INF;
46
47         private Boolean leftToRight = null;
48
49         private UnitValue[] insets = null;    // Never null elements but if unset array is null
50
51         private UnitValue alignX = null, alignY = null;
52
53         private BoundSize gridGapX = null, gridGapY = null;
54
55         private BoundSize width = BoundSize.NULL_SIZE, height = BoundSize.NULL_SIZE;
56
57         private BoundSize packW = BoundSize.NULL_SIZE, packH = BoundSize.NULL_SIZE;
58
59         private float pwAlign = 0.5f, phAlign = 1.0f;
60
61         private int debugMillis = 0;
62
63         private int hideMode = 0;
64
65         private boolean noCache = false;
66
67         private boolean flowX = true;
68
69         private boolean fillX = false, fillY = false;
70
71         private boolean topToBottom = true;
72
73         private boolean noGrid = false;
74
75         private boolean visualPadding = true;
76
77         /** Empty constructor.
78          */
79         public LC()
80         {
81         }
82
83         // ************************************************************************
84         // * JavaBean get/set methods.
85         // ************************************************************************
86
87
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.
91          */
92         public boolean isNoCache()
93         {
94                 return noCache;
95         }
96
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.
100          */
101         public void setNoCache(boolean b)
102         {
103                 this.noCache = b;
104         }
105
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
108          * by this property.
109          * @return The current alignment.
110          */
111         public final UnitValue getAlignX()
112         {
113                 return alignX;
114         }
115
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
118          * by this property.
119          * @param uv The new alignment. Use {@link ConstraintParser#parseAlignKeywords(String, boolean)} to create the {@link UnitValue}. May be <code>null</code>.
120          */
121         public final void setAlignX(UnitValue uv)
122         {
123                 this.alignX = uv;
124         }
125
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
128          * by this property.
129          * @return The current alignment.
130          */
131         public final UnitValue getAlignY()
132         {
133                 return alignY;
134         }
135
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
138          * by this property.
139          * @param uv The new alignment. Use {@link ConstraintParser#parseAlignKeywords(String, boolean)} to create the {@link UnitValue}. May be <code>null</code>.
140          */
141         public final void setAlignY(UnitValue uv)
142         {
143                 this.alignY = uv;
144         }
145
146         /** If <code>&gt; 0</code> the debug decorations will be repainted every <code>millis</code>. No debug information if <code>&lt;= 0</code> (default).
147          * @return The current debug repaint interval.
148          */
149         public final int getDebugMillis()
150         {
151                 return debugMillis;
152         }
153
154         /** If <code>&gt; 0</code> the debug decorations will be repainted every <code>millis</code>. No debug information if <code>&lt;= 0</code> (default).
155          * @param millis The new debug repaint interval.
156          */
157         public final void setDebugMillis(int millis)
158         {
159                 this.debugMillis = millis;
160         }
161
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.
164          */
165         public final boolean isFillX()
166         {
167                 return fillX;
168         }
169
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.
172          */
173         public final void setFillX(boolean b)
174         {
175                 this.fillX = b;
176         }
177
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.
180          */
181         public final boolean isFillY()
182         {
183                 return fillY;
184         }
185
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.
188          */
189         public final void setFillY(boolean b)
190         {
191                 this.fillY = b;
192         }
193
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)
198          */
199         public final boolean isFlowX()
200         {
201                 return flowX;
202         }
203
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)
208          */
209         public final void setFlowX(boolean b)
210         {
211                 this.flowX = b;
212         }
213
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.
216          */
217         public final BoundSize getGridGapX()
218         {
219                 return gridGapX;
220         }
221
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.
224          */
225         public final void setGridGapX(BoundSize x)
226         {
227                 this.gridGapX = x;
228         }
229
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.
232          */
233         public final BoundSize getGridGapY()
234         {
235                 return gridGapY;
236         }
237
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.
240          */
241         public final void setGridGapY(BoundSize y)
242         {
243                 this.gridGapY = y;
244         }
245
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..
252          */
253         public final int getHideMode()
254         {
255                 return hideMode;
256         }
257
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..
264          */
265         public final void setHideMode(int mode)
266         {
267                 if (mode < 0 || mode > 3)
268                         throw new IllegalArgumentException("Wrong hideMode: " + mode);
269
270                 this.hideMode = mode;
271         }
272
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)
277          */
278         public final UnitValue[] getInsets()
279         {
280                 return insets != null ? new UnitValue[] {insets[0], insets[1], insets[2], insets[3]} : null;
281         }
282
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)
288          */
289         public final void setInsets(UnitValue[] ins)
290         {
291                 this.insets = ins != null ? new UnitValue[] {ins[0], ins[1], ins[2], ins[3]} : null;
292         }
293
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".
298          */
299         public final Boolean getLeftToRight()
300         {
301                 return leftToRight;
302         }
303
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".
308          */
309         public final void setLeftToRight(Boolean b)
310         {
311                 this.leftToRight = b;
312         }
313
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.
316          */
317         public final boolean isNoGrid()
318         {
319                 return noGrid;
320         }
321
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.
324          */
325         public final void setNoGrid(boolean b)
326         {
327                 this.noGrid = b;
328         }
329
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.
332          */
333         public final boolean isTopToBottom()
334         {
335                 return topToBottom;
336         }
337
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.
340          */
341         public final void setTopToBottom(boolean b)
342         {
343                 this.topToBottom = b;
344         }
345
346         /** If visual padding should be automatically used and compensated for by this layout instance.
347          * @return <code>true</code> if visual padding.
348          */
349         public final boolean isVisualPadding()
350         {
351                 return visualPadding;
352         }
353
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.
356          */
357         public final void setVisualPadding(boolean b)
358         {
359                 this.visualPadding = b;
360         }
361
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.
365          */
366         public final int getWrapAfter()
367         {
368                 return wrapAfter;
369         }
370
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.
374          */
375         public final void setWrapAfter(int count)
376         {
377                 this.wrapAfter = count;
378         }
379
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.
384          * <p>
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.
386          * <p>
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>.
389          * @since 3.5
390          */
391         public final BoundSize getPackWidth()
392         {
393                 return packW;
394         }
395
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.
400          * <p>
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.
402          * <p>
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.
405          * @since 3.5
406          */
407         public final void setPackWidth(BoundSize size)
408         {
409                 packW = size != null ? size : BoundSize.NULL_SIZE;
410         }
411
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.
416          * <p>
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.
418          * <p>
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>.
421          * @since 3.5
422          */
423         public final BoundSize getPackHeight()
424         {
425                 return packH;
426         }
427
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.
432          * <p>
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.
434          * <p>
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.
437          * @since 3.5
438          */
439         public final void setPackHeight(BoundSize size)
440         {
441                 packH = size != null ? size : BoundSize.NULL_SIZE;
442         }
443
444
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
448          * of course.
449          * @return The pack alignment. Always between 0f and 1f, inclusive.
450          * @since 3.5
451          */
452         public final float getPackHeightAlign()
453         {
454                 return phAlign;
455         }
456
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
460          * of course.
461          * @param align The pack alignment. Always between 0f and 1f, inclusive. Values outside this will be truncated.
462          * @since 3.5
463          */
464         public final void setPackHeightAlign(float align)
465         {
466                 phAlign = Math.max(0f, Math.min(1f, align));
467         }
468
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
472          * of course.
473          * @return The pack alignment. Always between 0f and 1f, inclusive.
474          * @since 3.5
475          */
476         public final float getPackWidthAlign()
477         {
478                 return pwAlign;
479         }
480
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
484          * of course.
485          * @param align The pack alignment. Always between 0f and 1f, inclusive. Values outside this will be truncated.
486          * @since 3.5
487          */
488         public final void setPackWidthAlign(float align)
489         {
490                 pwAlign = Math.max(0f, Math.min(1f, align));
491         }
492
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>.
498          * @since 3.5
499          */
500         public final BoundSize getWidth()
501         {
502                 return width;
503         }
504
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.
510          * @since 3.5
511          */
512         public final void setWidth(BoundSize size)
513         {
514                 this.width = size != null ? size : BoundSize.NULL_SIZE;
515         }
516
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>.
522          * @since 3.5
523          */
524         public final BoundSize getHeight()
525         {
526                 return height;
527         }
528
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.
534          * @since 3.5
535          */
536         public final void setHeight(BoundSize size)
537         {
538                 this.height = size != null ? size : BoundSize.NULL_SIZE;
539         }
540
541         // ************************************************************************
542         // * Builder methods.
543         // ************************************************************************
544
545         /** Short for, and thus same as, <code>.pack("pref", "pref")</code>.
546          * <p>
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.
549          * <p>
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>.
552          * @since 3.5
553          */
554         public final LC pack()
555         {
556                 return pack("pref", "pref");
557         }
558
559         /** Sets the pack width and height.
560          * <p>
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.
563          * <p>
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>.
568          * @since 3.5
569          */
570         public final LC pack(String width, String height)
571         {
572                 setPackWidth(width != null ? ConstraintParser.parseBoundSize(width, false, true) : BoundSize.NULL_SIZE);
573                 setPackHeight(height != null ? ConstraintParser.parseBoundSize(height, false, false) : BoundSize.NULL_SIZE);
574                 return this;
575         }
576
577         /** Sets the pack width and height alignment.
578          * <p>
579          * Same functionality as {@link #setPackHeightAlign(float)} and {@link #setPackWidthAlign(float)}
580          * only this method returns <code>this</code> for chaining multiple calls.
581          * <p>
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>.
586          * @since 3.5
587          */
588         public final LC packAlign(float alignX, float alignY)
589         {
590                 setPackWidthAlign(alignX);
591                 setPackHeightAlign(alignY);
592                 return this;
593         }
594
595         /** Sets a wrap after the number of columns/rows that is defined in the {@link net.miginfocom.layout.AC}.
596          * <p>
597          * Same functionality as calling {@link #setWrapAfter(int)} with <code>0</code> only this method returns <code>this</code> for chaining multiple calls.
598          * <p>
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>.
601          */
602         public final LC wrap()
603         {
604                 setWrapAfter(0);
605                 return this;
606         }
607
608         /** Same functionality as {@link #setWrapAfter(int)} only this method returns <code>this</code> for chaining multiple calls.
609          * <p>
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>.
613          */
614         public final LC wrapAfter(int count)
615         {
616                 setWrapAfter(count);
617                 return this;
618         }
619
620         /** Same functionality as calling {@link #setNoCache(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
621          * <p>
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>.
624          */
625         public final LC noCache()
626         {
627                 setNoCache(true);
628                 return this;
629         }
630
631         /** Same functionality as calling {@link #setFlowX(boolean)} with <code>false</code> only this method returns <code>this</code> for chaining multiple calls.
632          * <p>
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>.
635          */
636         public final LC flowY()
637         {
638                 setFlowX(false);
639                 return this;
640         }
641
642         /** Same functionality as calling {@link #setFlowX(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
643          * <p>
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>.
646          */
647         public final LC flowX()
648         {
649                 setFlowX(true);
650                 return this;
651         }
652
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.
655          * <p>
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>.
658          */
659         public final LC fill()
660         {
661                 setFillX(true);
662                 setFillY(true);
663                 return this;
664         }
665
666         /** Same functionality as calling {@link #setFillX(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
667          * <p>
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>.
670          */
671         public final LC fillX()
672         {
673                 setFillX(true);
674                 return this;
675         }
676
677         /** Same functionality as calling {@link #setFillY(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
678          * <p>
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>.
681          */
682         public final LC fillY()
683         {
684                 setFillY(true);
685                 return this;
686         }
687
688         /** Same functionality as {@link #setLeftToRight(Boolean)} only this method returns <code>this</code> for chaining multiple calls.
689          * <p>
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>.
693          */
694         public final LC leftToRight(boolean b)
695         {
696                 setLeftToRight(b ? Boolean.TRUE : Boolean.FALSE);
697                 return this;
698         }
699
700         /** Same functionality as setLeftToRight(false) only this method returns <code>this</code> for chaining multiple calls.
701          * <p>
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>.
704          * @since 3.7.2
705          */
706         public final LC rightToLeft()
707         {
708                 setLeftToRight(Boolean.FALSE);
709                 return this;
710         }
711
712         /** Same functionality as calling {@link #setTopToBottom(boolean)} with <code>false</code> only this method returns <code>this</code> for chaining multiple calls.
713          * <p>
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>.
716          */
717         public final LC bottomToTop()
718         {
719                 setTopToBottom(false);
720                 return this;
721         }
722
723         /** Same functionality as calling {@link #setTopToBottom(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
724          * <p>
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>.
727          * @since 3.7.2
728          */
729         public final LC topToBottom()
730         {
731                 setTopToBottom(true);
732                 return this;
733         }
734
735         /** Same functionality as calling {@link #setNoGrid(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
736          * <p>
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>.
739          */
740         public final LC noGrid()
741         {
742                 setNoGrid(true);
743                 return this;
744         }
745
746         /** Same functionality as calling {@link #setVisualPadding(boolean)} with <code>false</code> only this method returns <code>this</code> for chaining multiple calls.
747          * <p>
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>.
750          */
751         public final LC noVisualPadding()
752         {
753                 setVisualPadding(false);
754                 return this;
755         }
756
757         /** Sets the same inset (expressed as a <code>UnitValue</code>, e.g. "10px" or "20mm") all around.
758          * <p>
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[])
764          */
765         public final LC insetsAll(String allSides)
766         {
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
770                 return this;
771         }
772
773         /** Same functionality as <code>setInsets(ConstraintParser.parseInsets(s, true))</code>. This method returns <code>this</code>
774          * for chaining multiple calls.
775          * <p>
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[])
780          */
781         public final LC insets(String s)
782         {
783                 insets = ConstraintParser.parseInsets(s, true);
784                 return this;
785         }
786
787         /** Sets the different insets (expressed as a <code>UnitValue</code>s, e.g. "10px" or "20mm") for the corresponding sides.
788          * <p>
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[])
800          */
801         public final LC insets(String top, String left, String bottom, String right)
802         {
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)};
808                 return this;
809         }
810
811         /** Same functionality as <code>setAlignX(ConstraintParser.parseUnitValueOrAlign(unitValue, true))</code> only this method returns <code>this</code>
812          * for chaining multiple calls.
813          * <p>
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)
818          */
819         public final LC alignX(String align)
820         {
821                 setAlignX(ConstraintParser.parseUnitValueOrAlign(align, true, null));
822                 return this;
823         }
824
825         /** Same functionality as <code>setAlignY(ConstraintParser.parseUnitValueOrAlign(align, false))</code> only this method returns <code>this</code> for chaining multiple calls.
826          * <p>
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)
831          */
832         public final LC alignY(String align)
833         {
834                 setAlignY(ConstraintParser.parseUnitValueOrAlign(align, false, null));
835                 return this;
836         }
837
838         /** Sets both the alignX and alignY as the same time.
839          * <p>
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)
846          */
847         public final LC align(String ax, String ay)
848         {
849                 if (ax != null)
850                         alignX(ax);
851
852                 if (ay != null)
853                         alignY(ay);
854
855                 return this;
856         }
857
858         /** Same functionality as <code>setGridGapX(ConstraintParser.parseBoundSize(boundsSize, true, true))</code> only this method
859          * returns <code>this</code> for chaining multiple calls.
860          * <p>
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)
866          */
867         public final LC gridGapX(String boundsSize)
868         {
869                 setGridGapX(ConstraintParser.parseBoundSize(boundsSize, true, true));
870                 return this;
871         }
872
873         /** Same functionality as <code>setGridGapY(ConstraintParser.parseBoundSize(boundsSize, true, false))</code> only this method
874          * returns <code>this</code> for chaining multiple calls.
875          * <p>
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)
881          */
882         public final LC gridGapY(String boundsSize)
883         {
884                 setGridGapY(ConstraintParser.parseBoundSize(boundsSize, true, false));
885                 return this;
886         }
887
888         /** Sets both grid gaps at the same time. see {@link #gridGapX(String)} and {@link #gridGapY(String)}.
889          * <p>
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)
898          */
899         public final LC gridGap(String gapx, String gapy)
900         {
901                 if (gapx != null)
902                         gridGapX(gapx);
903
904                 if (gapy != null)
905                         gridGapY(gapy);
906
907                 return this;
908         }
909
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)
913          */
914         public final LC debug()
915         {
916                 setDebugMillis(300);
917                 return this;
918         }
919
920         /** Same functionality as {@link #setDebugMillis(int repaintMillis)} only this method returns <code>this</code> for chaining multiple calls.
921          * <p>
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)
926          */
927         public final LC debug(int repaintMillis)
928         {
929                 setDebugMillis(repaintMillis);
930                 return this;
931         }
932
933         /** Same functionality as {@link #setHideMode(int mode)} only this method returns <code>this</code> for chaining multiple calls.
934          * <p>
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)
943          */
944         public final LC hideMode(int mode)
945         {
946                 setHideMode(mode);
947                 return this;
948         }
949
950         /** The minimum width for the container. The value will override any value that is set on the container itself.
951          * <p>
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>.
955          */
956         public final LC minWidth(String width)
957         {
958                 setWidth(LayoutUtil.derive(getWidth(), ConstraintParser.parseUnitValue(width, true), null, null));
959                 return this;
960         }
961
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.
964          * <p>
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>.
968          */
969         public final LC width(String width)
970         {
971                 setWidth(ConstraintParser.parseBoundSize(width, false, true));
972                 return this;
973         }
974
975         /** The maximum width for the container. The value will override any value that is set on the container itself.
976          * <p>
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>.
980          */
981         public final LC maxWidth(String width)
982         {
983                 setWidth(LayoutUtil.derive(getWidth(), null, null, ConstraintParser.parseUnitValue(width, true)));
984                 return this;
985         }
986
987         /** The minimum height for the container. The value will override any value that is set on the container itself.
988          * <p>
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>.
992          */
993         public final LC minHeight(String height)
994         {
995                 setHeight(LayoutUtil.derive(getHeight(), ConstraintParser.parseUnitValue(height, false), null, null));
996                 return this;
997         }
998
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.
1001          * <p>
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>.
1005          */
1006         public final LC height(String height)
1007         {
1008                 setHeight(ConstraintParser.parseBoundSize(height, false, false));
1009                 return this;
1010         }
1011
1012         /** The maximum height for the container. The value will override any value that is set on the container itself.
1013          * <p>
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>.
1017          */
1018         public final LC maxHeight(String height)
1019         {
1020                 setHeight(LayoutUtil.derive(getHeight(), null, null, ConstraintParser.parseUnitValue(height, false)));
1021                 return this;
1022         }
1023 //
1024 //      // ************************************************
1025 //      // Persistence Delegate and Serializable combined.
1026 //      // ************************************************
1027 //
1028 //      private Object readResolve() throws ObjectStreamException
1029 //      {
1030 //              return LayoutUtil.getSerializedObject(this);
1031 //      }
1032 //
1033 //      @Override
1034 //      public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
1035 //      {
1036 //              LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
1037 //      }
1038 //
1039 //      @Override
1040 //      public void writeExternal(ObjectOutput out) throws IOException
1041 //      {
1042 //              if (getClass() == LC.class)
1043 //                      LayoutUtil.writeAsXML(out, this);
1044 //      }
1045 }