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

Diff of /classpath/java/awt/CardLayout.java

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

revision 1.6 by mkoch, Wed Oct 2 12:58:39 2002 UTC revision 1.7 by tromey, Sun Nov 10 23:11:12 2002 UTC
# Line 165  public class CardLayout implements Layou Line 165  public class CardLayout implements Layou
165     */     */
166    public void layoutContainer (Container parent)    public void layoutContainer (Container parent)
167    {    {
168      int width = parent.width;      synchronized (parent.getTreeLock ())
169      int height = parent.height;        {
170            int width = parent.width;
171            int height = parent.height;
172    
173      Insets ins = parent.getInsets ();          Insets ins = parent.getInsets ();
174    
175      int num = parent.ncomponents;          int num = parent.ncomponents;
176      Component[] comps = parent.component;          Component[] comps = parent.component;
177    
178      int x = ins.left + hgap;          int x = ins.left + hgap;
179      int y = ins.top + vgap;          int y = ins.top + vgap;
180      width = width - 2 * hgap - ins.left - ins.right;          width = width - 2 * hgap - ins.left - ins.right;
181      height = height - 2 * vgap - ins.top - ins.bottom;          height = height - 2 * vgap - ins.top - ins.bottom;
182    
183      for (int i = 0; i < num; ++i)          for (int i = 0; i < num; ++i)
184        comps[i].setBounds (x, y, width, height);            comps[i].setBounds (x, y, width, height);
185          }
186    }    }
187    
188    /** Get the maximum layout size of the container.    /** Get the maximum layout size of the container.
# Line 287  public class CardLayout implements Layou Line 290  public class CardLayout implements Layou
290    private void gotoComponent (Container parent, int what,    private void gotoComponent (Container parent, int what,
291                                Component target)                                Component target)
292    {    {
293      int num = parent.ncomponents;      synchronized (parent.getTreeLock ())
     // This is more efficient than calling getComponents().  
     Component[] comps = parent.component;  
     int choice = -1;  
   
     if (what == FIRST)  
       choice = 0;  
     else if (what == LAST)  
       choice = num - 1;  
     else if (what >= 0)  
       choice = what;  
   
     for (int i = 0; i < num; ++i)  
294        {        {
295          // If TARGET is set then we are looking for a specific          int num = parent.ncomponents;
296          // component.          // This is more efficient than calling getComponents().
297          if (target != null)          Component[] comps = parent.component;
298            {          int choice = -1;
299              if (target == comps[i])  
300                choice = i;          if (what == FIRST)
301            }            choice = 0;
302            else if (what == LAST)
303              choice = num - 1;
304            else if (what >= 0)
305              choice = what;
306    
307          if (comps[i].isVisible ())          for (int i = 0; i < num; ++i)
308            {            {
309              if (what == NEXT)              // If TARGET is set then we are looking for a specific
310                // component.
311                if (target != null)
312                {                {
313                  choice = i + 1;                  if (target == comps[i])
314                  if (choice == num)                    choice = i;
                   choice = 0;  
315                }                }
316              else if (what == PREV)  
317                {              if (comps[i].isVisible ())
                 choice = i - 1;  
                 if (choice < 0)  
                   choice = num - 1;  
               }  
             else if (choice == i)  
318                {                {
319                  // Do nothing if we're already looking at the right                  if (what == NEXT)
320                  // component.                    {
321                  return;                      choice = i + 1;
322                }                      if (choice == num)
323              comps[i].setVisible (false);                        choice = 0;
324                      }
325                    else if (what == PREV)
326                      {
327                        choice = i - 1;
328                        if (choice < 0)
329                          choice = num - 1;
330                      }
331                    else if (choice == i)
332                      {
333                        // Do nothing if we're already looking at the right
334                        // component.
335                        return;
336                      }
337                    comps[i].setVisible (false);
338    
339              if (choice >= 0)                  if (choice >= 0)
340                break;                    break;
341                  }
342            }            }
       }  
343    
344      if (choice >= 0 && choice < num)          if (choice >= 0 && choice < num)
345        comps[choice].setVisible (true);            comps[choice].setVisible (true);
346          }
347    }    }
348    
349    // Compute the size according to WHAT.    // Compute the size according to WHAT.
350    private Dimension getSize (Container parent, int what)    private Dimension getSize (Container parent, int what)
351    {    {
352      int w = 0, h = 0, num = parent.ncomponents;      synchronized (parent.getTreeLock ())
     Component[] comps = parent.component;  
   
     for (int i = 0; i < num; ++i)  
353        {        {
354          Dimension d;          int w = 0, h = 0, num = parent.ncomponents;
355            Component[] comps = parent.component;
356    
357          if (what == MIN)          for (int i = 0; i < num; ++i)
358            d = comps[i].getMinimumSize ();            {
359          else if (what == MAX)              Dimension d;
           d = comps[i].getMaximumSize ();  
         else  
           d = comps[i].getPreferredSize ();  
360    
361          w = Math.max (d.width, w);              if (what == MIN)
362          h = Math.max (d.height, h);                d = comps[i].getMinimumSize ();
363        }              else if (what == MAX)
364                  d = comps[i].getMaximumSize ();
365                else
366                  d = comps[i].getPreferredSize ();
367    
368                w = Math.max (d.width, w);
369                h = Math.max (d.height, h);
370              }
371    
372      Insets i = parent.getInsets ();          Insets i = parent.getInsets ();
373      w += 2 * hgap + i.right + i.left;          w += 2 * hgap + i.right + i.left;
374      h += 2 * vgap + i.bottom + i.top;          h += 2 * vgap + i.bottom + i.top;
375    
376      // Handle overflow.          // Handle overflow.
377      if (w < 0)          if (w < 0)
378        w = Integer.MAX_VALUE;            w = Integer.MAX_VALUE;
379      if (h < 0)          if (h < 0)
380        h = Integer.MAX_VALUE;            h = Integer.MAX_VALUE;
381    
382      return new Dimension (w, h);          return new Dimension (w, h);
383          }
384    }    }
385    
386    /**    /**

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

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