classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] FYI: Implemened some methods in javax.swing.SizeRequirement


From: Roman Kennke
Subject: [cp-patches] FYI: Implemened some methods in javax.swing.SizeRequirements
Date: Thu, 19 May 2005 17:20:11 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204

I implemented the following methods in javax.swing.SizeRequirements:

2005-05-19  Roman Kennke  <address@hidden>

       * javax/swing/SizeRequirements.java
       (constructors): Implemented.
       (getTiledSizeRequirements): Implemented.
       (calculateTiledPositions): Implemented.

/Roman

Index: javax/swing/SizeRequirements.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/SizeRequirements.java,v
retrieving revision 1.6
diff -u -r1.6 SizeRequirements.java
--- javax/swing/SizeRequirements.java   19 May 2005 13:33:15 -0000      1.6
+++ javax/swing/SizeRequirements.java   19 May 2005 15:17:25 -0000
@@ -87,7 +87,7 @@
    */
   public SizeRequirements()
   {
-    // TODO
+    this (0, 0, 0, 0.5F);
   }
 
   /**
@@ -101,7 +101,10 @@
    */
   public SizeRequirements(int min, int pref, int max, float align)
   {
-    // TODO
+    minimum = min;
+    preferred = pref;
+    maximum = max;
+    alignment = align;
   }
 
   /**
@@ -129,7 +132,14 @@
   public static SizeRequirements
   getTiledSizeRequirements(SizeRequirements[] children)
   {
-    return null; // TODO
+    SizeRequirements result = new SizeRequirements();
+    for (int i = 0; i < children.length; i++)
+      {
+        result.minimum += children[i].minimum;
+        result.preferred += children[i].preferred;
+        result.maximum += children[i].maximum;
+      }
+    return result;
   }
 
   /**
@@ -162,6 +172,9 @@
    * The calculated offset and span values for each component are then
    * stored in the arrays <code>offsets</code> and <code>spans</code>.
    *
+   * The components are placed in the forward direction, beginning with
+   * an offset of 0.
+   *
    * @param allocated the amount of allocated space
    * @param total the total size requirements of the components
    * @param children the size requirement of each component
@@ -171,9 +184,9 @@
   public static void calculateTiledPositions(int allocated,
                                              SizeRequirements total,
                                              SizeRequirements[] children,
-                                             int[] offset, int[] spans)
+                                             int[] offsets, int[] spans)
   {
-    // TODO
+    calculateTiledPositions(allocated, total, children, offsets, spans, true);
   }
 
   /**
@@ -189,16 +202,110 @@
    * The calculated offset and span values for each component are then
    * stored in the arrays <code>offsets</code> and <code>spans</code>.
    *
+   * Depending on the value of <code>forward</code> the components are
+   * placed in the forward direction (left-right or top-bottom), where
+   * the offsets begin with 0, or in the reverse direction
+   * (right-left or bottom-top).
+   *
+   * @param allocated the amount of allocated space
+   * @param total the total size requirements of the components
+   * @param children the size requirement of each component
+   * @param offsets will hold the offset values for each component
+   * @param spans will hold the span values for each component
+   * @param forward whether the components should be placed in the forward
+   *     direction (left-right or top-bottom) or reverse direction
+   *     (right-left or bottom-top)
+   */
+  public static void calculateTiledPositions(int allocated,
+                                             SizeRequirements total,
+                                             SizeRequirements[] children,
+                                             int[] offsets, int[] spans,
+                                             boolean forward)
+  {
+    if (forward)
+      {
+        int offset = 0;
+        for (int i = 0; i < children.length; i++)
+          {
+            offsets[i] = offset;
+            spans[i] = children[i].preferred;
+            offset += children[i].preferred;
+          }
+      }
+    else
+      {
+        int offset = allocated;
+        for (int i = 0; i < children.length; i++)
+          {
+            offset -= children[i].preferred;
+            offsets[i] = offset;
+            spans[i] = children[i].preferred;
+          }
+      }
+  }
+
+  /**
+   * Calculate the offsets and spans of the components, when they should
+   * be placed end-to-end.
+   *
+   * You must specify the amount of allocated space in
+   * <code>allocated</code>, the total size requirements of the set of
+   * components in <code>total</code> (this can be calculated using
+   * address@hidden #getTiledSizeRequirements} and the size requirements of the
+   * components in <code>children</code>.
+   *
+   * The calculated offset and span values for each component are then
+   * stored in the arrays <code>offsets</code> and <code>spans</code>.
+   *
+   * The components are tiled in the forward direction, beginning with
+   * an offset of 0.
+   * 
+   * @param allocated the amount of allocated space
+   * @param total the total size requirements of the components
+   * @param children the size requirement of each component
+   * @param offsets will hold the offset values for each component
+   * @param spans will hold the span values for each component
+   */
+  public static void calculateAlignedPositions(int allocated,
+                                               SizeRequirements total,
+                                               SizeRequirements[] children,
+                                               int[] offsets, int[] spans)
+  {
+    calculateTiledPositions(allocated, total, children, offsets, spans, true);
+  }
+
+  /**
+   * Calculate the offsets and spans of the components, when they should
+   * be placed end-to-end.
+   *
+   * You must specify the amount of allocated space in
+   * <code>allocated</code>, the total size requirements of the set of
+   * components in <code>total</code> (this can be calculated using
+   * address@hidden #getTiledSizeRequirements} and the size requirements of the
+   * components in <code>children</code>.
+   *
+   * The calculated offset and span values for each component are then
+   * stored in the arrays <code>offsets</code> and <code>spans</code>.
+   *
+   * Depending on the value of <code>forward</code> the components are
+   * placed in the forward direction (left-right or top-bottom), where
+   * the offsets begin with 0, or in the reverse direction
+   * (right-left or bottom-top).
+   *
    * @param allocated the amount of allocated space
    * @param total the total size requirements of the components
    * @param children the size requirement of each component
    * @param offsets will hold the offset values for each component
    * @param spans will hold the span values for each component
+   * @param forward whether the components should be placed in the forward
+   *     direction (left-right or top-bottom) or reverse direction
+   *     (right-left or bottom-top)
    */
   public static void calculateAlignedPositions(int allocated,
                                                SizeRequirements total,
                                                SizeRequirements[] children,
-                                               int[] offset, int[] spans)
+                                               int[] offset, int[] spans,
+                                               boolean forward)
   {
     // TODO
   }

reply via email to

[Prev in Thread] Current Thread [Next in Thread]