/[classpath]/classpath/java/awt/FlowLayout.java
ViewVC logotype

Diff of /classpath/java/awt/FlowLayout.java

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

revision 1.7 by tromey, Tue Jan 29 16:30:26 2002 UTC revision 1.8 by tromey, Sun Nov 10 23:11:12 2002 UTC
# Line 150  public class FlowLayout implements Layou Line 150  public class FlowLayout implements Layou
150     */     */
151    public void layoutContainer (Container parent)    public void layoutContainer (Container parent)
152    {    {
153      int num = parent.getComponentCount ();      synchronized (parent.getTreeLock ())
     // This is more efficient than calling getComponents().  
     Component[] comps = parent.component;  
   
     Dimension d = parent.getSize ();  
     Insets ins = parent.getInsets ();  
   
     ComponentOrientation orient = parent.getComponentOrientation ();  
     boolean left_to_right = orient.isLeftToRight ();  
   
     int y = ins.top + vgap;  
     int i = 0;  
     while (i < num)  
154        {        {
155          // Find the components which go in the current row.          int num = parent.getComponentCount ();
156          int new_w = ins.left + hgap + ins.right;          // This is more efficient than calling getComponents().
157          int new_h = 0;          Component[] comps = parent.component;
158          int j;  
159          boolean found_one = false;          Dimension d = parent.getSize ();
160          for (j = i; j < num && ! found_one; ++j)          Insets ins = parent.getInsets ();
161    
162            ComponentOrientation orient = parent.getComponentOrientation ();
163            boolean left_to_right = orient.isLeftToRight ();
164    
165            int y = ins.top + vgap;
166            int i = 0;
167            while (i < num)
168            {            {
169              // Skip invisible items.              // Find the components which go in the current row.
170              if (! comps[i].visible)              int new_w = ins.left + hgap + ins.right;
171                continue;              int new_h = 0;
172                int j;
173              Dimension c = comps[i].getPreferredSize ();              boolean found_one = false;
174                for (j = i; j < num && ! found_one; ++j)
             int next_w = new_w + hgap + c.width;  
             if (next_w <= d.width || ! found_one)  
               {  
                 new_w = next_w;  
                 new_h = Math.max (new_h, c.height);  
                 found_one = true;  
               }  
             else  
175                {                {
176                  // Must start a new row, and we already found an item                  // Skip invisible items.
177                  break;                  if (! comps[i].visible)
178                      continue;
179    
180                    Dimension c = comps[i].getPreferredSize ();
181    
182                    int next_w = new_w + hgap + c.width;
183                    if (next_w <= d.width || ! found_one)
184                      {
185                        new_w = next_w;
186                        new_h = Math.max (new_h, c.height);
187                        found_one = true;
188                      }
189                    else
190                      {
191                        // Must start a new row, and we already found an item
192                        break;
193                      }
194                }                }
           }  
195    
196          // Set the location of each component for this row.              // Set the location of each component for this row.
197          int x;              int x;
198    
199          int myalign = align;              int myalign = align;
200          if (align == LEADING)              if (align == LEADING)
201            myalign = left_to_right ? LEFT : RIGHT;                myalign = left_to_right ? LEFT : RIGHT;
202          else if (align == TRAILING)              else if (align == TRAILING)
203            myalign = left_to_right ? RIGHT : LEFT;                myalign = left_to_right ? RIGHT : LEFT;
204    
205          if (myalign == LEFT)              if (myalign == LEFT)
206            x = ins.left + hgap;                x = ins.left + hgap;
207          else if (myalign == CENTER)              else if (myalign == CENTER)
208            x = (d.width - new_w) / 2;                x = (d.width - new_w) / 2;
209          else              else
210            x = d.width - new_w;                x = d.width - new_w;
211    
212          for (int k = i; k < j; ++k)              for (int k = i; k < j; ++k)
           {  
             if (comps[k].visible)  
213                {                {
214                  Dimension c = comps[k].getPreferredSize ();                  if (comps[k].visible)
215                  comps[k].setBounds (x, y, c.width, new_h);                    {
216                  x += c.width + hgap;                      Dimension c = comps[k].getPreferredSize ();
217                        comps[k].setBounds (x, y, c.width, new_h);
218                        x += c.width + hgap;
219                      }
220                }                }
           }  
221    
222          // Advance to next row.              // Advance to next row.
223          i = j;              i = j;
224          y += new_h + vgap;              y += new_h + vgap;
225              }
226        }        }
227    }    }
228    
# Line 304  public class FlowLayout implements Layou Line 307  public class FlowLayout implements Layou
307    // This method is used to compute the various sizes.    // This method is used to compute the various sizes.
308    private Dimension getSize (Container parent, boolean is_min)    private Dimension getSize (Container parent, boolean is_min)
309    {    {
310      int w, h, num = parent.getComponentCount ();      synchronized (parent.getTreeLock ())
     // This is more efficient than calling getComponents().  
     Component[] comps = parent.component;  
   
     w = 0;  
     h = 0;  
     for (int i = 0; i < num; ++i)  
311        {        {
312          if (! comps[i].visible)          int w, h, num = parent.getComponentCount ();
313            continue;          // This is more efficient than calling getComponents().
314            Component[] comps = parent.component;
315    
316            w = 0;
317            h = 0;
318            for (int i = 0; i < num; ++i)
319              {
320                if (! comps[i].visible)
321                  continue;
322    
323          // FIXME: can we just directly read the fields in Component?              // FIXME: can we just directly read the fields in Component?
324          // Or will that not work with subclassing?              // Or will that not work with subclassing?
325          Dimension d;              Dimension d;
   
         if (is_min)  
           d = comps[i].getMinimumSize ();  
         else  
           d = comps[i].getPreferredSize ();  
326    
327          w += d.width;              if (is_min)
328          h = Math.max (d.height, h);                d = comps[i].getMinimumSize ();
329        }              else
330                  d = comps[i].getPreferredSize ();
331    
332      Insets ins = parent.getInsets ();              w += d.width;
333                h = Math.max (d.height, h);
334              }
335    
336      w += (num + 1) * hgap + ins.left + ins.right;          Insets ins = parent.getInsets ();
     h += 2 * vgap + ins.top + ins.bottom;  
337    
338      return new Dimension (w, h);          w += (num + 1) * hgap + ins.left + ins.right;
339            h += 2 * vgap + ins.top + ins.bottom;
340    
341            return new Dimension (w, h);
342          }
343    }    }
344    
345    /**    /**

Legend:
Removed from v.1.7  
changed lines
  Added in v.1.8

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