summaryrefslogtreecommitdiff
path: root/prototypes/miglayout/net/miginfocom/layout/LC.java
blob: 82d33191f177b2a304e7745b4a91ba250bb1f8fa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
package net.miginfocom.layout;

import java.io.*;
/*
 * License (BSD):
 * ==============
 *
 * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without modification,
 * are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright notice, this list
 * of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright notice, this
 * list of conditions and the following disclaimer in the documentation and/or other
 * materials provided with the distribution.
 * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
 * used to endorse or promote products derived from this software without specific
 * prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
 * OF SUCH DAMAGE.
 *
 * @version 1.0
 * @author Mikael Grev, MiG InfoCom AB
 *         Date: 2006-sep-08
 */

/** Contains the constraints for an instance of the {@link LC} layout manager.
 */
public final class LC implements Externalizable
{
	// See the corresponding set/get method for documentation of the property!

	private int wrapAfter = LayoutUtil.INF;

	private Boolean leftToRight = null;

	private UnitValue[] insets = null;    // Never null elememts but if unset array is null

	private UnitValue alignX = null, alignY = null;

	private BoundSize gridGapX = null, gridGapY = null;

	private int debugMillis = 0;

	private int hideMode = 0;

	private boolean noCache = false;

	private boolean flowX = true;

	private boolean fillX = false, fillY = false;

	private boolean topToBottom = true;

	private boolean noGrid = false;

	private boolean visualPadding = true;

	/** Empty constructor.
	 */
	public LC()
	{
	}

	// ************************************************************************
	// * JavaBean get/set methods.
	// ************************************************************************


	/** 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
	 * 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>.
	 * @return <code>true</code> means no cache and slightly slower layout.
	 */
	public boolean isNoCache()
	{
		return noCache;
	}

	/** 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
	 * 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>.
	 * @param b <code>true</code> means no cache and slightly slower layout.
	 */
	public void setNoCache(boolean b)
	{
		this.noCache = b;
	}

	/** 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
	 * in the parent. <code>null</code> is default and that means top/left alignment. The relative distances between the components will not be affected
	 * by this property.
	 * @return The current alignment.
	 */
	public final UnitValue getAlignX()
	{
		return alignX;
	}

	/** 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
	 * in the parent. <code>null</code> is default and that means top/left alignment. The relative distances between the components will not be affected
	 * by this property.
	 * @param uv The new alignment. Use {@link ConstraintParser#parseAlignKeywords(String, boolean)} to create the {@link UnitValue}. May be <code>null</code>.
	 */
	public final void setAlignX(UnitValue uv)
	{
		this.alignX = uv;
	}

	/** 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
	 * in the parent. <code>null</code> is default and that means top/left alignment. The relative distances between the components will not be affected
	 * by this property.
	 * @return The current alignment.
	 */
	public final UnitValue getAlignY()
	{
		return alignY;
	}

	/** 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
	 * in the parent. <code>null</code> is default and that means top/left alignment. The relative distances between the components will not be affected
	 * by this property.
	 * @param uv The new alignment. Use {@link ConstraintParser#parseAlignKeywords(String, boolean)} to create the {@link UnitValue}. May be <code>null</code>.
	 */
	public final void setAlignY(UnitValue uv)
	{
		this.alignY = uv;
	}

	/** If <code>&gt; 0</code> the debug decorations will be repainted every <code>millis</code>. No debug information if <code>&lt;= 0</code> (default).
	 * @return The current debug repaint interval.
	 */
	public final int getDebugMillis()
	{
		return debugMillis;
	}

	/** If <code>&gt; 0</code> the debug decorations will be repainted every <code>millis</code>. No debug information if <code>&lt;= 0</code> (default).
	 * @param millis The new debug repaint interval.
	 */
	public final void setDebugMillis(int millis)
	{
		this.debugMillis = millis;
	}

	/** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller.
	 * @return <code>true</code> means fill. <code>false</code> is default.
	 */
	public final boolean isFillX()
	{
		return fillX;
	}

	/** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller.
	 * @param b <code>true</code> means fill. <code>false</code> is default.
	 */
	public final void setFillX(boolean b)
	{
		this.fillX = b;
	}

	/** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller.
	 * @return <code>true</code> means fill. <code>false</code> is default.
	 */
	public final boolean isFillY()
	{
		return fillY;
	}

	/** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller.
	 * @param b <code>true</code> means fill. <code>false</code> is default.
	 */
	public final void setFillY(boolean b)
	{
		this.fillY = b;
	}

	/** The default flow direction. Normally (which is <code>true</code>) this is horizontal and that means that the "next" component
	 * will be put in the cell to the right (or to the left if left-to-right is false).
	 * @return <code>true</code> is the default flow horizontally.
	 * @see #setLeftToRight(Boolean)
	 */
	public final boolean isFlowX()
	{
		return flowX;
	}

	/** The default flow direction. Normally (which is <code>true</code>) this is horizontal and that means that the "next" component
	 * will be put in the cell to the right (or to the left if left-to-right is false).
	 * @param b <code>true</code> is the default flow horizontally.
	 * @see #setLeftToRight(Boolean)
	 */
	public final void setFlowX(boolean b)
	{
		this.flowX = b;
	}

	/** 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.
	 * @return The default grid gap between columns in the grid. <code>null</code> if the platform default is used.
	 */
	public final BoundSize getGridGapX()
	{
		return gridGapX;
	}

	/** 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.
	 * @param x The default grid gap between columns in the grid. If <code>null</code> the platform default is used.
	 */
	public final void setGridGapX(BoundSize x)
	{
		this.gridGapX = x;
	}

	/** 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.
	 * @return The default grid gap between rows in the grid. <code>null</code> if the platform default is used.
	 */
	public final BoundSize getGridGapY()
	{
		return gridGapY;
	}

	/** 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.
	 * @param y The default grid gap between rows in the grid. If <code>null</code> the platform default is used.
	 */
	public final void setGridGapY(BoundSize y)
	{
		this.gridGapY = y;
	}

	/** How a component that is hidden (not visible) should be treated by default.
	 * @return The mode:<br>
	 * 0 == Normal. Bounds will be caclulated as if the component was visible.<br>
	 * 1 == If hidden the size will be 0, 0 but the gaps remain.<br>
	 * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br>
	 * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
	 */
	public final int getHideMode()
	{
		return hideMode;
	}

	/** How a component that is hidden (not visible) should be treated.
	 * @param mode The mode:<br>
	 * 0 == Normal. Bounds will be caclulated as if the component was visible.<br>
	 * 1 == If hidden the size will be 0, 0 but the gaps remain.<br>
	 * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br>
	 * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
	 */
	public final void setHideMode(int mode)
	{
		if (mode < 0 || mode > 3)
			throw new IllegalArgumentException("Wrong hideMode: " + mode);

		this.hideMode = mode;
	}

	/** The insets for the layed out panel. The insets will be an empty space around the components in the panel. <code>null</code> values
	 * 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)}.
	 * @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.
	 * @see net.miginfocom.layout.ConstraintParser#parseInsets(String, boolean)
	 */
	public final UnitValue[] getInsets()
	{
		return insets != null ? new UnitValue[] {insets[0], insets[1], insets[2], insets[3]} : null;
	}

	/** The insets for the layed out panel. The insets will be an empty space around the components in the panel. <code>null</code> values
	 * 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)}.
	 * @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
	 * the platform default for that side. The array is copied for storage.
	 * @see net.miginfocom.layout.ConstraintParser#parseInsets(String, boolean)
	 */
	public final void setInsets(UnitValue[] ins)
	{
		this.insets = ins != null ? new UnitValue[] {ins[0], ins[1], ins[2], ins[3]} : null;
	}

	/** If the layout should be forced to be left-to-right or right-to-left. A value of <code>null</code> is default and
	 * means that this will be picked up from the {@link java.util.Locale} that the container being layed out is reporting.
	 * @return <code>Boolean.TRUE</code> if force left-to-right. <code>Boolean.FALSE</code> if force tight-to-left. <code>null</code>
	 * for the default "let the current Locale decide".
	 */
	public final Boolean getLeftToRight()
	{
		return leftToRight;
	}

	/** If the layout should be forced to be left-to-right or right-to-left. A value of <code>null</code> is default and
	 * means that this will be picked up from the {@link java.util.Locale} that the container being layed out is reporting.
	 * @param b <code>Boolean.TRUE</code> to force left-to-right. <code>Boolean.FALSE</code> to force tight-to-left. <code>null</code>
	 * for the default "let the current Locale decide".
	 */
	public final void setLeftToRight(Boolean b)
	{
		this.leftToRight = b;
	}

	/** 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.
	 * @return <code>true</code> means not grid based. <code>false</code> is default.
	 */
	public final boolean isNoGrid()
	{
		return noGrid;
	}

	/** 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.
	 * @param b <code>true</code> means no grid. <code>false</code> is default.
	 */
	public final void setNoGrid(boolean b)
	{
		this.noGrid = b;
	}

	/** If the layout should go from the default top-to-bottom in the grid instead of the optinal bottom-to-top.
	 * @return <code>true</code> for the default top-to-bottom.
	 */
	public final boolean isTopToBottom()
	{
		return topToBottom;
	}

	/** If the layout should go from the default top-to-bottom in the grid instead of the optinal bottom-to-top.
	 * @param b <code>true</code> for the default top-to-bottom.
	 */
	public final void setTopToBottom(boolean b)
	{
		this.topToBottom = b;
	}

	/** If visual padding should be automatically used and compensated for by this layout instance.
	 * @return <code>true</code> if visual padding.
	 */
	public final boolean isVisualPadding()
	{
		return visualPadding;
	}

	/** If visual padding should be automatically used and compensated for by this layout instance.
	 * @param b <code>true</code> turns on visual padding.
	 */
	public final void setVisualPadding(boolean b)
	{
		this.visualPadding = b;
	}

	/** Returns after what cell the grid should always auto wrap.
	 * @return After what cell the grid should always auto wrap. If <code>0</code> the number of columns/rows in the
	 * {@link net.miginfocom.layout.AC} is used. <code>LayoutUtil.INF</code> is used for no auto wrap.
	 */
	public final int getWrapAfter()
	{
		return wrapAfter;
	}

	/** Sets after what cell the grid should always auto wrap.
	 * @param count After what cell the grid should always auto wrap. If <code>0</code> the number of columns/rows in the
	 * {@link net.miginfocom.layout.AC} is used. <code>LayoutUtil.INF</code> is used for no auto wrap.
	 */
	public final void setWrapAfter(int count)
	{
		this.wrapAfter = count;
	}

	// ************************************************************************
	// * Builder methods.
	// ************************************************************************

	/** Sets a wrap after the number of columns/rows that is defined in the {@link net.miginfocom.layout.AC}.
	 * <p>
	 * Same functionality as {@link #setWrapAfter(int 0)} only this method returns <code>this</code> for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 */
	public final LC wrap()
	{
		setWrapAfter(0);
		return this;
	}

	/** Same functionality as {@link #setWrapAfter(int)} only this method returns <code>this</code> for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @param count After what cell the grid should always auto wrap. If <code>0</code> the number of columns/rows in the
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 */
	public final LC wrapAfter(int count)
	{
		setWrapAfter(count);
		return this;
	}

	/** Same functionality as {@link #setNoCache(boolean true)} only this method returns <code>this</code> for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 */
	public final LC noCache()
	{
		setNoCache(true);
		return this;
	}

	/** Same functionality as {@link #setFlowX(boolean false)} only this method returns <code>this</code> for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 */
	public final LC flowY()
	{
		setFlowX(false);
		return this;
	}

	/** Same functionality as {@link #setFlowX(boolean true)} only this method returns <code>this</code> for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 */
	public final LC flowX()
	{
		setFlowX(true);
		return this;
	}

	/** Same functionality as {@link #setFillX(boolean true)} and {@link #setFillY(boolean true)} conmbined.T his method returns
	 * <code>this</code> for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 */
	public final LC fill()
	{
		setFillX(true);
		setFillY(true);
		return this;
	}

	/** Same functionality as {@link #setFillX(boolean true)} only this method returns <code>this</code> for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 */
	public final LC fillX()
	{
		setFillX(true);
		return this;
	}

	/** Same functionality as {@link #setFillY(boolean true)} only this method returns <code>this</code> for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 */
	public final LC fillY()
	{
		setFillY(true);
		return this;
	}

	/** Same functionality as {@link #setLeftToRight(Boolean)} only this method returns <code>this</code> for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @param b <code>true</code> for forcing left-to-right. <code>false</code> for forcing right-to-left.
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 */
	public final LC leftToRight(boolean b)
	{
		setLeftToRight(b ? Boolean.TRUE : Boolean.FALSE); // Not .valueOf du to retroweaver...
		return this;
	}

	/** Same functionality as {@link #setTopToBottom(boolean false)} only this method returns <code>this</code> for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 */
	public final LC bottomToTop()
	{
		setTopToBottom(false);
		return this;
	}

	/** Same functionality as {@link #setNoGrid(boolean true)} only this method returns <code>this</code> for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 */
	public final LC noGrid()
	{
		setNoGrid(true);
		return this;
	}

	/** Same functionality as {@link #setVisualPadding(boolean false)} only this method returns <code>this</code> for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 */
	public final LC noVisualPadding()
	{
		setVisualPadding(false);
		return this;
	}

	/** Sets the same inset (expressed as a <code>UnitValue</code>, e.g. "10px" or "20mm") all around.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @param allSides The unit value to set for all sides. May be <code>null</code> which means that the default panel insets
	 * for the platform is used.
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 * @see #setInsets(UnitValue[])
	 */
	public final LC insetsAll(String allSides)
	{
		UnitValue insH = ConstraintParser.parseUnitValue(allSides, true);
		UnitValue insV = ConstraintParser.parseUnitValue(allSides, false);
		insets = new UnitValue[] {insV, insH, insV, insH}; // No setter to avoid copy again
		return this;
	}

	/** Same functionality as <code>setInsets(ConstraintParser.parseInsets(s, true))</code>. This method returns <code>this</code>
	 * for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @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.
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 * @see #setInsets(UnitValue[])
	 */
	public final LC insets(String s)
	{
		insets = ConstraintParser.parseInsets(s, true);
		return this;
	}

	/** Sets the different insets (expressed as a <code>UnitValue</code>s, e.g. "10px" or "20mm") for the corresponding sides.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @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
	 * side for the platform will be used.
	 * @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
	 * side for the platform will be used.
	 * @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
	 * side for the platform will be used.
	 * @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
	 * side for the platform will be used.
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 * @see #setInsets(UnitValue[])
	 */
	public final LC insets(String top, String left, String bottom, String right)
	{
		insets = new UnitValue[] { // No setter to avoid copy again
				ConstraintParser.parseUnitValue(top, false),
				ConstraintParser.parseUnitValue(left, true),
				ConstraintParser.parseUnitValue(bottom, false),
				ConstraintParser.parseUnitValue(right, true)};
		return this;
	}

	/** Same functionality as <code>setAlignX(ConstraintParser.parseUnitValueOrAlign(unitValue, true))</code> only this method returns <code>this</code>
	 * for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @param align The align keyword or for instance "100px". E.g "left", "right", "leading" or "trailing".
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 * @see #setAlignX(UnitValue)
	 */
	public final LC alignX(String align)
	{
		setAlignX(ConstraintParser.parseUnitValueOrAlign(align, true, null));
		return this;
	}

	/** Same functionality as <code>setAlignY(ConstraintParser.parseUnitValueOrAlign(align, false))</code> only this method returns <code>this</code> for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @param align The align keyword or for instance "100px". E.g "top" or "bottom".
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 * @see #setAlignY(UnitValue)
	 */
	public final LC alignY(String align)
	{
		setAlignY(ConstraintParser.parseUnitValueOrAlign(align, false, null));
		return this;
	}

	/** Sets both the alignX and alignY as the same time.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @param ax The align keyword or for instance "100px". E.g "left", "right", "leading" or "trailing".
	 * @param ay The align keyword or for instance "100px". E.g "top" or "bottom".
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 * @see #alignX(String)
	 * @see #alignY(String)
	 */
	public final LC align(String ax, String ay)
	{
		if (ax != null)
			alignX(ax);

		if (ay != null)
			alignY(ay);

		return this;
	}

	/** Same functionality as <code>setGridGapX(ConstraintParser.parseBoundSize(boundsSize, true, true))</code> only this method
	 * returns <code>this</code> for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @param boundsSize The <code>BoundSize</code> of the gap. This is a minimum and/or preferred and/or maximum size. E.g.
	 * <code>"50:100:200"</code> or <code>"100px"</code>.
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 * @see #setGridGapX(BoundSize)
	 */
	public final LC gridGapX(String boundsSize)
	{
		setGridGapX(ConstraintParser.parseBoundSize(boundsSize, true, true));
		return this;
	}

	/** Same functionality as <code>setGridGapY(ConstraintParser.parseBoundSize(boundsSize, true, false))</code> only this method
	 * returns <code>this</code> for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @param boundsSize The <code>BoundSize</code> of the gap. This is a minimum and/or preferred and/or maximum size. E.g.
	 * <code>"50:100:200"</code> or <code>"100px"</code>.
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 * @see #setGridGapY(BoundSize)
	 */
	public final LC gridGapY(String boundsSize)
	{
		setGridGapY(ConstraintParser.parseBoundSize(boundsSize, true, false));
		return this;
	}

	/** Sets both grid gaps at the same time. see {@link #gridGapX(String)} and {@link #gridGapY(String)}.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @param gapx The <code>BoundSize</code> of the gap. This is a minimum and/or preferred and/or maximum size. E.g.
	 * <code>"50:100:200"</code> or <code>"100px"</code>.
	 * @param gapy The <code>BoundSize</code> of the gap. This is a minimum and/or preferred and/or maximum size. E.g.
	 * <code>"50:100:200"</code> or <code>"100px"</code>.
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 * @see #gridGapX(String)
	 * @see #gridGapY(String)
	 */
	public final LC gridGap(String gapx, String gapy)
	{
		if (gapx != null)
			gridGapX(gapx);

		if (gapy != null)
			gridGapY(gapy);

		return this;
	}

	/** Same functionality as {@link #setDebugMillis(int repaintMillis)} only this method returns <code>this</code> for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @param repaintMillis The new debug repaint interval.
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 * @see #setDebugMillis(int)
	 */
	public final LC debug(int repaintMillis)
	{
		setDebugMillis(repaintMillis);
		return this;
	}

	/** Same functionality as {@link #setHideMode(int mode)} only this method returns <code>this</code> for chaining multiple calls.
	 * <p>
	 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
	 * @param mode The mode:<br>
	 * 0 == Normal. Bounds will be caclulated as if the component was visible.<br>
	 * 1 == If hidden the size will be 0, 0 but the gaps remain.<br>
	 * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br>
	 * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
	 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
	 * @see #setHideMode(int)
	 */
	public final LC hideMode(int mode)
	{
		setHideMode(mode);
		return this;
	}

	// ************************************************
	// Persistence Delegate and Serializable combined.
	// ************************************************

	private Object readResolve() throws ObjectStreamException
	{
		return LayoutUtil.getSerializedObject(this);
	}

	public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
	{
		LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
	}

	public void writeExternal(ObjectOutput out) throws IOException
	{
		if (getClass() == LC.class)
			LayoutUtil.writeAsXML(out, this);
	}
}