/[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.7 by tromey, Sun Nov 10 23:11:12 2002 UTC revision 1.8 by tromey, Wed Jan 15 22:51:43 2003 UTC
# Line 1  Line 1 
1  // CardLayout.java - Card-based layout engine  // CardLayout.java - Card-based layout engine
2    
3  /* Copyright (C) 1999, 2000, 2002  Free Software Foundation  /* Copyright (C) 1999, 2000, 2002, 2003  Free Software Foundation
4    
5  This file is part of GNU Classpath.  This file is part of GNU Classpath.
6    
# Line 110  public class CardLayout implements Layou Line 110  public class CardLayout implements Layou
110     */     */
111    public void first (Container parent)    public void first (Container parent)
112    {    {
113      gotoComponent (parent, FIRST, null);      gotoComponent (parent, FIRST);
114    }    }
115    
116    /** Return this layout manager's horizontal gap.  */    /** Return this layout manager's horizontal gap.  */
# Line 154  public class CardLayout implements Layou Line 154  public class CardLayout implements Layou
154     */     */
155    public void last (Container parent)    public void last (Container parent)
156    {    {
157      gotoComponent (parent, LAST, null);      gotoComponent (parent, LAST);
158    }    }
159    
160    /**    /**
# Line 210  public class CardLayout implements Layou Line 210  public class CardLayout implements Layou
210     */     */
211    public void next (Container parent)    public void next (Container parent)
212    {    {
213      gotoComponent (parent, NEXT, null);      gotoComponent (parent, NEXT);
214    }    }
215    
216    /** Get the preferred layout size of the container.    /** Get the preferred layout size of the container.
# Line 228  public class CardLayout implements Layou Line 228  public class CardLayout implements Layou
228     */     */
229    public void previous (Container parent)    public void previous (Container parent)
230    {    {
231      gotoComponent (parent, PREV, null);      gotoComponent (parent, PREV);
232    }    }
233    
234    /** Remove the indicated component from this layout manager.    /** Remove the indicated component from this layout manager.
# Line 273  public class CardLayout implements Layou Line 273  public class CardLayout implements Layou
273    {    {
274      Object target = tab.get (name);      Object target = tab.get (name);
275      if (target != null)      if (target != null)
276        gotoComponent (parent, NONE, (Component) target);        {
277            int num = parent.ncomponents;
278            // This is more efficient than calling getComponents().
279            Component[] comps = parent.component;
280            for (int i = 0; i < num; ++i)
281              {
282                if (comps[i].isVisible())
283                  {
284                    if (target == comps[i])
285                      return;
286                    comps[i].setVisible (false);
287                  }
288              }
289            ((Component) target).setVisible (true);
290          }
291    }    }
292    
293    /**    /**
# Line 286  public class CardLayout implements Layou Line 300  public class CardLayout implements Layou
300      return getClass ().getName () + "[" + hgap + "," + vgap + "]";      return getClass ().getName () + "[" + hgap + "," + vgap + "]";
301    }    }
302    
303    // This implements first(), last(), next(), and previous().    /** This implements first(), last(), next(), and previous().
304    private void gotoComponent (Container parent, int what,     * @param parent The parent container
305                                Component target)     * @param what The type of goto: FIRST, LAST, NEXT or PREV
306       */
307      private void gotoComponent (Container parent, int what)
308    {    {
309      synchronized (parent.getTreeLock ())      synchronized (parent.getTreeLock ())
310        {        {
# Line 301  public class CardLayout implements Layou Line 317  public class CardLayout implements Layou
317            choice = 0;            choice = 0;
318          else if (what == LAST)          else if (what == LAST)
319            choice = num - 1;            choice = num - 1;
         else if (what >= 0)  
           choice = what;  
320    
321          for (int i = 0; i < num; ++i)          for (int i = 0; i < num; ++i)
322            {            {
             // If TARGET is set then we are looking for a specific  
             // component.  
             if (target != null)  
               {  
                 if (target == comps[i])  
                   choice = i;  
               }  
   
323              if (comps[i].isVisible ())              if (comps[i].isVisible ())
324                {                {
325                  if (what == NEXT)                  if (what == NEXT)
# Line 335  public class CardLayout implements Layou Line 341  public class CardLayout implements Layou
341                      return;                      return;
342                    }                    }
343                  comps[i].setVisible (false);                  comps[i].setVisible (false);
344    
345                  if (choice >= 0)                  if (choice >= 0)
346                    break;                    break;
347                }                }
# Line 403  public class CardLayout implements Layou Line 409  public class CardLayout implements Layou
409    private int LAST = 1;    private int LAST = 1;
410    private int NEXT = 2;    private int NEXT = 2;
411    private int PREV = 3;    private int PREV = 3;
   private int NONE = 4;  
412    
413    // These constants are used by the private getSize method.    // These constants are used by the private getSize method.
414    private int MIN = 0;    private int MIN = 0;

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