source: trunk/src/gcc/libjava/java/awt/CardLayout.java@ 2228

Last change on this file since 2228 was 1392, checked in by bird, 22 years ago

This commit was generated by cvs2svn to compensate for changes in r1391,
which included commits to RCS files with non-trunk default branches.

  • Property cvs2svn:cvs-rev set to 1.1.1.2
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 10.8 KB
Line 
1// CardLayout.java - Card-based layout engine
2
3/* Copyright (C) 1999, 2000, 2002, 2003 Free Software Foundation
4
5This file is part of GNU Classpath.
6
7GNU Classpath is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU Classpath is distributed in the hope that it will be useful, but
13WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU Classpath; see the file COPYING. If not, write to the
19Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
2002111-1307 USA.
21
22Linking this library statically or dynamically with other modules is
23making a combined work based on this library. Thus, the terms and
24conditions of the GNU General Public License cover the whole
25combination.
26
27As a special exception, the copyright holders of this library give you
28permission to link this library with independent modules to produce an
29executable, regardless of the license terms of these independent
30modules, and to copy and distribute the resulting executable under
31terms of your choice, provided that you also meet, for each linked
32independent module, the terms and conditions of the license of that
33module. An independent module is a module which is not derived from
34or based on this library. If you modify this library, you may extend
35this exception to your version of the library, but you are not
36obligated to do so. If you do not wish to do so, delete this
37exception statement from your version. */
38
39
40package java.awt;
41
42import java.util.Enumeration;
43import java.util.Hashtable;
44import java.io.Serializable;
45
46/** This class implements a card-based layout scheme. Each included
47 * component is treated as a card. Only one card can be shown at a
48 * time. This class includes methods for changing which card is
49 * shown.
50 *
51 * @author Tom Tromey <[email protected]>
52 * @author Aaron M. Renn ([email protected])
53 */
54public class CardLayout implements LayoutManager2, Serializable
55{
56 static final long serialVersionUID = -4328196481005934313L;
57
58 /**
59 * Initializes a new instance of <code>CardLayout</code> with horizontal
60 * and vertical gaps of 0.
61 */
62 public CardLayout ()
63 {
64 this (0, 0);
65 }
66
67 /**
68 * Create a new <code>CardLayout</code> object with the specified
69 * horizontal and vertical gaps.
70 * @param hgap The horizontal gap
71 * @param vgap The vertical gap
72 */
73 public CardLayout (int hgap, int vgap)
74 {
75 this.hgap = hgap;
76 this.vgap = vgap;
77 this.tab = new Hashtable ();
78 }
79
80 /** Add a new component to the layout. The constraint must be a
81 * string which is used to name the component. This string can
82 * later be used to refer to the particular component.
83 * @param comp The component to add
84 * @param constraints The name by which the component can later be called
85 * @exception IllegalArgumentException If `constraints' is not a
86 * <code>String</code>
87 */
88 public void addLayoutComponent (Component comp, Object constraints)
89 {
90 if (! (constraints instanceof String))
91 throw new IllegalArgumentException ("Object " + constraints
92 + " is not a string");
93 tab.put (constraints, comp);
94 }
95
96 /** Add a new component to the layout. The name can be used later
97 * to refer to the component.
98 * @param name The name by which the component can later be called
99 * @param comp The component to add
100 * @deprecated This method is deprecated in favor of
101 * <code>addLayoutComponent(Component, Object)</code>.
102 */
103 public void addLayoutComponent (String name, Component comp)
104 {
105 addLayoutComponent (comp, name);
106 }
107
108 /** Cause the first component in the container to be displayed.
109 * @param parent The parent container
110 */
111 public void first (Container parent)
112 {
113 gotoComponent (parent, FIRST);
114 }
115
116 /** Return this layout manager's horizontal gap. */
117 public int getHgap ()
118 {
119 return hgap;
120 }
121
122 /** Return this layout manager's x alignment. This method always
123 * returns Component.CENTER_ALIGNMENT.
124 * @param parent Container using this layout manager instance
125 */
126 public float getLayoutAlignmentX (Container parent)
127 {
128 return Component.CENTER_ALIGNMENT;
129 }
130
131 /** Returns this layout manager's y alignment. This method always
132 * returns Component.CENTER_ALIGNMENT.
133 * @param parent Container using this layout manager instance
134 */
135 public float getLayoutAlignmentY (Container parent)
136 {
137 return Component.CENTER_ALIGNMENT;
138 }
139
140 /** Return this layout manager's vertical gap. */
141 public int getVgap ()
142 {
143 return vgap;
144 }
145
146 /** Invalidate this layout manager's state. */
147 public void invalidateLayout (Container target)
148 {
149 // Do nothing.
150 }
151
152 /** Cause the last component in the container to be displayed.
153 * @param parent The parent container
154 */
155 public void last (Container parent)
156 {
157 gotoComponent (parent, LAST);
158 }
159
160 /**
161 * Lays out the container. This is done by resizing the child components
162 * to be the same size as the parent, less insets and gaps.
163 *
164 * @param parent The parent container.
165 */
166 public void layoutContainer (Container parent)
167 {
168 synchronized (parent.getTreeLock ())
169 {
170 int width = parent.width;
171 int height = parent.height;
172
173 Insets ins = parent.getInsets ();