1 package net.miginfocom.layout;
4 import java.util.ArrayList;
9 * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com)
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without modification,
13 * are permitted provided that the following conditions are met:
14 * Redistributions of source code must retain the above copyright notice, this list
15 * of conditions and the following disclaimer.
16 * Redistributions in binary form must reproduce the above copyright notice, this
17 * list of conditions and the following disclaimer in the documentation and/or other
18 * materials provided with the distribution.
19 * Neither the name of the MiG InfoCom AB nor the names of its contributors may be
20 * used to endorse or promote products derived from this software without specific
21 * prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
27 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
29 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
35 * @author Mikael Grev, MiG InfoCom AB
39 /** A simple value holder for one component's constraint.
41 public final class CC implements Externalizable
43 private static final BoundSize DEF_GAP = BoundSize.NULL_SIZE; // Only used to denote default wrap/newline gap.
45 static final String[] DOCK_SIDES = {"north", "west", "south", "east"};
47 // See the getters and setters for information about the properties below.
49 private int dock = -1;
51 private UnitValue[] pos = null; // [x1, y1, x2, y2]
53 private UnitValue[] padding = null; // top, left, bottom, right
55 private UnitValue[] visualPadding = null; // top, left, bottom, right
57 private Boolean flowX = null;
61 private int split = 1;
63 private int spanX = 1, spanY = 1;
65 private int cellX = -1, cellY = 0; // If cellX is -1 then cellY is also considered -1. cellY is never negative.
67 private String tag = null;
69 private String id = null;
71 private int hideMode = -1;
73 private DimConstraint hor = new DimConstraint();
75 private DimConstraint ver = new DimConstraint();
77 private BoundSize newline = null;
79 private BoundSize wrap = null;
81 private boolean boundsInGrid = true;
83 private boolean external = false;
85 private Float pushX = null, pushY = null;
87 private AnimSpec animSpec = AnimSpec.DEF;
90 // ***** Tmp cache field
92 private static final String[] EMPTY_ARR = new String[0];
94 private transient String[] linkTargets = null;
96 /** Empty constructor.
102 String[] getLinkTargets()
104 if (linkTargets == null) {
105 final ArrayList<String> targets = new ArrayList<String>(2);
108 for (int i = 0; i < pos.length ; i++)
109 addLinkTargetIDs(targets, pos[i]);
112 linkTargets = targets.size() == 0 ? EMPTY_ARR : targets.toArray(new String[targets.size()]);
117 private void addLinkTargetIDs(ArrayList<String> targets, UnitValue uv)
120 String linkId = uv.getLinkTargetId();
121 if (linkId != null) {
124 for (int i = uv.getSubUnitCount() - 1; i >= 0; i--) {
125 UnitValue subUv = uv.getSubUnitValue(i);
126 if (subUv.isLinkedDeep())
127 addLinkTargetIDs(targets, subUv);
133 // **********************************************************
134 // Chaining constraint setters
135 // **********************************************************
137 /** Specifies that the component should be put in the end group <code>s</code> and will thus share the same ending
138 * coordinate as them within the group.
140 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
141 * @param s A name to associate on the group that should be the same for other rows/columns in the same group.
142 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
144 public final CC endGroupX(String s)
150 /** Specifies that the component should be put in the size group <code>s</code> and will thus share the same size
151 * as them within the group.
153 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
154 * @param s A name to associate on the group that should be the same for other rows/columns in the same group.
155 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
157 public final CC sizeGroupX(String s)
163 /** The minimum size for the component. The value will override any value that is set on the component itself.
165 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
166 * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm".
167 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
169 public final CC minWidth(String size)
171 hor.setSize(LayoutUtil.derive(hor.getSize(), ConstraintParser.parseUnitValue(size, true), null, null));
175 /** 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
176 * the component itself.
178 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
179 * @param size The size expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px".
180 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
182 public final CC width(String size)
184 hor.setSize(ConstraintParser.parseBoundSize(size, false, true));
188 /** The maximum size for the component. The value will override any value that is set on the component itself.
190 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
191 * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm".
192 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
194 public final CC maxWidth(String size)
196 hor.setSize(LayoutUtil.derive(hor.getSize(), null, null, ConstraintParser.parseUnitValue(size, true)));
201 /** The horizontal gap before and/or after the component. The gap is towards cell bounds and/or other component bounds.
203 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
204 * @param before The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
205 * @param after The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
206 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
208 public final CC gapX(String before, String after)
211 hor.setGapBefore(ConstraintParser.parseBoundSize(before, true, true));
214 hor.setGapAfter(ConstraintParser.parseBoundSize(after, true, true));
219 /** Same functionality as <code>getHorizontal().setAlign(ConstraintParser.parseUnitValue(unitValue, true))</code> only this method
220 * returns <code>this</code> for chaining multiple calls.
222 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
223 * @param align The align keyword or for instance "100px". E.g "left", "right", "leading" or "trailing".
224 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
226 public final CC alignX(String align)
228 hor.setAlign(ConstraintParser.parseUnitValueOrAlign(align, true, null));
232 /** The grow priority compared to other components in the same cell.
234 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
235 * @param p The grow priority.
236 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
238 public final CC growPrioX(int p)
240 hor.setGrowPriority(p);
244 /** Grow priority for the component horizontally and optionally vertically.
246 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
247 * @param widthHeight The new shrink weight and height. 1-2 arguments, never null.
248 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
251 public final CC growPrio(int ... widthHeight)
253 switch (widthHeight.length) {
255 throw new IllegalArgumentException("Illegal argument count: " + widthHeight.length);
257 growPrioY(widthHeight[1]);
259 growPrioX(widthHeight[0]);
264 /** Grow weight for the component horizontally. It default to weight <code>100</code>.
266 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
267 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
270 public final CC growX()
272 hor.setGrow(ResizeConstraint.WEIGHT_100);
276 /** Grow weight for the component horizontally.
278 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
279 * @param w The new grow weight.
280 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
282 public final CC growX(float w)
284 hor.setGrow(new Float(w));
288 /** grow weight for the component horizontally and optionally vertically.
290 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
291 * @param widthHeight The new shrink weight and height. 1-2 arguments, never null.
292 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
295 public final CC grow(float ... widthHeight)
297 switch (widthHeight.length) {
299 throw new IllegalArgumentException("Illegal argument count: " + widthHeight.length);
301 growY(widthHeight[1]);
303 growX(widthHeight[0]);
308 /** The shrink priority compared to other components in the same cell.
310 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
311 * @param p The shrink priority.
312 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
314 public final CC shrinkPrioX(int p)
316 hor.setShrinkPriority(p);
320 /** Shrink priority for the component horizontally and optionally vertically.
322 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
323 * @param widthHeight The new shrink weight and height. 1-2 arguments, never null.
324 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
327 public final CC shrinkPrio(int ... widthHeight)
329 switch (widthHeight.length) {
331 throw new IllegalArgumentException("Illegal argument count: " + widthHeight.length);
333 shrinkPrioY(widthHeight[1]);
335 shrinkPrioX(widthHeight[0]);
340 /** Shrink weight for the component horizontally.
342 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
343 * @param w The new shrink weight.
344 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
346 public final CC shrinkX(float w)
348 hor.setShrink(new Float(w));
352 /** Shrink weight for the component horizontally and optionally vertically.
354 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
355 * @param widthHeight The new shrink weight and height. 1-2 arguments, never null.
356 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
359 public final CC shrink(float ... widthHeight)
361 switch (widthHeight.length) {
363 throw new IllegalArgumentException("Illegal argument count: " + widthHeight.length);
365 shrinkY(widthHeight[1]);
367 shrinkX(widthHeight[0]);
372 /** The end group that this component should be placed in.
374 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
375 * @param s The name of the group. If <code>null</code> that means no group (default)
376 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
378 public final CC endGroupY(String s)
384 /** The end group(s) that this component should be placed in.
386 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
387 * @param xy The end group for x and y respectively. 1-2 arguments, not null.
388 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
391 public final CC endGroup(String ... xy)
395 throw new IllegalArgumentException("Illegal argument count: " + xy.length);
404 /** The size group that this component should be placed in.
406 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
407 * @param s The name of the group. If <code>null</code> that means no group (default)
408 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
410 public final CC sizeGroupY(String s)
416 /** The size group(s) that this component should be placed in.
418 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
419 * @param xy The size group for x and y respectively. 1-2 arguments, not null.
420 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
423 public final CC sizeGroup(String ... xy)
427 throw new IllegalArgumentException("Illegal argument count: " + xy.length);
436 /** The minimum size for the component. The value will override any value that is set on the component itself.
438 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
439 * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm".
440 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
442 public final CC minHeight(String size)
444 ver.setSize(LayoutUtil.derive(ver.getSize(), ConstraintParser.parseUnitValue(size, false), null, null));
448 /** 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
449 * the component itself.
451 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
452 * @param size The size expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px".
453 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
455 public final CC height(String size)
457 ver.setSize(ConstraintParser.parseBoundSize(size, false, false));
461 /** The maximum size for the component. The value will override any value that is set on the component itself.
463 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
464 * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm".
465 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
467 public final CC maxHeight(String size)
469 ver.setSize(LayoutUtil.derive(ver.getSize(), null, null, ConstraintParser.parseUnitValue(size, false)));
473 /** The vertical gap before (normally above) and/or after (normally below) the component. The gap is towards cell bounds and/or other component bounds.
475 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
476 * @param before The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
477 * @param after The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
478 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
480 public final CC gapY(String before, String after)
483 ver.setGapBefore(ConstraintParser.parseBoundSize(before, true, false));
486 ver.setGapAfter(ConstraintParser.parseBoundSize(after, true, false));
491 /** Same functionality as <code>getVertical().setAlign(ConstraintParser.parseUnitValue(unitValue, true))</code> only this method
492 * returns <code>this</code> for chaining multiple calls.
494 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
495 * @param align The align keyword or for instance "100px". E.g "top" or "bottom".
496 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
498 public final CC alignY(String align)
500 ver.setAlign(ConstraintParser.parseUnitValueOrAlign(align, false, null));
504 /** The grow priority compared to other components in the same cell.
506 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
507 * @param p The grow priority.
508 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
510 public final CC growPrioY(int p)
512 ver.setGrowPriority(p);
516 /** Grow weight for the component vertically. Defaults to <code>100</code>.
518 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
519 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
522 public final CC growY()
524 ver.setGrow(ResizeConstraint.WEIGHT_100);
528 /** Grow weight for the component vertically.
530 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
531 * @param w The new grow weight.
532 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
534 public final CC growY(float w)
540 /** Grow weight for the component vertically.
542 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
543 * @param w The new grow weight.
544 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
547 public final CC growY(Float w)
553 /** The shrink priority compared to other components in the same cell.
555 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
556 * @param p The shrink priority.
557 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
559 public final CC shrinkPrioY(int p)
561 ver.setShrinkPriority(p);
565 /** Shrink weight for the component horizontally.
567 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
568 * @param w The new shrink weight.
569 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
571 public final CC shrinkY(float w)
573 ver.setShrink(new Float(w));
577 /** How this component, if hidden (not visible), should be treated.
579 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
580 * @param mode The mode. Default to the mode in the {@link net.miginfocom.layout.LC}.
581 * 0 == Normal. Bounds will be calculated as if the component was visible.<br>
582 * 1 == If hidden the size will be 0, 0 but the gaps remain.<br>
583 * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br>
584 * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
585 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
587 public final CC hideMode(int mode)
593 /** The id used to reference this component in some constraints.
595 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
596 * @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".
597 * The dot should never be first or last if present.
598 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
600 public final CC id(String s)
606 /** Same functionality as {@link #setTag(String tag)} only this method returns <code>this</code> for chaining multiple calls.
608 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
609 * @param tag The new tag. May be <code>null</code>.
610 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
611 * @see #setTag(String)
613 public final CC tag(String tag)
619 /** Set the cell(s) that the component should occupy in the grid. Same functionality as {@link #setCellX(int col)} and
620 * {@link #setCellY(int row)} together with {@link #setSpanX(int width)} and {@link #setSpanY(int height)}. This method
621 * returns <code>this</code> for chaining multiple calls.
623 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
624 * @param colRowWidthHeight cellX, cellY, spanX, spanY respectively. 1-4 arguments, not null.
625 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
626 * @see #setCellX(int)
627 * @see #setCellY(int)
628 * @see #setSpanX(int)
629 * @see #setSpanY(int)
630 * @since 3.7.2. Replacing cell(int, int) and cell(int, int, int, int)
632 public final CC cell(int ... colRowWidthHeight)
634 switch (colRowWidthHeight.length) {
636 throw new IllegalArgumentException("Illegal argument count: " + colRowWidthHeight.length);
638 setSpanY(colRowWidthHeight[3]);
640 setSpanX(colRowWidthHeight[2]);
642 setCellY(colRowWidthHeight[1]);
644 setCellX(colRowWidthHeight[0]);
649 /** Same functionality as <code>spanX(cellsX).spanY(cellsY)</code> which means this cell will span cells in both x and y.
650 * This method returns <code>this</code> for chaining multiple calls.
652 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
653 * Since 3.7.2 this takes an array/vararg whereas it previously only took two specific values, xSpan and ySpan.
654 * @param cells spanX and spanY, when present, and in that order.
655 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
656 * @see #setSpanY(int)
657 * @see #setSpanX(int)
660 * @since 3.7.2 Replaces span(int, int).
662 public final CC span(int ... cells)
664 if (cells == null || cells.length == 0) {
665 setSpanX(LayoutUtil.INF);
667 } else if (cells.length == 1) {
677 /** Corresponds exactly to the "gap left right top bottom" keyword.
678 * @param args Same as for the "gap" keyword. Length 1-4, never null buf elements can be null.
679 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
682 public final CC gap(String ... args)
684 switch (args.length) {
686 throw new IllegalArgumentException("Illegal argument count: " + args.length);
699 /** Sets the horizontal gap before the component.
701 * Note! This is currently same as gapLeft(). This might change in 4.x.
702 * @param boundsSize The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
703 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
706 public final CC gapBefore(String boundsSize)
708 hor.setGapBefore(ConstraintParser.parseBoundSize(boundsSize, true, true));
712 /** Sets the horizontal gap after the component.
714 * Note! This is currently same as gapRight(). This might change in 4.x.
715 * @param boundsSize The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
716 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
719 public final CC gapAfter(String boundsSize)
721 hor.setGapAfter(ConstraintParser.parseBoundSize(boundsSize, true, true));
725 /** Sets the gap above the component.
726 * @param boundsSize The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
727 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
730 public final CC gapTop(String boundsSize)
732 ver.setGapBefore(ConstraintParser.parseBoundSize(boundsSize, true, false));
736 /** Sets the gap to the left the component.
737 * @param boundsSize The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
738 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
741 public final CC gapLeft(String boundsSize)
743 hor.setGapBefore(ConstraintParser.parseBoundSize(boundsSize, true, true));
747 /** Sets the gap below the component.
748 * @param boundsSize The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
749 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
752 public final CC gapBottom(String boundsSize)
754 ver.setGapAfter(ConstraintParser.parseBoundSize(boundsSize, true, false));
758 /** Sets the gap to the right of the component.
759 * @param boundsSize The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!".
760 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
763 public final CC gapRight(String boundsSize)
765 hor.setGapAfter(ConstraintParser.parseBoundSize(boundsSize, true, true));
769 /** Same functionality as calling {@link #setSpanY(int)} with <code>LayoutUtil.INF</code> which means this cell will span the rest of the column.
770 * This method returns <code>this</code> for chaining multiple calls.
772 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
773 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
774 * @see #setSpanY(int)
777 public final CC spanY()
779 return spanY(LayoutUtil.INF);
782 /** Same functionality as {@link #setSpanY(int)} only this method returns <code>this</code> for chaining multiple calls.
784 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
785 * @param cells The number of cells to span (i.e. merge).
786 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
787 * @see #setSpanY(int)
789 public final CC spanY(int cells)
795 /** Same functionality as {@link #setSpanX(int)} which means this cell will span the rest of the row.
796 * This method returns <code>this</code> for chaining multiple calls.
798 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
799 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
800 * @see #setSpanX(int)
803 public final CC spanX()
805 return spanX(LayoutUtil.INF);
808 /** Same functionality as {@link #setSpanX(int)} only this method returns <code>this</code> for chaining multiple calls.
810 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
811 * @param cells The number of cells to span (i.e. merge).
812 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
813 * @see #setSpanY(int)
815 public final CC spanX(int cells)
821 /** Same functionality as <code>pushX().pushY()</code> which means this cell will push in both x and y dimensions.
822 * This method returns <code>this</code> for chaining multiple calls.
824 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
825 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
826 * @see #setPushX(Float)
827 * @see #setPushX(Float)
831 public final CC push()
833 return pushX().pushY();
836 /** Same functionality as <code>pushX(weightX).pushY(weightY)</code> which means this cell will push in both x and y dimensions.
837 * This method returns <code>this</code> for chaining multiple calls.
839 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
840 * @param weightX The weight used in the push.
841 * @param weightY The weight used in the push.
842 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
843 * @see #setPushY(Float)
844 * @see #setPushX(Float)
848 public final CC push(Float weightX, Float weightY)
850 return pushX(weightX).pushY(weightY);
853 /** Same functionality as {@link #setPushY(Float)} which means this cell will push the rest of the column.
854 * This method returns <code>this</code> for chaining multiple calls.
856 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
857 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
858 * @see #setPushY(Float)
860 public final CC pushY()
862 return pushY(ResizeConstraint.WEIGHT_100);
865 /** Same functionality as {@link #setPushY(Float weight)} only this method returns <code>this</code> for chaining multiple calls.
867 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
868 * @param weight The weight used in the push.
869 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
870 * @see #setPushY(Float)
872 public final CC pushY(Float weight)
878 /** Same functionality as {@link #setPushX(Float)} which means this cell will push the rest of the row.
879 * This method returns <code>this</code> for chaining multiple calls.
881 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
882 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
883 * @see #setPushX(Float)
885 public final CC pushX()
887 return pushX(ResizeConstraint.WEIGHT_100);
890 /** Same functionality as {@link #setPushX(Float weight)} only this method returns <code>this</code> for chaining multiple calls.
892 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
893 * @param weight The weight used in the push.
894 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>.
895 * @see #setPushY(Float)
897 public final CC pushX(Float weight)
903 /** Same functionality as {@link #setSplit(int parts)} only this method returns <code>this</code> for chaining multiple calls.
905 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
906 * @param parts The number of parts (i.e. component slots) the cell should be divided into.
907 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
908 * @see #setSplit(int)
910 public final CC split(int parts)
916 /** Same functionality as split(LayoutUtil.INF), which means split until one of the keywords that breaks the split is found for
917 * a component after this one (e.g. wrap, newline and skip).
919 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
920 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
921 * @see #setSplit(int)
924 public final CC split()
926 setSplit(LayoutUtil.INF);
930 /** Same functionality as {@link #setSkip(int)} only this method returns <code>this</code> for chaining multiple calls.
932 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
933 * @param cells How many cells in the grid that should be skipped <b>before</b> the component that this constraint belongs to
934 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
937 public final CC skip(int cells)
943 /** Same functionality as skip(1).
945 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
946 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
950 public final CC skip()
956 /** Same functionality as calling {@link #setExternal(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
958 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
959 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
960 * @see #setExternal(boolean)
962 public final CC external()
968 /** Same functionality as calling {@link #setFlowX(Boolean)} with <code>Boolean.TRUE</code> only this method returns <code>this</code> for chaining multiple calls.
970 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
971 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
972 * @see #setFlowX(Boolean)
974 public final CC flowX()
976 setFlowX(Boolean.TRUE);
980 /** Same functionality as calling {@link #setFlowX(Boolean)} with <code>Boolean.FALSE</code> only this method returns <code>this</code> for chaining multiple calls.
982 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
983 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
984 * @see #setFlowX(Boolean)
986 public final CC flowY()
988 setFlowX(Boolean.FALSE);
993 /** Same functionality as {@link #growX()} and {@link #growY()}.
995 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
996 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1000 public final CC grow()
1007 /** Same functionality as calling {@link #setNewline(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
1009 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1010 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1011 * @see #setNewline(boolean)
1013 public final CC newline()
1019 /** Same functionality as {@link #setNewlineGapSize(BoundSize)} only this method returns <code>this</code> for chaining multiple calls.
1021 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1022 * @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".
1023 * 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
1024 * {@link #setNewlineGapSize(BoundSize)}.
1025 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1026 * @see #setNewlineGapSize(BoundSize)
1028 public final CC newline(String gapSize)
1030 BoundSize bs = ConstraintParser.parseBoundSize(gapSize, true, (flowX != null && flowX == false));
1032 setNewlineGapSize(bs);
1039 /** Same functionality as calling {@link #setWrap(boolean)} with <code>true</code> only this method returns <code>this</code> for chaining multiple calls.
1041 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1042 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1043 * @see #setWrap(boolean)
1045 public final CC wrap()
1051 /** Same functionality as {@link #setWrapGapSize(BoundSize)} only this method returns <code>this</code> for chaining multiple calls.
1053 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1054 * @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".
1055 * 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
1056 * {@link #setWrapGapSize(BoundSize)}.
1057 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1058 * @see #setWrapGapSize(BoundSize)
1060 public final CC wrap(String gapSize)
1062 BoundSize bs = ConstraintParser.parseBoundSize(gapSize, true, (flowX != null && flowX == false));
1071 /** Same functionality as calling {@link #setDockSide(int)} with <code>0</code> only this method returns <code>this</code> for chaining multiple calls.
1073 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1074 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1075 * @see #setDockSide(int)
1077 public final CC dockNorth()
1083 /** Same functionality as calling {@link #setDockSide(int)} with <code>1</code> only this method returns <code>this</code> for chaining multiple calls.
1085 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1086 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1087 * @see #setDockSide(int)
1089 public final CC dockWest()
1095 /** Same functionality as calling {@link #setDockSide(int)} with <code>2</code> only this method returns <code>this</code> for chaining multiple calls.
1097 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1098 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1099 * @see #setDockSide(int)
1101 public final CC dockSouth()
1107 /** Same functionality as calling {@link #setDockSide(int)} with <code>3</code> only this method returns <code>this</code> for chaining multiple calls.
1109 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1110 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1111 * @see #setDockSide(int)
1113 public final CC dockEast()
1119 /** Sets the x-coordinate for the component. This is used to set the x coordinate position to a specific value. The component
1120 * bounds is still precalculated to the grid cell and this method should be seen as a way to correct the x position.
1122 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1123 * @param x The x position as a UnitValue. E.g. "10" or "40mm" or "container.x+10".
1124 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1125 * @see #setPos(UnitValue[])
1126 * @see #setBoundsInGrid(boolean)
1128 public final CC x(String x)
1130 return corrPos(x, 0);
1133 /** Sets the y-coordinate for the component. This is used to set the y coordinate position to a specific value. The component
1134 * bounds is still precalculated to the grid cell and this method should be seen as a way to correct the y position.
1136 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1137 * @param y The y position as a UnitValue. E.g. "10" or "40mm" or "container.x+10".
1138 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1139 * @see #setPos(UnitValue[])
1140 * @see #setBoundsInGrid(boolean)
1142 public final CC y(String y)
1144 return corrPos(y, 1);
1147 /** Sets the x2-coordinate for the component (right side). This is used to set the x2 coordinate position to a specific value. The component
1148 * bounds is still precalculated to the grid cell and this method should be seen as a way to correct the x position.
1150 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1151 * @param x2 The x2 side's position as a UnitValue. E.g. "10" or "40mm" or "container.x2 - 10".
1152 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1153 * @see #setPos(UnitValue[])
1154 * @see #setBoundsInGrid(boolean)
1156 public final CC x2(String x2)
1158 return corrPos(x2, 2);
1161 /** Sets the y2-coordinate for the component (bottom side). This is used to set the y2 coordinate position to a specific value. The component
1162 * bounds is still precalculated to the grid cell and this method should be seen as a way to correct the y position.
1164 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1165 * @param y2 The y2 side's position as a UnitValue. E.g. "10" or "40mm" or "container.x2 - 10".
1166 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1167 * @see #setPos(UnitValue[])
1168 * @see #setBoundsInGrid(boolean)
1170 public final CC y2(String y2)
1172 return corrPos(y2, 3);
1175 private final CC corrPos(String uv, int ix)
1177 UnitValue[] b = getPos();
1179 b = new UnitValue[4];
1181 b[ix] = ConstraintParser.parseUnitValue(uv, (ix % 2 == 0));
1184 setBoundsInGrid(true);
1188 /** Same functionality as {@link #x(String x)} and {@link #y(String y)} together.
1190 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1191 * @param x The x position as a UnitValue. E.g. "10" or "40mm" or "container.x+10".
1192 * @param y The y position as a UnitValue. E.g. "10" or "40mm" or "container.x+10".
1193 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1194 * @see #setPos(UnitValue[])
1196 public final CC pos(String x, String y)
1198 UnitValue[] b = getPos();
1200 b = new UnitValue[4];
1202 b[0] = ConstraintParser.parseUnitValue(x, true);
1203 b[1] = ConstraintParser.parseUnitValue(y, false);
1206 setBoundsInGrid(false);
1210 /** Same functionality as {@link #x(String x)}, {@link #y(String y)}, {@link #y2(String y)} and {@link #y2(String y)} together.
1212 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1213 * @param x The x position as a UnitValue. E.g. "10" or "40mm" or "container.x+10".
1214 * @param y The y position as a UnitValue. E.g. "10" or "40mm" or "container.x+10".
1215 * @param x2 The x2 side's position as a UnitValue. E.g. "10" or "40mm" or "container.x2 - 10".
1216 * @param y2 The y2 side's position as a UnitValue. E.g. "10" or "40mm" or "container.x2 - 10".
1217 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1218 * @see #setPos(UnitValue[])
1220 public final CC pos(String x, String y, String x2, String y2)
1222 setPos(new UnitValue[] {
1223 ConstraintParser.parseUnitValue(x, true),
1224 ConstraintParser.parseUnitValue(y, false),
1225 ConstraintParser.parseUnitValue(x2, true),
1226 ConstraintParser.parseUnitValue(y2, false),
1228 setBoundsInGrid(false);
1232 /** Same functionality as {@link #setPadding(UnitValue[])} but the unit values as absolute pixels. This method returns <code>this</code> for chaining multiple calls.
1234 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1235 * @param top The top padding that will be added to the y coordinate at the last stage in the layout.
1236 * @param left The top padding that will be added to the x coordinate at the last stage in the layout.
1237 * @param bottom The top padding that will be added to the y2 coordinate at the last stage in the layout.
1238 * @param right The top padding that will be added to the x2 coordinate at the last stage in the layout.
1239 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1240 * @see #setTag(String)
1242 public final CC pad(int top, int left, int bottom, int right)
1244 setPadding(new UnitValue[] {
1245 new UnitValue(top), new UnitValue(left), new UnitValue(bottom), new UnitValue(right)
1250 /** Same functionality as <code>setPadding(ConstraintParser.parseInsets(pad, false))}</code> only this method returns <code>this</code> for chaining multiple calls.
1252 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1253 * @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.
1254 * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>.
1255 * @see #setTag(String)
1257 public final CC pad(String pad)
1259 setPadding(pad != null ? ConstraintParser.parseInsets(pad, false) : null);
1263 // **********************************************************
1265 // **********************************************************
1267 /** Returns the horizontal dimension constraint for this component constraint. It has constraints for the horizontal size
1268 * and grow/shrink priorities and weights.
1270 * 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
1271 * constraint for later use.
1272 * @return The current dimension constraint. Never <code>null</code>.
1274 public DimConstraint getHorizontal()
1279 /** Sets the horizontal dimension constraint for this component constraint. It has constraints for the horizontal size
1280 * and grow/shrink priorities and weights.
1281 * @param h The new dimension constraint. If <code>null</code> it will be reset to <code>new DimConstraint();</code>
1283 public void setHorizontal(DimConstraint h)
1285 hor = h != null ? h : new DimConstraint();
1288 /** Returns the vertical dimension constraint for this component constraint. It has constraints for the vertical size
1289 * and grow/shrink priorities and weights.
1291 * 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
1292 * constraint for later use.
1293 * @return The current dimension constraint. Never <code>null</code>.
1295 public DimConstraint getVertical()
1300 /** Sets the vertical dimension constraint for this component constraint. It has constraints for the vertical size
1301 * and grow/shrink priorities and weights.
1302 * @param v The new dimension constraint. If <code>null</code> it will be reset to <code>new DimConstraint();</code>
1304 public void setVertical(DimConstraint v)
1306 ver = v != null ? v : new DimConstraint();
1309 /** Returns the vertical or horizontal dim constraint.
1311 * 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
1312 * constraint for later use.
1313 * @param isHor If the horizontal constraint should be returned.
1314 * @return The dim constraint. Never <code>null</code>.
1316 public DimConstraint getDimConstraint(boolean isHor)
1318 return isHor ? hor : ver;
1321 /** Returns the absolute positioning of one or more of the edges. This will be applied last in the layout cycle and will not
1322 * affect the flow or grid positions. The positioning is relative to the parent and can not (as padding) be used
1323 * to adjust the edges relative to the old value. May be <code>null</code> and elements may be <code>null</code>.
1324 * <code>null</code> value(s) for the x2 and y2 will be interpreted as to keep the preferred size and thus the x1
1325 * and x2 will just absolutely positions the component.
1327 * Note that {@link #setBoundsInGrid(boolean)} changes the interpretation of this property slightly.
1329 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1330 * @return The current value as a new array, free to modify.
1332 public UnitValue[] getPos()
1334 return pos != null ? new UnitValue[] {pos[0], pos[1], pos[2], pos[3]} : null;
1337 /** Sets absolute positioning of one or more of the edges. This will be applied last in the layout cycle and will not
1338 * affect the flow or grid positions. The positioning is relative to the parent and can not (as padding) be used
1339 * to adjust the edges relative to the old value. May be <code>null</code> and elements may be <code>null</code>.
1340 * <code>null</code> value(s) for the x2 and y2 will be interpreted as to keep the preferred size and thus the x1
1341 * and x2 will just absolutely positions the component.
1343 * Note that {@link #setBoundsInGrid(boolean)} changes the interpretation of this property slightly.
1345 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1346 * @param pos <code>UnitValue[] {x, y, x2, y2}</code>. Must be <code>null</code> or of length 4. Elements can be <code>null</code>.
1348 public void setPos(UnitValue[] pos)
1350 this.pos = pos != null ? new UnitValue[] {pos[0], pos[1], pos[2], pos[3]} : null;
1354 /** Returns if the absolute <code>pos</code> value should be corrections to the component that is in a normal cell. If <code>false</code>
1355 * 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.
1357 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1358 * @return The current value.
1361 public boolean isBoundsInGrid()
1363 return boundsInGrid;
1366 /** Sets if the absolute <code>pos</code> value should be corrections to the component that is in a normal cell. If <code>false</code>
1367 * 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.
1369 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1370 * @param b <code>true</code> for bounds taken from the grid position. <code>false</code> is default.
1371 * @see #setPos(UnitValue[])
1373 void setBoundsInGrid(boolean b)
1375 this.boundsInGrid = b;
1378 /** Returns the absolute cell position in the grid or <code>-1</code> if cell positioning is not used.
1380 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1381 * @return The current value.
1383 public int getCellX()
1388 /** 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.
1389 * If there's already a component in that cell they will split the cell. The flow will then continue after this cell.
1391 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1392 * @param x The x-position or <code>-1</code> to disable cell positioning.
1394 public void setCellX(int x)
1399 /** Returns the absolute cell position in the grid or <code>-1</code> if cell positioning is not used.
1401 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1402 * @return The current value.
1404 public int getCellY()
1406 return cellX < 0 ? -1 : cellY;
1409 /** 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.
1410 * If there's already a component in that cell they will split the cell. The flow will then continue after this cell.
1412 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1413 * @param y The y-position or <code>-1</code> to disable cell positioning.
1415 public void setCellY(int y)
1419 cellY = y < 0 ? 0 : y;
1422 /** Sets the docking side. -1 means no docking.<br>
1423 * Valid sides are: <code> north = 0, west = 1, south = 2, east = 3</code>.
1425 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1426 * @return The current side.
1428 public int getDockSide()
1433 /** Sets the docking side. -1 means no docking.<br>
1434 * Valid sides are: <code> north = 0, west = 1, south = 2, east = 3</code>.
1436 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1437 * @param side -1 or 0-3.
1439 public void setDockSide(int side)
1441 if (side < -1 || side > 3)
1442 throw new IllegalArgumentException("Illegal dock side: " + side);
1446 /** Returns if this component should have its bounds handled by an external source and not this layout manager.
1448 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1449 * @return The current value.
1451 public boolean isExternal()
1456 /** 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
1457 * handler which is normally by the use of some <code>component.setBounds(x, y, width, height)</code> directly (for Swing).
1459 * The bounds <b>will not</b> affect the minimum and preferred size of the container.
1461 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1462 * @param b <code>true</code> means that the bounds are not changed.
1464 public void setExternal(boolean b)
1469 /** Returns if the flow in the <b>cell</b> is in the horizontal dimension. Vertical if <code>false</code>. Only the first
1470 * component is a cell can set the flow.
1472 * If <code>null</code> the flow direction is inherited by from the {@link net.miginfocom.layout.LC}.
1474 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1475 * @return The current value.
1477 public Boolean getFlowX()
1482 /** Sets if the flow in the <b>cell</b> is in the horizontal dimension. Vertical if <code>false</code>. Only the first
1483 * component is a cell can set the flow.
1485 * If <code>null</code> the flow direction is inherited by from the {@link net.miginfocom.layout.LC}.
1487 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1488 * @param b <code>Boolean.TRUE</code> means horizontal flow in the cell.
1490 public void setFlowX(Boolean b)
1495 /** Sets how a component that is hidden (not visible) should be treated by default.
1496 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1497 * @return The mode:<br>
1498 * 0 == Normal. Bounds will be calculated as if the component was visible.<br>
1499 * 1 == If hidden the size will be 0, 0 but the gaps remain.<br>
1500 * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br>
1501 * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
1503 public int getHideMode()
1508 /** Sets how a component that is hidden (not visible) should be treated by default.
1509 * @param mode The mode:<br>
1510 * 0 == Normal. Bounds will be calculated as if the component was visible.<br>
1511 * 1 == If hidden the size will be 0, 0 but the gaps remain.<br>
1512 * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br>
1513 * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid..
1515 public void setHideMode(int mode)
1517 if (mode < -1 || mode > 3)
1518 throw new IllegalArgumentException("Wrong hideMode: " + mode);
1523 /** Returns the id used to reference this component in some constraints.
1525 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1526 * @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".
1527 * The dot should never be first or last if present.
1529 public String getId()
1534 /** Sets the id used to reference this component in some constraints.
1536 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1537 * @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".
1538 * The dot should never be first or last if present.
1540 public void setId(String id)
1545 /** Returns the absolute resizing in the last stage of the layout cycle. May be <code>null</code> and elements may be <code>null</code>.
1547 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1548 * @return The current value. <code>null</code> or of length 4.
1550 public UnitValue[] getPadding()
1552 return padding != null ? new UnitValue[] {padding[0], padding[1], padding[2], padding[3]} : null;
1555 /** Sets the absolute resizing in the last stage of the layout cycle. These values are added to the edges and can thus for
1556 * instance be used to grow or reduce the size or move the component an absolute number of pixels. May be <code>null</code>
1557 * and elements may be <code>null</code>.
1559 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1560 * @param sides top, left, bottom right. Must be <code>null</code> or of length 4.
1562 public void setPadding(UnitValue[] sides)
1564 this.padding = sides != null ? new UnitValue[] {sides[0], sides[1], sides[2], sides[3]} : null;
1567 /** Returns the visual padding used when laying out this Component. May be <code>null</code> and elements may be <code>null</code>.
1569 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1570 * @return The current value. <code>null</code> or of length 4.
1572 public UnitValue[] getVisualPadding()
1574 return visualPadding != null ? new UnitValue[] {visualPadding[0], visualPadding[1], visualPadding[2], visualPadding[3]} : null;
1577 /** Sets the visual padding used when laying out this Component.
1579 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1580 * @param sides top, left, bottom right. Must be <code>null</code> or of length 4.
1582 public void setVisualPadding(UnitValue[] sides)
1584 this.visualPadding = sides != null ? new UnitValue[] {sides[0], sides[1], sides[2], sides[3]} : null;
1587 /** Returns how many cells in the grid that should be skipped <b>before</b> the component that this constraint belongs to.
1589 * Note that only the first component will be checked for this property.
1591 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1592 * @return The current value. 0 if no skip.
1594 public int getSkip()
1599 /** Sets how many cells in the grid that should be skipped <b>before</b> the component that this constraint belongs to.
1601 * Note that only the first component will be checked for this property.
1603 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1604 * @param cells How many cells in the grid that should be skipped <b>before</b> the component that this constraint belongs to
1606 public void setSkip(int cells)
1611 /** Returns the number of cells the cell that this constraint's component will span in the indicated dimension. <code>1</code> is default and
1612 * 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.
1614 * Note that only the first component will be checked for this property.
1616 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1617 * @return The current value.
1619 public int getSpanX()
1624 /** Sets the number of cells the cell that this constraint's component will span in the indicated dimension. <code>1</code> is default and
1625 * 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.
1627 * Note that only the first component will be checked for this property.
1629 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1630 * @param cells The number of cells to span (i.e. merge).
1632 public void setSpanX(int cells)
1637 /** Returns the number of cells the cell that this constraint's component will span in the indicated dimension. <code>1</code> is default and
1638 * 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.
1640 * Note that only the first component will be checked for this property.
1642 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1643 * @return The current value.
1645 public int getSpanY()
1650 /** Sets the number of cells the cell that this constraint's component will span in the indicated dimension. <code>1</code> is default and
1651 * 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.
1653 * Note that only the first component will be checked for this property.
1655 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1656 * @param cells The number of cells to span (i.e. merge).
1658 public void setSpanY(int cells)
1663 /** "pushx" indicates that the column that this component is in (this first if the component spans) should default to growing.
1664 * If any other column has been set to grow this push value on the component does nothing as the column's explicit grow weight
1665 * will take precedence. Push is normally used when the grid has not been defined in the layout.
1667 * If multiple components in a column has push weights set the largest one will be used for the column.
1668 * @return The current push value. Default is <code>null</code>.
1670 public Float getPushX()
1675 /** "pushx" indicates that the column that this component is in (this first if the component spans) should default to growing.
1676 * If any other column has been set to grow this push value on the component does nothing as the column's explicit grow weight
1677 * will take precedence. Push is normally used when the grid has not been defined in the layout.
1679 * If multiple components in a column has push weights set the largest one will be used for the column.
1680 * @param weight The new push value. Default is <code>null</code>.
1682 public void setPushX(Float weight)
1684 this.pushX = weight;
1687 /** "pushx" indicates that the row that this component is in (this first if the component spans) should default to growing.
1688 * If any other row has been set to grow this push value on the component does nothing as the row's explicit grow weight
1689 * will take precedence. Push is normally used when the grid has not been defined in the layout.
1691 * If multiple components in a row has push weights set the largest one will be used for the row.
1692 * @return The current push value. Default is <code>null</code>.
1694 public Float getPushY()
1699 /** "pushx" indicates that the row that this component is in (this first if the component spans) should default to growing.
1700 * If any other row has been set to grow this push value on the component does nothing as the row's explicit grow weight
1701 * will take precedence. Push is normally used when the grid has not been defined in the layout.
1703 * If multiple components in a row has push weights set the largest one will be used for the row.
1704 * @param weight The new push value. Default is <code>null</code>.
1706 public void setPushY(Float weight)
1708 this.pushY = weight;
1711 /** Returns in how many parts the current cell (that this constraint's component will be in) should be split in. If for instance
1712 * it is split in two, the next component will also share the same cell. Note that the cell can also span a number of
1713 * cells, which means that you can for instance span three cells and split that big cell for two components. Split can be
1714 * 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>).
1716 * Note that only the first component will be checked for this property.
1718 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1719 * @return The current value.
1721 public int getSplit()
1726 /** Sets in how many parts the current cell (that this constraint's component will be in) should be split in. If for instance
1727 * it is split in two, the next component will also share the same cell. Note that the cell can also span a number of
1728 * cells, which means that you can for instance span three cells and split that big cell for two components. Split can be
1729 * 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>).
1731 * Note that only the first component will be checked for this property.
1733 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1734 * @param parts The number of parts (i.e. component slots) the cell should be divided into.
1736 public void setSplit(int parts)
1741 /** Tags the component with metadata. Currently only used to tag buttons with for instance "cancel" or "ok" to make them
1742 * show up in the correct order depending on platform. See {@link PlatformDefaults#setButtonOrder(String)} for information.
1744 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1745 * @return The current value. May be <code>null</code>.
1747 public String getTag()
1752 /** Optional tag that gives more context to this constraint's component. It is for instance used to tag buttons in a
1753 * button bar with the button type such as "ok", "help" or "cancel".
1755 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1756 * @param tag The new tag. May be <code>null</code>.
1758 public void setTag(String tag)
1763 /** Returns if the flow should wrap to the next line/column <b>after</b> the component that this constraint belongs to.
1765 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1766 * @return The current value.
1768 public boolean isWrap()
1770 return wrap != null;
1773 /** Sets if the flow should wrap to the next line/column <b>after</b> the component that this constraint belongs to.
1775 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1776 * @param b <code>true</code> means wrap after.
1778 public void setWrap(boolean b)
1780 wrap = b ? (wrap == null ? DEF_GAP : wrap) : null;
1783 /** Returns the wrap size if it is a custom size. If wrap was set to true with {@link #setWrap(boolean)} then this method will
1784 * return <code>null</code> since that means that the gap size should be the default one as defined in the rows spec.
1785 * @return The custom gap size. NOTE! Will return <code>null</code> for both no wrap <b>and</b> default wrap.
1787 * @see #setWrap(boolean)
1790 public BoundSize getWrapGapSize()
1792 return wrap == DEF_GAP ? null : wrap;
1795 /** Set the wrap size and turns wrap on if <code>!= null</code>.
1796 * @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".
1797 * A non-null value will turn on wrap though.
1799 * @see #setWrap(boolean)
1802 public void setWrapGapSize(BoundSize s)
1804 wrap = s == null ? (wrap != null ? DEF_GAP : null) : s;
1807 /** Returns if the flow should wrap to the next line/column <b>before</b> the component that this constraint belongs to.
1809 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1810 * @return The current value.
1812 public boolean isNewline()
1814 return newline != null;
1817 /** Sets if the flow should wrap to the next line/column <b>before</b> the component that this constraint belongs to.
1819 * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com.
1820 * @param b <code>true</code> means wrap before.
1822 public void setNewline(boolean b)
1824 newline = b ? (newline == null ? DEF_GAP : newline) : null;
1827 /** Returns the newline size if it is a custom size. If newline was set to true with {@link #setNewline(boolean)} then this method will
1828 * return <code>null</code> since that means that the gap size should be the default one as defined in the rows spec.
1829 * @return The custom gap size. NOTE! Will return <code>null</code> for both no newline <b>and</b> default newline.
1831 * @see #setNewline(boolean)
1834 public BoundSize getNewlineGapSize()
1836 return newline == DEF_GAP ? null : newline;
1839 /** Set the newline size and turns newline on if <code>!= null</code>.
1840 * @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".
1841 * A non-null value will turn on newline though.
1843 * @see #setNewline(boolean)
1846 public void setNewlineGapSize(BoundSize s)
1848 newline = s == null ? (newline != null ? DEF_GAP : null) : s;
1851 /** Returns the animation spec. Default is a spec where animation is off (prio 0).
1852 * @return Never null.
1854 public AnimSpec getAnimSpec()
1860 // ************************************************
1861 // Persistence Delegate and Serializable combined.
1862 // ************************************************
1864 private Object readResolve() throws ObjectStreamException
1866 return LayoutUtil.getSerializedObject(this);
1870 public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException
1872 LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in));
1876 public void writeExternal(ObjectOutput out) throws IOException
1878 if (getClass() == CC.class)
1879 LayoutUtil.writeAsXML(out, this);