1 package net.miginfocom.layout;
3 import java.util.ArrayList;
8 * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
11 * Redistribution and use in source and binary forms, with or without modification,
12 * are permitted provided that the following conditions are met:
13 * Redistributions of source code must retain the above copyright notice, this list
14 * of conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice, this
16 * list of conditions and the following disclaimer in the documentation and/or other
17 * materials provided with the distribution.
18 * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
19 * used to endorse or promote products derived from this software without specific
20 * prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
26 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
28 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
34 * @author Mikael Grev, MiG InfoCom AB
38 /** A simple value holder for one component's constraint.
40 public final class CC// s implements Externalizable
42 private static final BoundSize DEF_GAP = BoundSize.NULL_SIZE; // Only used to denote default wrap/newline gap.
44 static final String[] DOCK_SIDES = {"north", "west", "south", "east"};
46 // See the getters and setters for information about the properties below.
48 private int dock = -1;
50 private UnitValue[] pos = null; // [x1, y1, x2, y2]
52 private UnitValue[] padding = null; // top, left, bottom, right
54 private UnitValue[] visualPadding = null; // top, left, bottom, right
56 private Boolean flowX = null;
60 private int split = 1;
62 private int spanX = 1, spanY = 1;
64 private int cellX = -1, cellY = 0; // If cellX is -1 then cellY is also considered -1. cellY is never negative.
66 private String tag = null;
68 private String id = null;
70 private int hideMode = -1;
72 private DimConstraint hor = new DimConstraint();
74 private DimConstraint ver = new DimConstraint();
76 private BoundSize newline = null;
78 private BoundSize wrap = null;
80 private boolean boundsInGrid = true;
82 private boolean external = false;
84 private Float pushX = null, pushY = null;
86 private AnimSpec animSpec = AnimSpec.DEF;
89 // ***** Tmp cache field
91 private static final String[] EMPTY_ARR = new String[0];
93 private transient String[] linkTargets = null;
95 /** Empty constructor.
101 String[] getLinkTargets()
103 if (linkTargets == null) {
104 final ArrayList<String> targets = new ArrayList<String>(2);
107 for (int i = 0; i < pos.length ; i++)
108 addLinkTargetIDs(targets, pos[i]);
111 linkTargets = targets.size() == 0 ? EMPTY_ARR : targets.toArray(new String[targets.size()]);
116 private void addLinkTargetIDs(ArrayList<String> targets, UnitValue uv)
119 String linkId = uv.getLinkTargetId();
120 if (linkId != null) {
123 for (int i = uv.getSubUnitCount() - 1; i >= 0; i--) {
124 UnitValue subUv = uv.getSubUnitValue(i);
125 if (subUv.isLinkedDeep())
126 addLinkTargetIDs(targets, subUv);
132 // **********************************************************
133 // Chaining constraint setters
134 // **********************************************************
136 /** Specifies that the component should be put in the end group <code>s</code> and will thus share the same ending
137 * coordinate as them within the group.
139 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
140 * @param s A name to associate on the group that should be the same for other rows/columns in the same group.
141 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
143 public final CC endGroupX(String s)
149 /** Specifies that the component should be put in the size group <code>s</code> and will thus share the same size
150 * as them within the group.
152 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
153 * @param s A name to associate on the group that should be the same for other rows/columns in the same group.
154 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
156 public final CC sizeGroupX(String s)
162 /** The minimum size for the component. The value will override any value that is set on the component itself.
164 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
165 * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm".
166 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
168 public final CC minWidth(String size)
170 hor.setSize(LayoutUtil.derive(hor.getSize(), ConstraintParser.parseUnitValue(size, true), null, null));
174 /** The size for the component as a min and/or preferred and/or maximum size. The value will override any value that is set on
175 * the component itself.
177 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
178 * @param size The size expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px".
179 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
181 public final CC width(String size)
183 hor.setSize(ConstraintParser.parseBoundSize(size, false, true));
187 /** The maximum size for the component. The value will override any value that is set on the component itself.
189 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
190 * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm".
191 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
193 public final CC maxWidth(String size)
195 hor.setSize(LayoutUtil.derive(hor.getSize(), null, null, ConstraintParser.parseUnitValue(size, true)));
200 /** The horizontal gap before and/or after the component. The gap is towards cell bounds and/or other component bounds.
202 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
203 * @param before The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
204 * @param after The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
205 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
207 public final CC gapX(String before, String after)
210 hor.setGapBefore(ConstraintParser.parseBoundSize(before, true, true));
213 hor.setGapAfter(ConstraintParser.parseBoundSize(after, true, true));
218 /** Same functionality as <code>getHorizontal().setAlign(ConstraintParser.parseUnitValue(unitValue, true))</code> only this method
219 * returns <code>this</code> for chaining multiple calls.
221 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
222 * @param align The align keyword or for instance "100px". E.g "left", "right", "leading" or "trailing".
223 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
225 public final CC alignX(String align)
227 hor.setAlign(ConstraintParser.parseUnitValueOrAlign(align, true, null));
231 /** The grow priority compared to other components in the same cell.
233 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
234 * @param p The grow priority.
235 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
237 public final CC growPrioX(int p)
239 hor.setGrowPriority(p);
243 /** Grow priority for the component horizontally and optionally vertically.
245 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
246 * @param widthHeight The new shrink weight and height. 1-2 arguments, never null.
247 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
250 public final CC growPrio(int ... widthHeight)
252 switch (widthHeight.length) {
254 throw new IllegalArgumentException("Illegal argument count: " + widthHeight.length);
256 growPrioY(widthHeight[1]);
258 growPrioX(widthHeight[0]);
263 /** Grow weight for the component horizontally. It default to weight <code>100</code>.
265 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
266 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
269 public final CC growX()
271 hor.setGrow(ResizeConstraint.WEIGHT_100);
275 /** Grow weight for the component horizontally.
277 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
278 * @param w The new grow weight.
279 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
281 public final CC growX(float w)
283 hor.setGrow(new Float(w));
287 /** grow weight for the component horizontally and optionally vertically.
289 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
290 * @param widthHeight The new shrink weight and height. 1-2 arguments, never null.
291 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
294 public final CC grow(float ... widthHeight)
296 switch (widthHeight.length) {
298 throw new IllegalArgumentException("Illegal argument count: " + widthHeight.length);
300 growY(widthHeight[1]);
302 growX(widthHeight[0]);
307 /** The shrink priority compared to other components in the same cell.
309 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
310 * @param p The shrink priority.
311 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
313 public final CC shrinkPrioX(int p)
315 hor.setShrinkPriority(p);
319 /** Shrink priority for the component horizontally and optionally vertically.
321 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
322 * @param widthHeight The new shrink weight and height. 1-2 arguments, never null.
323 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
326 public final CC shrinkPrio(int ... widthHeight)
328 switch (widthHeight.length) {
330 throw new IllegalArgumentException("Illegal argument count: " + widthHeight.length);
332 shrinkPrioY(widthHeight[1]);
334 shrinkPrioX(widthHeight[0]);
339 /** Shrink weight for the component horizontally.
341 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
342 * @param w The new shrink weight.
343 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
345 public final CC shrinkX(float w)
347 hor.setShrink(new Float(w));
351 /** Shrink weight for the component horizontally and optionally vertically.
353 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
354 * @param widthHeight The new shrink weight and height. 1-2 arguments, never null.
355 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
358 public final CC shrink(float ... widthHeight)
360 switch (widthHeight.length) {
362 throw new IllegalArgumentException("Illegal argument count: " + widthHeight.length);
364 shrinkY(widthHeight[1]);
366 shrinkX(widthHeight[0]);
371 /** The end group that this component should be placed in.
373 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
374 * @param s The name of the group. If <code>null</code> that means no group (default)
375 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
377 public final CC endGroupY(String s)
383 /** The end group(s) that this component should be placed in.
385 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
386 * @param xy The end group for x and y respectively. 1-2 arguments, not null.
387 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
390 public final CC endGroup(String ... xy)
394 throw new IllegalArgumentException("Illegal argument count: " + xy.length);
403 /** The size group that this component should be placed in.
405 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
406 * @param s The name of the group. If <code>null</code> that means no group (default)
407 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
409 public final CC sizeGroupY(String s)
415 /** The size group(s) that this component should be placed in.
417 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
418 * @param xy The size group for x and y respectively. 1-2 arguments, not null.
419 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
422 public final CC sizeGroup(String ... xy)
426 throw new IllegalArgumentException("Illegal argument count: " + xy.length);
435 /** The minimum size for the component. The value will override any value that is set on the component itself.
437 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
438 * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm".
439 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
441 public final CC minHeight(String size)
443 ver.setSize(LayoutUtil.derive(ver.getSize(), ConstraintParser.parseUnitValue(size, false), null, null));
447 /** The size for the component as a min and/or preferred and/or maximum size. The value will override any value that is set on
448 * the component itself.
450 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
451 * @param size The size expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px".
452 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
454 public final CC height(String size)
456 ver.setSize(ConstraintParser.parseBoundSize(size, false, false));
460 /** The maximum size for the component. The value will override any value that is set on the component itself.
462 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
463 * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm".
464 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
466 public final CC maxHeight(String size)
468 ver.setSize(LayoutUtil.derive(ver.getSize(), null, null, ConstraintParser.parseUnitValue(size, false)));
472 /** The vertical gap before (normally above) and/or after (normally below) the component. The gap is towards cell bounds and/or other component bounds.
474 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
475 * @param before The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
476 * @param after The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
477 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
479 public final CC gapY(String before, String after)
482 ver.setGapBefore(ConstraintParser.parseBoundSize(before, true, false));
485 ver.setGapAfter(ConstraintParser.parseBoundSize(after, true, false));
490 /** Same functionality as <code>getVertical().setAlign(ConstraintParser.parseUnitValue(unitValue, true))</code> only this method
491 * returns <code>this</code> for chaining multiple calls.
493 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
494 * @param align The align keyword or for instance "100px". E.g "top" or "bottom".
495 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
497 public final CC alignY(String align)
499 ver.setAlign(ConstraintParser.parseUnitValueOrAlign(align, false, null));
503 /** The grow priority compared to other components in the same cell.
505 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
506 * @param p The grow priority.
507 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
509 public final CC growPrioY(int p)
511 ver.setGrowPriority(p);
515 /** Grow weight for the component vertically. Defaults to <code>100</code>.
517 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
518 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
521 public final CC growY()
523 ver.setGrow(ResizeConstraint.WEIGHT_100);
527 /** Grow weight for the component vertically.
529 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
530 * @param w The new grow weight.
531 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
533 public final CC growY(float w)
539 /** Grow weight for the component vertically.
541 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
542 * @param w The new grow weight.
543 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
546 public final CC growY(Float w)
552 /** The shrink priority compared to other components in the same cell.
554 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
555 * @param p The shrink priority.
556 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
558 public final CC shrinkPrioY(int p)
560 ver.setShrinkPriority(p);
564 /** Shrink weight for the component horizontally.
566 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
567 * @param w The new shrink weight.
568 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
570 public final CC shrinkY(float w)
572 ver.setShrink(new Float(w));
576 /** How this component, if hidden (not visible), should be treated.
578 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
579 * @param mode The mode. Default to the mode in the {@link net.miginfocom.layout.LC}.
580 * 0 == Normal. Bounds will be calculated as if the component was visible.<br>
581 * 1 == If hidden the size will be 0, 0 but the gaps remain.<br>
582 * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br>
583 * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
584 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
586 public final CC hideMode(int mode)
592 /** The id used to reference this component in some constraints.
594 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
595 * @param s The id or <code>null</code>. May consist of a groupID and an componentID which are separated by a dot: ".". E.g. "grp1.id1".
596 * The dot should never be first or last if present.
597 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
599 public final CC id(String s)
605 /** Same functionality as {@link #setTag(String tag)} only this method returns <code>this</code> for chaining multiple calls.
607 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
608 * @param tag The new tag. May be <code>null</code>.
609 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
610 * @see #setTag(String)
612 public final CC tag(String tag)
618 /** Set the cell(s) that the component should occupy in the grid. Same functionality as {@link #setCellX(int col)} and
619 * {@link #setCellY(int row)} together with {@link #setSpanX(int width)} and {@link #setSpanY(int height)}. This method
620 * returns <code>this</code> for chaining multiple calls.
622 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
623 * @param colRowWidthHeight cellX, cellY, spanX, spanY respectively. 1-4 arguments, not null.
624 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
625 * @see #setCellX(int)
626 * @see #setCellY(int)
627 * @see #setSpanX(int)
628 * @see #setSpanY(int)
629 * @since 3.7.2. Replacing cell(int, int) and cell(int, int, int, int)
631 public final CC cell(int ... colRowWidthHeight)
633 switch (colRowWidthHeight.length) {
635 throw new IllegalArgumentException("Illegal argument count: " + colRowWidthHeight.length);
637 setSpanY(colRowWidthHeight[3]);
639 setSpanX(colRowWidthHeight[2]);
641 setCellY(colRowWidthHeight[1]);
643 setCellX(colRowWidthHeight[0]);
648 /** Same functionality as <code>spanX(cellsX).spanY(cellsY)</code> which means this cell will span cells in both x and y.
649 * This method returns <code>this</code> for chaining multiple calls.
651 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
652 * Since 3.7.2 this takes an array/vararg whereas it previously only took two specific values, xSpan and ySpan.
653 * @param cells spanX and spanY, when present, and in that order.
654 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
655 * @see #setSpanY(int)
656 * @see #setSpanX(int)
659 * @since 3.7.2 Replaces span(int, int).
661 public final CC span(int ... cells)
663 if (cells == null || cells.length == 0) {
664 setSpanX(LayoutUtil.INF);
666 } else if (cells.length == 1) {
676 /** Corresponds exactly to the "gap left right top bottom" keyword.
677 * @param args Same as for the "gap" keyword. Length 1-4, never null buf elements can be null.
678 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
681 public final CC gap(String ... args)
683 switch (args.length) {
685 throw new IllegalArgumentException("Illegal argument count: " + args.length);
698 /** Sets the horizontal gap before the component.
700 * Note! This is currently same as gapLeft(). This might change in 4.x.
701 * @param boundsSize The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
702 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
705 public final CC gapBefore(String boundsSize)
707 hor.setGapBefore(ConstraintParser.parseBoundSize(boundsSize, true, true));
711 /** Sets the horizontal gap after the component.
713 * Note! This is currently same as gapRight(). This might change in 4.x.
714 * @param boundsSize The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
715 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
718 public final CC gapAfter(String boundsSize)
720 hor.setGapAfter(ConstraintParser.parseBoundSize(boundsSize, true, true));
724 /** Sets the gap above the component.
725 * @param boundsSize The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
726 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
729 public final CC gapTop(String boundsSize)
731 ver.setGapBefore(ConstraintParser.parseBoundSize(boundsSize, true, false));
735 /** Sets the gap to the left the component.
736 * @param boundsSize The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
737 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
740 public final CC gapLeft(String boundsSize)
742 hor.setGapBefore(ConstraintParser.parseBoundSize(boundsSize, true, true));
746 /** Sets the gap below the component.
747 * @param boundsSize The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
748 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
751 public final CC gapBottom(String boundsSize)
753 ver.setGapAfter(ConstraintParser.parseBoundSize(boundsSize, true, false));
757 /** Sets the gap to the right of the component.
758 * @param boundsSize The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
759 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
762 public final CC gapRight(String boundsSize)
764 hor.setGapAfter(ConstraintParser.parseBoundSize(boundsSize, true, true));
768 /** Same functionality as calling {@link #setSpanY(int)} with <code>LayoutUtil.INF</code> which means this cell will span the rest of the column.
769 * This method returns <code>this</code> for chaining multiple calls.
771 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
772 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
773 * @see #setSpanY(int)
776 public final CC spanY()
778 return spanY(LayoutUtil.INF);
781 /** Same functionality as {@link #setSpanY(int)} only this method returns <code>this</code> for chaining multiple calls.
783 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
784 * @param cells The number of cells to span (i.e. merge).
785 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
786 * @see #setSpanY(int)
788 public final CC spanY(int cells)
794 /** Same functionality as {@link #setSpanX(int)} which means this cell will span the rest of the row.
795 * This method returns <code>this</code> for chaining multiple calls.
797 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
798 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
799 * @see #setSpanX(int)
802 public final CC spanX()
804 return spanX(LayoutUtil.INF);
807 /** Same functionality as {@link #setSpanX(int)} only this method returns <code>this</code> for chaining multiple calls.
809 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
810 * @param cells The number of cells to span (i.e. merge).
811 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
812 * @see #setSpanY(int)
814 public final CC spanX(int cells)
820 /** Same functionality as <code>pushX().pushY()</code> which means this cell will push in both x and y dimensions.
821 * This method returns <code>this</code> for chaining multiple calls.
823 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
824 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
825 * @see #setPushX(Float)
826 * @see #setPushX(Float)
830 public final CC push()
832 return pushX().pushY();
835 /** Same functionality as <code>pushX(weightX).pushY(weightY)</code> which means this cell will push in both x and y dimensions.
836 * This method returns <code>this</code> for chaining multiple calls.
838 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
839 * @param weightX The weight used in the push.
840 * @param weightY The weight used in the push.
841 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
842 * @see #setPushY(Float)
843 * @see #setPushX(Float)
847 public final CC push(Float weightX, Float weightY)
849 return pushX(weightX).pushY(weightY);
852 /** Same functionality as {@link #setPushY(Float)} which means this cell will push the rest of the column.
853 * This method returns <code>this</code> for chaining multiple calls.
855 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
856 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
857 * @see #setPushY(Float)
859 public final CC pushY()
861 return pushY(ResizeConstraint.WEIGHT_100);
864 /** Same functionality as {@link #setPushY(Float weight)} only this method returns <code>this</code> for chaining multiple calls.
866 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
867 * @param weight The weight used in the push.
868 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
869 * @see #setPushY(Float)
871 public final CC pushY(Float weight)
877 /** Same functionality as {@link #setPushX(Float)} which means this cell will push the rest of the row.
878 * This method returns <code>this</code> for chaining multiple calls.
880 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
881 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
882 * @see #setPushX(Float)
884 public final CC pushX()
886 return pushX(ResizeConstraint.WEIGHT_100);
889 /** Same functionality as {@link #setPushX(Float weight)} only this method returns <code>this</code> for chaining multiple calls.
891 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
892 * @param weight The weight used in the push.
893 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
894 * @see #setPushY(Float)
896 public final CC pushX(Float weight)
902 /** Same functionality as {@link #setSplit(int parts)} only this method returns <code>this</code> for chaining multiple calls.
904 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
905 * @param parts The number of parts (i.e. component slots) the cell should be divided into.
906 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
907 * @see #setSplit(int)
909 public final CC split(int parts)
915 /** Same functionality as split(LayoutUtil.INF), which means split until one of the keywords that breaks the split is found for
916 * a component after this one (e.g. wrap, newline and skip).
918 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
919 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
920 * @see #setSplit(int)
923 public final CC split()
925 setSplit(LayoutUtil.INF);
929 /** Same functionality as {@link #setSkip(int)} only this method returns <code>this</code> for chaining multiple calls.
931 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
932 * @param cells How many cells in the grid that should be skipped <b>before</b> the component that this constraint belongs to
933 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
936 public final CC skip(int cells)
942 /** Same functionality as skip(1).
944 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
945 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
949 public final CC skip()
955 /** Same functionality as calling {@link #setExternal(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
957 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
958 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
959 * @see #setExternal(boolean)
961 public final CC external()
967 /** Same functionality as calling {@link #setFlowX(Boolean)} with <code>Boolean.TRUE</code> only this method returns <code>this</code> for chaining multiple calls.
969 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
970 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
971 * @see #setFlowX(Boolean)
973 public final CC flowX()
975 setFlowX(Boolean.TRUE);
979 /** Same functionality as calling {@link #setFlowX(Boolean)} with <code>Boolean.FALSE</code> only this method returns <code>this</code> for chaining multiple calls.
981 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
982 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
983 * @see #setFlowX(Boolean)
985 public final CC flowY()
987 setFlowX(Boolean.FALSE);
992 /** Same functionality as {@link #growX()} and {@link #growY()}.
994 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
995 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
999 public final CC grow()
1006 /** Same functionality as calling {@link #setNewline(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
1008 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1009 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1010 * @see #setNewline(boolean)
1012 public final CC newline()
1018 /** Same functionality as {@link #setNewlineGapSize(BoundSize)} only this method returns <code>this</code> for chaining multiple calls.
1020 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1021 * @param gapSize The gap size that will override the gap size in the row/column constraints if <code>!= null</code>. E.g. "5px" or "unrel".
1022 * If <code>null</code> or <code>""</code> the newline size will be set to the default size and turned on. This is different compared to
1023 * {@link #setNewlineGapSize(BoundSize)}.
1024 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1025 * @see #setNewlineGapSize(BoundSize)
1027 public final CC newline(String gapSize)
1029 BoundSize bs = ConstraintParser.parseBoundSize(gapSize, true, (flowX != null && flowX == false));
1031 setNewlineGapSize(bs);
1038 /** Same functionality as calling {@link #setWrap(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
1040 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1041 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1042 * @see #setWrap(boolean)
1044 public final CC wrap()
1050 /** Same functionality as {@link #setWrapGapSize(BoundSize)} only this method returns <code>this</code> for chaining multiple calls.
1052 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1053 * @param gapSize The gap size that will override the gap size in the row/column constraints if <code>!= null</code>. E.g. "5px" or "unrel".
1054 * If <code>null</code> or <code>""</code> the wrap size will be set to the default size and turned on. This is different compared to
1055 * {@link #setWrapGapSize(BoundSize)}.
1056 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1057 * @see #setWrapGapSize(BoundSize)
1059 public final CC wrap(String gapSize)
1061 BoundSize bs = ConstraintParser.parseBoundSize(gapSize, true, (flowX != null && flowX == false));
1070 /** Same functionality as calling {@link #setDockSide(int)} with <code>0</code> only this method returns <code>this</code> for chaining multiple calls.
1072 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1073 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1074 * @see #setDockSide(int)
1076 public final CC dockNorth()
1082 /** Same functionality as calling {@link #setDockSide(int)} with <code>1</code> only this method returns <code>this</code> for chaining multiple calls.
1084 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1085 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1086 * @see #setDockSide(int)
1088 public final CC dockWest()
1094 /** Same functionality as calling {@link #setDockSide(int)} with <code>2</code> only this method returns <code>this</code> for chaining multiple calls.
1096 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1097 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1098 * @see #setDockSide(int)
1100 public final CC dockSouth()
1106 /** Same functionality as calling {@link #setDockSide(int)} with <code>3</code> only this method returns <code>this</code> for chaining multiple calls.
1108 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1109 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1110 * @see #setDockSide(int)
1112 public final CC dockEast()
1118 /** Sets the x-coordinate for the component. This is used to set the x coordinate position to a specific value. The component
1119 * bounds is still precalculated to the grid cell and this method should be seen as a way to correct the x position.
1121 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1122 * @param x The x position as a UnitValue. E.g. "10" or "40mm" or "container.x+10".
1123 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1124 * @see #setPos(UnitValue[])
1125 * @see #setBoundsInGrid(boolean)
1127 public final CC x(String x)
1129 return corrPos(x, 0);
1132 /** Sets the y-coordinate for the component. This is used to set the y coordinate position to a specific value. The component
1133 * bounds is still precalculated to the grid cell and this method should be seen as a way to correct the y position.
1135 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1136 * @param y The y position as a UnitValue. E.g. "10" or "40mm" or "container.x+10".
1137 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1138 * @see #setPos(UnitValue[])
1139 * @see #setBoundsInGrid(boolean)
1141 public final CC y(String y)
1143 return corrPos(y, 1);
1146 /** Sets the x2-coordinate for the component (right side). This is used to set the x2 coordinate position to a specific value. The component
1147 * bounds is still precalculated to the grid cell and this method should be seen as a way to correct the x position.
1149 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1150 * @param x2 The x2 side's position as a UnitValue. E.g. "10" or "40mm" or "container.x2 - 10".
1151 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1152 * @see #setPos(UnitValue[])
1153 * @see #setBoundsInGrid(boolean)
1155 public final CC x2(String x2)
1157 return corrPos(x2, 2);
1160 /** Sets the y2-coordinate for the component (bottom side). This is used to set the y2 coordinate position to a specific value. The component
1161 * bounds is still precalculated to the grid cell and this method should be seen as a way to correct the y position.
1163 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1164 * @param y2 The y2 side's position as a UnitValue. E.g. "10" or "40mm" or "container.x2 - 10".
1165 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1166 * @see #setPos(UnitValue[])
1167 * @see #setBoundsInGrid(boolean)
1169 public final CC y2(String y2)
1171 return corrPos(y2, 3);
1174 private final CC corrPos(String uv, int ix)
1176 UnitValue[] b = getPos();
1178 b = new UnitValue[4];
1180 b[ix] = ConstraintParser.parseUnitValue(uv, (ix % 2 == 0));
1183 setBoundsInGrid(true);
1187 /** Same functionality as {@link #x(String x)} and {@link #y(String y)} together.
1189 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1190 * @param x The x position as a UnitValue. E.g. "10" or "40mm" or "container.x+10".
1191 * @param y The y position as a UnitValue. E.g. "10" or "40mm" or "container.x+10".
1192 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1193 * @see #setPos(UnitValue[])
1195 public final CC pos(String x, String y)
1197 UnitValue[] b = getPos();
1199 b = new UnitValue[4];
1201 b[0] = ConstraintParser.parseUnitValue(x, true);
1202 b[1] = ConstraintParser.parseUnitValue(y, false);
1205 setBoundsInGrid(false);
1209 /** Same functionality as {@link #x(String x)}, {@link #y(String y)}, {@link #y2(String y)} and {@link #y2(String y)} together.
1211 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1212 * @param x The x position as a UnitValue. E.g. "10" or "40mm" or "container.x+10".
1213 * @param y The y position as a UnitValue. E.g. "10" or "40mm" or "container.x+10".
1214 * @param x2 The x2 side's position as a UnitValue. E.g. "10" or "40mm" or "container.x2 - 10".
1215 * @param y2 The y2 side's position as a UnitValue. E.g. "10" or "40mm" or "container.x2 - 10".
1216 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1217 * @see #setPos(UnitValue[])
1219 public final CC pos(String x, String y, String x2, String y2)
1221 setPos(new UnitValue[] {
1222 ConstraintParser.parseUnitValue(x, true),
1223 ConstraintParser.parseUnitValue(y, false),
1224 ConstraintParser.parseUnitValue(x2, true),
1225 ConstraintParser.parseUnitValue(y2, false),
1227 setBoundsInGrid(false);
1231 /** Same functionality as {@link #setPadding(UnitValue[])} but the unit values as absolute pixels. This method returns <code>this</code> for chaining multiple calls.
1233 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1234 * @param top The top padding that will be added to the y coordinate at the last stage in the layout.
1235 * @param left The top padding that will be added to the x coordinate at the last stage in the layout.
1236 * @param bottom The top padding that will be added to the y2 coordinate at the last stage in the layout.
1237 * @param right The top padding that will be added to the x2 coordinate at the last stage in the layout.
1238 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1239 * @see #setTag(String)
1241 public final CC pad(int top, int left, int bottom, int right)
1243 setPadding(new UnitValue[] {
1244 new UnitValue(top), new UnitValue(left), new UnitValue(bottom), new UnitValue(right)
1249 /** Same functionality as <code>setPadding(ConstraintParser.parseInsets(pad, false))}</code> only this method returns <code>this</code> for chaining multiple calls.
1251 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1252 * @param pad 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.
1253 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1254 * @see #setTag(String)
1256 public final CC pad(String pad)
1258 setPadding(pad != null ? ConstraintParser.parseInsets(pad, false) : null);
1262 // **********************************************************
1264 // **********************************************************
1266 /** Returns the horizontal dimension constraint for this component constraint. It has constraints for the horizontal size
1267 * and grow/shrink priorities and weights.
1269 * Note! If any changes is to be made it must be made direct when the object is returned. It is not allowed to save the
1270 * constraint for later use.
1271 * @return The current dimension constraint. Never <code>null</code>.
1273 public DimConstraint getHorizontal()
1278 /** Sets the horizontal dimension constraint for this component constraint. It has constraints for the horizontal size
1279 * and grow/shrink priorities and weights.
1280 * @param h The new dimension constraint. If <code>null</code> it will be reset to <code>new DimConstraint();</code>
1282 public void setHorizontal(DimConstraint h)
1284 hor = h != null ? h : new DimConstraint();
1287 /** Returns the vertical dimension constraint for this component constraint. It has constraints for the vertical size
1288 * and grow/shrink priorities and weights.
1290 * Note! If any changes is to be made it must be made direct when the object is returned. It is not allowed to save the
1291 * constraint for later use.
1292 * @return The current dimension constraint. Never <code>null</code>.
1294 public DimConstraint getVertical()
1299 /** Sets the vertical dimension constraint for this component constraint. It has constraints for the vertical size
1300 * and grow/shrink priorities and weights.
1301 * @param v The new dimension constraint. If <code>null</code> it will be reset to <code>new DimConstraint();</code>
1303 public void setVertical(DimConstraint v)
1305 ver = v != null ? v : new DimConstraint();
1308 /** Returns the vertical or horizontal dim constraint.
1310 * Note! If any changes is to be made it must be made direct when the object is returned. It is not allowed to save the
1311 * constraint for later use.
1312 * @param isHor If the horizontal constraint should be returned.
1313 * @return The dim constraint. Never <code>null</code>.
1315 public DimConstraint getDimConstraint(boolean isHor)
1317 return isHor ? hor : ver;
1320 /** Returns the absolute positioning of one or more of the edges. This will be applied last in the layout cycle and will not
1321 * affect the flow or grid positions. The positioning is relative to the parent and can not (as padding) be used
1322 * to adjust the edges relative to the old value. May be <code>null</code> and elements may be <code>null</code>.
1323 * <code>null</code> value(s) for the x2 and y2 will be interpreted as to keep the preferred size and thus the x1
1324 * and x2 will just absolutely positions the component.
1326 * Note that {@link #setBoundsInGrid(boolean)} changes the interpretation of this property slightly.
1328 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1329 * @return The current value as a new array, free to modify.
1331 public UnitValue[] getPos()
1333 return pos != null ? new UnitValue[] {pos[0], pos[1], pos[2], pos[3]} : null;
1336 /** Sets absolute positioning of one or more of the edges. This will be applied last in the layout cycle and will not
1337 * affect the flow or grid positions. The positioning is relative to the parent and can not (as padding) be used
1338 * to adjust the edges relative to the old value. May be <code>null</code> and elements may be <code>null</code>.
1339 * <code>null</code> value(s) for the x2 and y2 will be interpreted as to keep the preferred size and thus the x1
1340 * and x2 will just absolutely positions the component.
1342 * Note that {@link #setBoundsInGrid(boolean)} changes the interpretation of this property slightly.
1344 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1345 * @param pos <code>UnitValue[] {x, y, x2, y2}</code>. Must be <code>null</code> or of length 4. Elements can be <code>null</code>.
1347 public void setPos(UnitValue[] pos)
1349 this.pos = pos != null ? new UnitValue[] {pos[0], pos[1], pos[2], pos[3]} : null;
1353 /** Returns if the absolute <code>pos</code> value should be corrections to the component that is in a normal cell. If <code>false</code>
1354 * the value of <code>pos</code> is truly absolute in that it will not affect the grid or have a default bounds in the grid.
1356 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1357 * @return The current value.
1360 public boolean isBoundsInGrid()
1362 return boundsInGrid;
1365 /** Sets if the absolute <code>pos</code> value should be corrections to the component that is in a normal cell. If <code>false</code>
1366 * the value of <code>pos</code> is truly absolute in that it will not affect the grid or have a default bounds in the grid.
1368 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1369 * @param b <code>true</code> for bounds taken from the grid position. <code>false</code> is default.
1370 * @see #setPos(UnitValue[])
1372 void setBoundsInGrid(boolean b)
1374 this.boundsInGrid = b;
1377 /** Returns the absolute cell position in the grid or <code>-1</code> if cell positioning is not used.
1379 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1380 * @return The current value.
1382 public int getCellX()
1387 /** Set an absolute cell x-position in the grid. If >= 0 this point points to the absolute cell that this constaint's component should occupy.
1388 * If there's already a component in that cell they will split the cell. The flow will then continue after this cell.
1390 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1391 * @param x The x-position or <code>-1</code> to disable cell positioning.
1393 public void setCellX(int x)
1398 /** Returns the absolute cell position in the grid or <code>-1</code> if cell positioning is not used.
1400 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1401 * @return The current value.
1403 public int getCellY()
1405 return cellX < 0 ? -1 : cellY;
1408 /** Set an absolute cell x-position in the grid. If >= 0 this point points to the absolute cell that this constaint's component should occupy.
1409 * If there's already a component in that cell they will split the cell. The flow will then continue after this cell.
1411 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1412 * @param y The y-position or <code>-1</code> to disable cell positioning.
1414 public void setCellY(int y)
1418 cellY = y < 0 ? 0 : y;
1421 /** Sets the docking side. -1 means no docking.<br>
1422 * Valid sides are: <code> north = 0, west = 1, south = 2, east = 3</code>.
1424 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1425 * @return The current side.
1427 public int getDockSide()
1432 /** Sets the docking side. -1 means no docking.<br>
1433 * Valid sides are: <code> north = 0, west = 1, south = 2, east = 3</code>.
1435 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1436 * @param side -1 or 0-3.
1438 public void setDockSide(int side)
1440 if (side < -1 || side > 3)
1441 throw new IllegalArgumentException("Illegal dock side: " + side);
1445 /** Returns if this component should have its bounds handled by an external source and not this layout manager.
1447 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1448 * @return The current value.
1450 public boolean isExternal()
1455 /** If this boolean is true this component is not handled in any way by the layout manager and the component can have its bounds set by an external
1456 * handler which is normally by the use of some <code>component.setBounds(x, y, width, height)</code> directly (for Swing).
1458 * The bounds <b>will not</b> affect the minimum and preferred size of the container.
1460 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1461 * @param b <code>true</code> means that the bounds are not changed.
1463 public void setExternal(boolean b)
1468 /** Returns if the flow in the <b>cell</b> is in the horizontal dimension. Vertical if <code>false</code>. Only the first
1469 * component is a cell can set the flow.
1471 * If <code>null</code> the flow direction is inherited by from the {@link net.miginfocom.layout.LC}.
1473 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1474 * @return The current value.
1476 public Boolean getFlowX()
1481 /** Sets if the flow in the <b>cell</b> is in the horizontal dimension. Vertical if <code>false</code>. Only the first
1482 * component is a cell can set the flow.
1484 * If <code>null</code> the flow direction is inherited by from the {@link net.miginfocom.layout.LC}.
1486 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1487 * @param b <code>Boolean.TRUE</code> means horizontal flow in the cell.
1489 public void setFlowX(Boolean b)
1494 /** Sets how a component that is hidden (not visible) should be treated by default.
1495 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1496 * @return The mode:<br>
1497 * 0 == Normal. Bounds will be calculated as if the component was visible.<br>
1498 * 1 == If hidden the size will be 0, 0 but the gaps remain.<br>
1499 * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br>
1500 * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
1502 public int getHideMode()
1507 /** Sets how a component that is hidden (not visible) should be treated by default.
1508 * @param mode The mode:<br>
1509 * 0 == Normal. Bounds will be calculated as if the component was visible.<br>
1510 * 1 == If hidden the size will be 0, 0 but the gaps remain.<br>
1511 * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br>
1512 * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
1514 public void setHideMode(int mode)
1516 if (mode < -1 || mode > 3)
1517 throw new IllegalArgumentException("Wrong hideMode: " + mode);
1522 /** Returns the id used to reference this component in some constraints.
1524 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1525 * @return The id or <code>null</code>. May consist of a groupID and an componentID which are separated by a dot: ".". E.g. "grp1.id1".
1526 * The dot should never be first or last if present.
1528 public String getId()
1533 /** Sets the id used to reference this component in some constraints.
1535 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1536 * @param id The id or <code>null</code>. May consist of a groupID and an componentID which are separated by a dot: ".". E.g. "grp1.id1".
1537 * The dot should never be first or last if present.
1539 public void setId(String id)
1544 /** Returns the absolute resizing in the last stage of the layout cycle. May be <code>null</code> and elements may be <code>null</code>.
1546 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1547 * @return The current value. <code>null</code> or of length 4.
1549 public UnitValue[] getPadding()
1551 return padding != null ? new UnitValue[] {padding[0], padding[1], padding[2], padding[3]} : null;
1554 /** Sets the absolute resizing in the last stage of the layout cycle. These values are added to the edges and can thus for
1555 * instance be used to grow or reduce the size or move the component an absolute number of pixels. May be <code>null</code>
1556 * and elements may be <code>null</code>.
1558 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1559 * @param sides top, left, bottom right. Must be <code>null</code> or of length 4.
1561 public void setPadding(UnitValue[] sides)
1563 this.padding = sides != null ? new UnitValue[] {sides[0], sides[1], sides[2], sides[3]} : null;
1566 /** Returns the visual padding used when laying out this Component. May be <code>null</code> and elements may be <code>null</code>.
1568 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1569 * @return The current value. <code>null</code> or of length 4.
1571 public UnitValue[] getVisualPadding()
1573 return visualPadding != null ? new UnitValue[] {visualPadding[0], visualPadding[1], visualPadding[2], visualPadding[3]} : null;
1576 /** Sets the visual padding used when laying out this Component.
1578 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1579 * @param sides top, left, bottom right. Must be <code>null</code> or of length 4.
1581 public void setVisualPadding(UnitValue[] sides)
1583 this.visualPadding = sides != null ? new UnitValue[] {sides[0], sides[1], sides[2], sides[3]} : null;
1586 /** Returns how many cells in the grid that should be skipped <b>before</b> the component that this constraint belongs to.
1588 * Note that only the first component will be checked for this property.
1590 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1591 * @return The current value. 0 if no skip.
1593 public int getSkip()
1598 /** Sets how many cells in the grid that should be skipped <b>before</b> the component that this constraint belongs to.
1600 * Note that only the first component will be checked for this property.
1602 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1603 * @param cells How many cells in the grid that should be skipped <b>before</b> the component that this constraint belongs to
1605 public void setSkip(int cells)
1610 /** Returns the number of cells the cell that this constraint's component will span in the indicated dimension. <code>1</code> is default and
1611 * means that it only spans the current cell. <code>LayoutUtil.INF</code> is used to indicate a span to the end of the column/row.
1613 * Note that only the first component will be checked for this property.
1615 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1616 * @return The current value.
1618 public int getSpanX()
1623 /** Sets the number of cells the cell that this constraint's component will span in the indicated dimension. <code>1</code> is default and
1624 * means that it only spans the current cell. <code>LayoutUtil.INF</code> is used to indicate a span to the end of the column/row.
1626 * Note that only the first component will be checked for this property.
1628 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1629 * @param cells The number of cells to span (i.e. merge).
1631 public void setSpanX(int cells)
1636 /** Returns the number of cells the cell that this constraint's component will span in the indicated dimension. <code>1</code> is default and
1637 * means that it only spans the current cell. <code>LayoutUtil.INF</code> is used to indicate a span to the end of the column/row.
1639 * Note that only the first component will be checked for this property.
1641 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1642 * @return The current value.
1644 public int getSpanY()
1649 /** Sets the number of cells the cell that this constraint's component will span in the indicated dimension. <code>1</code> is default and
1650 * means that it only spans the current cell. <code>LayoutUtil.INF</code> is used to indicate a span to the end of the column/row.
1652 * Note that only the first component will be checked for this property.
1654 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1655 * @param cells The number of cells to span (i.e. merge).
1657 public void setSpanY(int cells)
1662 /** "pushx" indicates that the column that this component is in (this first if the component spans) should default to growing.
1663 * If any other column has been set to grow this push value on the component does nothing as the column's explicit grow weight
1664 * will take precedence. Push is normally used when the grid has not been defined in the layout.
1666 * If multiple components in a column has push weights set the largest one will be used for the column.
1667 * @return The current push value. Default is <code>null</code>.
1669 public Float getPushX()
1674 /** "pushx" indicates that the column that this component is in (this first if the component spans) should default to growing.
1675 * If any other column has been set to grow this push value on the component does nothing as the column's explicit grow weight
1676 * will take precedence. Push is normally used when the grid has not been defined in the layout.
1678 * If multiple components in a column has push weights set the largest one will be used for the column.
1679 * @param weight The new push value. Default is <code>null</code>.
1681 public void setPushX(Float weight)
1683 this.pushX = weight;
1686 /** "pushx" indicates that the row that this component is in (this first if the component spans) should default to growing.
1687 * If any other row has been set to grow this push value on the component does nothing as the row's explicit grow weight
1688 * will take precedence. Push is normally used when the grid has not been defined in the layout.
1690 * If multiple components in a row has push weights set the largest one will be used for the row.
1691 * @return The current push value. Default is <code>null</code>.
1693 public Float getPushY()
1698 /** "pushx" indicates that the row that this component is in (this first if the component spans) should default to growing.
1699 * If any other row has been set to grow this push value on the component does nothing as the row's explicit grow weight
1700 * will take precedence. Push is normally used when the grid has not been defined in the layout.
1702 * If multiple components in a row has push weights set the largest one will be used for the row.
1703 * @param weight The new push value. Default is <code>null</code>.
1705 public void setPushY(Float weight)
1707 this.pushY = weight;
1710 /** Returns in how many parts the current cell (that this constraint's component will be in) should be split in. If for instance
1711 * it is split in two, the next component will also share the same cell. Note that the cell can also span a number of
1712 * cells, which means that you can for instance span three cells and split that big cell for two components. Split can be
1713 * set to a very high value to make all components in the same row/column share the same cell (e.g. <code>LayoutUtil.INF</code>).
1715 * Note that only the first component will be checked for this property.
1717 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1718 * @return The current value.
1720 public int getSplit()
1725 /** Sets in how many parts the current cell (that this constraint's component will be in) should be split in. If for instance
1726 * it is split in two, the next component will also share the same cell. Note that the cell can also span a number of
1727 * cells, which means that you can for instance span three cells and split that big cell for two components. Split can be
1728 * set to a very high value to make all components in the same row/column share the same cell (e.g. <code>LayoutUtil.INF</code>).
1730 * Note that only the first component will be checked for this property.
1732 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1733 * @param parts The number of parts (i.e. component slots) the cell should be divided into.
1735 public void setSplit(int parts)
1740 /** Tags the component with metadata. Currently only used to tag buttons with for instance "cancel" or "ok" to make them
1741 * show up in the correct order depending on platform. See {@link PlatformDefaults#setButtonOrder(String)} for information.
1743 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1744 * @return The current value. May be <code>null</code>.
1746 public String getTag()
1751 /** Optional tag that gives more context to this constraint's component. It is for instance used to tag buttons in a
1752 * button bar with the button type such as "ok", "help" or "cancel".
1754 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1755 * @param tag The new tag. May be <code>null</code>.
1757 public void setTag(String tag)
1762 /** Returns if the flow should wrap to the next line/column <b>after</b> the component that this constraint belongs to.
1764 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1765 * @return The current value.
1767 public boolean isWrap()
1769 return wrap != null;
1772 /** Sets if the flow should wrap to the next line/column <b>after</b> the component that this constraint belongs to.
1774 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1775 * @param b <code>true</code> means wrap after.
1777 public void setWrap(boolean b)
1779 wrap = b ? (wrap == null ? DEF_GAP : wrap) : null;
1782 /** Returns the wrap size if it is a custom size. If wrap was set to true with {@link #setWrap(boolean)} then this method will
1783 * return <code>null</code> since that means that the gap size should be the default one as defined in the rows spec.
1784 * @return The custom gap size. NOTE! Will return <code>null</code> for both no wrap <b>and</b> default wrap.
1786 * @see #setWrap(boolean)
1789 public BoundSize getWrapGapSize()
1791 return wrap == DEF_GAP ? null : wrap;
1794 /** Set the wrap size and turns wrap on if <code>!= null</code>.
1795 * @param s The custom gap size. NOTE! <code>null</code> will not turn on or off wrap, it will only set the wrap gap size to "default".
1796 * A non-null value will turn on wrap though.
1798 * @see #setWrap(boolean)
1801 public void setWrapGapSize(BoundSize s)
1803 wrap = s == null ? (wrap != null ? DEF_GAP : null) : s;
1806 /** Returns if the flow should wrap to the next line/column <b>before</b> the component that this constraint belongs to.
1808 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1809 * @return The current value.
1811 public boolean isNewline()
1813 return newline != null;
1816 /** Sets if the flow should wrap to the next line/column <b>before</b> the component that this constraint belongs to.
1818 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1819 * @param b <code>true</code> means wrap before.
1821 public void setNewline(boolean b)
1823 newline = b ? (newline == null ? DEF_GAP : newline) : null;
1826 /** Returns the newline size if it is a custom size. If newline was set to true with {@link #setNewline(boolean)} then this method will
1827 * return <code>null</code> since that means that the gap size should be the default one as defined in the rows spec.
1828 * @return The custom gap size. NOTE! Will return <code>null</code> for both no newline <b>and</b> default newline.
1830 * @see #setNewline(boolean)
1833 public BoundSize getNewlineGapSize()
1835 return newline == DEF_GAP ? null : newline;
1838 /** Set the newline size and turns newline on if <code>!= null</code>.
1839 * @param s The custom gap size. NOTE! <code>null</code> will not turn on or off newline, it will only set the newline gap size to "default".
1840 * A non-null value will turn on newline though.
1842 * @see #setNewline(boolean)
1845 public void setNewlineGapSize(BoundSize s)
1847 newline = s == null ? (newline != null ? DEF_GAP : null) : s;
1850 /** Returns the animation spec. Default is a spec where animation is off (prio 0).
1851 * @return Never null.
1853 public AnimSpec getAnimSpec()
1859 // // ************************************************
1860 // // Persistence Delegate and Serializable combined.
1861 // // ************************************************
1863 // private Object readResolve() throws ObjectStreamException
1865 // return LayoutUtil.getSerializedObject(this);
1869 // public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
1871 // LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
1875 // public void writeExternal(ObjectOutput out) throws IOException
1877 // if (getClass() == CC.class)
1878 // LayoutUtil.writeAsXML(out, this);