home *** CD-ROM | disk | FTP | other *** search
- package java.awt;
-
- import java.util.Enumeration;
- import java.util.Hashtable;
-
- public class CardLayout implements LayoutManager {
- Hashtable tab;
- int hgap;
- int vgap;
-
- public CardLayout() {
- this(0, 0);
- }
-
- public CardLayout(int hgap, int vgap) {
- this.tab = new Hashtable();
- this.hgap = hgap;
- this.vgap = vgap;
- }
-
- public void addLayoutComponent(String name, Component comp) {
- if (this.tab.size() > 0) {
- comp.hide();
- }
-
- this.tab.put(name, comp);
- }
-
- public void removeLayoutComponent(Component comp) {
- Enumeration e = this.tab.keys();
-
- while(e.hasMoreElements()) {
- String key = (String)e.nextElement();
- if (this.tab.get(key) == comp) {
- this.tab.remove(key);
- return;
- }
- }
-
- }
-
- public Dimension preferredLayoutSize(Container parent) {
- Insets insets = parent.insets();
- int ncomponents = parent.countComponents();
- int w = 0;
- int h = 0;
-
- for(int i = 0; i < ncomponents; ++i) {
- Component comp = parent.getComponent(i);
- Dimension d = comp.preferredSize();
- if (d.width > w) {
- w = d.width;
- }
-
- if (d.height > h) {
- h = d.height;
- }
- }
-
- return new Dimension(insets.left + insets.right + w + this.hgap * 2, insets.top + insets.bottom + h + this.vgap * 2);
- }
-
- public Dimension minimumLayoutSize(Container parent) {
- Insets insets = parent.insets();
- int ncomponents = parent.countComponents();
- int w = 0;
- int h = 0;
-
- for(int i = 0; i < ncomponents; ++i) {
- Component comp = parent.getComponent(i);
- Dimension d = comp.minimumSize();
- if (d.width > w) {
- w = d.width;
- }
-
- if (d.height > h) {
- h = d.height;
- }
- }
-
- return new Dimension(insets.left + insets.right + w + this.hgap * 2, insets.top + insets.bottom + h + this.vgap * 2);
- }
-
- public void layoutContainer(Container parent) {
- synchronized(parent){}
-
- try {
- Insets insets = parent.insets();
- int ncomponents = parent.countComponents();
-
- for(int i = 0; i < ncomponents; ++i) {
- Component comp = parent.getComponent(i);
- if (comp.visible) {
- comp.reshape(this.hgap + insets.left, this.vgap + insets.top, parent.width - (this.hgap * 2 + insets.left + insets.right), parent.height - (this.vgap * 2 + insets.top + insets.bottom));
- }
- }
- } catch (Throwable var9) {
- throw var9;
- }
-
- }
-
- void checkLayout(Container parent) {
- if (parent.getLayout() != this) {
- throw new IllegalArgumentException("wrong parent for CardLayout");
- }
- }
-
- public void first(Container parent) {
- synchronized(parent){}
-
- try {
- this.checkLayout(parent);
- int ncomponents = parent.countComponents();
-
- for(int i = 0; i < ncomponents; ++i) {
- Component comp = parent.getComponent(i);
- if (comp.visible) {
- comp.hide();
- comp = parent.getComponent(0);
- comp.show();
- parent.validate();
- return;
- }
- }
-
- } catch (Throwable var8) {
- throw var8;
- }
- }
-
- public void next(Container parent) {
- synchronized(parent){}
-
- try {
- this.checkLayout(parent);
- int ncomponents = parent.countComponents();
-
- for(int i = 0; i < ncomponents; ++i) {
- Component comp = parent.getComponent(i);
- if (comp.visible) {
- comp.hide();
- comp = parent.getComponent(i + 1 < ncomponents ? i + 1 : 0);
- comp.show();
- parent.validate();
- return;
- }
- }
-
- } catch (Throwable var8) {
- throw var8;
- }
- }
-
- public void previous(Container parent) {
- synchronized(parent){}
-
- try {
- this.checkLayout(parent);
- int ncomponents = parent.countComponents();
-
- for(int i = 0; i < ncomponents; ++i) {
- Component comp = parent.getComponent(i);
- if (comp.visible) {
- comp.hide();
- comp = parent.getComponent(i > 0 ? i - 1 : ncomponents - 1);
- comp.show();
- parent.validate();
- return;
- }
- }
-
- } catch (Throwable var8) {
- throw var8;
- }
- }
-
- public void last(Container parent) {
- synchronized(parent){}
-
- try {
- this.checkLayout(parent);
- int ncomponents = parent.countComponents();
-
- for(int i = 0; i < ncomponents; ++i) {
- Component comp = parent.getComponent(i);
- if (comp.visible) {
- comp.hide();
- comp = parent.getComponent(ncomponents - 1);
- comp.show();
- parent.validate();
- return;
- }
- }
-
- } catch (Throwable var8) {
- throw var8;
- }
- }
-
- public void show(Container parent, String name) {
- synchronized(parent){}
-
- try {
- this.checkLayout(parent);
- Component next = (Component)this.tab.get(name);
- if (next != null && !next.visible) {
- int ncomponents = parent.countComponents();
-
- for(int i = 0; i < ncomponents; ++i) {
- Component comp = parent.getComponent(i);
- if (comp.visible) {
- comp.hide();
- break;
- }
- }
-
- next.show();
- parent.validate();
- }
- } catch (Throwable var10) {
- throw var10;
- }
-
- }
-
- public String toString() {
- return this.getClass().getName() + "[hgap=" + this.hgap + ",vgap=" + this.vgap + "]";
- }
- }
-