| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| CC |
|
| 1.5923076923076922;1.592 |
| 1 | package net.miginfocom.layout; | |
| 2 | ||
| 3 | import java.io.*; | |
| 4 | import java.util.ArrayList; | |
| 5 | /* | |
| 6 | * License (BSD): | |
| 7 | * ============== | |
| 8 | * | |
| 9 | * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com) | |
| 10 | * All rights reserved. | |
| 11 | * | |
| 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. | |
| 22 | * | |
| 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 | |
| 32 | * OF SUCH DAMAGE. | |
| 33 | * | |
| 34 | * @version 1.0 | |
| 35 | * @author Mikael Grev, MiG InfoCom AB | |
| 36 | * Date: 2006-sep-08 | |
| 37 | */ | |
| 38 | ||
| 39 | /** A simple value holder for one component's constraint. | |
| 40 | */ | |
| 41 | public final class CC implements Externalizable | |
| 42 | { | |
| 43 | private static final BoundSize DEF_GAP = BoundSize.NULL_SIZE; // Only used to denote default wrap/newline gap. | |
| 44 | ||
| 45 | static final String[] DOCK_SIDES = {"north", "west", "south", "east"}; | |
| 46 | ||
| 47 | // See the getters and setters for information about the properties below. | |
| 48 | ||
| 49 | private int dock = -1; | |
| 50 | ||
| 51 | private UnitValue[] pos = null; // [x1, y1, x2, y2] | |
| 52 | ||
| 53 | private UnitValue[] padding = null; // top, left, bottom, right | |
| 54 | ||
| 55 | private Boolean flowX = null; | |
| 56 | ||
| 57 | private int skip = 0; | |
| 58 | ||
| 59 | private int split = 1; | |
| 60 | ||
| 61 | private int spanX = 1, spanY = 1; | |
| 62 | ||
| 63 | private int cellX = -1, cellY = 0; // If cellX is -1 then cellY is also considered -1. cellY is never negative. | |
| 64 | ||
| 65 | private String tag = null; | |
| 66 | ||
| 67 | private String id = null; | |
| 68 | ||
| 69 | private int hideMode = -1; | |
| 70 | ||
| 71 | private DimConstraint hor = new DimConstraint(); | |
| 72 | ||
| 73 | private DimConstraint ver = new DimConstraint(); | |
| 74 | ||
| 75 | private BoundSize newline = null; | |
| 76 | ||
| 77 | private BoundSize wrap = null; | |
| 78 | ||
| 79 | private boolean boundsInGrid = true; | |
| 80 | ||
| 81 | private boolean external = false; | |
| 82 | ||
| 83 | private Float pushX = null, pushY = null; | |
| 84 | ||
| 85 | ||
| 86 | // ***** Tmp cache field | |
| 87 | ||
| 88 | private static final String[] EMPTY_ARR = new String[0]; | |
| 89 | ||
| 90 | private transient String[] linkTargets = null; | |
| 91 | ||
| 92 | /** Empty constructor. | |
| 93 | */ | |
| 94 | public CC() | |
| 95 | { | |
| 96 | } | |
| 97 | ||
| 98 | String[] getLinkTargets() | |
| 99 | { | |
| 100 | if (linkTargets == null) { | |
| 101 | final ArrayList<String> targets = new ArrayList<String>(2); | |
| 102 | ||
| 103 | if (pos != null) { | |
| 104 | for (int i = 0; i < pos.length ; i++) | |
| 105 | addLinkTargetIDs(targets, pos[i]); | |
| 106 | } | |
| 107 | ||
| 108 | linkTargets = targets.size() == 0 ? EMPTY_ARR : targets.toArray(new String[targets.size()]); | |
| 109 | } | |
| 110 | return linkTargets; | |
| 111 | } | |
| 112 | ||
| 113 | private void addLinkTargetIDs(ArrayList<String> targets, UnitValue uv) | |
| 114 | { | |
| 115 | if (uv != null) { | |
| 116 | String linkId = uv.getLinkTargetId(); | |
| 117 | if (linkId != null) { | |
| 118 | targets.add(linkId); | |
| 119 | } else { | |
| 120 | for (int i = uv.getSubUnitCount() - 1; i >= 0; i--) { | |
| 121 | UnitValue subUv = uv.getSubUnitValue(i); | |
| 122 | if (subUv.isLinkedDeep()) | |
| 123 | addLinkTargetIDs(targets, subUv); | |
| 124 | } | |
| 125 | } | |
| 126 | } | |
| 127 | } | |
| 128 | ||
| 129 | // ********************************************************** | |
| 130 | // Chaining constraint setters | |
| 131 | // ********************************************************** | |
| 132 | ||
| 133 | /** Specifies that the component should be put in the end group <code>s</code> and will thus share the same ending | |
| 134 | * coordinate as them within the group. | |
| 135 | * <p> | |
| 136 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 137 | * @param s A name to associate on the group that should be the same for other rows/columns in the same group. | |
| 138 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 139 | */ | |
| 140 | public final CC endGroupX(String s) | |
| 141 | { | |
| 142 | hor.setEndGroup(s); | |
| 143 | return this; | |
| 144 | } | |
| 145 | ||
| 146 | /** Specifies that the component should be put in the size group <code>s</code> and will thus share the same size | |
| 147 | * as them within the group. | |
| 148 | * <p> | |
| 149 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 150 | * @param s A name to associate on the group that should be the same for other rows/columns in the same group. | |
| 151 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 152 | */ | |
| 153 | public final CC sizeGroupX(String s) | |
| 154 | { | |
| 155 | hor.setSizeGroup(s); | |
| 156 | return this; | |
| 157 | } | |
| 158 | ||
| 159 | /** The minimum size for the component. The value will override any value that is set on the component itself. | |
| 160 | * <p> | |
| 161 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 162 | * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". | |
| 163 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 164 | */ | |
| 165 | public final CC minWidth(String size) | |
| 166 | { | |
| 167 | hor.setSize(LayoutUtil.derive(hor.getSize(), ConstraintParser.parseUnitValue(size, true), null, null)); | |
| 168 | return this; | |
| 169 | } | |
| 170 | ||
| 171 | /** 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 | |
| 172 | * the component itself. | |
| 173 | * <p> | |
| 174 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 175 | * @param size The size expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px". | |
| 176 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 177 | */ | |
| 178 | public final CC width(String size) | |
| 179 | { | |
| 180 | hor.setSize(ConstraintParser.parseBoundSize(size, false, true)); | |
| 181 | return this; | |
| 182 | } | |
| 183 | ||
| 184 | /** The maximum size for the component. The value will override any value that is set on the component itself. | |
| 185 | * <p> | |
| 186 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 187 | * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". | |
| 188 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 189 | */ | |
| 190 | public final CC maxWidth(String size) | |
| 191 | { | |
| 192 | hor.setSize(LayoutUtil.derive(hor.getSize(), null, null, ConstraintParser.parseUnitValue(size, true))); | |
| 193 | return this; | |
| 194 | } | |
| 195 | ||
| 196 | ||
| 197 | /** The horizontal gap before and/or after the component. The gap is towards cell bounds and/or other component bounds. | |
| 198 | * <p> | |
| 199 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 200 | * @param before The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!". | |
| 201 | * @param after The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!". | |
| 202 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 203 | */ | |
| 204 | public final CC gapX(String before, String after) | |
| 205 | { | |
| 206 | if (before != null) | |
| 207 | hor.setGapBefore(ConstraintParser.parseBoundSize(before, true, true)); | |
| 208 | ||
| 209 | if (after != null) | |
| 210 | hor.setGapAfter(ConstraintParser.parseBoundSize(after, true, true)); | |
| 211 | ||
| 212 | return this; | |
| 213 | } | |
| 214 | ||
| 215 | /** Same functionality as <code>getHorizontal().setAlign(ConstraintParser.parseUnitValue(unitValue, true))</code> only this method | |
| 216 | * returns <code>this</code> for chaining multiple calls. | |
| 217 | * <p> | |
| 218 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 219 | * @param align The align keyword or for instance "100px". E.g "left", "right", "leading" or "trailing". | |
| 220 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 221 | */ | |
| 222 | public final CC alignX(String align) | |
| 223 | { | |
| 224 | hor.setAlign(ConstraintParser.parseUnitValueOrAlign(align, true, null)); | |
| 225 | return this; | |
| 226 | } | |
| 227 | ||
| 228 | /** The grow priority compared to other components in the same cell. | |
| 229 | * <p> | |
| 230 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 231 | * @param p The grow priority. | |
| 232 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 233 | */ | |
| 234 | public final CC growPrioX(int p) | |
| 235 | { | |
| 236 | hor.setGrowPriority(p); | |
| 237 | return this; | |
| 238 | } | |
| 239 | ||
| 240 | /** Grow priority for the component horizontally and optionally vertically. | |
| 241 | * <p> | |
| 242 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 243 | * @param widthHeight The new shrink weight and height. 1-2 arguments, never null. | |
| 244 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 245 | * @since 3.7.2 | |
| 246 | */ | |
| 247 | public final CC growPrio(int ... widthHeight) | |
| 248 | { | |
| 249 | switch (widthHeight.length) { | |
| 250 | default: | |
| 251 | throw new IllegalArgumentException("Illegal argument count: " + widthHeight.length); | |
| 252 | case 2: | |
| 253 | growPrioY(widthHeight[1]); | |
| 254 | case 1: | |
| 255 | growPrioX(widthHeight[0]); | |
| 256 | } | |
| 257 | return this; | |
| 258 | } | |
| 259 | ||
| 260 | /** Grow weight for the component horizontally. It default to weight <code>100</code>. | |
| 261 | * <p> | |
| 262 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 263 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 264 | * @see #growX(float) | |
| 265 | */ | |
| 266 | public final CC growX() | |
| 267 | { | |
| 268 | hor.setGrow(ResizeConstraint.WEIGHT_100); | |
| 269 | return this; | |
| 270 | } | |
| 271 | ||
| 272 | /** Grow weight for the component horizontally. | |
| 273 | * <p> | |
| 274 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 275 | * @param w The new grow weight. | |
| 276 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 277 | */ | |
| 278 | public final CC growX(float w) | |
| 279 | { | |
| 280 | hor.setGrow(new Float(w)); | |
| 281 | return this; | |
| 282 | } | |
| 283 | ||
| 284 | /** grow weight for the component horizontally and optionally vertically. | |
| 285 | * <p> | |
| 286 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 287 | * @param widthHeight The new shrink weight and height. 1-2 arguments, never null. | |
| 288 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 289 | * @since 3.7.2 | |
| 290 | */ | |
| 291 | public final CC grow(float ... widthHeight) | |
| 292 | { | |
| 293 | switch (widthHeight.length) { | |
| 294 | default: | |
| 295 | throw new IllegalArgumentException("Illegal argument count: " + widthHeight.length); | |
| 296 | case 2: | |
| 297 | growY(widthHeight[1]); | |
| 298 | case 1: | |
| 299 | growX(widthHeight[0]); | |
| 300 | } | |
| 301 | return this; | |
| 302 | } | |
| 303 | ||
| 304 | /** The shrink priority compared to other components in the same cell. | |
| 305 | * <p> | |
| 306 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 307 | * @param p The shrink priority. | |
| 308 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 309 | */ | |
| 310 | public final CC shrinkPrioX(int p) | |
| 311 | { | |
| 312 | hor.setShrinkPriority(p); | |
| 313 | return this; | |
| 314 | } | |
| 315 | ||
| 316 | /** Shrink priority for the component horizontally and optionally vertically. | |
| 317 | * <p> | |
| 318 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 319 | * @param widthHeight The new shrink weight and height. 1-2 arguments, never null. | |
| 320 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 321 | * @since 3.7.2 | |
| 322 | */ | |
| 323 | public final CC shrinkPrio(int ... widthHeight) | |
| 324 | { | |
| 325 | switch (widthHeight.length) { | |
| 326 | default: | |
| 327 | throw new IllegalArgumentException("Illegal argument count: " + widthHeight.length); | |
| 328 | case 2: | |
| 329 | shrinkPrioY(widthHeight[1]); | |
| 330 | case 1: | |
| 331 | shrinkPrioX(widthHeight[0]); | |
| 332 | } | |
| 333 | return this; | |
| 334 | } | |
| 335 | ||
| 336 | /** Shrink weight for the component horizontally. | |
| 337 | * <p> | |
| 338 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 339 | * @param w The new shrink weight. | |
| 340 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 341 | */ | |
| 342 | public final CC shrinkX(float w) | |
| 343 | { | |
| 344 | hor.setShrink(new Float(w)); | |
| 345 | return this; | |
| 346 | } | |
| 347 | ||
| 348 | /** Shrink weight for the component horizontally and optionally vertically. | |
| 349 | * <p> | |
| 350 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 351 | * @param widthHeight The new shrink weight and height. 1-2 arguments, never null. | |
| 352 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 353 | * @since 3.7.2 | |
| 354 | */ | |
| 355 | public final CC shrink(float ... widthHeight) | |
| 356 | { | |
| 357 | switch (widthHeight.length) { | |
| 358 | default: | |
| 359 | throw new IllegalArgumentException("Illegal argument count: " + widthHeight.length); | |
| 360 | case 2: | |
| 361 | shrinkY(widthHeight[1]); | |
| 362 | case 1: | |
| 363 | shrinkX(widthHeight[0]); | |
| 364 | } | |
| 365 | return this; | |
| 366 | } | |
| 367 | ||
| 368 | /** The end group that this component should be placed in. | |
| 369 | * <p> | |
| 370 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 371 | * @param s The name of the group. If <code>null</code> that means no group (default) | |
| 372 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 373 | */ | |
| 374 | public final CC endGroupY(String s) | |
| 375 | { | |
| 376 | ver.setEndGroup(s); | |
| 377 | return this; | |
| 378 | } | |
| 379 | ||
| 380 | /** The end group(s) that this component should be placed in. | |
| 381 | * <p> | |
| 382 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 383 | * @param xy The end group for x and y respectively. 1-2 arguments, not null. | |
| 384 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 385 | * @since 3.7.2 | |
| 386 | */ | |
| 387 | public final CC endGroup(String ... xy) | |
| 388 | { | |
| 389 | switch (xy.length) { | |
| 390 | default: | |
| 391 | throw new IllegalArgumentException("Illegal argument count: " + xy.length); | |
| 392 | case 2: | |
| 393 | endGroupY(xy[1]); | |
| 394 | case 1: | |
| 395 | endGroupX(xy[0]); | |
| 396 | } | |
| 397 | return this; | |
| 398 | } | |
| 399 | ||
| 400 | /** The size group that this component should be placed in. | |
| 401 | * <p> | |
| 402 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 403 | * @param s The name of the group. If <code>null</code> that means no group (default) | |
| 404 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 405 | */ | |
| 406 | public final CC sizeGroupY(String s) | |
| 407 | { | |
| 408 | ver.setSizeGroup(s); | |
| 409 | return this; | |
| 410 | } | |
| 411 | ||
| 412 | /** The size group(s) that this component should be placed in. | |
| 413 | * <p> | |
| 414 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 415 | * @param xy The size group for x and y respectively. 1-2 arguments, not null. | |
| 416 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 417 | * @since 3.7.2 | |
| 418 | */ | |
| 419 | public final CC sizeGroup(String ... xy) | |
| 420 | { | |
| 421 | switch (xy.length) { | |
| 422 | default: | |
| 423 | throw new IllegalArgumentException("Illegal argument count: " + xy.length); | |
| 424 | case 2: | |
| 425 | sizeGroupY(xy[1]); | |
| 426 | case 1: | |
| 427 | sizeGroupX(xy[0]); | |
| 428 | } | |
| 429 | return this; | |
| 430 | } | |
| 431 | ||
| 432 | /** The minimum size for the component. The value will override any value that is set on the component itself. | |
| 433 | * <p> | |
| 434 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 435 | * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". | |
| 436 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 437 | */ | |
| 438 | public final CC minHeight(String size) | |
| 439 | { | |
| 440 | ver.setSize(LayoutUtil.derive(ver.getSize(), ConstraintParser.parseUnitValue(size, false), null, null)); | |
| 441 | return this; | |
| 442 | } | |
| 443 | ||
| 444 | /** 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 | |
| 445 | * the component itself. | |
| 446 | * <p> | |
| 447 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 448 | * @param size The size expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px". | |
| 449 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 450 | */ | |
| 451 | public final CC height(String size) | |
| 452 | { | |
| 453 | ver.setSize(ConstraintParser.parseBoundSize(size, false, false)); | |
| 454 | return this; | |
| 455 | } | |
| 456 | ||
| 457 | /** The maximum size for the component. The value will override any value that is set on the component itself. | |
| 458 | * <p> | |
| 459 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 460 | * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". | |
| 461 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 462 | */ | |
| 463 | public final CC maxHeight(String size) | |
| 464 | { | |
| 465 | ver.setSize(LayoutUtil.derive(ver.getSize(), null, null, ConstraintParser.parseUnitValue(size, false))); | |
| 466 | return this; | |
| 467 | } | |
| 468 | ||
| 469 | /** The vertical gap before (normally above) and/or after (normally below) the component. The gap is towards cell bounds and/or other component bounds. | |
| 470 | * <p> | |
| 471 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 472 | * @param before The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!". | |
| 473 | * @param after The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!". | |
| 474 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 475 | */ | |
| 476 | public final CC gapY(String before, String after) | |
| 477 | { | |
| 478 | if (before != null) | |
| 479 | ver.setGapBefore(ConstraintParser.parseBoundSize(before, true, false)); | |
| 480 | ||
| 481 | if (after != null) | |
| 482 | ver.setGapAfter(ConstraintParser.parseBoundSize(after, true, false)); | |
| 483 | ||
| 484 | return this; | |
| 485 | } | |
| 486 | ||
| 487 | /** Same functionality as <code>getVertical().setAlign(ConstraintParser.parseUnitValue(unitValue, true))</code> only this method | |
| 488 | * returns <code>this</code> for chaining multiple calls. | |
| 489 | * <p> | |
| 490 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 491 | * @param align The align keyword or for instance "100px". E.g "top" or "bottom". | |
| 492 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 493 | */ | |
| 494 | public final CC alignY(String align) | |
| 495 | { | |
| 496 | ver.setAlign(ConstraintParser.parseUnitValueOrAlign(align, false, null)); | |
| 497 | return this; | |
| 498 | } | |
| 499 | ||
| 500 | /** The grow priority compared to other components in the same cell. | |
| 501 | * <p> | |
| 502 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 503 | * @param p The grow priority. | |
| 504 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 505 | */ | |
| 506 | public final CC growPrioY(int p) | |
| 507 | { | |
| 508 | ver.setGrowPriority(p); | |
| 509 | return this; | |
| 510 | } | |
| 511 | ||
| 512 | /** Grow weight for the component vertically. Defaults to <code>100</code>. | |
| 513 | * <p> | |
| 514 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 515 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 516 | * @see #growY(Float) | |
| 517 | */ | |
| 518 | public final CC growY() | |
| 519 | { | |
| 520 | ver.setGrow(ResizeConstraint.WEIGHT_100); | |
| 521 | return this; | |
| 522 | } | |
| 523 | ||
| 524 | /** Grow weight for the component vertically. | |
| 525 | * <p> | |
| 526 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 527 | * @param w The new grow weight. | |
| 528 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 529 | */ | |
| 530 | public final CC growY(Float w) | |
| 531 | { | |
| 532 | ver.setGrow(w); | |
| 533 | return this; | |
| 534 | } | |
| 535 | ||
| 536 | /** The shrink priority compared to other components in the same cell. | |
| 537 | * <p> | |
| 538 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 539 | * @param p The shrink priority. | |
| 540 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 541 | */ | |
| 542 | public final CC shrinkPrioY(int p) | |
| 543 | { | |
| 544 | ver.setShrinkPriority(p); | |
| 545 | return this; | |
| 546 | } | |
| 547 | ||
| 548 | /** Shrink weight for the component horizontally. | |
| 549 | * <p> | |
| 550 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 551 | * @param w The new shrink weight. | |
| 552 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 553 | */ | |
| 554 | public final CC shrinkY(float w) | |
| 555 | { | |
| 556 | ver.setShrink(new Float(w)); | |
| 557 | return this; | |
| 558 | } | |
| 559 | ||
| 560 | /** How this component, if hidden (not visible), should be treated. | |
| 561 | * <p> | |
| 562 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 563 | * @param mode The mode. Default to the mode in the {@link net.miginfocom.layout.LC}. | |
| 564 | * 0 == Normal. Bounds will be calculated as if the component was visible.<br> | |
| 565 | * 1 == If hidden the size will be 0, 0 but the gaps remain.<br> | |
| 566 | * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br> | |
| 567 | * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid.. | |
| 568 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 569 | */ | |
| 570 | public final CC hideMode(int mode) | |
| 571 | { | |
| 572 | setHideMode(mode); | |
| 573 | return this; | |
| 574 | } | |
| 575 | ||
| 576 | /** The id used to reference this component in some constraints. | |
| 577 | * <p> | |
| 578 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 579 | * @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". | |
| 580 | * The dot should never be first or last if present. | |
| 581 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 582 | */ | |
| 583 | public final CC id(String s) | |
| 584 | { | |
| 585 | setId(s); | |
| 586 | return this; | |
| 587 | } | |
| 588 | ||
| 589 | /** Same functionality as {@link #setTag(String tag)} only this method returns <code>this</code> for chaining multiple calls. | |
| 590 | * <p> | |
| 591 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 592 | * @param tag The new tag. May be <code>null</code>. | |
| 593 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 594 | * @see #setTag(String) | |
| 595 | */ | |
| 596 | public final CC tag(String tag) | |
| 597 | { | |
| 598 | setTag(tag); | |
| 599 | return this; | |
| 600 | } | |
| 601 | ||
| 602 | /** Set the cell(s) that the component should occupy in the grid. Same functionality as {@link #setCellX(int col)} and | |
| 603 | * {@link #setCellY(int row)} together with {@link #setSpanX(int width)} and {@link #setSpanY(int height)}. This method | |
| 604 | * returns <code>this</code> for chaining multiple calls. | |
| 605 | * <p> | |
| 606 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 607 | * @param colRowWidthHeight cellX, cellY, spanX, spanY repectively. 1-4 arguments, not null. | |
| 608 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 609 | * @see #setCellX(int) | |
| 610 | * @see #setCellY(int) | |
| 611 | * @see #setSpanX(int) | |
| 612 | * @see #setSpanY(int) | |
| 613 | * @since 3.7.2. Replacing cell(int, int) and cell(int, int, int, int) | |
| 614 | */ | |
| 615 | public final CC cell(int ... colRowWidthHeight) | |
| 616 | { | |
| 617 | switch (colRowWidthHeight.length) { | |
| 618 | default: | |
| 619 | throw new IllegalArgumentException("Illegal argument count: " + colRowWidthHeight.length); | |
| 620 | case 4: | |
| 621 | setSpanY(colRowWidthHeight[3]); | |
| 622 | case 3: | |
| 623 | setSpanX(colRowWidthHeight[2]); | |
| 624 | case 2: | |
| 625 | setCellY(colRowWidthHeight[1]); | |
| 626 | case 1: | |
| 627 | setCellX(colRowWidthHeight[0]); | |
| 628 | } | |
| 629 | return this; | |
| 630 | } | |
| 631 | ||
| 632 | /** Same functionality as <code>spanX(cellsX).spanY(cellsY)</code> which means this cell will span cells in both x and y. | |
| 633 | * This method returns <code>this</code> for chaining multiple calls. | |
| 634 | * <p> | |
| 635 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 636 | * Since 3.7.2 this takes an array/vararg whereas it previously only took two specific values, xSpan and ySpan. | |
| 637 | * @param cells spanX and spanY, when present, and in that order. | |
| 638 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 639 | * @see #setSpanY(int) | |
| 640 | * @see #setSpanX(int) | |
| 641 | * @see #spanY() | |
| 642 | * @see #spanX() | |
| 643 | * @since 3.7.2 Replaces span(int, int). | |
| 644 | */ | |
| 645 | public final CC span(int ... cells) | |
| 646 | { | |
| 647 | if (cells == null || cells.length == 0) { | |
| 648 | setSpanX(LayoutUtil.INF); | |
| 649 | setSpanY(1); | |
| 650 | } else if (cells.length == 1) { | |
| 651 | setSpanX(cells[0]); | |
| 652 | setSpanY(1); | |
| 653 | } else { | |
| 654 | setSpanX(cells[0]); | |
| 655 | setSpanY(cells[1]); | |
| 656 | } | |
| 657 | return this; | |
| 658 | } | |
| 659 | ||
| 660 | /** Corresponds exactly to the "gap left right top bottom" keyword. | |
| 661 | * @param args Same as for the "gap" keyword. Length 1-4, never null buf elements can be null. | |
| 662 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 663 | * @since 3.7.2 | |
| 664 | */ | |
| 665 | public final CC gap(String ... args) | |
| 666 | { | |
| 667 | switch (args.length) { | |
| 668 | default: | |
| 669 | throw new IllegalArgumentException("Illegal argument count: " + args.length); | |
| 670 | case 4: | |
| 671 | gapBottom(args[3]); | |
| 672 | case 3: | |
| 673 | gapTop(args[2]); | |
| 674 | case 2: | |
| 675 | gapRight(args[1]); | |
| 676 | case 1: | |
| 677 | gapLeft(args[0]); | |
| 678 | } | |
| 679 | return this; | |
| 680 | } | |
| 681 | ||
| 682 | /** Sets the horizontal gap before the component. | |
| 683 | * <p> | |
| 684 | * Note! This is currently same as gapLeft(). This might change in 4.x. | |
| 685 | * @param boundsSize The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!". | |
| 686 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 687 | * @since 3.7.2 | |
| 688 | */ | |
| 689 | public final CC gapBefore(String boundsSize) | |
| 690 | { | |
| 691 | hor.setGapBefore(ConstraintParser.parseBoundSize(boundsSize, true, true)); | |
| 692 | return this; | |
| 693 | } | |
| 694 | ||
| 695 | /** Sets the horizontal gap after the component. | |
| 696 | * <p> | |
| 697 | * Note! This is currently same as gapLeft(). This might change in 4.x. | |
| 698 | * @param boundsSize The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!". | |
| 699 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 700 | * @since 3.7.2 | |
| 701 | */ | |
| 702 | public final CC gapAfter(String boundsSize) | |
| 703 | { | |
| 704 | hor.setGapAfter(ConstraintParser.parseBoundSize(boundsSize, true, true)); | |
| 705 | return this; | |
| 706 | } | |
| 707 | ||
| 708 | /** Sets the gap above the component. | |
| 709 | * @param boundsSize The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!". | |
| 710 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 711 | * @since 3.7.2 | |
| 712 | */ | |
| 713 | public final CC gapTop(String boundsSize) | |
| 714 | { | |
| 715 | ver.setGapBefore(ConstraintParser.parseBoundSize(boundsSize, true, false)); | |
| 716 | return this; | |
| 717 | } | |
| 718 | ||
| 719 | /** Sets the gap to the left the component. | |
| 720 | * @param boundsSize The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!". | |
| 721 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 722 | * @since 3.7.2 | |
| 723 | */ | |
| 724 | public final CC gapLeft(String boundsSize) | |
| 725 | { | |
| 726 | hor.setGapBefore(ConstraintParser.parseBoundSize(boundsSize, true, true)); | |
| 727 | return this; | |
| 728 | } | |
| 729 | ||
| 730 | /** Sets the gap below the component. | |
| 731 | * @param boundsSize The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!". | |
| 732 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 733 | * @since 3.7.2 | |
| 734 | */ | |
| 735 | public final CC gapBottom(String boundsSize) | |
| 736 | { | |
| 737 | ver.setGapAfter(ConstraintParser.parseBoundSize(boundsSize, true, false)); | |
| 738 | return this; | |
| 739 | } | |
| 740 | ||
| 741 | /** Sets the gap to the right of the component. | |
| 742 | * @param boundsSize The size of the gap expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px!". | |
| 743 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 744 | * @since 3.7.2 | |
| 745 | */ | |
| 746 | public final CC gapRight(String boundsSize) | |
| 747 | { | |
| 748 | hor.setGapAfter(ConstraintParser.parseBoundSize(boundsSize, true, true)); | |
| 749 | return this; | |
| 750 | } | |
| 751 | ||
| 752 | /** Same functionality as {@link #setSpanY(int LayoutUtil.INF)} which means this cell will span the rest of the column. | |
| 753 | * This method returns <code>this</code> for chaining multiple calls. | |
| 754 | * <p> | |
| 755 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 756 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 757 | * @see #setSpanY(int) | |
| 758 | * @see #spanY() | |
| 759 | */ | |
| 760 | public final CC spanY() | |
| 761 | { | |
| 762 | return spanY(LayoutUtil.INF); | |
| 763 | } | |
| 764 | ||
| 765 | /** Same functionality as {@link #setSpanY(int)} only this method returns <code>this</code> for chaining multiple calls. | |
| 766 | * <p> | |
| 767 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 768 | * @param cells The number of cells to span (i.e. merge). | |
| 769 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 770 | * @see #setSpanY(int) | |
| 771 | */ | |
| 772 | public final CC spanY(int cells) | |
| 773 | { | |
| 774 | setSpanY(cells); | |
| 775 | return this; | |
| 776 | } | |
| 777 | ||
| 778 | /** Same functionality as {@link #setSpanX(int)} which means this cell will span the rest of the row. | |
| 779 | * This method returns <code>this</code> for chaining multiple calls. | |
| 780 | * <p> | |
| 781 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 782 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 783 | * @see #setSpanX(int) | |
| 784 | * @see #spanX() | |
| 785 | */ | |
| 786 | public final CC spanX() | |
| 787 | { | |
| 788 | return spanX(LayoutUtil.INF); | |
| 789 | } | |
| 790 | ||
| 791 | /** Same functionality as {@link #setSpanX(int)} only this method returns <code>this</code> for chaining multiple calls. | |
| 792 | * <p> | |
| 793 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 794 | * @param cells The number of cells to span (i.e. merge). | |
| 795 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 796 | * @see #setSpanY(int) | |
| 797 | */ | |
| 798 | public final CC spanX(int cells) | |
| 799 | { | |
| 800 | setSpanX(cells); | |
| 801 | return this; | |
| 802 | } | |
| 803 | ||
| 804 | /** Same functionality as <code>pushX().pushY()</code> which means this cell will push in both x and y dimensions. | |
| 805 | * This method returns <code>this</code> for chaining multiple calls. | |
| 806 | * <p> | |
| 807 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 808 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 809 | * @see #setPushX(Float) | |
| 810 | * @see #setPushX(Float) | |
| 811 | * @see #pushY() | |
| 812 | * @see #pushX() | |
| 813 | */ | |
| 814 | public final CC push() | |
| 815 | { | |
| 816 | return pushX().pushY(); | |
| 817 | } | |
| 818 | ||
| 819 | /** Same functionality as <code>pushX(weightX).pushY(weightY)</code> which means this cell will push in both x and y dimensions. | |
| 820 | * This method returns <code>this</code> for chaining multiple calls. | |
| 821 | * <p> | |
| 822 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 823 | * @param weightX The weight used in the push. | |
| 824 | * @param weightY The weight used in the push. | |
| 825 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 826 | * @see #setPushY(Float) | |
| 827 | * @see #setPushX(Float) | |
| 828 | * @see #pushY() | |
| 829 | * @see #pushX() | |
| 830 | */ | |
| 831 | public final CC push(Float weightX, Float weightY) | |
| 832 | { | |
| 833 | return pushX(weightX).pushY(weightY); | |
| 834 | } | |
| 835 | ||
| 836 | /** Same functionality as {@link #setPushY(Float))} which means this cell will push the rest of the column. | |
| 837 | * This method returns <code>this</code> for chaining multiple calls. | |
| 838 | * <p> | |
| 839 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 840 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 841 | * @see #setPushY(Float) | |
| 842 | */ | |
| 843 | public final CC pushY() | |
| 844 | { | |
| 845 | return pushY(ResizeConstraint.WEIGHT_100); | |
| 846 | } | |
| 847 | ||
| 848 | /** Same functionality as {@link #setPushY(Float weight)} only this method returns <code>this</code> for chaining multiple calls. | |
| 849 | * <p> | |
| 850 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 851 | * @param weight The weight used in the push. | |
| 852 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 853 | * @see #setPushY(Float) | |
| 854 | */ | |
| 855 | public final CC pushY(Float weight) | |
| 856 | { | |
| 857 | setPushY(weight); | |
| 858 | return this; | |
| 859 | } | |
| 860 | ||
| 861 | /** Same functionality as {@link #setPushX(Float)} which means this cell will push the rest of the row. | |
| 862 | * This method returns <code>this</code> for chaining multiple calls. | |
| 863 | * <p> | |
| 864 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 865 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 866 | * @see #setPushX(Float) | |
| 867 | */ | |
| 868 | public final CC pushX() | |
| 869 | { | |
| 870 | return pushX(ResizeConstraint.WEIGHT_100); | |
| 871 | } | |
| 872 | ||
| 873 | /** Same functionality as {@link #setPushX(Float weight)} only this method returns <code>this</code> for chaining multiple calls. | |
| 874 | * <p> | |
| 875 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 876 | * @param weight The weight used in the push. | |
| 877 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 878 | * @see #setPushY(Float) | |
| 879 | */ | |
| 880 | public final CC pushX(Float weight) | |
| 881 | { | |
| 882 | setPushX(weight); | |
| 883 | return this; | |
| 884 | } | |
| 885 | ||
| 886 | /** Same functionality as {@link #setSplit(int parts)} only this method returns <code>this</code> for chaining multiple calls. | |
| 887 | * <p> | |
| 888 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 889 | * @param parts The number of parts (i.e. component slots) the cell should be divided into. | |
| 890 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 891 | * @see #setSplit(int) | |
| 892 | */ | |
| 893 | public final CC split(int parts) | |
| 894 | { | |
| 895 | setSplit(parts); | |
| 896 | return this; | |
| 897 | } | |
| 898 | ||
| 899 | /** Same functionality as split(LayoutUtil.INF), which means split until one of the keywords that breaks the split is found for | |
| 900 | * a component after this one (e.g. wrap, newline and skip). | |
| 901 | * <p> | |
| 902 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 903 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 904 | * @see #setSplit(int) | |
| 905 | * @since 3.7.2 | |
| 906 | */ | |
| 907 | public final CC split() | |
| 908 | { | |
| 909 | setSplit(LayoutUtil.INF); | |
| 910 | return this; | |
| 911 | } | |
| 912 | ||
| 913 | /** Same functionality as {@link #setSkip(int)} only this method returns <code>this</code> for chaining multiple calls. | |
| 914 | * <p> | |
| 915 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 916 | * @param cells How many cells in the grid that should be skipped <b>before</b> the component that this constraint belongs to | |
| 917 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 918 | * @see #setSkip(int) | |
| 919 | */ | |
| 920 | public final CC skip(int cells) | |
| 921 | { | |
| 922 | setSkip(cells); | |
| 923 | return this; | |
| 924 | } | |
| 925 | ||
| 926 | /** Same functionality as skip(1). | |
| 927 | * <p> | |
| 928 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 929 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 930 | * @see #setSkip(int) | |
| 931 | * @since 3.7.2 | |
| 932 | */ | |
| 933 | public final CC skip() | |
| 934 | { | |
| 935 | setSkip(1); | |
| 936 | return this; | |
| 937 | } | |
| 938 | ||
| 939 | /** Same functionality as {@link #setExternal(boolean true)} only this method returns <code>this</code> for chaining multiple calls. | |
| 940 | * <p> | |
| 941 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 942 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 943 | * @see #setExternal(boolean) | |
| 944 | */ | |
| 945 | public final CC external() | |
| 946 | { | |
| 947 | setExternal(true); | |
| 948 | return this; | |
| 949 | } | |
| 950 | ||
| 951 | /** Same functionality as {@link #setFlowX(Boolean .TRUE)} only this method returns <code>this</code> for chaining multiple calls. | |
| 952 | * <p> | |
| 953 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 954 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 955 | * @see #setFlowX(Boolean) | |
| 956 | */ | |
| 957 | public final CC flowX() | |
| 958 | { | |
| 959 | setFlowX(Boolean.TRUE); | |
| 960 | return this; | |
| 961 | } | |
| 962 | ||
| 963 | /** Same functionality as {@link #setFlowX(Boolean .FALSE)} only this method returns <code>this</code> for chaining multiple calls. | |
| 964 | * <p> | |
| 965 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 966 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 967 | * @see #setFlowX(Boolean) | |
| 968 | */ | |
| 969 | public final CC flowY() | |
| 970 | { | |
| 971 | setFlowX(Boolean.FALSE); | |
| 972 | return this; | |
| 973 | } | |
| 974 | ||
| 975 | ||
| 976 | /** Same functionality as {@link #growX()} and {@link #growY()}. | |
| 977 | * <p> | |
| 978 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 979 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 980 | * @see #growX() | |
| 981 | * @see #growY() | |
| 982 | */ | |
| 983 | public final CC grow() | |
| 984 | { | |
| 985 | growX(); | |
| 986 | growY(); | |
| 987 | return this; | |
| 988 | } | |
| 989 | ||
| 990 | /** Same functionality as {@link #setNewline(boolean true)} only this method returns <code>this</code> for chaining multiple calls. | |
| 991 | * <p> | |
| 992 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 993 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 994 | * @see #setNewline(boolean) | |
| 995 | */ | |
| 996 | public final CC newline() | |
| 997 | { | |
| 998 | setNewline(true); | |
| 999 | return this; | |
| 1000 | } | |
| 1001 | ||
| 1002 | /** Same functionality as {@link #setNewlineGapSize(BoundSize)} only this method returns <code>this</code> for chaining multiple calls. | |
| 1003 | * <p> | |
| 1004 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1005 | * @param gapSize The gap size that will override the gap size in the row/colum constraints if <code>!= null</code>. E.g. "5px" or "unrel". | |
| 1006 | * 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 | |
| 1007 | * {@link #setNewlineGapSize(BoundSize)}. | |
| 1008 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 1009 | * @see #setNewlineGapSize(BoundSize) | |
| 1010 | */ | |
| 1011 | public final CC newline(String gapSize) | |
| 1012 | { | |
| 1013 | BoundSize bs = ConstraintParser.parseBoundSize(gapSize, true, (flowX != null && flowX == false)); | |
| 1014 | if (bs != null) { | |
| 1015 | setNewlineGapSize(bs); | |
| 1016 | } else { | |
| 1017 | setNewline(true); | |
| 1018 | } | |
| 1019 | return this; | |
| 1020 | } | |
| 1021 | ||
| 1022 | /** Same functionality as {@link #setWrap(boolean true)} only this method returns <code>this</code> for chaining multiple calls. | |
| 1023 | * <p> | |
| 1024 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1025 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 1026 | * @see #setWrap(boolean) | |
| 1027 | */ | |
| 1028 | public final CC wrap() | |
| 1029 | { | |
| 1030 | setWrap(true); | |
| 1031 | return this; | |
| 1032 | } | |
| 1033 | ||
| 1034 | /** Same functionality as {@link #setWrapGapSize(BoundSize)} only this method returns <code>this</code> for chaining multiple calls. | |
| 1035 | * <p> | |
| 1036 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1037 | * @param gapSize The gap size that will override the gap size in the row/colum constraints if <code>!= null</code>. E.g. "5px" or "unrel". | |
| 1038 | * 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 | |
| 1039 | * {@link #setWrapGapSize(BoundSize)}. | |
| 1040 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 1041 | * @see #setWrapGapSize(BoundSize) | |
| 1042 | */ | |
| 1043 | public final CC wrap(String gapSize) | |
| 1044 | { | |
| 1045 | BoundSize bs = ConstraintParser.parseBoundSize(gapSize, true, (flowX != null && flowX == false)); | |
| 1046 | if (bs != null) { | |
| 1047 | setWrapGapSize(bs); | |
| 1048 | } else { | |
| 1049 | setWrap(true); | |
| 1050 | } | |
| 1051 | return this; | |
| 1052 | } | |
| 1053 | ||
| 1054 | /** Same functionality as {@link #setDockSide(int 0)} only this method returns <code>this</code> for chaining multiple calls. | |
| 1055 | * <p> | |
| 1056 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1057 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 1058 | * @see #setDockSide(int) | |
| 1059 | */ | |
| 1060 | public final CC dockNorth() | |
| 1061 | { | |
| 1062 | setDockSide(0); | |
| 1063 | return this; | |
| 1064 | } | |
| 1065 | ||
| 1066 | /** Same functionality as {@link #setDockSide(int 1)} only this method returns <code>this</code> for chaining multiple calls. | |
| 1067 | * <p> | |
| 1068 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1069 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 1070 | * @see #setDockSide(int) | |
| 1071 | */ | |
| 1072 | public final CC dockWest() | |
| 1073 | { | |
| 1074 | setDockSide(1); | |
| 1075 | return this; | |
| 1076 | } | |
| 1077 | ||
| 1078 | /** Same functionality as {@link #setDockSide(int 2)} only this method returns <code>this</code> for chaining multiple calls. | |
| 1079 | * <p> | |
| 1080 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1081 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 1082 | * @see #setDockSide(int) | |
| 1083 | */ | |
| 1084 | public final CC dockSouth() | |
| 1085 | { | |
| 1086 | setDockSide(2); | |
| 1087 | return this; | |
| 1088 | } | |
| 1089 | ||
| 1090 | /** Same functionality as {@link #setDockSide(int 3)} only this method returns <code>this</code> for chaining multiple calls. | |
| 1091 | * <p> | |
| 1092 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1093 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 1094 | * @see #setDockSide(int) | |
| 1095 | */ | |
| 1096 | public final CC dockEast() | |
| 1097 | { | |
| 1098 | setDockSide(3); | |
| 1099 | return this; | |
| 1100 | } | |
| 1101 | ||
| 1102 | /** Sets the x-coordinate for the component. This is used to set the x coordinate position to a specific value. The component | |
| 1103 | * bounds is still precalculated to the grid cell and this method should be seen as a way to correct the x position. | |
| 1104 | * <p> | |
| 1105 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1106 | * @param x The x position as a UnitValue. E.g. "10" or "40mm" or "container.x+10". | |
| 1107 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 1108 | * @see #setPos(UnitValue[]) | |
| 1109 | * @see #setBoundsInGrid(boolean) | |
| 1110 | */ | |
| 1111 | public final CC x(String x) | |
| 1112 | { | |
| 1113 | return corrPos(x, 0); | |
| 1114 | } | |
| 1115 | ||
| 1116 | /** Sets the y-coordinate for the component. This is used to set the y coordinate position to a specific value. The component | |
| 1117 | * bounds is still precalculated to the grid cell and this method should be seen as a way to correct the y position. | |
| 1118 | * <p> | |
| 1119 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1120 | * @param y The y position as a UnitValue. E.g. "10" or "40mm" or "container.x+10". | |
| 1121 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 1122 | * @see #setPos(UnitValue[]) | |
| 1123 | * @see #setBoundsInGrid(boolean) | |
| 1124 | */ | |
| 1125 | public final CC y(String y) | |
| 1126 | { | |
| 1127 | return corrPos(y, 1); | |
| 1128 | } | |
| 1129 | ||
| 1130 | /** Sets the x2-coordinate for the component (right side). This is used to set the x2 coordinate position to a specific value. The component | |
| 1131 | * bounds is still precalculated to the grid cell and this method should be seen as a way to correct the x position. | |
| 1132 | * <p> | |
| 1133 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1134 | * @param x2 The x2 side's position as a UnitValue. E.g. "10" or "40mm" or "container.x2 - 10". | |
| 1135 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 1136 | * @see #setPos(UnitValue[]) | |
| 1137 | * @see #setBoundsInGrid(boolean) | |
| 1138 | */ | |
| 1139 | public final CC x2(String x2) | |
| 1140 | { | |
| 1141 | return corrPos(x2, 2); | |
| 1142 | } | |
| 1143 | ||
| 1144 | /** Sets the y2-coordinate for the component (bottom side). This is used to set the y2 coordinate position to a specific value. The component | |
| 1145 | * bounds is still precalculated to the grid cell and this method should be seen as a way to correct the y position. | |
| 1146 | * <p> | |
| 1147 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1148 | * @param y2 The y2 side's position as a UnitValue. E.g. "10" or "40mm" or "container.x2 - 10". | |
| 1149 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 1150 | * @see #setPos(UnitValue[]) | |
| 1151 | * @see #setBoundsInGrid(boolean) | |
| 1152 | */ | |
| 1153 | public final CC y2(String y2) | |
| 1154 | { | |
| 1155 | return corrPos(y2, 3); | |
| 1156 | } | |
| 1157 | ||
| 1158 | private final CC corrPos(String uv, int ix) | |
| 1159 | { | |
| 1160 | UnitValue[] b = getPos(); | |
| 1161 | if (b == null) | |
| 1162 | b = new UnitValue[4]; | |
| 1163 | ||
| 1164 | b[ix] = ConstraintParser.parseUnitValue(uv, (ix % 2 == 0)); | |
| 1165 | setPos(b); | |
| 1166 | ||
| 1167 | setBoundsInGrid(true); | |
| 1168 | return this; | |
| 1169 | } | |
| 1170 | ||
| 1171 | /** Same functionality as {@link #x(String x)} and {@link #y(String y)} toghether. | |
| 1172 | * <p> | |
| 1173 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1174 | * @param x The x position as a UnitValue. E.g. "10" or "40mm" or "container.x+10". | |
| 1175 | * @param y The y position as a UnitValue. E.g. "10" or "40mm" or "container.x+10". | |
| 1176 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 1177 | * @see #setPos(UnitValue[]) | |
| 1178 | */ | |
| 1179 | public final CC pos(String x, String y) | |
| 1180 | { | |
| 1181 | UnitValue[] b = getPos(); | |
| 1182 | if (b == null) | |
| 1183 | b = new UnitValue[4]; | |
| 1184 | ||
| 1185 | b[0] = ConstraintParser.parseUnitValue(x, true); | |
| 1186 | b[1] = ConstraintParser.parseUnitValue(y, false); | |
| 1187 | setPos(b); | |
| 1188 | ||
| 1189 | setBoundsInGrid(false); | |
| 1190 | return this; | |
| 1191 | } | |
| 1192 | ||
| 1193 | /** Same functionality as {@link #x(String x)}, {@link #y(String y)}, {@link #y2(String y)} and {@link #y2(String y)} toghether. | |
| 1194 | * <p> | |
| 1195 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1196 | * @param x The x position as a UnitValue. E.g. "10" or "40mm" or "container.x+10". | |
| 1197 | * @param y The y position as a UnitValue. E.g. "10" or "40mm" or "container.x+10". | |
| 1198 | * @param x2 The x2 side's position as a UnitValue. E.g. "10" or "40mm" or "container.x2 - 10". | |
| 1199 | * @param y2 The y2 side's position as a UnitValue. E.g. "10" or "40mm" or "container.x2 - 10". | |
| 1200 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 1201 | * @see #setPos(UnitValue[]) | |
| 1202 | */ | |
| 1203 | public final CC pos(String x, String y, String x2, String y2) | |
| 1204 | { | |
| 1205 | setPos(new UnitValue[] { | |
| 1206 | ConstraintParser.parseUnitValue(x, true), | |
| 1207 | ConstraintParser.parseUnitValue(y, false), | |
| 1208 | ConstraintParser.parseUnitValue(x2, true), | |
| 1209 | ConstraintParser.parseUnitValue(y2, false), | |
| 1210 | }); | |
| 1211 | setBoundsInGrid(false); | |
| 1212 | return this; | |
| 1213 | } | |
| 1214 | ||
| 1215 | /** Same functionality as {@link #setPadding(UnitValue[])} but the unit values as absolute pixels. This method returns <code>this</code> for chaining multiple calls. | |
| 1216 | * <p> | |
| 1217 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1218 | * @param top The top padding that will be added to the y coordinate at the last stage in the layout. | |
| 1219 | * @param left The top padding that will be added to the x coordinate at the last stage in the layout. | |
| 1220 | * @param bottom The top padding that will be added to the y2 coordinate at the last stage in the layout. | |
| 1221 | * @param right The top padding that will be added to the x2 coordinate at the last stage in the layout. | |
| 1222 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 1223 | * @see #setTag(String) | |
| 1224 | */ | |
| 1225 | public final CC pad(int top, int left, int bottom, int right) | |
| 1226 | { | |
| 1227 | setPadding(new UnitValue[] { | |
| 1228 | new UnitValue(top), new UnitValue(left), new UnitValue(bottom), new UnitValue(right) | |
| 1229 | }); | |
| 1230 | return this; | |
| 1231 | } | |
| 1232 | ||
| 1233 | /** Same functionality as <code>setPadding(ConstraintParser.parseInsets(pad, false))}</code> only this method returns <code>this</code> for chaining multiple calls. | |
| 1234 | * <p> | |
| 1235 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1236 | * @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. | |
| 1237 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. | |
| 1238 | * @see #setTag(String) | |
| 1239 | */ | |
| 1240 | public final CC pad(String pad) | |
| 1241 | { | |
| 1242 | setPadding(pad != null ? ConstraintParser.parseInsets(pad, false) : null); | |
| 1243 | return this; | |
| 1244 | } | |
| 1245 | ||
| 1246 | // ********************************************************** | |
| 1247 | // Bean properties | |
| 1248 | // ********************************************************** | |
| 1249 | ||
| 1250 | /** Returns the horizontal dimension constraint for this component constraint. It has constraints for the horizontal size | |
| 1251 | * and grow/shink priorities and weights. | |
| 1252 | * <p> | |
| 1253 | * 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 | |
| 1254 | * constraint for later use. | |
| 1255 | * @return The current dimension constraint. Never <code>null</code>. | |
| 1256 | */ | |
| 1257 | public DimConstraint getHorizontal() | |
| 1258 | { | |
| 1259 | return hor; | |
| 1260 | } | |
| 1261 | ||
| 1262 | /** Sets the horizontal dimension constraint for this component constraint. It has constraints for the horizontal size | |
| 1263 | * and grow/shrink priorities and weights. | |
| 1264 | * @param h The new dimension constraint. If <code>null</code> it will be reset to <code>new DimConstraint();</code> | |
| 1265 | */ | |
| 1266 | public void setHorizontal(DimConstraint h) | |
| 1267 | { | |
| 1268 | hor = h != null ? h : new DimConstraint(); | |
| 1269 | } | |
| 1270 | ||
| 1271 | /** Returns the vertical dimension constraint for this component constraint. It has constraints for the vertical size | |
| 1272 | * and grow/shrink priorities and weights. | |
| 1273 | * <p> | |
| 1274 | * 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 | |
| 1275 | * constraint for later use. | |
| 1276 | * @return The current dimension constraint. Never <code>null</code>. | |
| 1277 | */ | |
| 1278 | public DimConstraint getVertical() | |
| 1279 | { | |
| 1280 | return ver; | |
| 1281 | } | |
| 1282 | ||
| 1283 | /** Sets the vertical dimension constraint for this component constraint. It has constraints for the vertical size | |
| 1284 | * and grow/shrink priorities and weights. | |
| 1285 | * @param v The new dimension constraint. If <code>null</code> it will be reset to <code>new DimConstraint();</code> | |
| 1286 | */ | |
| 1287 | public void setVertical(DimConstraint v) | |
| 1288 | { | |
| 1289 | ver = v != null ? v : new DimConstraint(); | |
| 1290 | } | |
| 1291 | ||
| 1292 | /** Returns the vertical or horizontal dim constraint. | |
| 1293 | * <p> | |
| 1294 | * 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 | |
| 1295 | * constraint for later use. | |
| 1296 | * @param isHor If the horizontal constraint should be returned. | |
| 1297 | * @return The dim constraint. Never <code>null</code>. | |
| 1298 | */ | |
| 1299 | public DimConstraint getDimConstraint(boolean isHor) | |
| 1300 | { | |
| 1301 | return isHor ? hor : ver; | |
| 1302 | } | |
| 1303 | ||
| 1304 | /** Returns the absolute positioning of one or more of the edges. This will be applied last in the layout cycle and will not | |
| 1305 | * affect the flow or grid positions. The positioning is relative to the parent and can not (as padding) be used | |
| 1306 | * to adjust the edges relative to the old value. May be <code>null</code> and elements may be <code>null</code>. | |
| 1307 | * <code>null</code> value(s) for the x2 and y2 will be interpreted as to keep the preferred size and thus the x1 | |
| 1308 | * and x2 will just absolutely positions the component. | |
| 1309 | * <p> | |
| 1310 | * Note that {@link #setBoundsInGrid(boolean)} changes the interpretation of thisproperty slightly. | |
| 1311 | * <p> | |
| 1312 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1313 | * @return The current value as a new array, free to modify. | |
| 1314 | */ | |
| 1315 | public UnitValue[] getPos() | |
| 1316 | { | |
| 1317 | return pos != null ? new UnitValue[] {pos[0], pos[1], pos[2], pos[3]} : null; | |
| 1318 | } | |
| 1319 | ||
| 1320 | /** Sets 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. | |
| 1325 | * <p> | |
| 1326 | * Note that {@link #setBoundsInGrid(boolean)} changes the interpretation of thisproperty slightly. | |
| 1327 | * <p> | |
| 1328 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1329 | * @param pos <code>UnitValue[] {x, y, x2, y2}</code>. Must be <code>null</code> or of length 4. Elements can be <code>null</code>. | |
| 1330 | */ | |
| 1331 | public void setPos(UnitValue[] pos) | |
| 1332 | { | |
| 1333 | this.pos = pos != null ? new UnitValue[] {pos[0], pos[1], pos[2], pos[3]} : null; | |
| 1334 | linkTargets = null; | |
| 1335 | } | |
| 1336 | ||
| 1337 | /** Returns if the absolute <code>pos</code> value should be corrections to the component that is in a normal cell. If <code>false</code> | |
| 1338 | * 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. | |
| 1339 | * <p> | |
| 1340 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1341 | * @return The current value. | |
| 1342 | * @see #getPos() | |
| 1343 | */ | |
| 1344 | public boolean isBoundsInGrid() | |
| 1345 | { | |
| 1346 | return boundsInGrid; | |
| 1347 | } | |
| 1348 | ||
| 1349 | /** Sets if the absolute <code>pos</code> value should be corrections to the component that is in a normal cell. If <code>false</code> | |
| 1350 | * 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. | |
| 1351 | * <p> | |
| 1352 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1353 | * @param b <code>true</code> for bounds taken from the grid position. <code>false</code> is default. | |
| 1354 | * @see #setPos(UnitValue[]) | |
| 1355 | */ | |
| 1356 | void setBoundsInGrid(boolean b) | |
| 1357 | { | |
| 1358 | this.boundsInGrid = b; | |
| 1359 | } | |
| 1360 | ||
| 1361 | /** Returns the absolute cell position in the grid or <code>-1</code> if cell positioning is not used. | |
| 1362 | * <p> | |
| 1363 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1364 | * @return The current value. | |
| 1365 | */ | |
| 1366 | public int getCellX() | |
| 1367 | { | |
| 1368 | return cellX; | |
| 1369 | } | |
| 1370 | ||
| 1371 | /** 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. | |
| 1372 | * If there's already a component in that cell they will split the cell. The flow will then continue after this cell. | |
| 1373 | * <p> | |
| 1374 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1375 | * @param x The x-position or <code>-1</code> to disable cell positioning. | |
| 1376 | */ | |
| 1377 | public void setCellX(int x) | |
| 1378 | { | |
| 1379 | cellX = x; | |
| 1380 | } | |
| 1381 | ||
| 1382 | /** Returns the absolute cell position in the grid or <code>-1</code> if cell positioning is not used. | |
| 1383 | * <p> | |
| 1384 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1385 | * @return The current value. | |
| 1386 | */ | |
| 1387 | public int getCellY() | |
| 1388 | { | |
| 1389 | return cellX < 0 ? -1 : cellY; | |
| 1390 | } | |
| 1391 | ||
| 1392 | /** 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. | |
| 1393 | * If there's already a component in that cell they will split the cell. The flow will then continue after this cell. | |
| 1394 | * <p> | |
| 1395 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1396 | * @param y The y-position or <code>-1</code> to disable cell positioning. | |
| 1397 | */ | |
| 1398 | public void setCellY(int y) | |
| 1399 | { | |
| 1400 | if (y < 0) | |
| 1401 | cellX = -1; | |
| 1402 | cellY = y < 0 ? 0 : y; | |
| 1403 | } | |
| 1404 | ||
| 1405 | /** Sets the docking side. -1 means no docking.<br> | |
| 1406 | * Valid sides are: <code> north = 0, west = 1, south = 2, east = 3</code>. | |
| 1407 | * <p> | |
| 1408 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1409 | * @return The current side. | |
| 1410 | */ | |
| 1411 | public int getDockSide() | |
| 1412 | { | |
| 1413 | return dock; | |
| 1414 | } | |
| 1415 | ||
| 1416 | /** Sets the docking side. -1 means no docking.<br> | |
| 1417 | * Valid sides are: <code> north = 0, west = 1, south = 2, east = 3</code>. | |
| 1418 | * <p> | |
| 1419 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1420 | * @param side -1 or 0-3. | |
| 1421 | */ | |
| 1422 | public void setDockSide(int side) | |
| 1423 | { | |
| 1424 | if (side < -1 || side > 3) | |
| 1425 | throw new IllegalArgumentException("Illegal dock side: " + side); | |
| 1426 | dock = side; | |
| 1427 | } | |
| 1428 | ||
| 1429 | /** Returns if this component should have its bounds handled by an external source and not this layout manager. | |
| 1430 | * <p> | |
| 1431 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1432 | * @return The current value. | |
| 1433 | */ | |
| 1434 | public boolean isExternal() | |
| 1435 | { | |
| 1436 | return external; | |
| 1437 | } | |
| 1438 | ||
| 1439 | /** 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 | |
| 1440 | * handler which is normally by the use of some <code>component.setBounds(x, y, width, height)</code> directly (for Swing). | |
| 1441 | * <p> | |
| 1442 | * The bounds <b>will not</b> affect the minimum and preferred size of the container. | |
| 1443 | * <p> | |
| 1444 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1445 | * @param b <code>true</code> means that the bounds are not changed. | |
| 1446 | */ | |
| 1447 | public void setExternal(boolean b) | |
| 1448 | { | |
| 1449 | this.external = b; | |
| 1450 | } | |
| 1451 | ||
| 1452 | /** Returns if the flow in the <b>cell</b> is in the horizontal dimension. Vertical if <code>false</code>. Only the first | |
| 1453 | * component is a cell can set the flow. | |
| 1454 | * <p> | |
| 1455 | * If <code>null</code> the flow direction is inherited by from the {@link net.miginfocom.layout.LC}. | |
| 1456 | * <p> | |
| 1457 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1458 | * @return The current value. | |
| 1459 | */ | |
| 1460 | public Boolean getFlowX() | |
| 1461 | { | |
| 1462 | return flowX; | |
| 1463 | } | |
| 1464 | ||
| 1465 | /** Sets if the flow in the <b>cell</b> is in the horizontal dimension. Vertical if <code>false</code>. Only the first | |
| 1466 | * component is a cell can set the flow. | |
| 1467 | * <p> | |
| 1468 | * If <code>null</code> the flow direction is inherited by from the {@link net.miginfocom.layout.LC}. | |
| 1469 | * <p> | |
| 1470 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1471 | * @param b <code>Boolean.TRUE</code> means horizontal flow in the cell. | |
| 1472 | */ | |
| 1473 | public void setFlowX(Boolean b) | |
| 1474 | { | |
| 1475 | this.flowX = b; | |
| 1476 | } | |
| 1477 | ||
| 1478 | /** Sets how a component that is hidden (not visible) should be treated by default. | |
| 1479 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1480 | * @return The mode:<br> | |
| 1481 | * 0 == Normal. Bounds will be calculated as if the component was visible.<br> | |
| 1482 | * 1 == If hidden the size will be 0, 0 but the gaps remain.<br> | |
| 1483 | * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br> | |
| 1484 | * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid.. | |
| 1485 | */ | |
| 1486 | public int getHideMode() | |
| 1487 | { | |
| 1488 | return hideMode; | |
| 1489 | } | |
| 1490 | ||
| 1491 | /** Sets how a component that is hidden (not visible) should be treated by default. | |
| 1492 | * @param mode The mode:<br> | |
| 1493 | * 0 == Normal. Bounds will be calculated as if the component was visible.<br> | |
| 1494 | * 1 == If hidden the size will be 0, 0 but the gaps remain.<br> | |
| 1495 | * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br> | |
| 1496 | * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid.. | |
| 1497 | */ | |
| 1498 | public void setHideMode(int mode) | |
| 1499 | { | |
| 1500 | if (mode < -1 || mode > 3) | |
| 1501 | throw new IllegalArgumentException("Wrong hideMode: " + mode); | |
| 1502 | ||
| 1503 | hideMode = mode; | |
| 1504 | } | |
| 1505 | ||
| 1506 | /** Returns the id used to reference this component in some constraints. | |
| 1507 | * <p> | |
| 1508 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1509 | * @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". | |
| 1510 | * The dot should never be first or last if present. | |
| 1511 | */ | |
| 1512 | public String getId() | |
| 1513 | { | |
| 1514 | return id; | |
| 1515 | } | |
| 1516 | ||
| 1517 | /** Sets the id used to reference this component in some constraints. | |
| 1518 | * <p> | |
| 1519 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1520 | * @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". | |
| 1521 | * The dot should never be first or last if present. | |
| 1522 | */ | |
| 1523 | public void setId(String id) | |
| 1524 | { | |
| 1525 | this.id = id; | |
| 1526 | } | |
| 1527 | ||
| 1528 | /** Returns the absolute resizing in the last stage of the layout cycle. May be <code>null</code> and elements may be <code>null</code>. | |
| 1529 | * <p> | |
| 1530 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1531 | * @return The current value. <code>null</code> or of length 4. | |
| 1532 | */ | |
| 1533 | public UnitValue[] getPadding() | |
| 1534 | { | |
| 1535 | return padding != null ? new UnitValue[] {padding[0], padding[1], padding[2], padding[3]} : null; | |
| 1536 | } | |
| 1537 | ||
| 1538 | /** Sets the absolute resizing in the last stage of the layout cycle. These values are added to the edges and can thus for | |
| 1539 | * instance be used to grow or reduce the size or move the component an absolute number of pixels. May be <code>null</code> | |
| 1540 | * and elements may be <code>null</code>. | |
| 1541 | * <p> | |
| 1542 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1543 | * @param sides top, left, bottom right. Must be <code>null</code> or of length 4. | |
| 1544 | */ | |
| 1545 | public void setPadding(UnitValue[] sides) | |
| 1546 | { | |
| 1547 | this.padding = sides != null ? new UnitValue[] {sides[0], sides[1], sides[2], sides[3]} : null; | |
| 1548 | } | |
| 1549 | ||
| 1550 | /** Returns how many cells in the grid that should be skipped <b>before</b> the component that this constraint belongs to. | |
| 1551 | * <p> | |
| 1552 | * Note that only the first component will be checked for this property. | |
| 1553 | * <p> | |
| 1554 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1555 | * @return The current value. 0 if no skip. | |
| 1556 | */ | |
| 1557 | public int getSkip() | |
| 1558 | { | |
| 1559 | return skip; | |
| 1560 | } | |
| 1561 | ||
| 1562 | /** Sets how many cells in the grid that should be skipped <b>before</b> the component that this constraint belongs to. | |
| 1563 | * <p> | |
| 1564 | * Note that only the first component will be checked for this property. | |
| 1565 | * <p> | |
| 1566 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1567 | * @param cells How many cells in the grid that should be skipped <b>before</b> the component that this constraint belongs to | |
| 1568 | */ | |
| 1569 | public void setSkip(int cells) | |
| 1570 | { | |
| 1571 | this.skip = cells; | |
| 1572 | } | |
| 1573 | ||
| 1574 | /** Returns the number of cells the cell that this constraint's component will span in the indicated dimension. <code>1</code> is default and | |
| 1575 | * 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. | |
| 1576 | * <p> | |
| 1577 | * Note that only the first component will be checked for this property. | |
| 1578 | * <p> | |
| 1579 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1580 | * @return The current value. | |
| 1581 | */ | |
| 1582 | public int getSpanX() | |
| 1583 | { | |
| 1584 | return spanX; | |
| 1585 | } | |
| 1586 | ||
| 1587 | /** Sets the number of cells the cell that this constraint's component will span in the indicated dimension. <code>1</code> is default and | |
| 1588 | * 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. | |
| 1589 | * <p> | |
| 1590 | * Note that only the first component will be checked for this property. | |
| 1591 | * <p> | |
| 1592 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1593 | * @param cells The number of cells to span (i.e. merge). | |
| 1594 | */ | |
| 1595 | public void setSpanX(int cells) | |
| 1596 | { | |
| 1597 | this.spanX = cells; | |
| 1598 | } | |
| 1599 | ||
| 1600 | /** Returns the number of cells the cell that this constraint's component will span in the indicated dimension. <code>1</code> is default and | |
| 1601 | * 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. | |
| 1602 | * <p> | |
| 1603 | * Note that only the first component will be checked for this property. | |
| 1604 | * <p> | |
| 1605 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1606 | * @return The current value. | |
| 1607 | */ | |
| 1608 | public int getSpanY() | |
| 1609 | { | |
| 1610 | return spanY; | |
| 1611 | } | |
| 1612 | ||
| 1613 | /** Sets the number of cells the cell that this constraint's component will span in the indicated dimension. <code>1</code> is default and | |
| 1614 | * 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. | |
| 1615 | * <p> | |
| 1616 | * Note that only the first component will be checked for this property. | |
| 1617 | * <p> | |
| 1618 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1619 | * @param cells The number of cells to span (i.e. merge). | |
| 1620 | */ | |
| 1621 | public void setSpanY(int cells) | |
| 1622 | { | |
| 1623 | this.spanY = cells; | |
| 1624 | } | |
| 1625 | ||
| 1626 | /** "pushx" indicates that the column that this component is in (this first if the component spans) should default to growing. | |
| 1627 | * If any other column has been set to grow this push value on the component does nothing as the column's explicit grow weight | |
| 1628 | * will take precedence. Push is normally used when the grid has not been defined in the layout. | |
| 1629 | * <p> | |
| 1630 | * If multiple components in a column has push weights set the largest one will be used for the column. | |
| 1631 | * @return The current push value. Default is <code>null</code>. | |
| 1632 | */ | |
| 1633 | public Float getPushX() | |
| 1634 | { | |
| 1635 | return pushX; | |
| 1636 | } | |
| 1637 | ||
| 1638 | /** "pushx" indicates that the column that this component is in (this first if the component spans) should default to growing. | |
| 1639 | * If any other column has been set to grow this push value on the component does nothing as the column's explicit grow weight | |
| 1640 | * will take precedence. Push is normally used when the grid has not been defined in the layout. | |
| 1641 | * <p> | |
| 1642 | * If multiple components in a column has push weights set the largest one will be used for the column. | |
| 1643 | * @param weight The new push value. Default is <code>null</code>. | |
| 1644 | */ | |
| 1645 | public void setPushX(Float weight) | |
| 1646 | { | |
| 1647 | this.pushX = weight; | |
| 1648 | } | |
| 1649 | ||
| 1650 | /** "pushx" indicates that the row that this component is in (this first if the component spans) should default to growing. | |
| 1651 | * If any other row has been set to grow this push value on the component does nothing as the row's explicit grow weight | |
| 1652 | * will take precedence. Push is normally used when the grid has not been defined in the layout. | |
| 1653 | * <p> | |
| 1654 | * If multiple components in a row has push weights set the largest one will be used for the row. | |
| 1655 | * @return The current push value. Default is <code>null</code>. | |
| 1656 | */ | |
| 1657 | public Float getPushY() | |
| 1658 | { | |
| 1659 | return pushY; | |
| 1660 | } | |
| 1661 | ||
| 1662 | /** "pushx" indicates that the row that this component is in (this first if the component spans) should default to growing. | |
| 1663 | * If any other row has been set to grow this push value on the component does nothing as the row's explicit grow weight | |
| 1664 | * will take precedence. Push is normally used when the grid has not been defined in the layout. | |
| 1665 | * <p> | |
| 1666 | * If multiple components in a row has push weights set the largest one will be used for the row. | |
| 1667 | * @param weight The new push value. Default is <code>null</code>. | |
| 1668 | */ | |
| 1669 | public void setPushY(Float weight) | |
| 1670 | { | |
| 1671 | this.pushY = weight; | |
| 1672 | } | |
| 1673 | ||
| 1674 | /** Returns in how many parts the current cell (that this constraint's component will be in) should be split in. If for instance | |
| 1675 | * it is split in two, the next component will also share the same cell. Note that the cell can also span a number of | |
| 1676 | * cells, which means that you can for instance span three cells and split that big cell for two components. Split can be | |
| 1677 | * 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>). | |
| 1678 | * <p> | |
| 1679 | * Note that only the first component will be checked for this property. | |
| 1680 | * <p> | |
| 1681 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1682 | * @return The current value. | |
| 1683 | */ | |
| 1684 | public int getSplit() | |
| 1685 | { | |
| 1686 | return split; | |
| 1687 | } | |
| 1688 | ||
| 1689 | /** Sets in how many parts the current cell (that this constraint's component will be in) should be split in. If for instance | |
| 1690 | * it is split in two, the next component will also share the same cell. Note that the cell can also span a number of | |
| 1691 | * cells, which means that you can for instance span three cells and split that big cell for two components. Split can be | |
| 1692 | * 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>). | |
| 1693 | * <p> | |
| 1694 | * Note that only the first component will be checked for this property. | |
| 1695 | * <p> | |
| 1696 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1697 | * @param parts The number of parts (i.e. component slots) the cell should be divided into. | |
| 1698 | */ | |
| 1699 | public void setSplit(int parts) | |
| 1700 | { | |
| 1701 | this.split = parts; | |
| 1702 | } | |
| 1703 | ||
| 1704 | /** Tags the component with metadata. Currently only used to tag buttons with for instance "cancel" or "ok" to make them | |
| 1705 | * show up in the correct order depending on platform. See {@link PlatformDefaults#setButtonOrder(String)} for information. | |
| 1706 | * <p> | |
| 1707 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1708 | * @return The current value. May be <code>null</code>. | |
| 1709 | */ | |
| 1710 | public String getTag() | |
| 1711 | { | |
| 1712 | return tag; | |
| 1713 | } | |
| 1714 | ||
| 1715 | /** Optinal tag that gives more context to this constraint's component. It is for instance used to tag buttons in a | |
| 1716 | * button bar with the button type such as "ok", "help" or "cancel". | |
| 1717 | * <p> | |
| 1718 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1719 | * @param tag The new tag. May be <code>null</code>. | |
| 1720 | */ | |
| 1721 | public void setTag(String tag) | |
| 1722 | { | |
| 1723 | this.tag = tag; | |
| 1724 | } | |
| 1725 | ||
| 1726 | /** Returns if the flow should wrap to the next line/column <b>after</b> the component that this constraint belongs to. | |
| 1727 | * <p> | |
| 1728 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1729 | * @return The current value. | |
| 1730 | */ | |
| 1731 | public boolean isWrap() | |
| 1732 | { | |
| 1733 | return wrap != null; | |
| 1734 | } | |
| 1735 | ||
| 1736 | /** Sets if the flow should wrap to the next line/column <b>after</b> the component that this constraint belongs to. | |
| 1737 | * <p> | |
| 1738 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1739 | * @param b <code>true</code> means wrap after. | |
| 1740 | */ | |
| 1741 | public void setWrap(boolean b) | |
| 1742 | { | |
| 1743 | wrap = b ? (wrap == null ? DEF_GAP : wrap) : null; | |
| 1744 | } | |
| 1745 | ||
| 1746 | /** Returns the wrap size if it is a custom size. If wrap was set to true with {@link #setWrap(boolean)} then this method will | |
| 1747 | * return <code>null</code> since that means that the gap size should be the default one as defined in the rows spec. | |
| 1748 | * @return The custom gap size. NOTE! Will return <code>null</code> for both no wrap <b>and</b> default wrap. | |
| 1749 | * @see #isWrap() | |
| 1750 | * @see #setWrap(boolean) | |
| 1751 | * @since 2.4.2 | |
| 1752 | */ | |
| 1753 | public BoundSize getWrapGapSize() | |
| 1754 | { | |
| 1755 | return wrap == DEF_GAP ? null : wrap; | |
| 1756 | } | |
| 1757 | ||
| 1758 | /** Set the wrap size and turns wrap on if <code>!= null</code>. | |
| 1759 | * @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". | |
| 1760 | * A non-null value will turn on wrap though. | |
| 1761 | * @see #isWrap() | |
| 1762 | * @see #setWrap(boolean) | |
| 1763 | * @since 2.4.2 | |
| 1764 | */ | |
| 1765 | public void setWrapGapSize(BoundSize s) | |
| 1766 | { | |
| 1767 | wrap = s == null ? (wrap != null ? DEF_GAP : null) : s; | |
| 1768 | } | |
| 1769 | ||
| 1770 | /** Returns if the flow should wrap to the next line/column <b>before</b> the component that this constraint belongs to. | |
| 1771 | * <p> | |
| 1772 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1773 | * @return The current value. | |
| 1774 | */ | |
| 1775 | public boolean isNewline() | |
| 1776 | { | |
| 1777 | return newline != null; | |
| 1778 | } | |
| 1779 | ||
| 1780 | /** Sets if the flow should wrap to the next line/column <b>before</b> the component that this constraint belongs to. | |
| 1781 | * <p> | |
| 1782 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 1783 | * @param b <code>true</code> means wrap before. | |
| 1784 | */ | |
| 1785 | public void setNewline(boolean b) | |
| 1786 | { | |
| 1787 | newline = b ? (newline == null ? DEF_GAP : newline) : null; | |
| 1788 | } | |
| 1789 | ||
| 1790 | /** Returns the newline size if it is a custom size. If newline was set to true with {@link #setNewline(boolean)} then this method will | |
| 1791 | * return <code>null</code> since that means that the gap size should be the default one as defined in the rows spec. | |
| 1792 | * @return The custom gap size. NOTE! Will return <code>null</code> for both no newline <b>and</b> default newline. | |
| 1793 | * @see #isNewline() | |
| 1794 | * @see #setNewline(boolean) | |
| 1795 | * @since 2.4.2 | |
| 1796 | */ | |
| 1797 | public BoundSize getNewlineGapSize() | |
| 1798 | { | |
| 1799 | return newline == DEF_GAP ? null : newline; | |
| 1800 | } | |
| 1801 | ||
| 1802 | /** Set the newline size and turns newline on if <code>!= null</code>. | |
| 1803 | * @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". | |
| 1804 | * A non-null value will turn on newline though. | |
| 1805 | * @see #isNewline() | |
| 1806 | * @see #setNewline(boolean) | |
| 1807 | * @since 2.4.2 | |
| 1808 | */ | |
| 1809 | public void setNewlineGapSize(BoundSize s) | |
| 1810 | { | |
| 1811 | newline = s == null ? (newline != null ? DEF_GAP : null) : s; | |
| 1812 | } | |
| 1813 | ||
| 1814 | // ************************************************ | |
| 1815 | // Persistence Delegate and Serializable combined. | |
| 1816 | // ************************************************ | |
| 1817 | ||
| 1818 | private Object readResolve() throws ObjectStreamException | |
| 1819 | { | |
| 1820 | return LayoutUtil.getSerializedObject(this); | |
| 1821 | } | |
| 1822 | ||
| 1823 | public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException | |
| 1824 | { | |
| 1825 | LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in)); | |
| 1826 | } | |
| 1827 | ||
| 1828 | public void writeExternal(ObjectOutput out) throws IOException | |
| 1829 | { | |
| 1830 | if (getClass() == CC.class) | |
| 1831 | LayoutUtil.writeAsXML(out, this); | |
| 1832 | } | |
| 1833 | } |