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

Diff of /classpath/java/awt/GridLayout.java

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

revision 1.10 by tromey, Sun Nov 10 17:35:58 2002 UTC revision 1.11 by tromey, Sun Nov 10 23:11:12 2002 UTC
# Line 153  public class GridLayout implements Layou Line 153  public class GridLayout implements Layou
153     */     */
154    public void layoutContainer (Container parent)    public void layoutContainer (Container parent)
155    {    {
156      int num = parent.ncomponents;      synchronized (parent.getTreeLock ())
157          {
158            int num = parent.ncomponents;
159    
160      // There's no point, and handling this would mean adding special          // There's no point, and handling this would mean adding special
161      // cases.          // cases.
162      if (num == 0)          if (num == 0)
163        return;            return;
164    
165      // This is more efficient than calling getComponents().          // This is more efficient than calling getComponents().
166      Component[] comps = parent.component;          Component[] comps = parent.component;
167    
168      int real_rows = rows;          int real_rows = rows;
169      int real_cols = cols;          int real_cols = cols;
170      if (real_rows == 0)          if (real_rows == 0)
171        real_rows = (num + real_cols - 1) / real_cols;            real_rows = (num + real_cols - 1) / real_cols;
172      else          else
173        real_cols = (num + real_rows - 1) / real_rows;            real_cols = (num + real_rows - 1) / real_rows;
   
     // We might have less than a single row.  In this case we expand  
     // to fill.  
     if (num < real_cols)  
       real_cols = num;  
   
     Dimension d = parent.getSize ();  
     Insets ins = parent.getInsets ();  
   
     // Compute width and height of each cell in the grid.  
     int tw = d.width - ins.left - ins.right;  
     tw = (tw - (real_cols - 1) * hgap) / real_cols;  
     int th = d.height - ins.top - ins.bottom;  
     th = (th - (real_rows - 1) * vgap) / real_rows;  
   
     // If the cells are too small, still try to do something.  
     if (tw < 0)  
       tw = 1;  
     if (th < 0)  
       th = 1;  
   
     int x = ins.left;  
     int y = ins.top;  
     int i = 0;  
     int recount = 0;  
174    
175      while (i < num)          // We might have less than a single row.  In this case we expand
176        {          // to fill.
177          comps[i].setBounds (x, y, tw, th);          if (num < real_cols)
178              real_cols = num;
179    
180            Dimension d = parent.getSize ();
181            Insets ins = parent.getInsets ();
182    
183            // Compute width and height of each cell in the grid.
184            int tw = d.width - ins.left - ins.right;
185            tw = (tw - (real_cols - 1) * hgap) / real_cols;
186            int th = d.height - ins.top - ins.bottom;
187            th = (th - (real_rows - 1) * vgap) / real_rows;
188    
189            // If the cells are too small, still try to do something.
190            if (tw < 0)
191              tw = 1;
192            if (th < 0)
193              th = 1;
194    
195            int x = ins.left;
196            int y = ins.top;
197            int i = 0;
198            int recount = 0;
199    
200          ++i;          while (i < num)
         ++recount;  
         if (recount == real_cols)  
201            {            {
202              recount = 0;              comps[i].setBounds (x, y, tw, th);
203              y += vgap + th;  
204              x = ins.left;              ++i;
205                ++recount;
206                if (recount == real_cols)
207                  {
208                    recount = 0;
209                    y += vgap + th;
210                    x = ins.left;
211                  }
212                else
213                  x += hgap + tw;
214            }            }
         else  
           x += hgap + tw;  
215        }        }
216    }    }
217    
# Line 301  public class GridLayout implements Layou Line 304  public class GridLayout implements Layou
304    // This method is used to compute the various sizes.    // This method is used to compute the various sizes.
305    private Dimension getSize (Container parent, boolean is_min)    private Dimension getSize (Container parent, boolean is_min)
306    {    {
307      int w = 0, h = 0, num = parent.ncomponents;      synchronized (parent.getTreeLock ())
     // This is more efficient than calling getComponents().  
     Component[] comps = parent.component;  
   
     for (int i = 0; i < num; ++i)  
308        {        {
309          Dimension d;          int w = 0, h = 0, num = parent.ncomponents;
310            // This is more efficient than calling getComponents().
311            Component[] comps = parent.component;
312    
313          if (is_min)          for (int i = 0; i < num; ++i)
314            d = comps[i].getMinimumSize ();            {
315                Dimension d;
316    
317                if (is_min)
318                  d = comps[i].getMinimumSize ();
319                else
320                  d = comps[i].getPreferredSize ();
321    
322                w = Math.max (d.width, w);
323                h = Math.max (d.height, h);
324              }
325    
326            int real_rows = rows;
327            int real_cols = cols;
328            if (real_rows == 0)
329              real_rows = (num + real_cols - 1) / real_cols;
330          else          else
331            d = comps[i].getPreferredSize ();            real_cols = (num + real_rows - 1) / real_rows;
332    
333          w = Math.max (d.width, w);          Insets ins = parent.getInsets ();
334          h = Math.max (d.height, h);          // We subtract out an extra gap here because the gaps are only
335            // between cells.
336            w = ins.left + ins.right + real_cols * (w + hgap) - hgap;
337            h = ins.top + ins.bottom + real_rows * (h + vgap) - vgap;
338            return new Dimension (w, h);
339        }        }
   
     int real_rows = rows;  
     int real_cols = cols;  
     if (real_rows == 0)  
       real_rows = (num + real_cols - 1) / real_cols;  
     else  
       real_cols = (num + real_rows - 1) / real_rows;  
   
     Insets ins = parent.getInsets ();  
     // We subtract out an extra gap here because the gaps are only  
     // between cells.  
     w = ins.left + ins.right + real_cols * (w + hgap) - hgap;  
     h = ins.top + ins.bottom + real_rows * (h + vgap) - vgap;  
     return new Dimension (w, h);  
340    }    }
341    
342    /**    /**

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.11

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