42 |
import java.util.Enumeration; |
import java.util.Enumeration; |
43 |
import java.util.Hashtable; |
import java.util.Hashtable; |
44 |
|
|
45 |
/** This class implements a card-based layout scheme. Each included |
/** |
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 |
* 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 |
* time. This class includes methods for changing which card is |
49 |
* shown. |
* shown. |
50 |
* |
* |
51 |
* @author Tom Tromey <tromey@redhat.com> |
* @author Tom Tromey (tromey@redhat.com) |
52 |
* @author Aaron M. Renn (arenn@urbanophile.com) |
* @author Aaron M. Renn (arenn@urbanophile.com) |
53 |
*/ |
*/ |
54 |
public class CardLayout implements LayoutManager2, Serializable |
public class CardLayout implements LayoutManager2, Serializable |
67 |
/** |
/** |
68 |
* Create a new <code>CardLayout</code> object with the specified |
* Create a new <code>CardLayout</code> object with the specified |
69 |
* horizontal and vertical gaps. |
* horizontal and vertical gaps. |
70 |
|
* |
71 |
* @param hgap The horizontal gap |
* @param hgap The horizontal gap |
72 |
* @param vgap The vertical gap |
* @param vgap The vertical gap |
73 |
*/ |
*/ |
78 |
this.tab = new Hashtable (); |
this.tab = new Hashtable (); |
79 |
} |
} |
80 |
|
|
81 |
/** Add a new component to the layout. The constraint must be a |
/** |
82 |
|
* Add a new component to the layout. The constraint must be a |
83 |
* string which is used to name the component. This string can |
* string which is used to name the component. This string can |
84 |
* later be used to refer to the particular component. |
* later be used to refer to the particular component. |
85 |
|
* |
86 |
* @param comp The component to add |
* @param comp The component to add |
87 |
* @param constraints The name by which the component can later be called |
* @param constraints The name by which the component can later be called |
88 |
|
* |
89 |
* @exception IllegalArgumentException If `constraints' is not a |
* @exception IllegalArgumentException If `constraints' is not a |
90 |
* <code>String</code> |
* <code>String</code> |
91 |
*/ |
*/ |
97 |
addLayoutComponent ((String) constraints, comp); |
addLayoutComponent ((String) constraints, comp); |
98 |
} |
} |
99 |
|
|
100 |
/** Add a new component to the layout. The name can be used later |
/** |
101 |
|
* Add a new component to the layout. The name can be used later |
102 |
* to refer to the component. |
* to refer to the component. |
103 |
|
* |
104 |
* @param name The name by which the component can later be called |
* @param name The name by which the component can later be called |
105 |
* @param comp The component to add |
* @param comp The component to add |
106 |
|
* |
107 |
* @deprecated This method is deprecated in favor of |
* @deprecated This method is deprecated in favor of |
108 |
* <code>addLayoutComponent(Component, Object)</code>. |
* <code>addLayoutComponent(Component, Object)</code>. |
109 |
*/ |
*/ |
117 |
comp.setVisible(false); |
comp.setVisible(false); |
118 |
} |
} |
119 |
|
|
120 |
/** Cause the first component in the container to be displayed. |
/** |
121 |
|
* Cause the first component in the container to be displayed. |
122 |
|
* |
123 |
* @param parent The parent container |
* @param parent The parent container |
124 |
*/ |
*/ |
125 |
public void first (Container parent) |
public void first (Container parent) |
127 |
gotoComponent (parent, FIRST); |
gotoComponent (parent, FIRST); |
128 |
} |
} |
129 |
|
|
130 |
/** Return this layout manager's horizontal gap. */ |
/** |
131 |
|
* Return this layout manager's horizontal gap. |
132 |
|
* |
133 |
|
* @return the horizontal gap |
134 |
|
*/ |
135 |
public int getHgap () |
public int getHgap () |
136 |
{ |
{ |
137 |
return hgap; |
return hgap; |
138 |
} |
} |
139 |
|
|
140 |
/** Return this layout manager's x alignment. This method always |
/** |
141 |
|
* Return this layout manager's x alignment. This method always |
142 |
* returns Component.CENTER_ALIGNMENT. |
* returns Component.CENTER_ALIGNMENT. |
143 |
|
* |
144 |
* @param parent Container using this layout manager instance |
* @param parent Container using this layout manager instance |
145 |
|
* |
146 |
|
* @return the x-axis alignment |
147 |
*/ |
*/ |
148 |
public float getLayoutAlignmentX (Container parent) |
public float getLayoutAlignmentX (Container parent) |
149 |
{ |
{ |
150 |
return Component.CENTER_ALIGNMENT; |
return Component.CENTER_ALIGNMENT; |
151 |
} |
} |
152 |
|
|
153 |
/** Returns this layout manager's y alignment. This method always |
/** |
154 |
|
* Returns this layout manager's y alignment. This method always |
155 |
* returns Component.CENTER_ALIGNMENT. |
* returns Component.CENTER_ALIGNMENT. |
156 |
|
* |
157 |
* @param parent Container using this layout manager instance |
* @param parent Container using this layout manager instance |
158 |
|
* |
159 |
|
* @return the y-axis alignment |
160 |
*/ |
*/ |
161 |
public float getLayoutAlignmentY (Container parent) |
public float getLayoutAlignmentY (Container parent) |
162 |
{ |
{ |
163 |
return Component.CENTER_ALIGNMENT; |
return Component.CENTER_ALIGNMENT; |
164 |
} |
} |
165 |
|
|
166 |
/** Return this layout manager's vertical gap. */ |
/** |
167 |
|
* Return this layout manager's vertical gap. |
168 |
|
* |
169 |
|
* @return the vertical gap |
170 |
|
*/ |
171 |
public int getVgap () |
public int getVgap () |
172 |
{ |
{ |
173 |
return vgap; |
return vgap; |
174 |
} |
} |
175 |
|
|
176 |
/** Invalidate this layout manager's state. */ |
/** |
177 |
|
* Invalidate this layout manager's state. |
178 |
|
*/ |
179 |
public void invalidateLayout (Container target) |
public void invalidateLayout (Container target) |
180 |
{ |
{ |
181 |
// Do nothing. |
// Do nothing. |
182 |
} |
} |
183 |
|
|
184 |
/** Cause the last component in the container to be displayed. |
/** |
185 |
|
* Cause the last component in the container to be displayed. |
186 |
|
* |
187 |
* @param parent The parent container |
* @param parent The parent container |
188 |
*/ |
*/ |
189 |
public void last (Container parent) |
public void last (Container parent) |
219 |
} |
} |
220 |
} |
} |
221 |
|
|
222 |
/** Get the maximum layout size of the container. |
/** |
223 |
|
* Get the maximum layout size of the container. |
224 |
|
* |
225 |
* @param target The parent container |
* @param target The parent container |
226 |
|
* |
227 |
|
* @return the maximum layout size |
228 |
*/ |
*/ |
229 |
public Dimension maximumLayoutSize (Container target) |
public Dimension maximumLayoutSize (Container target) |
230 |
{ |
{ |
233 |
return getSize (target, MAX); |
return getSize (target, MAX); |
234 |
} |
} |
235 |
|
|
236 |
/** Get the minimum layout size of the container. |
/** |
237 |
|
* Get the minimum layout size of the container. |
238 |
|
* |
239 |
* @param target The parent container |
* @param target The parent container |
240 |
|
* |
241 |
|
* @return the minimum layout size |
242 |
*/ |
*/ |
243 |
public Dimension minimumLayoutSize (Container target) |
public Dimension minimumLayoutSize (Container target) |
244 |
{ |
{ |
245 |
return getSize (target, MIN); |
return getSize (target, MIN); |
246 |
} |
} |
247 |
|
|
248 |
/** Cause the next component in the container to be displayed. If |
/** |
249 |
|
* Cause the next component in the container to be displayed. If |
250 |
* this current card is the last one in the deck, the first |
* this current card is the last one in the deck, the first |
251 |
* component is displayed. |
* component is displayed. |
252 |
|
* |
253 |
* @param parent The parent container |
* @param parent The parent container |
254 |
*/ |
*/ |
255 |
public void next (Container parent) |
public void next (Container parent) |
257 |
gotoComponent (parent, NEXT); |
gotoComponent (parent, NEXT); |
258 |
} |
} |
259 |
|
|
260 |
/** Get the preferred layout size of the container. |
/** |
261 |
* @param target The parent container |
* Get the preferred layout size of the container. |
262 |
|
* |
263 |
|
* @param parent The parent container |
264 |
|
* |
265 |
|
* @return the preferred layout size |
266 |
*/ |
*/ |
267 |
public Dimension preferredLayoutSize (Container parent) |
public Dimension preferredLayoutSize (Container parent) |
268 |
{ |
{ |
269 |
return getSize (parent, PREF); |
return getSize (parent, PREF); |
270 |
} |
} |
271 |
|
|
272 |
/** Cause the previous component in the container to be displayed. |
/** |
273 |
|
* Cause the previous component in the container to be displayed. |
274 |
* If this current card is the first one in the deck, the last |
* If this current card is the first one in the deck, the last |
275 |
* component is displayed. |
* component is displayed. |
276 |
|
* |
277 |
* @param parent The parent container |
* @param parent The parent container |
278 |
*/ |
*/ |
279 |
public void previous (Container parent) |
public void previous (Container parent) |
281 |
gotoComponent (parent, PREV); |
gotoComponent (parent, PREV); |
282 |
} |
} |
283 |
|
|
284 |
/** Remove the indicated component from this layout manager. |
/** |
285 |
|
* Remove the indicated component from this layout manager. |
286 |
|
* |
287 |
* @param comp The component to remove |
* @param comp The component to remove |
288 |
*/ |
*/ |
289 |
public void removeLayoutComponent (Component comp) |
public void removeLayoutComponent (Component comp) |
302 |
} |
} |
303 |
} |
} |
304 |
|
|
305 |
/** Set this layout manager's horizontal gap. |
/** |
306 |
|
* Set this layout manager's horizontal gap. |
307 |
|
* |
308 |
* @param hgap The new gap |
* @param hgap The new gap |
309 |
*/ |
*/ |
310 |
public void setHgap (int hgap) |
public void setHgap (int hgap) |
312 |
this.hgap = hgap; |
this.hgap = hgap; |
313 |
} |
} |
314 |
|
|
315 |
/** Set this layout manager's vertical gap. |
/** |
316 |
|
* Set this layout manager's vertical gap. |
317 |
|
* |
318 |
* @param vgap The new gap |
* @param vgap The new gap |
319 |
*/ |
*/ |
320 |
public void setVgap (int vgap) |
public void setVgap (int vgap) |
322 |
this.vgap = vgap; |
this.vgap = vgap; |
323 |
} |
} |
324 |
|
|
325 |
/** Cause the named component to be shown. If the component name is |
/** |
326 |
|
* Cause the named component to be shown. If the component name is |
327 |
* unknown, this method does nothing. |
* unknown, this method does nothing. |
328 |
|
* |
329 |
* @param parent The parent container |
* @param parent The parent container |
330 |
* @param name The name of the component to show |
* @param name The name of the component to show |
331 |
*/ |
*/ |
360 |
return getClass ().getName () + "[" + hgap + "," + vgap + "]"; |
return getClass ().getName () + "[" + hgap + "," + vgap + "]"; |
361 |
} |
} |
362 |
|
|
363 |
/** This implements first(), last(), next(), and previous(). |
/** |
364 |
|
* This implements first(), last(), next(), and previous(). |
365 |
|
* |
366 |
* @param parent The parent container |
* @param parent The parent container |
367 |
* @param what The type of goto: FIRST, LAST, NEXT or PREV |
* @param what The type of goto: FIRST, LAST, NEXT or PREV |
368 |
*/ |
*/ |