/[classpath]/classpath/javax/swing/SizeRequirements.java
ViewVC logotype

Diff of /classpath/javax/swing/SizeRequirements.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.12 by rabbit78, Sun Sep 25 10:17:19 2005 UTC revision 1.13 by rabbit78, Sun Sep 25 14:02:03 2005 UTC
# Line 355  public class SizeRequirements implements Line 355  public class SizeRequirements implements
355      // Now we can layout the components along the baseline.      // Now we can layout the components along the baseline.
356      for (int i = 0; i < children.length; i++)      for (int i = 0; i < children.length; i++)
357        {        {
358          // FIXME: Handle the case when span[i] results in exceeding          float align = children[i].alignment;
359          // the available space.          // Try to fit the component into the available space.
360          spans[i] = children[i].preferred;          int[] spanAndOffset = new int[2];
361          offset[i] = baseline - (int) (children[i].alignment * ((float) spans[i]));          if (align < .5F)
362              adjustFromRight(children[i], baseline, allocated, spanAndOffset);
363            else
364              adjustFromLeft(children[i], baseline, allocated, spanAndOffset);
365            spans[i] = spanAndOffset[0];
366            offset[i] = spanAndOffset[1];
367        }        }
368    }    }
369    
370    /**    /**
371       * Adjusts the span and offset of a component for the aligned layout.
372       *
373       * @param reqs
374       * @param baseline
375       * @param allocated
376       * @param spanAndOffset
377       */
378      private static void adjustFromRight(SizeRequirements reqs, int baseline,
379                                          int allocated, int[] spanAndOffset)
380      {
381        float right = allocated - baseline;
382        // If the resulting span exceeds the maximum of the component, then adjust
383        // accordingly.
384        float maxRight = ((float) reqs.maximum) * (1.F - reqs.alignment);
385        if (right / (1.F - reqs.alignment) > reqs.maximum)
386          right = maxRight;
387        // If we have not enough space on the left side, then adjust accordingly.
388        if (right / (1.F - reqs.alignment) * reqs.alignment > allocated - baseline)
389          right = ((float) (allocated - baseline))
390                 / reqs.alignment * (1.F - reqs.alignment);
391        // If we are below the minimum, then adjust upwards.
392          float minRight = ((float) reqs.minimum) * (1.F - reqs.alignment);
393        if (right / (1.F - reqs.alignment) < reqs.minimum)
394          right = Math.max(minRight, maxRight);
395    
396        spanAndOffset[0] = (int) (right / (1.F - reqs.alignment));
397        spanAndOffset[1] = baseline -
398                           (int) (((float) spanAndOffset[0]) * reqs.alignment);
399      }
400    
401      /**
402       * Adjusts the span and offset of a component for the aligned layout.
403       *
404       * @param reqs
405       * @param baseline
406       * @param allocated
407       * @param spanAndOffset
408       */
409      private static void adjustFromLeft(SizeRequirements reqs, int baseline,
410                                         int allocated, int[] spanAndOffset)
411      {
412        float left = baseline;
413        // If the resulting span exceeds the maximum of the component, then adjust
414        // accordingly.
415        float maxLeft = ((float) reqs.maximum) * reqs.alignment;
416        if (left / reqs.alignment > reqs.maximum)
417          left = maxLeft;
418        // If we have not enough space on the right side, then adjust accordingly.
419        if (left / reqs.alignment * (1.F - reqs.alignment) > allocated - baseline)
420          left = ((float) (allocated - baseline))
421                 / (1.F - reqs.alignment) * reqs.alignment;
422    
423        // If we are below the minimum, then adjust upwards.
424        float minLeft = ((float) reqs.minimum) * reqs.alignment;
425        if (left / reqs.alignment < reqs.minimum)
426          left = Math.max(minLeft, maxLeft);
427    
428        spanAndOffset[0] = (int) (left / reqs.alignment);
429        spanAndOffset[1] = baseline -
430                           (int) (((float) spanAndOffset[0]) * reqs.alignment);
431      }
432    
433      /**
434     * Returns an array of new preferred sizes for the children based on     * Returns an array of new preferred sizes for the children based on
435     * <code>delta</code>. <code>delta</code> specifies a change in the     * <code>delta</code>. <code>delta</code> specifies a change in the
436     * allocated space. The sizes of the children will be shortened or     * allocated space. The sizes of the children will be shortened or

Legend:
Removed from v.1.12  
changed lines
  Added in v.1.13

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26