Source for javax.swing.SizeRequirements

   1: /* SizeRequirements.java --
   2:    Copyright (C) 2002, 2005 Free Software Foundation, Inc.
   3: 
   4: This file is part of GNU Classpath.
   5: 
   6: GNU Classpath is free software; you can redistribute it and/or modify
   7: it under the terms of the GNU General Public License as published by
   8: the Free Software Foundation; either version 2, or (at your option)
   9: any later version.
  10: 
  11: GNU Classpath is distributed in the hope that it will be useful, but
  12: WITHOUT ANY WARRANTY; without even the implied warranty of
  13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  14: General Public License for more details.
  15: 
  16: You should have received a copy of the GNU General Public License
  17: along with GNU Classpath; see the file COPYING.  If not, write to the
  18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  19: 02110-1301 USA.
  20: 
  21: Linking this library statically or dynamically with other modules is
  22: making a combined work based on this library.  Thus, the terms and
  23: conditions of the GNU General Public License cover the whole
  24: combination.
  25: 
  26: As a special exception, the copyright holders of this library give you
  27: permission to link this library with independent modules to produce an
  28: executable, regardless of the license terms of these independent
  29: modules, and to copy and distribute the resulting executable under
  30: terms of your choice, provided that you also meet, for each linked
  31: independent module, the terms and conditions of the license of that
  32: module.  An independent module is a module which is not derived from
  33: or based on this library.  If you modify this library, you may extend
  34: this exception to your version of the library, but you are not
  35: obligated to do so.  If you do not wish to do so, delete this
  36: exception statement from your version. */
  37: 
  38: package javax.swing;
  39: 
  40: import java.io.Serializable;
  41: 
  42: /**
  43:  * This class calculates information about the size and position requirements
  44:  * of components.
  45:  *
  46:  * Two types of layout are supported:
  47:  * <ul>
  48:  * <li>Tiled: the components are placed at position top-left or bottom-right
  49:  *    position within their allocated space</li>
  50:  * <li>Aligned: the components are placed aligned in their allocated space
  51:  *    according to their alignment value</li>
  52:  * </ul>
  53:  *
  54:  * @author Andrew Selkirk
  55:  * @author Roman Kennke (roman@kennke.org)
  56:  */
  57: public class SizeRequirements implements Serializable
  58: {
  59:   /**
  60:    * The serialVersionUID.
  61:    */
  62:   private static final long serialVersionUID = 9217749429906736553L;
  63: 
  64:   /**
  65:    * The minimum reasonable width or height of a component.
  66:    */
  67:   public int minimum;
  68: 
  69:   /**
  70:    * The preferred width or height of a component.
  71:    */
  72:   public int preferred;
  73: 
  74:   /**
  75:    * The maximum reasonable width or height of a component.
  76:    */
  77:   public int maximum;
  78: 
  79:   /**
  80:    * The horizontal or vertical alignment of a component.
  81:    */
  82:   public float alignment;
  83: 
  84:   /**
  85:    * Creates a SizeRequirements object with minimum, preferred and
  86:    * maximum size set to zero, and an alignment value of 0.5.
  87:    */
  88:   public SizeRequirements()
  89:   {
  90:     this (0, 0, 0, 0.5F);
  91:   }
  92: 
  93:   /**
  94:    * Creates a SizeRequirements object with the specified minimum,
  95:    * preferred, maximum and alignment values.
  96:    *
  97:    * @param min the minimum reasonable size of the component
  98:    * @param pref the preferred size of the component
  99:    * @param max the maximum size of the component
 100:    * @param align the alignment of the component
 101:    */
 102:   public SizeRequirements(int min, int pref, int max, float align)
 103:   {
 104:     minimum = min;
 105:     preferred = pref;
 106:     maximum = max;
 107:     alignment = align;
 108:   }
 109: 
 110:   /**
 111:    * Returns a String representation of this SizeRequirements object,
 112:    * containing information about the minimum, preferred, maximum and
 113:    * alignment value.
 114:    *
 115:    * @return a String representation of this SizeRequirements object
 116:    */
 117:   public String toString()
 118:   {
 119:     return null; // TODO
 120:   }
 121: 
 122:   /**
 123:    * Calculates how much space is nessecary to place a set of components
 124:    * end-to-end. The size requirements of the components is specified
 125:    * in <code>children</code>.
 126:    *
 127:    * @param children the SizeRequirements of each of the components
 128:    *
 129:    * @return the SizeRequirements that describe how much space is needed
 130:    *     to place the components end-to-end
 131:    */
 132:   public static SizeRequirements
 133:   getTiledSizeRequirements(SizeRequirements[] children)
 134:   {
 135:     SizeRequirements result = new SizeRequirements();
 136:     for (int i = 0; i < children.length; i++)
 137:       {
 138:         result.minimum += children[i].minimum;
 139:         result.preferred += children[i].preferred;
 140:         result.maximum += children[i].maximum;
 141:       }
 142:     return result;
 143:   }
 144: 
 145:   /**
 146:    * Calculates how much space is nessecary to place a set of components
 147:    * aligned according to their alignment value.
 148:    * The size requirements of the components is specified in
 149:    * <code>children</code>.
 150:    *
 151:    * @param children the SizeRequirements of each of the components
 152:    *
 153:    * @return the SizeRequirements that describe how much space is needed
 154:    *     to place the components aligned
 155:    */
 156:   public static SizeRequirements
 157:   getAlignedSizeRequirements(SizeRequirements[] children)
 158:   {
 159:     return null; // TODO
 160:   }
 161: 
 162:   /**
 163:    * Calculate the offsets and spans of the components, when they should
 164:    * be placed end-to-end.
 165:    *
 166:    * You must specify the amount of allocated space in
 167:    * <code>allocated</code>, the total size requirements of the set of
 168:    * components in <code>total</code> (this can be calculated using
 169:    * {@link #getTiledSizeRequirements} and the size requirements of the
 170:    * components in <code>children</code>.
 171:    *
 172:    * The calculated offset and span values for each component are then
 173:    * stored in the arrays <code>offsets</code> and <code>spans</code>.
 174:    *
 175:    * The components are placed in the forward direction, beginning with
 176:    * an offset of 0.
 177:    *
 178:    * @param allocated the amount of allocated space
 179:    * @param total the total size requirements of the components
 180:    * @param children the size requirement of each component
 181:    * @param offsets will hold the offset values for each component
 182:    * @param spans will hold the span values for each component
 183:    */
 184:   public static void calculateTiledPositions(int allocated,
 185:                                              SizeRequirements total,
 186:                                              SizeRequirements[] children,
 187:                                              int[] offsets, int[] spans)
 188:   {
 189:     calculateTiledPositions(allocated, total, children, offsets, spans, true);
 190:   }
 191: 
 192:   /**
 193:    * Calculate the offsets and spans of the components, when they should
 194:    * be placed end-to-end.
 195:    *
 196:    * You must specify the amount of allocated space in
 197:    * <code>allocated</code>, the total size requirements of the set of
 198:    * components in <code>total</code> (this can be calculated using
 199:    * {@link #getTiledSizeRequirements} and the size requirements of the
 200:    * components in <code>children</code>.
 201:    *
 202:    * The calculated offset and span values for each component are then
 203:    * stored in the arrays <code>offsets</code> and <code>spans</code>.
 204:    *
 205:    * Depending on the value of <code>forward</code> the components are
 206:    * placed in the forward direction (left-right or top-bottom), where
 207:    * the offsets begin with 0, or in the reverse direction
 208:    * (right-left or bottom-top).
 209:    *
 210:    * @param allocated the amount of allocated space
 211:    * @param total the total size requirements of the components
 212:    * @param children the size requirement of each component
 213:    * @param offsets will hold the offset values for each component
 214:    * @param spans will hold the span values for each component
 215:    * @param forward whether the components should be placed in the forward
 216:    *     direction (left-right or top-bottom) or reverse direction
 217:    *     (right-left or bottom-top)
 218:    */
 219:   public static void calculateTiledPositions(int allocated,
 220:                                              SizeRequirements total,
 221:                                              SizeRequirements[] children,
 222:                                              int[] offsets, int[] spans,
 223:                                              boolean forward)
 224:   {
 225:     if (forward)
 226:       {
 227:         int offset = 0;
 228:         for (int i = 0; i < children.length; i++)
 229:           {
 230:             offsets[i] = offset;
 231:             spans[i] = children[i].preferred;
 232:             offset += children[i].preferred;
 233:           }
 234:       }
 235:     else
 236:       {
 237:         int offset = allocated;
 238:         for (int i = 0; i < children.length; i++)
 239:           {
 240:             offset -= children[i].preferred;
 241:             offsets[i] = offset;
 242:             spans[i] = children[i].preferred;
 243:           }
 244:       }
 245:   }
 246: 
 247:   /**
 248:    * Calculate the offsets and spans of the components, when they should
 249:    * be placed end-to-end.
 250:    *
 251:    * You must specify the amount of allocated space in
 252:    * <code>allocated</code>, the total size requirements of the set of
 253:    * components in <code>total</code> (this can be calculated using
 254:    * {@link #getTiledSizeRequirements} and the size requirements of the
 255:    * components in <code>children</code>.
 256:    *
 257:    * The calculated offset and span values for each component are then
 258:    * stored in the arrays <code>offsets</code> and <code>spans</code>.
 259:    *
 260:    * The components are tiled in the forward direction, beginning with
 261:    * an offset of 0.
 262:    * 
 263:    * @param allocated the amount of allocated space
 264:    * @param total the total size requirements of the components
 265:    * @param children the size requirement of each component
 266:    * @param offsets will hold the offset values for each component
 267:    * @param spans will hold the span values for each component
 268:    */
 269:   public static void calculateAlignedPositions(int allocated,
 270:                                                SizeRequirements total,
 271:                                                SizeRequirements[] children,
 272:                                                int[] offsets, int[] spans)
 273:   {
 274:     calculateTiledPositions(allocated, total, children, offsets, spans, true);
 275:   }
 276: 
 277:   /**
 278:    * Calculate the offsets and spans of the components, when they should
 279:    * be placed end-to-end.
 280:    *
 281:    * You must specify the amount of allocated space in
 282:    * <code>allocated</code>, the total size requirements of the set of
 283:    * components in <code>total</code> (this can be calculated using
 284:    * {@link #getTiledSizeRequirements} and the size requirements of the
 285:    * components in <code>children</code>.
 286:    *
 287:    * The calculated offset and span values for each component are then
 288:    * stored in the arrays <code>offsets</code> and <code>spans</code>.
 289:    *
 290:    * Depending on the value of <code>forward</code> the components are
 291:    * placed in the forward direction (left-right or top-bottom), where
 292:    * the offsets begin with 0, or in the reverse direction
 293:    * (right-left or bottom-top).
 294:    *
 295:    * @param allocated the amount of allocated space
 296:    * @param total the total size requirements of the components
 297:    * @param children the size requirement of each component
 298:    * @param spans will hold the span values for each component
 299:    * @param forward whether the components should be placed in the forward
 300:    *     direction (left-right or top-bottom) or reverse direction
 301:    *     (right-left or bottom-top)
 302:    */
 303:   public static void calculateAlignedPositions(int allocated,
 304:                                                SizeRequirements total,
 305:                                                SizeRequirements[] children,
 306:                                                int[] offset, int[] spans,
 307:                                                boolean forward)
 308:   {
 309:     // TODO
 310:   }
 311: 
 312:   /**
 313:    * Returns an array of new preferred sizes for the children based on
 314:    * <code>delta</code>. <code>delta</code> specifies a change in the
 315:    * allocated space. The sizes of the children will be shortened or
 316:    * lengthened to accomodate the new allocation.
 317:    *
 318:    * @param delta the change of the size of the total allocation for
 319:    *     the components
 320:    * @param children the size requirements of each component
 321:    *
 322:    * @return the new preferred sizes for each component
 323:    */
 324:   public static int[] adjustSizes(int delta, SizeRequirements[] children)
 325:   {
 326:     return null; // TODO
 327:   }
 328: }