| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| LC |
|
| 1.2073170731707317;1.207 |
| 1 | package net.miginfocom.layout; | |
| 2 | ||
| 3 | import java.io.*; | |
| 4 | /* | |
| 5 | * License (BSD): | |
| 6 | * ============== | |
| 7 | * | |
| 8 | * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com) | |
| 9 | * All rights reserved. | |
| 10 | * | |
| 11 | * Redistribution and use in source and binary forms, with or without modification, | |
| 12 | * are permitted provided that the following conditions are met: | |
| 13 | * Redistributions of source code must retain the above copyright notice, this list | |
| 14 | * of conditions and the following disclaimer. | |
| 15 | * Redistributions in binary form must reproduce the above copyright notice, this | |
| 16 | * list of conditions and the following disclaimer in the documentation and/or other | |
| 17 | * materials provided with the distribution. | |
| 18 | * Neither the name of the MiG InfoCom AB nor the names of its contributors may be | |
| 19 | * used to endorse or promote products derived from this software without specific | |
| 20 | * prior written permission. | |
| 21 | * | |
| 22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
| 23 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 24 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
| 25 | * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
| 26 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 27 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |
| 28 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
| 29 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 30 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
| 31 | * OF SUCH DAMAGE. | |
| 32 | * | |
| 33 | * @version 1.0 | |
| 34 | * @author Mikael Grev, MiG InfoCom AB | |
| 35 | * Date: 2006-sep-08 | |
| 36 | */ | |
| 37 | ||
| 38 | /** Contains the constraints for an instance of the {@link LC} layout manager. | |
| 39 | */ | |
| 40 | public final class LC implements Externalizable | |
| 41 | { | |
| 42 | // See the corresponding set/get method for documentation of the property! | |
| 43 | ||
| 44 | private int wrapAfter = LayoutUtil.INF; | |
| 45 | ||
| 46 | private Boolean leftToRight = null; | |
| 47 | ||
| 48 | private UnitValue[] insets = null; // Never null elememts but if unset array is null | |
| 49 | ||
| 50 | private UnitValue alignX = null, alignY = null; | |
| 51 | ||
| 52 | private BoundSize gridGapX = null, gridGapY = null; | |
| 53 | ||
| 54 | private BoundSize width = BoundSize.NULL_SIZE, height = BoundSize.NULL_SIZE; | |
| 55 | ||
| 56 | private BoundSize packW = BoundSize.NULL_SIZE, packH = BoundSize.NULL_SIZE; | |
| 57 | ||
| 58 | private float pwAlign = 0.5f, phAlign = 1.0f; | |
| 59 | ||
| 60 | private int debugMillis = 0; | |
| 61 | ||
| 62 | private int hideMode = 0; | |
| 63 | ||
| 64 | private boolean noCache = false; | |
| 65 | ||
| 66 | private boolean flowX = true; | |
| 67 | ||
| 68 | private boolean fillX = false, fillY = false; | |
| 69 | ||
| 70 | private boolean topToBottom = true; | |
| 71 | ||
| 72 | private boolean noGrid = false; | |
| 73 | ||
| 74 | private boolean visualPadding = true; | |
| 75 | ||
| 76 | /** Empty constructor. | |
| 77 | */ | |
| 78 | public LC() | |
| 79 | { | |
| 80 | } | |
| 81 | ||
| 82 | // ************************************************************************ | |
| 83 | // * JavaBean get/set methods. | |
| 84 | // ************************************************************************ | |
| 85 | ||
| 86 | ||
| 87 | /** If components have sizes or positions linked to the bounds of the parent in some way (as for instance the <code>"%"</code> unit has) the cache | |
| 88 | * must be turned off for the panel. If components does not get the correct or expected size or position try to set this property to <code>true</code>. | |
| 89 | * @return <code>true</code> means no cache and slightly slower layout. | |
| 90 | */ | |
| 91 | public boolean isNoCache() | |
| 92 | { | |
| 93 | return noCache; | |
| 94 | } | |
| 95 | ||
| 96 | /** If components have sizes or positions linked to the bounds of the parent in some way (as for instance the <code>"%"</code> unit has) the cache | |
| 97 | * must be turned off for the panel. If components does not get the correct or expected size or position try to set this property to <code>true</code>. | |
| 98 | * @param b <code>true</code> means no cache and slightly slower layout. | |
| 99 | */ | |
| 100 | public void setNoCache(boolean b) | |
| 101 | { | |
| 102 | this.noCache = b; | |
| 103 | } | |
| 104 | ||
| 105 | /** If the laid out components' bounds in total is less than the final size of the container these align values will be used to align the components | |
| 106 | * in the parent. <code>null</code> is default and that means top/left alignment. The relative distances between the components will not be affected | |
| 107 | * by this property. | |
| 108 | * @return The current alignment. | |
| 109 | */ | |
| 110 | public final UnitValue getAlignX() | |
| 111 | { | |
| 112 | return alignX; | |
| 113 | } | |
| 114 | ||
| 115 | /** If the laid out components' bounds in total is less than the final size of the container these align values will be used to align the components | |
| 116 | * in the parent. <code>null</code> is default and that means top/left alignment. The relative distances between the components will not be affected | |
| 117 | * by this property. | |
| 118 | * @param uv The new alignment. Use {@link ConstraintParser#parseAlignKeywords(String, boolean)} to create the {@link UnitValue}. May be <code>null</code>. | |
| 119 | */ | |
| 120 | public final void setAlignX(UnitValue uv) | |
| 121 | { | |
| 122 | this.alignX = uv; | |
| 123 | } | |
| 124 | ||
| 125 | /** If the laid out components' bounds in total is less than the final size of the container these align values will be used to align the components | |
| 126 | * in the parent. <code>null</code> is default and that means top/left alignment. The relative distances between the components will not be affected | |
| 127 | * by this property. | |
| 128 | * @return The current alignment. | |
| 129 | */ | |
| 130 | public final UnitValue getAlignY() | |
| 131 | { | |
| 132 | return alignY; | |
| 133 | } | |
| 134 | ||
| 135 | /** If the laid out components' bounds in total is less than the final size of the container these align values will be used to align the components | |
| 136 | * in the parent. <code>null</code> is default and that means top/left alignment. The relative distances between the components will not be affected | |
| 137 | * by this property. | |
| 138 | * @param uv The new alignment. Use {@link ConstraintParser#parseAlignKeywords(String, boolean)} to create the {@link UnitValue}. May be <code>null</code>. | |
| 139 | */ | |
| 140 | public final void setAlignY(UnitValue uv) | |
| 141 | { | |
| 142 | this.alignY = uv; | |
| 143 | } | |
| 144 | ||
| 145 | /** If <code>> 0</code> the debug decorations will be repainted every <code>millis</code>. No debug information if <code><= 0</code> (default). | |
| 146 | * @return The current debug repaint interval. | |
| 147 | */ | |
| 148 | public final int getDebugMillis() | |
| 149 | { | |
| 150 | return debugMillis; | |
| 151 | } | |
| 152 | ||
| 153 | /** If <code>> 0</code> the debug decorations will be repainted every <code>millis</code>. No debug information if <code><= 0</code> (default). | |
| 154 | * @param millis The new debug repaint interval. | |
| 155 | */ | |
| 156 | public final void setDebugMillis(int millis) | |
| 157 | { | |
| 158 | this.debugMillis = millis; | |
| 159 | } | |
| 160 | ||
| 161 | /** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller. | |
| 162 | * @return <code>true</code> means fill. <code>false</code> is default. | |
| 163 | */ | |
| 164 | public final boolean isFillX() | |
| 165 | { | |
| 166 | return fillX; | |
| 167 | } | |
| 168 | ||
| 169 | /** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller. | |
| 170 | * @param b <code>true</code> means fill. <code>false</code> is default. | |
| 171 | */ | |
| 172 | public final void setFillX(boolean b) | |
| 173 | { | |
| 174 | this.fillX = b; | |
| 175 | } | |
| 176 | ||
| 177 | /** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller. | |
| 178 | * @return <code>true</code> means fill. <code>false</code> is default. | |
| 179 | */ | |
| 180 | public final boolean isFillY() | |
| 181 | { | |
| 182 | return fillY; | |
| 183 | } | |
| 184 | ||
| 185 | /** If the layout should always claim the whole bounds of the laid out container even if the preferred size is smaller. | |
| 186 | * @param b <code>true</code> means fill. <code>false</code> is default. | |
| 187 | */ | |
| 188 | public final void setFillY(boolean b) | |
| 189 | { | |
| 190 | this.fillY = b; | |
| 191 | } | |
| 192 | ||
| 193 | /** The default flow direction. Normally (which is <code>true</code>) this is horizontal and that means that the "next" component | |
| 194 | * will be put in the cell to the right (or to the left if left-to-right is false). | |
| 195 | * @return <code>true</code> is the default flow horizontally. | |
| 196 | * @see #setLeftToRight(Boolean) | |
| 197 | */ | |
| 198 | public final boolean isFlowX() | |
| 199 | { | |
| 200 | return flowX; | |
| 201 | } | |
| 202 | ||
| 203 | /** The default flow direction. Normally (which is <code>true</code>) this is horizontal and that means that the "next" component | |
| 204 | * will be put in the cell to the right (or to the left if left-to-right is false). | |
| 205 | * @param b <code>true</code> is the default flow horizontally. | |
| 206 | * @see #setLeftToRight(Boolean) | |
| 207 | */ | |
| 208 | public final void setFlowX(boolean b) | |
| 209 | { | |
| 210 | this.flowX = b; | |
| 211 | } | |
| 212 | ||
| 213 | /** If non-<code>null</code> (<code>null</code> is default) these value will be used as the default gaps between the columns in the grid. | |
| 214 | * @return The default grid gap between columns in the grid. <code>null</code> if the platform default is used. | |
| 215 | */ | |
| 216 | public final BoundSize getGridGapX() | |
| 217 | { | |
| 218 | return gridGapX; | |
| 219 | } | |
| 220 | ||
| 221 | /** If non-<code>null</code> (<code>null</code> is default) these value will be used as the default gaps between the columns in the grid. | |
| 222 | * @param x The default grid gap between columns in the grid. If <code>null</code> the platform default is used. | |
| 223 | */ | |
| 224 | public final void setGridGapX(BoundSize x) | |
| 225 | { | |
| 226 | this.gridGapX = x; | |
| 227 | } | |
| 228 | ||
| 229 | /** If non-<code>null</code> (<code>null</code> is default) these value will be used as the default gaps between the rows in the grid. | |
| 230 | * @return The default grid gap between rows in the grid. <code>null</code> if the platform default is used. | |
| 231 | */ | |
| 232 | public final BoundSize getGridGapY() | |
| 233 | { | |
| 234 | return gridGapY; | |
| 235 | } | |
| 236 | ||
| 237 | /** If non-<code>null</code> (<code>null</code> is default) these value will be used as the default gaps between the rows in the grid. | |
| 238 | * @param y The default grid gap between rows in the grid. If <code>null</code> the platform default is used. | |
| 239 | */ | |
| 240 | public final void setGridGapY(BoundSize y) | |
| 241 | { | |
| 242 | this.gridGapY = y; | |
| 243 | } | |
| 244 | ||
| 245 | /** How a component that is hidden (not visible) should be treated by default. | |
| 246 | * @return The mode:<br> | |
| 247 | * 0 == Normal. Bounds will be caclulated as if the component was visible.<br> | |
| 248 | * 1 == If hidden the size will be 0, 0 but the gaps remain.<br> | |
| 249 | * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br> | |
| 250 | * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid.. | |
| 251 | */ | |
| 252 | public final int getHideMode() | |
| 253 | { | |
| 254 | return hideMode; | |
| 255 | } | |
| 256 | ||
| 257 | /** How a component that is hidden (not visible) should be treated. | |
| 258 | * @param mode The mode:<br> | |
| 259 | * 0 == Normal. Bounds will be caclulated as if the component was visible.<br> | |
| 260 | * 1 == If hidden the size will be 0, 0 but the gaps remain.<br> | |
| 261 | * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br> | |
| 262 | * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid.. | |
| 263 | */ | |
| 264 | public final void setHideMode(int mode) | |
| 265 | { | |
| 266 | if (mode < 0 || mode > 3) | |
| 267 | throw new IllegalArgumentException("Wrong hideMode: " + mode); | |
| 268 | ||
| 269 | this.hideMode = mode; | |
| 270 | } | |
| 271 | ||
| 272 | /** The insets for the layed out panel. The insets will be an empty space around the components in the panel. <code>null</code> values | |
| 273 | * means that the default panel insets for the platform is used. See {@link PlatformDefaults#setDialogInsets(net.miginfocom.layout.UnitValue, net.miginfocom.layout.UnitValue, net.miginfocom.layout.UnitValue, net.miginfocom.layout.UnitValue)}. | |
| 274 | * @return The insets. Of length 4 (top, left, bottom, right) or <code>null</code>. The elements (1 to 4) may be <code>null</code>. The array is a copy and can be used freely. | |
| 275 | * @see net.miginfocom.layout.ConstraintParser#parseInsets(String, boolean) | |
| 276 | */ | |
| 277 | public final UnitValue[] getInsets() | |
| 278 | { | |
| 279 | return insets != null ? new UnitValue[] {insets[0], insets[1], insets[2], insets[3]} : null; | |
| 280 | } | |
| 281 | ||
| 282 | /** The insets for the layed out panel. The insets will be an empty space around the components in the panel. <code>null</code> values | |
| 283 | * means that the default panel insets for the platform is used. See {@link PlatformDefaults#setDialogInsets(net.miginfocom.layout.UnitValue, net.miginfocom.layout.UnitValue, net.miginfocom.layout.UnitValue, net.miginfocom.layout.UnitValue)}. | |
| 284 | * @param ins The new insets. Must be of length 4 (top, left, bottom, right) or <code>null</code>. The elements (1 to 4) may be <code>null</code> to use | |
| 285 | * the platform default for that side. The array is copied for storage. | |
| 286 | * @see net.miginfocom.layout.ConstraintParser#parseInsets(String, boolean) | |
| 287 | */ | |
| 288 | public final void setInsets(UnitValue[] ins) | |
| 289 | { | |
| 290 | this.insets = ins != null ? new UnitValue[] {ins[0], ins[1], ins[2], ins[3]} : null; | |
| 291 | } | |
| 292 | ||
| 293 | /** If the layout should be forced to be left-to-right or right-to-left. A value of <code>null</code> is default and | |
| 294 | * means that this will be picked up from the {@link java.util.Locale} that the container being layed out is reporting. | |
| 295 | * @return <code>Boolean.TRUE</code> if force left-to-right. <code>Boolean.FALSE</code> if force tight-to-left. <code>null</code> | |
| 296 | * for the default "let the current Locale decide". | |
| 297 | */ | |
| 298 | public final Boolean getLeftToRight() | |
| 299 | { | |
| 300 | return leftToRight; | |
| 301 | } | |
| 302 | ||
| 303 | /** If the layout should be forced to be left-to-right or right-to-left. A value of <code>null</code> is default and | |
| 304 | * means that this will be picked up from the {@link java.util.Locale} that the container being layed out is reporting. | |
| 305 | * @param b <code>Boolean.TRUE</code> to force left-to-right. <code>Boolean.FALSE</code> to force tight-to-left. <code>null</code> | |
| 306 | * for the default "let the current Locale decide". | |
| 307 | */ | |
| 308 | public final void setLeftToRight(Boolean b) | |
| 309 | { | |
| 310 | this.leftToRight = b; | |
| 311 | } | |
| 312 | ||
| 313 | /** If the whole layout should be non grid based. It is the same as setting the "nogrid" property on every row/column in the grid. | |
| 314 | * @return <code>true</code> means not grid based. <code>false</code> is default. | |
| 315 | */ | |
| 316 | public final boolean isNoGrid() | |
| 317 | { | |
| 318 | return noGrid; | |
| 319 | } | |
| 320 | ||
| 321 | /** If the whole layout should be non grid based. It is the same as setting the "nogrid" property on every row/column in the grid. | |
| 322 | * @param b <code>true</code> means no grid. <code>false</code> is default. | |
| 323 | */ | |
| 324 | public final void setNoGrid(boolean b) | |
| 325 | { | |
| 326 | this.noGrid = b; | |
| 327 | } | |
| 328 | ||
| 329 | /** If the layout should go from the default top-to-bottom in the grid instead of the optinal bottom-to-top. | |
| 330 | * @return <code>true</code> for the default top-to-bottom. | |
| 331 | */ | |
| 332 | public final boolean isTopToBottom() | |
| 333 | { | |
| 334 | return topToBottom; | |
| 335 | } | |
| 336 | ||
| 337 | /** If the layout should go from the default top-to-bottom in the grid instead of the optinal bottom-to-top. | |
| 338 | * @param b <code>true</code> for the default top-to-bottom. | |
| 339 | */ | |
| 340 | public final void setTopToBottom(boolean b) | |
| 341 | { | |
| 342 | this.topToBottom = b; | |
| 343 | } | |
| 344 | ||
| 345 | /** If visual padding should be automatically used and compensated for by this layout instance. | |
| 346 | * @return <code>true</code> if visual padding. | |
| 347 | */ | |
| 348 | public final boolean isVisualPadding() | |
| 349 | { | |
| 350 | return visualPadding; | |
| 351 | } | |
| 352 | ||
| 353 | /** If visual padding should be automatically used and compensated for by this layout instance. | |
| 354 | * @param b <code>true</code> turns on visual padding. | |
| 355 | */ | |
| 356 | public final void setVisualPadding(boolean b) | |
| 357 | { | |
| 358 | this.visualPadding = b; | |
| 359 | } | |
| 360 | ||
| 361 | /** Returns after what cell the grid should always auto wrap. | |
| 362 | * @return After what cell the grid should always auto wrap. If <code>0</code> the number of columns/rows in the | |
| 363 | * {@link net.miginfocom.layout.AC} is used. <code>LayoutUtil.INF</code> is used for no auto wrap. | |
| 364 | */ | |
| 365 | public final int getWrapAfter() | |
| 366 | { | |
| 367 | return wrapAfter; | |
| 368 | } | |
| 369 | ||
| 370 | /** Sets after what cell the grid should always auto wrap. | |
| 371 | * @param count After what cell the grid should always auto wrap. If <code>0</code> the number of columns/rows in the | |
| 372 | * {@link net.miginfocom.layout.AC} is used. <code>LayoutUtil.INF</code> is used for no auto wrap. | |
| 373 | */ | |
| 374 | public final void setWrapAfter(int count) | |
| 375 | { | |
| 376 | this.wrapAfter = count; | |
| 377 | } | |
| 378 | ||
| 379 | /** Returns the "pack width" for the <b>window</b> that this container is located in. When the size of this container changes | |
| 380 | * the size of the window will be corrected to be within this BoundsSize. It can be used to set the minimum and/or maximum size of the window | |
| 381 | * as well as the size window should optimally get. This optimal size is normaly its "preferred" size which is why "preferred" | |
| 382 | * is the normal value to set here. | |
| 383 | * <p> | |
| 384 | * ":push" can be appended to the bound size to only push the size bigger and never shrink it if the preferred size gets smaller. | |
| 385 | * <p> | |
| 386 | * E.g. "pref", "100:pref", "pref:700", "300::700", "pref:push" | |
| 387 | * @return The current value. Never <code>null</code>. Check if not set with <code>.isUnset()</code>. | |
| 388 | * @since 3.5 | |
| 389 | */ | |
| 390 | public final BoundSize getPackWidth() | |
| 391 | { | |
| 392 | return packW; | |
| 393 | } | |
| 394 | ||
| 395 | /** Sets the "pack width" for the <b>window</b> that this container is located in. When the size of this container changes | |
| 396 | * the size of the window will be corrected to be within this BoundsSize. It can be used to set the minimum and/or maximum size of the window | |
| 397 | * as well as the size window should optimally get. This optimal size is normaly its "preferred" size which is why "preferred" | |
| 398 | * is the normal value to set here. | |
| 399 | * <p> | |
| 400 | * ":push" can be appended to the bound size to only push the size bigger and never shrink it if the preferred size gets smaller. | |
| 401 | * <p> | |
| 402 | * E.g. "pref", "100:pref", "pref:700", "300::700", "pref:push" | |
| 403 | * @param size The new pack size. If <code>null</code> it will be corrected to an "unset" BoundSize. | |
| 404 | * @since 3.5 | |
| 405 | */ | |
| 406 | public final void setPackWidth(BoundSize size) | |
| 407 | { | |
| 408 | packW = size != null ? size : BoundSize.NULL_SIZE; | |
| 409 | } | |
| 410 | ||
| 411 | /** Returns the "pack height" for the <b>window</b> that this container is located in. When the size of this container changes | |
| 412 | * the size of the window will be corrected to be within this BoundsSize. It can be used to set the minimum and/or maximum size of the window | |
| 413 | * as well as the size window should optimally get. This optimal size is normaly its "preferred" size which is why "preferred" | |
| 414 | * is the normal value to set here. | |
| 415 | * <p> | |
| 416 | * ":push" can be appended to the bound size to only push the size bigger and never shrink it if the preferred size gets smaller. | |
| 417 | * <p> | |
| 418 | * E.g. "pref", "100:pref", "pref:700", "300::700", "pref:push" | |
| 419 | * @return The current value. Never <code>null</code>. Check if not set with <code>.isUnset()</code>. | |
| 420 | * @since 3.5 | |
| 421 | */ | |
| 422 | public final BoundSize getPackHeight() | |
| 423 | { | |
| 424 | return packH; | |
| 425 | } | |
| 426 | ||
| 427 | /** Sets the "pack height" for the <b>window</b> that this container is located in. When the size of this container changes | |
| 428 | * the size of the window will be corrected to be within this BoundsSize. It can be used to set the minimum and/or maximum size of the window | |
| 429 | * as well as the size window should optimally get. This optimal size is normaly its "preferred" size which is why "preferred" | |
| 430 | * is the normal value to set here. | |
| 431 | * <p> | |
| 432 | * ":push" can be appended to the bound size to only push the size bigger and never shrink it if the preferred size gets smaller. | |
| 433 | * <p> | |
| 434 | * E.g. "pref", "100:pref", "pref:700", "300::700", "pref:push" | |
| 435 | * @param size The new pack size. If <code>null</code> it will be corrected to an "unset" BoundSize. | |
| 436 | * @since 3.5 | |
| 437 | */ | |
| 438 | public final void setPackHeight(BoundSize size) | |
| 439 | { | |
| 440 | packH = size != null ? size : BoundSize.NULL_SIZE; | |
| 441 | } | |
| 442 | ||
| 443 | ||
| 444 | /** If there is a resize of the window due to packing (see {@link #setPackHeight(BoundSize)} this value, which is between 0f and 1f, | |
| 445 | * decides where the extra/surpurflous size is placed. 0f means that the window will resize so that the upper part moves up and the | |
| 446 | * lower side stays in the same place. 0.5f will expand/reduce the window equally upwards and downwards. 1f will do the opposite of 0f | |
| 447 | * of course. | |
| 448 | * @return The pack alignment. Always between 0f and 1f, inclusive. | |
| 449 | * @since 3.5 | |
| 450 | */ | |
| 451 | public final float getPackHeightAlign() | |
| 452 | { | |
| 453 | return phAlign; | |
| 454 | } | |
| 455 | ||
| 456 | /** If there is a resize of the window due to packing (see {@link #setPackHeight(BoundSize)} this value, which is between 0f and 1f, | |
| 457 | * decides where the extra/surpurflous size is placed. 0f means that the window will resize so that the upper part moves up and the | |
| 458 | * lower side stays in the same place. 0.5f will expand/reduce the window equally upwards and downwards. 1f will do the opposite of 0f | |
| 459 | * of course. | |
| 460 | * @param align The pack alignment. Always between 0f and 1f, inclusive. Values outside this will be truncated. | |
| 461 | * @since 3.5 | |
| 462 | */ | |
| 463 | public final void setPackHeightAlign(float align) | |
| 464 | { | |
| 465 | phAlign = Math.max(0f, Math.min(1f, align)); | |
| 466 | } | |
| 467 | ||
| 468 | /** If there is a resize of the window due to packing (see {@link #setPackHeight(BoundSize)} this value, which is between 0f and 1f, | |
| 469 | * decides where the extra/surpurflous size is placed. 0f means that the window will resize so that the left part moves left and the | |
| 470 | * right side stays in the same place. 0.5f will expand/reduce the window equally to the right and lefts. 1f will do the opposite of 0f | |
| 471 | * of course. | |
| 472 | * @return The pack alignment. Always between 0f and 1f, inclusive. | |
| 473 | * @since 3.5 | |
| 474 | */ | |
| 475 | public final float getPackWidthAlign() | |
| 476 | { | |
| 477 | return pwAlign; | |
| 478 | } | |
| 479 | ||
| 480 | /** If there is a resize of the window due to packing (see {@link #setPackHeight(BoundSize)} this value, which is between 0f and 1f, | |
| 481 | * decides where the extra/surpurflous size is placed. 0f means that the window will resize so that the left part moves left and the | |
| 482 | * right side stays in the same place. 0.5f will expand/reduce the window equally to the right and lefts. 1f will do the opposite of 0f | |
| 483 | * of course. | |
| 484 | * @param align The pack alignment. Always between 0f and 1f, inclusive. Values outside this will be truncated. | |
| 485 | * @since 3.5 | |
| 486 | */ | |
| 487 | public final void setPackWidthAlign(float align) | |
| 488 | { | |
| 489 | pwAlign = Math.max(0f, Math.min(1f, align)); | |
| 490 | } | |
| 491 | ||
| 492 | /** Returns the minimum/preferred/maximum size for the container that this layout constraint is set for. Any of these | |
| 493 | * sizes that is not <code>null</code> will be returned directly instead of determining the correspondig size through | |
| 494 | * asking the components in this container. | |
| 495 | * @return The width for the container that this layout constraint is set for. Not <code>null</code> but | |
| 496 | * all sizes can be <code>null</code>. | |
| 497 | * @since 3.5 | |
| 498 | */ | |
| 499 | public final BoundSize getWidth() | |
| 500 | { | |
| 501 | return width; | |
| 502 | } | |
| 503 | ||
| 504 | /** Sets the minimum/preferred/maximum size for the container that this layout constraint is set for. Any of these | |
| 505 | * sizes that is not <code>null</code> will be returned directly instead of determining the correspondig size through | |
| 506 | * asking the components in this container. | |
| 507 | * @param size The width for the container that this layout constraint is set for. <code>null</code> is translated to | |
| 508 | * a bound size containing only null sizes. | |
| 509 | * @since 3.5 | |
| 510 | */ | |
| 511 | public final void setWidth(BoundSize size) | |
| 512 | { | |
| 513 | this.width = size != null ? size : BoundSize.NULL_SIZE; | |
| 514 | } | |
| 515 | ||
| 516 | /** Returns the minimum/preferred/maximum size for the container that this layout constraint is set for. Any of these | |
| 517 | * sizes that is not <code>null</code> will be returned directly instead of determining the correspondig size through | |
| 518 | * asking the components in this container. | |
| 519 | * @return The height for the container that this layout constraint is set for. Not <code>null</code> but | |
| 520 | * all sizes can be <code>null</code>. | |
| 521 | * @since 3.5 | |
| 522 | */ | |
| 523 | public final BoundSize getHeight() | |
| 524 | { | |
| 525 | return height; | |
| 526 | } | |
| 527 | ||
| 528 | /** Sets the minimum/preferred/maximum size for the container that this layout constraint is set for. Any of these | |
| 529 | * sizes that is not <code>null</code> will be returned directly instead of determining the correspondig size through | |
| 530 | * asking the components in this container. | |
| 531 | * @param size The height for the container that this layout constraint is set for. <code>null</code> is translated to | |
| 532 | * a bound size containing only null sizes. | |
| 533 | * @since 3.5 | |
| 534 | */ | |
| 535 | public final void setHeight(BoundSize size) | |
| 536 | { | |
| 537 | this.height = size != null ? size : BoundSize.NULL_SIZE; | |
| 538 | } | |
| 539 | ||
| 540 | // ************************************************************************ | |
| 541 | // * Builder methods. | |
| 542 | // ************************************************************************ | |
| 543 | ||
| 544 | /** Short for, and thus same as, <code>.pack("pref", "pref")</code>. | |
| 545 | * <p> | |
| 546 | * Same functionality as {@link #setPackHeight(BoundSize)} and {@link #setPackWidth(net.miginfocom.layout.BoundSize)} | |
| 547 | * only this method returns <code>this</code> for chaining multiple calls. | |
| 548 | * <p> | |
| 549 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 550 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 551 | * @since 3.5 | |
| 552 | */ | |
| 553 | public final LC pack() | |
| 554 | { | |
| 555 | return pack("pref", "pref"); | |
| 556 | } | |
| 557 | ||
| 558 | /** Sets the pack width and height. | |
| 559 | * <p> | |
| 560 | * Same functionality as {@link #setPackHeight(BoundSize)} and {@link #setPackWidth(net.miginfocom.layout.BoundSize)} | |
| 561 | * only this method returns <code>this</code> for chaining multiple calls. | |
| 562 | * <p> | |
| 563 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 564 | * @param width The pack width. May be <code>null</code>. | |
| 565 | * @param height The pack height. May be <code>null</code>. | |
| 566 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 567 | * @since 3.5 | |
| 568 | */ | |
| 569 | public final LC pack(String width, String height) | |
| 570 | { | |
| 571 | setPackWidth(width != null ? ConstraintParser.parseBoundSize(width, false, false) : BoundSize.NULL_SIZE); | |
| 572 | setPackHeight(height != null ? ConstraintParser.parseBoundSize(height, false, false) : BoundSize.NULL_SIZE); | |
| 573 | return this; | |
| 574 | } | |
| 575 | ||
| 576 | /** Sets the pack width and height alignment. | |
| 577 | * <p> | |
| 578 | * Same functionality as {@link #setPackHeightAlign(float)} and {@link #setPackWidthAlign(float)} | |
| 579 | * only this method returns <code>this</code> for chaining multiple calls. | |
| 580 | * <p> | |
| 581 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 582 | * @param alignX The pack width alignment. 0.5f is default. | |
| 583 | * @param alignY The pack height alignment. 0.5f is default. | |
| 584 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 585 | * @since 3.5 | |
| 586 | */ | |
| 587 | public final LC packAlign(float alignX, float alignY) | |
| 588 | { | |
| 589 | setPackWidthAlign(alignX); | |
| 590 | setPackHeightAlign(alignY); | |
| 591 | return this; | |
| 592 | } | |
| 593 | ||
| 594 | /** Sets a wrap after the number of columns/rows that is defined in the {@link net.miginfocom.layout.AC}. | |
| 595 | * <p> | |
| 596 | * Same functionality as {@link #setWrapAfter(int 0)} only this method returns <code>this</code> for chaining multiple calls. | |
| 597 | * <p> | |
| 598 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 599 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 600 | */ | |
| 601 | public final LC wrap() | |
| 602 | { | |
| 603 | setWrapAfter(0); | |
| 604 | return this; | |
| 605 | } | |
| 606 | ||
| 607 | /** Same functionality as {@link #setWrapAfter(int)} only this method returns <code>this</code> for chaining multiple calls. | |
| 608 | * <p> | |
| 609 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 610 | * @param count After what cell the grid should always auto wrap. If <code>0</code> the number of columns/rows in the | |
| 611 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 612 | */ | |
| 613 | public final LC wrapAfter(int count) | |
| 614 | { | |
| 615 | setWrapAfter(count); | |
| 616 | return this; | |
| 617 | } | |
| 618 | ||
| 619 | /** Same functionality as {@link #setNoCache(boolean true)} only this method returns <code>this</code> for chaining multiple calls. | |
| 620 | * <p> | |
| 621 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 622 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 623 | */ | |
| 624 | public final LC noCache() | |
| 625 | { | |
| 626 | setNoCache(true); | |
| 627 | return this; | |
| 628 | } | |
| 629 | ||
| 630 | /** Same functionality as {@link #setFlowX(boolean false)} only this method returns <code>this</code> for chaining multiple calls. | |
| 631 | * <p> | |
| 632 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 633 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 634 | */ | |
| 635 | public final LC flowY() | |
| 636 | { | |
| 637 | setFlowX(false); | |
| 638 | return this; | |
| 639 | } | |
| 640 | ||
| 641 | /** Same functionality as {@link #setFlowX(boolean true)} only this method returns <code>this</code> for chaining multiple calls. | |
| 642 | * <p> | |
| 643 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 644 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 645 | */ | |
| 646 | public final LC flowX() | |
| 647 | { | |
| 648 | setFlowX(true); | |
| 649 | return this; | |
| 650 | } | |
| 651 | ||
| 652 | /** Same functionality as {@link #setFillX(boolean true)} and {@link #setFillY(boolean true)} conmbined.T his method returns | |
| 653 | * <code>this</code> for chaining multiple calls. | |
| 654 | * <p> | |
| 655 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 656 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 657 | */ | |
| 658 | public final LC fill() | |
| 659 | { | |
| 660 | setFillX(true); | |
| 661 | setFillY(true); | |
| 662 | return this; | |
| 663 | } | |
| 664 | ||
| 665 | /** Same functionality as {@link #setFillX(boolean true)} only this method returns <code>this</code> for chaining multiple calls. | |
| 666 | * <p> | |
| 667 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 668 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 669 | */ | |
| 670 | public final LC fillX() | |
| 671 | { | |
| 672 | setFillX(true); | |
| 673 | return this; | |
| 674 | } | |
| 675 | ||
| 676 | /** Same functionality as {@link #setFillY(boolean true)} only this method returns <code>this</code> for chaining multiple calls. | |
| 677 | * <p> | |
| 678 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 679 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 680 | */ | |
| 681 | public final LC fillY() | |
| 682 | { | |
| 683 | setFillY(true); | |
| 684 | return this; | |
| 685 | } | |
| 686 | ||
| 687 | /** Same functionality as {@link #setLeftToRight(Boolean)} only this method returns <code>this</code> for chaining multiple calls. | |
| 688 | * <p> | |
| 689 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 690 | * @param b <code>true</code> for forcing left-to-right. <code>false</code> for forcing right-to-left. | |
| 691 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 692 | */ | |
| 693 | public final LC leftToRight(boolean b) | |
| 694 | { | |
| 695 | setLeftToRight(b ? Boolean.TRUE : Boolean.FALSE); | |
| 696 | return this; | |
| 697 | } | |
| 698 | ||
| 699 | /** Same functionality as setLeftToRight(false) only this method returns <code>this</code> for chaining multiple calls. | |
| 700 | * <p> | |
| 701 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 702 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 703 | * @since 3.7.2 | |
| 704 | */ | |
| 705 | public final LC rightToLeft() | |
| 706 | { | |
| 707 | setLeftToRight(Boolean.FALSE); | |
| 708 | return this; | |
| 709 | } | |
| 710 | ||
| 711 | /** Same functionality as {@link #setTopToBottom(boolean false)} only this method returns <code>this</code> for chaining multiple calls. | |
| 712 | * <p> | |
| 713 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 714 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 715 | */ | |
| 716 | public final LC bottomToTop() | |
| 717 | { | |
| 718 | setTopToBottom(false); | |
| 719 | return this; | |
| 720 | } | |
| 721 | ||
| 722 | /** Same functionality as {@link #setTopToBottom(boolean true)} only this method returns <code>this</code> for chaining multiple calls. | |
| 723 | * <p> | |
| 724 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 725 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 726 | * @since 3.7.2 | |
| 727 | */ | |
| 728 | public final LC topToBottom() | |
| 729 | { | |
| 730 | setTopToBottom(true); | |
| 731 | return this; | |
| 732 | } | |
| 733 | ||
| 734 | /** Same functionality as {@link #setNoGrid(boolean true)} only this method returns <code>this</code> for chaining multiple calls. | |
| 735 | * <p> | |
| 736 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 737 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 738 | */ | |
| 739 | public final LC noGrid() | |
| 740 | { | |
| 741 | setNoGrid(true); | |
| 742 | return this; | |
| 743 | } | |
| 744 | ||
| 745 | /** Same functionality as {@link #setVisualPadding(boolean false)} only this method returns <code>this</code> for chaining multiple calls. | |
| 746 | * <p> | |
| 747 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 748 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 749 | */ | |
| 750 | public final LC noVisualPadding() | |
| 751 | { | |
| 752 | setVisualPadding(false); | |
| 753 | return this; | |
| 754 | } | |
| 755 | ||
| 756 | /** Sets the same inset (expressed as a <code>UnitValue</code>, e.g. "10px" or "20mm") all around. | |
| 757 | * <p> | |
| 758 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 759 | * @param allSides The unit value to set for all sides. May be <code>null</code> which means that the default panel insets | |
| 760 | * for the platform is used. | |
| 761 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 762 | * @see #setInsets(UnitValue[]) | |
| 763 | */ | |
| 764 | public final LC insetsAll(String allSides) | |
| 765 | { | |
| 766 | UnitValue insH = ConstraintParser.parseUnitValue(allSides, true); | |
| 767 | UnitValue insV = ConstraintParser.parseUnitValue(allSides, false); | |
| 768 | insets = new UnitValue[] {insV, insH, insV, insH}; // No setter to avoid copy again | |
| 769 | return this; | |
| 770 | } | |
| 771 | ||
| 772 | /** Same functionality as <code>setInsets(ConstraintParser.parseInsets(s, true))</code>. This method returns <code>this</code> | |
| 773 | * for chaining multiple calls. | |
| 774 | * <p> | |
| 775 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 776 | * @param s The string to parse. E.g. "10 10 10 10" or "20". If less than 4 groups the last will be used for the missing. | |
| 777 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 778 | * @see #setInsets(UnitValue[]) | |
| 779 | */ | |
| 780 | public final LC insets(String s) | |
| 781 | { | |
| 782 | insets = ConstraintParser.parseInsets(s, true); | |
| 783 | return this; | |
| 784 | } | |
| 785 | ||
| 786 | /** Sets the different insets (expressed as a <code>UnitValue</code>s, e.g. "10px" or "20mm") for the corresponding sides. | |
| 787 | * <p> | |
| 788 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 789 | * @param top The top inset. E.g. "10px" or "10mm" or "related". May be <code>null</code> in which case the default inset for this | |
| 790 | * side for the platform will be used. | |
| 791 | * @param left The left inset. E.g. "10px" or "10mm" or "related". May be <code>null</code> in which case the default inset for this | |
| 792 | * side for the platform will be used. | |
| 793 | * @param bottom The bottom inset. E.g. "10px" or "10mm" or "related". May be <code>null</code> in which case the default inset for this | |
| 794 | * side for the platform will be used. | |
| 795 | * @param right The right inset. E.g. "10px" or "10mm" or "related". May be <code>null</code> in which case the default inset for this | |
| 796 | * side for the platform will be used. | |
| 797 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 798 | * @see #setInsets(UnitValue[]) | |
| 799 | */ | |
| 800 | public final LC insets(String top, String left, String bottom, String right) | |
| 801 | { | |
| 802 | insets = new UnitValue[] { // No setter to avoid copy again | |
| 803 | ConstraintParser.parseUnitValue(top, false), | |
| 804 | ConstraintParser.parseUnitValue(left, true), | |
| 805 | ConstraintParser.parseUnitValue(bottom, false), | |
| 806 | ConstraintParser.parseUnitValue(right, true)}; | |
| 807 | return this; | |
| 808 | } | |
| 809 | ||
| 810 | /** Same functionality as <code>setAlignX(ConstraintParser.parseUnitValueOrAlign(unitValue, true))</code> only this method returns <code>this</code> | |
| 811 | * for chaining multiple calls. | |
| 812 | * <p> | |
| 813 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 814 | * @param align The align keyword or for instance "100px". E.g "left", "right", "leading" or "trailing". | |
| 815 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 816 | * @see #setAlignX(UnitValue) | |
| 817 | */ | |
| 818 | public final LC alignX(String align) | |
| 819 | { | |
| 820 | setAlignX(ConstraintParser.parseUnitValueOrAlign(align, true, null)); | |
| 821 | return this; | |
| 822 | } | |
| 823 | ||
| 824 | /** Same functionality as <code>setAlignY(ConstraintParser.parseUnitValueOrAlign(align, false))</code> only this method returns <code>this</code> for chaining multiple calls. | |
| 825 | * <p> | |
| 826 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 827 | * @param align The align keyword or for instance "100px". E.g "top" or "bottom". | |
| 828 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 829 | * @see #setAlignY(UnitValue) | |
| 830 | */ | |
| 831 | public final LC alignY(String align) | |
| 832 | { | |
| 833 | setAlignY(ConstraintParser.parseUnitValueOrAlign(align, false, null)); | |
| 834 | return this; | |
| 835 | } | |
| 836 | ||
| 837 | /** Sets both the alignX and alignY as the same time. | |
| 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 | * @param ax The align keyword or for instance "100px". E.g "left", "right", "leading" or "trailing". | |
| 841 | * @param ay The align keyword or for instance "100px". E.g "top" or "bottom". | |
| 842 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 843 | * @see #alignX(String) | |
| 844 | * @see #alignY(String) | |
| 845 | */ | |
| 846 | public final LC align(String ax, String ay) | |
| 847 | { | |
| 848 | if (ax != null) | |
| 849 | alignX(ax); | |
| 850 | ||
| 851 | if (ay != null) | |
| 852 | alignY(ay); | |
| 853 | ||
| 854 | return this; | |
| 855 | } | |
| 856 | ||
| 857 | /** Same functionality as <code>setGridGapX(ConstraintParser.parseBoundSize(boundsSize, true, true))</code> only this method | |
| 858 | * returns <code>this</code> for chaining multiple calls. | |
| 859 | * <p> | |
| 860 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 861 | * @param boundsSize The <code>BoundSize</code> of the gap. This is a minimum and/or preferred and/or maximum size. E.g. | |
| 862 | * <code>"50:100:200"</code> or <code>"100px"</code>. | |
| 863 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 864 | * @see #setGridGapX(BoundSize) | |
| 865 | */ | |
| 866 | public final LC gridGapX(String boundsSize) | |
| 867 | { | |
| 868 | setGridGapX(ConstraintParser.parseBoundSize(boundsSize, true, true)); | |
| 869 | return this; | |
| 870 | } | |
| 871 | ||
| 872 | /** Same functionality as <code>setGridGapY(ConstraintParser.parseBoundSize(boundsSize, true, false))</code> only this method | |
| 873 | * 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 boundsSize The <code>BoundSize</code> of the gap. This is a minimum and/or preferred and/or maximum size. E.g. | |
| 877 | * <code>"50:100:200"</code> or <code>"100px"</code>. | |
| 878 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 879 | * @see #setGridGapY(BoundSize) | |
| 880 | */ | |
| 881 | public final LC gridGapY(String boundsSize) | |
| 882 | { | |
| 883 | setGridGapY(ConstraintParser.parseBoundSize(boundsSize, true, false)); | |
| 884 | return this; | |
| 885 | } | |
| 886 | ||
| 887 | /** Sets both grid gaps at the same time. see {@link #gridGapX(String)} and {@link #gridGapY(String)}. | |
| 888 | * <p> | |
| 889 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 890 | * @param gapx The <code>BoundSize</code> of the gap. This is a minimum and/or preferred and/or maximum size. E.g. | |
| 891 | * <code>"50:100:200"</code> or <code>"100px"</code>. | |
| 892 | * @param gapy The <code>BoundSize</code> of the gap. This is a minimum and/or preferred and/or maximum size. E.g. | |
| 893 | * <code>"50:100:200"</code> or <code>"100px"</code>. | |
| 894 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 895 | * @see #gridGapX(String) | |
| 896 | * @see #gridGapY(String) | |
| 897 | */ | |
| 898 | public final LC gridGap(String gapx, String gapy) | |
| 899 | { | |
| 900 | if (gapx != null) | |
| 901 | gridGapX(gapx); | |
| 902 | ||
| 903 | if (gapy != null) | |
| 904 | gridGapY(gapy); | |
| 905 | ||
| 906 | return this; | |
| 907 | } | |
| 908 | ||
| 909 | /** Same functionality as {@link #setDebugMillis(int repaintMillis)} only this method returns <code>this</code> for chaining multiple calls. | |
| 910 | * <p> | |
| 911 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 912 | * @param repaintMillis The new debug repaint interval. | |
| 913 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 914 | * @see #setDebugMillis(int) | |
| 915 | */ | |
| 916 | public final LC debug(int repaintMillis) | |
| 917 | { | |
| 918 | setDebugMillis(repaintMillis); | |
| 919 | return this; | |
| 920 | } | |
| 921 | ||
| 922 | /** Same functionality as {@link #setHideMode(int mode)} only this method returns <code>this</code> for chaining multiple calls. | |
| 923 | * <p> | |
| 924 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 925 | * @param mode The mode:<br> | |
| 926 | * 0 == Normal. Bounds will be calculated as if the component was visible.<br> | |
| 927 | * 1 == If hidden the size will be 0, 0 but the gaps remain.<br> | |
| 928 | * 2 == If hidden the size will be 0, 0 and gaps set to zero.<br> | |
| 929 | * 3 == If hidden the component will be disregarded completely and not take up a cell in the grid.. | |
| 930 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 931 | * @see #setHideMode(int) | |
| 932 | */ | |
| 933 | public final LC hideMode(int mode) | |
| 934 | { | |
| 935 | setHideMode(mode); | |
| 936 | return this; | |
| 937 | } | |
| 938 | ||
| 939 | /** The minimum width for the container. The value will override any value that is set on the container itself. | |
| 940 | * <p> | |
| 941 | * For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com. | |
| 942 | * @param width The width expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". | |
| 943 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 944 | */ | |
| 945 | public final LC minWidth(String width) | |
| 946 | { | |
| 947 | setWidth(LayoutUtil.derive(getWidth(), ConstraintParser.parseUnitValue(width, true), null, null)); | |
| 948 | return this; | |
| 949 | } | |
| 950 | ||
| 951 | /** The width for the container as a min and/or preferred and/or maximum width. The value will override any value that is set on | |
| 952 | * the container itself. | |
| 953 | * <p> | |
| 954 | * For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com. | |
| 955 | * @param width The width expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px". | |
| 956 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 957 | */ | |
| 958 | public final LC width(String width) | |
| 959 | { | |
| 960 | setWidth(ConstraintParser.parseBoundSize(width, false, true)); | |
| 961 | return this; | |
| 962 | } | |
| 963 | ||
| 964 | /** The maximum width for the container. The value will override any value that is set on the container itself. | |
| 965 | * <p> | |
| 966 | * For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com. | |
| 967 | * @param width The width expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". | |
| 968 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 969 | */ | |
| 970 | public final LC maxWidth(String width) | |
| 971 | { | |
| 972 | setWidth(LayoutUtil.derive(getWidth(), null, null, ConstraintParser.parseUnitValue(width, true))); | |
| 973 | return this; | |
| 974 | } | |
| 975 | ||
| 976 | /** The minimum height for the container. The value will override any value that is set on the container itself. | |
| 977 | * <p> | |
| 978 | * For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com. | |
| 979 | * @param height The height expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". | |
| 980 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 981 | */ | |
| 982 | public final LC minHeight(String height) | |
| 983 | { | |
| 984 | setHeight(LayoutUtil.derive(getHeight(), ConstraintParser.parseUnitValue(height, false), null, null)); | |
| 985 | return this; | |
| 986 | } | |
| 987 | ||
| 988 | /** The height for the container as a min and/or preferred and/or maximum height. The value will override any value that is set on | |
| 989 | * the container itself. | |
| 990 | * <p> | |
| 991 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcontainers.com. | |
| 992 | * @param height The height expressed as a <code>BoundSize</code>. E.g. "50:100px:200mm" or "100px". | |
| 993 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 994 | */ | |
| 995 | public final LC height(String height) | |
| 996 | { | |
| 997 | setHeight(ConstraintParser.parseBoundSize(height, false, false)); | |
| 998 | return this; | |
| 999 | } | |
| 1000 | ||
| 1001 | /** The maximum height for the container. The value will override any value that is set on the container itself. | |
| 1002 | * <p> | |
| 1003 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcontainers.com. | |
| 1004 | * @param height The height expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". | |
| 1005 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. | |
| 1006 | */ | |
| 1007 | public final LC maxHeight(String height) | |
| 1008 | { | |
| 1009 | setHeight(LayoutUtil.derive(getHeight(), null, null, ConstraintParser.parseUnitValue(height, false))); | |
| 1010 | return this; | |
| 1011 | } | |
| 1012 | ||
| 1013 | // ************************************************ | |
| 1014 | // Persistence Delegate and Serializable combined. | |
| 1015 | // ************************************************ | |
| 1016 | ||
| 1017 | private Object readResolve() throws ObjectStreamException | |
| 1018 | { | |
| 1019 | return LayoutUtil.getSerializedObject(this); | |
| 1020 | } | |
| 1021 | ||
| 1022 | public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException | |
| 1023 | { | |
| 1024 | LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in)); | |
| 1025 | } | |
| 1026 | ||
| 1027 | public void writeExternal(ObjectOutput out) throws IOException | |
| 1028 | { | |
| 1029 | if (getClass() == LC.class) | |
| 1030 | LayoutUtil.writeAsXML(out, this); | |
| 1031 | } | |
| 1032 | } |