| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
| AC |
|
| 1.5277777777777777;1.528 |
| 1 | package net.miginfocom.layout; | |
| 2 | ||
| 3 | import java.io.*; | |
| 4 | import java.util.ArrayList; | |
| 5 | ||
| 6 | /* | |
| 7 | * License (BSD): | |
| 8 | * ============== | |
| 9 | * | |
| 10 | * Copyright (c) 2004, Mikael Grev, MiG InfoCom AB. (miglayout (at) miginfocom (dot) com) | |
| 11 | * All rights reserved. | |
| 12 | * | |
| 13 | * Redistribution and use in source and binary forms, with or without modification, | |
| 14 | * are permitted provided that the following conditions are met: | |
| 15 | * Redistributions of source code must retain the above copyright notice, this list | |
| 16 | * of conditions and the following disclaimer. | |
| 17 | * Redistributions in binary form must reproduce the above copyright notice, this | |
| 18 | * list of conditions and the following disclaimer in the documentation and/or other | |
| 19 | * materials provided with the distribution. | |
| 20 | * Neither the name of the MiG InfoCom AB nor the names of its contributors may be | |
| 21 | * used to endorse or promote products derived from this software without specific | |
| 22 | * prior written permission. | |
| 23 | * | |
| 24 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND | |
| 25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | |
| 26 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
| 27 | * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
| 28 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | |
| 29 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, | |
| 30 | * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
| 31 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 32 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | |
| 33 | * OF SUCH DAMAGE. | |
| 34 | * | |
| 35 | * @version 1.0 | |
| 36 | * @author Mikael Grev, MiG InfoCom AB | |
| 37 | * Date: 2006-sep-08 | |
| 38 | */ | |
| 39 | ||
| 40 | /** A constraint that holds the column <b>or</b> row constraints for the grid. It also holds the gaps between the rows and columns. | |
| 41 | * <p> | |
| 42 | * This class is a holder and builder for a number of {@link net.miginfocom.layout.DimConstraint}s. | |
| 43 | * <p> | |
| 44 | * For a more thorough explanation of what these constraints do, and how to build the constraints, see the White Paper or Cheat Sheet at www.migcomponents.com. | |
| 45 | * <p> | |
| 46 | * Note that there are two way to build this constraint. Through String (e.g. <code>"[100]3[200,fill]"</code> or through API (E.g. | |
| 47 | * <code>new AxisConstraint().size("100").gap("3").size("200").fill()</code>. | |
| 48 | */ | |
| 49 | public final class AC implements Externalizable | |
| 50 | { | |
| 51 | private final ArrayList<DimConstraint> cList = new ArrayList<DimConstraint>(8); | |
| 52 | ||
| 53 | private transient int curIx = 0; | |
| 54 | ||
| 55 | /** Constructor. Creates an instance that can be configured manually. Will be initialized with a default | |
| 56 | * {@link net.miginfocom.layout.DimConstraint}. | |
| 57 | */ | |
| 58 | public AC() | |
| 59 | { | |
| 60 | cList.add(new DimConstraint()); | |
| 61 | } | |
| 62 | ||
| 63 | /** Property. The different {@link net.miginfocom.layout.DimConstraint}s that this object consists of. | |
| 64 | * These <code><DimConstraints/code> contains all information in this class. | |
| 65 | * <p> | |
| 66 | * Yes, we are embarrassingly aware that the method is misspelled. | |
| 67 | * @return The different {@link net.miginfocom.layout.DimConstraint}s that this object consists of. A new list and | |
| 68 | * never <code>null</code>. | |
| 69 | */ | |
| 70 | public final DimConstraint[] getConstaints() | |
| 71 | { | |
| 72 | return cList.toArray(new DimConstraint[cList.size()]); | |
| 73 | } | |
| 74 | ||
| 75 | /** Sets the different {@link net.miginfocom.layout.DimConstraint}s that this object should consists of. | |
| 76 | * <p> | |
| 77 | * Yes, we are embarrassingly aware that the method is misspelled. | |
| 78 | * @param constr The different {@link net.miginfocom.layout.DimConstraint}s that this object consists of. The list | |
| 79 | * will be copied for storage. <code>null</code> or and emty array will reset the constraints to one <code>DimConstraint</code> | |
| 80 | * with default values. | |
| 81 | */ | |
| 82 | public final void setConstaints(DimConstraint[] constr) | |
| 83 | { | |
| 84 | if (constr == null || constr.length < 1 ) | |
| 85 | constr = new DimConstraint[] {new DimConstraint()}; | |
| 86 | ||
| 87 | cList.clear(); | |
| 88 | cList.ensureCapacity(constr.length); | |
| 89 | for (DimConstraint c : constr) | |
| 90 | cList.add(c); | |
| 91 | } | |
| 92 | ||
| 93 | /** Returns the number of rows/columns that this constraints currently have. | |
| 94 | * @return The number of rows/columns that this constraints currently have. At least 1. | |
| 95 | */ | |
| 96 | public int getCount() | |
| 97 | { | |
| 98 | return cList.size(); | |
| 99 | } | |
| 100 | ||
| 101 | /** Sets the total number of rows/columns to <code>size</code>. If the number of rows/columns is already more | |
| 102 | * than <code>size</code> nothing will happen. | |
| 103 | * @param size The total number of rows/columns | |
| 104 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 105 | */ | |
| 106 | public final AC count(int size) | |
| 107 | { | |
| 108 | makeSize(size); | |
| 109 | return this; | |
| 110 | } | |
| 111 | ||
| 112 | /** Specifies that the current row/column should not be grid-like. The while row/colum will have its components layed out | |
| 113 | * in one single cell. It is the same as to say that the cells in this column/row will all be merged (a.k.a spanned). | |
| 114 | * <p> | |
| 115 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 116 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 117 | */ | |
| 118 | public final AC noGrid() | |
| 119 | { | |
| 120 | return noGrid(curIx); | |
| 121 | } | |
| 122 | ||
| 123 | /** Specifies that the indicated rows/columns should not be grid-like. The while row/colum will have its components layed out | |
| 124 | * in one single cell. It is the same as to say that the cells in this column/row will all be merged (a.k.a spanned). | |
| 125 | * <p> | |
| 126 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 127 | * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint. | |
| 128 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 129 | */ | |
| 130 | public final AC noGrid(int... indexes) | |
| 131 | { | |
| 132 | for (int i = indexes.length - 1; i >= 0; i--) { | |
| 133 | int ix = indexes[i]; | |
| 134 | makeSize(ix); | |
| 135 | cList.get(ix).setNoGrid(true); | |
| 136 | } | |
| 137 | return this; | |
| 138 | } | |
| 139 | ||
| 140 | /** Sets the current row/column to <code>i</code>. If the current number of rows/columns is less than <code>i</code> a call | |
| 141 | * to {@link #count(int)} will set the size accordingly. | |
| 142 | * <p> | |
| 143 | * The next call to any of the constraint methods (e.g. {@link net.miginfocom.layout.AC#noGrid}) will be carried | |
| 144 | * out on this new row/column. | |
| 145 | * <p> | |
| 146 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 147 | * @param i The new current row/column. | |
| 148 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 149 | */ | |
| 150 | public final AC index(int i) | |
| 151 | { | |
| 152 | makeSize(i); | |
| 153 | curIx = i; | |
| 154 | return this; | |
| 155 | } | |
| 156 | ||
| 157 | /** Specifies that the current row/column's component should grow by default. It does not affect the size of the row/column. | |
| 158 | * <p> | |
| 159 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 160 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 161 | */ | |
| 162 | public final AC fill() | |
| 163 | { | |
| 164 | return fill(curIx); | |
| 165 | } | |
| 166 | ||
| 167 | /** Specifies that the indicated rows'/columns' component should grow by default. It does not affect the size of the row/column. | |
| 168 | * <p> | |
| 169 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 170 | * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint. | |
| 171 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 172 | */ | |
| 173 | public final AC fill(int... indexes) | |
| 174 | { | |
| 175 | for (int i = indexes.length - 1; i >= 0; i--) { | |
| 176 | int ix = indexes[i]; | |
| 177 | makeSize(ix); | |
| 178 | cList.get(ix).setFill(true); | |
| 179 | } | |
| 180 | return this; | |
| 181 | } | |
| 182 | ||
| 183 | // /** Specifies that the current row/column should be put in the end group <code>s</code> and will thus share the same ending | |
| 184 | // * coordinate within the group. | |
| 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 s A name to associate on the group that should be the same for other rows/columns in the same group. | |
| 188 | // * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 189 | // */ | |
| 190 | // public final AxisConstraint endGroup(String s) | |
| 191 | // { | |
| 192 | // return endGroup(s, curIx); | |
| 193 | // } | |
| 194 | // | |
| 195 | // /** Specifies that the indicated rows/columns should be put in the end group <code>s</code> and will thus share the same ending | |
| 196 | // * coordinate within the group. | |
| 197 | // * <p> | |
| 198 | // * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 199 | // * @param s A name to associate on the group that should be the same for other rows/columns in the same group. | |
| 200 | // * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint. | |
| 201 | // * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 202 | // */ | |
| 203 | // public final AxisConstraint endGroup(String s, int... indexes) | |
| 204 | // { | |
| 205 | // for (int i = indexes.length - 1; i >= 0; i--) { | |
| 206 | // int ix = indexes[i]; | |
| 207 | // makeSize(ix); | |
| 208 | // cList.get(ix).setEndGroup(s); | |
| 209 | // } | |
| 210 | // return this; | |
| 211 | // } | |
| 212 | ||
| 213 | /** Specifies that the current row/column should be put in the size group <code>s</code> and will thus share the same size | |
| 214 | * constraints as the other components in the group. | |
| 215 | * <p> | |
| 216 | * Same as <code>sizeGroup("")</code> | |
| 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 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 220 | * @since 3.7.2 | |
| 221 | */ | |
| 222 | public final AC sizeGroup() | |
| 223 | { | |
| 224 | return sizeGroup("", curIx); | |
| 225 | } | |
| 226 | ||
| 227 | /** Specifies that the current row/column should be put in the size group <code>s</code> and will thus share the same size | |
| 228 | * constraints as the other components in the group. | |
| 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 s A name to associate on the group that should be the same for other rows/columns in the same group. | |
| 232 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 233 | */ | |
| 234 | public final AC sizeGroup(String s) | |
| 235 | { | |
| 236 | return sizeGroup(s, curIx); | |
| 237 | } | |
| 238 | ||
| 239 | /** Specifies that the indicated rows/columns should be put in the size group <code>s</code> and will thus share the same size | |
| 240 | * constraints as the other components in the group. | |
| 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 s A name to associate on the group that should be the same for other rows/columns in the same group. | |
| 244 | * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint. | |
| 245 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 246 | */ | |
| 247 | public final AC sizeGroup(String s, int... indexes) | |
| 248 | { | |
| 249 | for (int i = indexes.length - 1; i >= 0; i--) { | |
| 250 | int ix = indexes[i]; | |
| 251 | makeSize(ix); | |
| 252 | cList.get(ix).setSizeGroup(s); | |
| 253 | } | |
| 254 | return this; | |
| 255 | } | |
| 256 | ||
| 257 | /** Specifies the current row/column's min and/or preferred and/or max size. E.g. <code>"10px"</code> or <code>"50:100:200"</code>. | |
| 258 | * <p> | |
| 259 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 260 | * @param s The minimum and/or preferred and/or maximum size of this row. The string will be interpreted | |
| 261 | * as a <b>BoundSize</b>. For more info on how <b>BoundSize</b> is formatted see the documentation. | |
| 262 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 263 | */ | |
| 264 | public final AC size(String s) | |
| 265 | { | |
| 266 | return size(s, curIx); | |
| 267 | } | |
| 268 | ||
| 269 | /** Specifies the indicated rows'/columns' min and/or preferred and/or max size. E.g. <code>"10px"</code> or <code>"50:100:200"</code>. | |
| 270 | * <p> | |
| 271 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 272 | * @param size The minimum and/or preferred and/or maximum size of this row. The string will be interpreted | |
| 273 | * as a <b>BoundSize</b>. For more info on how <b>BoundSize</b> is formatted see the documentation. | |
| 274 | * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint. | |
| 275 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 276 | */ | |
| 277 | public final AC size(String size, int... indexes) | |
| 278 | { | |
| 279 | BoundSize bs = ConstraintParser.parseBoundSize(size, false, true); | |
| 280 | for (int i = indexes.length - 1; i >= 0; i--) { | |
| 281 | int ix = indexes[i]; | |
| 282 | makeSize(ix); | |
| 283 | cList.get(ix).setSize(bs); | |
| 284 | } | |
| 285 | return this; | |
| 286 | } | |
| 287 | ||
| 288 | /** Specifies the gap size to be the default one <b>AND</b> moves to the next column/row. The method is called <code>.gap()</code> | |
| 289 | * rather the more natural <code>.next()</code> to indicate that it is very much related to the other <code>.gap(..)</code> methods. | |
| 290 | * <p> | |
| 291 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 292 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 293 | */ | |
| 294 | public final AC gap() | |
| 295 | { | |
| 296 | curIx++; | |
| 297 | return this; | |
| 298 | } | |
| 299 | ||
| 300 | /** Specifies the gap size to <code>size</code> <b>AND</b> moves to the next column/row. | |
| 301 | * <p> | |
| 302 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 303 | * @param size minimum and/or preferred and/or maximum size of the gap between this and the next row/column. | |
| 304 | * The string will be interpreted as a <b>BoundSize</b>. For more info on how <b>BoundSize</b> is formatted see the documentation. | |
| 305 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 306 | */ | |
| 307 | public final AC gap(String size) | |
| 308 | { | |
| 309 | return gap(size, curIx++); | |
| 310 | } | |
| 311 | ||
| 312 | /** Specifies the indicated rows'/columns' gap size to <code>size</code>. | |
| 313 | * <p> | |
| 314 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 315 | * @param size minimum and/or preferred and/or maximum size of the gap between this and the next row/column. | |
| 316 | * The string will be interpreted as a <b>BoundSize</b>. For more info on how <b>BoundSize</b> is formatted see the documentation. | |
| 317 | * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint. | |
| 318 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 319 | */ | |
| 320 | public final AC gap(String size, int... indexes) | |
| 321 | { | |
| 322 | BoundSize bsa = size != null ? ConstraintParser.parseBoundSize(size, true, true) : null; | |
| 323 | ||
| 324 | for (int i = indexes.length - 1; i >= 0; i--) { | |
| 325 | int ix = indexes[i]; | |
| 326 | makeSize(ix); | |
| 327 | if (bsa != null) | |
| 328 | cList.get(ix).setGapAfter(bsa); | |
| 329 | } | |
| 330 | return this; | |
| 331 | } | |
| 332 | ||
| 333 | /** Specifies the current row/column's columns default alignment <b>for its components</b>. It does not affect the positioning | |
| 334 | * or size of the columns/row itself. For columns it is the horizonal alignment (e.g. "left") and for rows it is the vertical | |
| 335 | * alignment (e.g. "top"). | |
| 336 | * <p> | |
| 337 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 338 | * @param side The default side to align the components. E.g. "top" or "left", or "leading" or "trailing" or "bottom" or "right". | |
| 339 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 340 | */ | |
| 341 | public final AC align(String side) | |
| 342 | { | |
| 343 | return align(side, curIx); | |
| 344 | } | |
| 345 | ||
| 346 | /** Specifies the indicated rows'/columns' columns default alignment <b>for its components</b>. It does not affect the positioning | |
| 347 | * or size of the columns/row itself. For columns it is the horizonal alignment (e.g. "left") and for rows it is the vertical | |
| 348 | * alignment (e.g. "top"). | |
| 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 side The default side to align the components. E.g. "top" or "left", or "before" or "after" or "bottom" or "right". | |
| 352 | * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint. | |
| 353 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 354 | */ | |
| 355 | public final AC align(String side, int... indexes) | |
| 356 | { | |
| 357 | UnitValue al = ConstraintParser.parseAlignKeywords(side, true); | |
| 358 | if (al == null) | |
| 359 | al = ConstraintParser.parseAlignKeywords(side, false); | |
| 360 | ||
| 361 | for (int i = indexes.length - 1; i >= 0; i--) { | |
| 362 | int ix = indexes[i]; | |
| 363 | makeSize(ix); | |
| 364 | cList.get(ix).setAlign(al); | |
| 365 | } | |
| 366 | return this; | |
| 367 | } | |
| 368 | ||
| 369 | /** Specifies the current row/column's grow priority. | |
| 370 | * <p> | |
| 371 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 372 | * @param p The new grow priority. | |
| 373 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 374 | */ | |
| 375 | public final AC growPrio(int p) | |
| 376 | { | |
| 377 | return growPrio(p, curIx); | |
| 378 | } | |
| 379 | ||
| 380 | /** Specifies the indicated rows'/columns' grow priority. | |
| 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 p The new grow priority. | |
| 384 | * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint. | |
| 385 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 386 | */ | |
| 387 | public final AC growPrio(int p, int... indexes) | |
| 388 | { | |
| 389 | for (int i = indexes.length - 1; i >= 0; i--) { | |
| 390 | int ix = indexes[i]; | |
| 391 | makeSize(ix); | |
| 392 | cList.get(ix).setGrowPriority(p); | |
| 393 | } | |
| 394 | return this; | |
| 395 | } | |
| 396 | ||
| 397 | /** Specifies the current row/column's grow weight within columns/rows with the <code>grow priority</code> 100f. | |
| 398 | * <p> | |
| 399 | * Same as <code>grow(100f)</code> | |
| 400 | * <p> | |
| 401 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 402 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 403 | * @since 3.7.2 | |
| 404 | */ | |
| 405 | public final AC grow() | |
| 406 | { | |
| 407 | return grow(1f, curIx); | |
| 408 | } | |
| 409 | ||
| 410 | /** Specifies the current row/column's grow weight within columns/rows with the same <code>grow priority</code>. | |
| 411 | * <p> | |
| 412 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 413 | * @param w The new grow weight. | |
| 414 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 415 | */ | |
| 416 | public final AC grow(float w) | |
| 417 | { | |
| 418 | return grow(w, curIx); | |
| 419 | } | |
| 420 | ||
| 421 | /** Specifies the indicated rows'/columns' grow weight within columns/rows with the same <code>grow priority</code>. | |
| 422 | * <p> | |
| 423 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 424 | * @param w The new grow weight. | |
| 425 | * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint. | |
| 426 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 427 | */ | |
| 428 | public final AC grow(float w, int... indexes) | |
| 429 | { | |
| 430 | Float gw = new Float(w); | |
| 431 | for (int i = indexes.length - 1; i >= 0; i--) { | |
| 432 | int ix = indexes[i]; | |
| 433 | makeSize(ix); | |
| 434 | cList.get(ix).setGrow(gw); | |
| 435 | } | |
| 436 | return this; | |
| 437 | } | |
| 438 | ||
| 439 | /** Specifies the current row/column's shrink priority. | |
| 440 | * <p> | |
| 441 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 442 | * @param p The new shrink priority. | |
| 443 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 444 | */ | |
| 445 | public final AC shrinkPrio(int p) | |
| 446 | { | |
| 447 | return shrinkPrio(p, curIx); | |
| 448 | } | |
| 449 | ||
| 450 | /** Specifies the indicated rows'/columns' shrink priority. | |
| 451 | * <p> | |
| 452 | * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. | |
| 453 | * @param p The new shrink priority. | |
| 454 | * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint. | |
| 455 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 456 | */ | |
| 457 | public final AC shrinkPrio(int p, int... indexes) | |
| 458 | { | |
| 459 | for (int i = indexes.length - 1; i >= 0; i--) { | |
| 460 | int ix = indexes[i]; | |
| 461 | makeSize(ix); | |
| 462 | cList.get(ix).setShrinkPriority(p); | |
| 463 | } | |
| 464 | return this; | |
| 465 | } | |
| 466 | ||
| 467 | /** Specifies that the current row/column's shrink weight withing the columns/rows with the <code>shrink priority</code> 100f. | |
| 468 | * <p> | |
| 469 | * Same as <code>shrink(100f)</code>. | |
| 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 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 473 | * @since 3.7.2 | |
| 474 | */ | |
| 475 | public final AC shrink() | |
| 476 | { | |
| 477 | return shrink(100f, curIx); | |
| 478 | } | |
| 479 | ||
| 480 | /** Specifies that the current row/column's shrink weight withing the columns/rows with the same <code>shrink priority</code>. | |
| 481 | * <p> | |
| 482 | * For a more thorough explanation of what this constraint does see the White Paper or Cheat Sheet at www.migcomponents.com. | |
| 483 | * @param w The shrink weight. | |
| 484 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 485 | * @since 3.7.2 | |
| 486 | */ | |
| 487 | public final AC shrink(float w) | |
| 488 | { | |
| 489 | return shrink(w, curIx); | |
| 490 | } | |
| 491 | ||
| 492 | /** Specifies the indicated rows'/columns' shrink weight withing the columns/rows with the same <code>shrink priority</code>. | |
| 493 | * <p> | |
| 494 | * For a more thorough explanation of what this constraint does see the White Paper or Cheat Sheet at www.migcomponents.com. | |
| 495 | * @param w The shrink weight. | |
| 496 | * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint. | |
| 497 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 498 | * @since 3.7.2 | |
| 499 | */ | |
| 500 | public final AC shrink(float w, int... indexes) | |
| 501 | { | |
| 502 | Float sw = new Float(w); | |
| 503 | for (int i = indexes.length - 1; i >= 0; i--) { | |
| 504 | int ix = indexes[i]; | |
| 505 | makeSize(ix); | |
| 506 | cList.get(ix).setShrink(sw); | |
| 507 | } | |
| 508 | return this; | |
| 509 | } | |
| 510 | ||
| 511 | /** Specifies that the current row/column's shrink weight withing the columns/rows with the same <code>shrink priority</code>. | |
| 512 | * <p> | |
| 513 | * For a more thorough explanation of what this constraint does see the White Paper or Cheat Sheet at www.migcomponents.com. | |
| 514 | * @param w The shrink weight. | |
| 515 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 516 | * @deprecated in 3.7.2. Use {@link #shrink(float)} instead. | |
| 517 | */ | |
| 518 | public final AC shrinkWeight(float w) | |
| 519 | { | |
| 520 | return shrink(w); | |
| 521 | } | |
| 522 | ||
| 523 | /** Specifies the indicated rows'/columns' shrink weight withing the columns/rows with the same <code>shrink priority</code>. | |
| 524 | * <p> | |
| 525 | * For a more thorough explanation of what this constraint does see the White Paper or Cheat Sheet at www.migcomponents.com. | |
| 526 | * @param w The shrink weight. | |
| 527 | * @param indexes The index(es) (0-based) of the columns/rows that should be affected by this constraint. | |
| 528 | * @return <code>this</code> so it is possible to chain calls. E.g. <code>new AxisConstraint().noGrid().gap().fill()</code>. | |
| 529 | * @deprecated in 3.7.2. Use {@link #shrink(float, int...)} instead. | |
| 530 | */ | |
| 531 | public final AC shrinkWeight(float w, int... indexes) | |
| 532 | { | |
| 533 | return shrink(w, indexes); | |
| 534 | } | |
| 535 | ||
| 536 | private void makeSize(int sz) | |
| 537 | { | |
| 538 | if (cList.size() <= sz) { | |
| 539 | cList.ensureCapacity(sz); | |
| 540 | for (int i = cList.size(); i <= sz; i++) | |
| 541 | cList.add(new DimConstraint()); | |
| 542 | } | |
| 543 | } | |
| 544 | ||
| 545 | // ************************************************ | |
| 546 | // Persistence Delegate and Serializable combined. | |
| 547 | // ************************************************ | |
| 548 | ||
| 549 | private Object readResolve() throws ObjectStreamException | |
| 550 | { | |
| 551 | return LayoutUtil.getSerializedObject(this); | |
| 552 | } | |
| 553 | ||
| 554 | public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException | |
| 555 | { | |
| 556 | LayoutUtil.setSerializedObject(this, LayoutUtil.readAsXML(in)); | |
| 557 | } | |
| 558 | ||
| 559 | public void writeExternal(ObjectOutput out) throws IOException | |
| 560 | { | |
| 561 | if (getClass() == AC.class) | |
| 562 | LayoutUtil.writeAsXML(out, this); | |
| 563 | } | |
| 564 | } |