36 import java.io.IOException;
37
38 /**
39 * A <code>CardLayout</code> object is a layout manager for a
40 * container. It treats each component in the container as a card.
41 * Only one card is visible at a time, and the container acts as
42 * a stack of cards. The first component added to a
43 * <code>CardLayout</code> object is the visible component when the
44 * container is first displayed.
45 * <p>
46 * The ordering of cards is determined by the container's own internal
47 * ordering of its component objects. <code>CardLayout</code>
48 * defines a set of methods that allow an application to flip
49 * through these cards sequentially, or to show a specified card.
50 * The {@link CardLayout#addLayoutComponent}
51 * method can be used to associate a string identifier with a given card
52 * for fast random access.
53 *
54 * @author Arthur van Hoff
55 * @see java.awt.Container
56 * @since JDK1.0
57 */
58
59 public class CardLayout implements LayoutManager2,
60 Serializable {
61
62 private static final long serialVersionUID = -4328196481005934313L;
63
64 /*
65 * This creates a Vector to store associated
66 * pairs of components and their names.
67 * @see java.util.Vector
68 */
69 Vector<Card> vector = new Vector<>();
70
71 /*
72 * A pair of Component and String that represents its name.
73 */
74 class Card implements Serializable {
75 static final long serialVersionUID = 6640330810709497518L;
76 public String name;
131 }
132
133 /**
134 * Creates a new card layout with the specified horizontal and
135 * vertical gaps. The horizontal gaps are placed at the left and
136 * right edges. The vertical gaps are placed at the top and bottom
137 * edges.
138 * @param hgap the horizontal gap.
139 * @param vgap the vertical gap.
140 */
141 public CardLayout(int hgap, int vgap) {
142 this.hgap = hgap;
143 this.vgap = vgap;
144 }
145
146 /**
147 * Gets the horizontal gap between components.
148 * @return the horizontal gap between components.
149 * @see java.awt.CardLayout#setHgap(int)
150 * @see java.awt.CardLayout#getVgap()
151 * @since JDK1.1
152 */
153 public int getHgap() {
154 return hgap;
155 }
156
157 /**
158 * Sets the horizontal gap between components.
159 * @param hgap the horizontal gap between components.
160 * @see java.awt.CardLayout#getHgap()
161 * @see java.awt.CardLayout#setVgap(int)
162 * @since JDK1.1
163 */
164 public void setHgap(int hgap) {
165 this.hgap = hgap;
166 }
167
168 /**
169 * Gets the vertical gap between components.
170 * @return the vertical gap between components.
171 * @see java.awt.CardLayout#setVgap(int)
172 * @see java.awt.CardLayout#getHgap()
173 */
174 public int getVgap() {
175 return vgap;
176 }
177
178 /**
179 * Sets the vertical gap between components.
180 * @param vgap the vertical gap between components.
181 * @see java.awt.CardLayout#getVgap()
182 * @see java.awt.CardLayout#setHgap(int)
183 * @since JDK1.1
184 */
185 public void setVgap(int vgap) {
186 this.vgap = vgap;
187 }
188
189 /**
190 * Adds the specified component to this card layout's internal
191 * table of names. The object specified by <code>constraints</code>
192 * must be a string. The card layout stores this string as a key-value
193 * pair that can be used for random access to a particular card.
194 * By calling the <code>show</code> method, an application can
195 * display the component with the specified name.
196 * @param comp the component to be added.
197 * @param constraints a tag that identifies a particular
198 * card in the layout.
199 * @see java.awt.CardLayout#show(java.awt.Container, java.lang.String)
200 * @exception IllegalArgumentException if the constraint is not a string.
201 */
202 public void addLayoutComponent(Component comp, Object constraints) {
203 synchronized (comp.getTreeLock()) {
|
36 import java.io.IOException;
37
38 /**
39 * A <code>CardLayout</code> object is a layout manager for a
40 * container. It treats each component in the container as a card.
41 * Only one card is visible at a time, and the container acts as
42 * a stack of cards. The first component added to a
43 * <code>CardLayout</code> object is the visible component when the
44 * container is first displayed.
45 * <p>
46 * The ordering of cards is determined by the container's own internal
47 * ordering of its component objects. <code>CardLayout</code>
48 * defines a set of methods that allow an application to flip
49 * through these cards sequentially, or to show a specified card.
50 * The {@link CardLayout#addLayoutComponent}
51 * method can be used to associate a string identifier with a given card
52 * for fast random access.
53 *
54 * @author Arthur van Hoff
55 * @see java.awt.Container
56 * @since 1.0
57 */
58
59 public class CardLayout implements LayoutManager2,
60 Serializable {
61
62 private static final long serialVersionUID = -4328196481005934313L;
63
64 /*
65 * This creates a Vector to store associated
66 * pairs of components and their names.
67 * @see java.util.Vector
68 */
69 Vector<Card> vector = new Vector<>();
70
71 /*
72 * A pair of Component and String that represents its name.
73 */
74 class Card implements Serializable {
75 static final long serialVersionUID = 6640330810709497518L;
76 public String name;
131 }
132
133 /**
134 * Creates a new card layout with the specified horizontal and
135 * vertical gaps. The horizontal gaps are placed at the left and
136 * right edges. The vertical gaps are placed at the top and bottom
137 * edges.
138 * @param hgap the horizontal gap.
139 * @param vgap the vertical gap.
140 */
141 public CardLayout(int hgap, int vgap) {
142 this.hgap = hgap;
143 this.vgap = vgap;
144 }
145
146 /**
147 * Gets the horizontal gap between components.
148 * @return the horizontal gap between components.
149 * @see java.awt.CardLayout#setHgap(int)
150 * @see java.awt.CardLayout#getVgap()
151 * @since 1.1
152 */
153 public int getHgap() {
154 return hgap;
155 }
156
157 /**
158 * Sets the horizontal gap between components.
159 * @param hgap the horizontal gap between components.
160 * @see java.awt.CardLayout#getHgap()
161 * @see java.awt.CardLayout#setVgap(int)
162 * @since 1.1
163 */
164 public void setHgap(int hgap) {
165 this.hgap = hgap;
166 }
167
168 /**
169 * Gets the vertical gap between components.
170 * @return the vertical gap between components.
171 * @see java.awt.CardLayout#setVgap(int)
172 * @see java.awt.CardLayout#getHgap()
173 */
174 public int getVgap() {
175 return vgap;
176 }
177
178 /**
179 * Sets the vertical gap between components.
180 * @param vgap the vertical gap between components.
181 * @see java.awt.CardLayout#getVgap()
182 * @see java.awt.CardLayout#setHgap(int)
183 * @since 1.1
184 */
185 public void setVgap(int vgap) {
186 this.vgap = vgap;
187 }
188
189 /**
190 * Adds the specified component to this card layout's internal
191 * table of names. The object specified by <code>constraints</code>
192 * must be a string. The card layout stores this string as a key-value
193 * pair that can be used for random access to a particular card.
194 * By calling the <code>show</code> method, an application can
195 * display the component with the specified name.
196 * @param comp the component to be added.
197 * @param constraints a tag that identifies a particular
198 * card in the layout.
199 * @see java.awt.CardLayout#show(java.awt.Container, java.lang.String)
200 * @exception IllegalArgumentException if the constraint is not a string.
201 */
202 public void addLayoutComponent(Component comp, Object constraints) {
203 synchronized (comp.getTreeLock()) {
|