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 |
|
|
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. */ |
154 |
*/ |
*/ |
155 |
public void last (Container parent) |
public void last (Container parent) |
156 |
{ |
{ |
157 |
gotoComponent (parent, LAST, null); |
gotoComponent (parent, LAST); |
158 |
} |
} |
159 |
|
|
160 |
/** |
/** |
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. |
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. |
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 |
/** |
/** |
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 |
{ |
{ |
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) |
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 |
} |
} |
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; |