home *** CD-ROM | disk | FTP | other *** search
/ Datatid 2000 #1 / Datatid-2000-01.iso / Internet / JAVA_NAVIGATOR / JAVANAVIGATOR.EXE / %MAINDIR% / files / JClass / TabPanel.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-08-31  |  6.4 KB  |  255 lines

  1. import java.awt.Component;
  2. import java.awt.Dimension;
  3. import java.awt.Event;
  4. import java.awt.Insets;
  5. import java.util.Vector;
  6.  
  7. public class TabPanel extends BaseTabbedPanel {
  8.    Vector vPanels;
  9.    String[] labels;
  10.    boolean bOsHack;
  11.  
  12.    public TabPanel() {
  13.       this(0, 0);
  14.    }
  15.  
  16.    public TabPanel(boolean bTabsOnTop) {
  17.       this(bTabsOnTop ? 0 : 1, bTabsOnTop ? 0 : 1);
  18.    }
  19.  
  20.    public TabPanel(int tabsPostion, int tabsStyle) {
  21.       super(tabsPostion, tabsStyle);
  22.       this.vPanels = new Vector();
  23.       String sOS = System.getProperty("os.name");
  24.       if (sOS.equals("Windows 95")) {
  25.          this.bOsHack = true;
  26.       } else {
  27.          this.bOsHack = false;
  28.       }
  29.    }
  30.  
  31.    public int addTabPanel(String sLabel, boolean bEnabled, Component panel) {
  32.       this.vPanels.addElement(panel);
  33.       return ((BaseTabbedPanel)this).addTab(sLabel, bEnabled);
  34.    }
  35.  
  36.    public int getCurrentPanelNdx() {
  37.       return super.curIndex;
  38.    }
  39.  
  40.    public void setCurrentPanelNdx(int index) {
  41.       this.showTabPanel(index);
  42.    }
  43.  
  44.    public Component add(Component comp) {
  45.       return this.add(comp, -1);
  46.    }
  47.  
  48.    private String createDefaultLabel(int i) {
  49.       String name = "tab - ";
  50.       name = name + String.valueOf(i);
  51.       return name;
  52.    }
  53.  
  54.    public synchronized Component add(Component comp, int pos) {
  55.       this.showTabPanel(this.addTabPanel(this.createDefaultLabel(this.vPanels.size()), true, comp));
  56.       this.updatePanelLabels();
  57.       return comp;
  58.    }
  59.  
  60.    public synchronized Component add(String name, Component comp) {
  61.       return comp;
  62.    }
  63.  
  64.    public void setPanelLabels(String[] sLabels) {
  65.       this.labels = sLabels;
  66.       this.updatePanelLabels();
  67.    }
  68.  
  69.    public String[] getPanelLabels() {
  70.       return this.labels;
  71.    }
  72.  
  73.    public void updatePanelLabels() {
  74.       try {
  75.          for(int i = 0; i < this.vPanels.size(); ++i) {
  76.             String newlabel;
  77.             if (this.labels != null) {
  78.                try {
  79.                   newlabel = this.labels[i];
  80.                } catch (ArrayIndexOutOfBoundsException var3) {
  81.                   newlabel = this.createDefaultLabel(i);
  82.                }
  83.             } else {
  84.                newlabel = this.createDefaultLabel(i);
  85.             }
  86.  
  87.             ((BaseTabbedPanel)this).setLabel(newlabel, i);
  88.          }
  89.  
  90.       } catch (Throwable var4) {
  91.       }
  92.    }
  93.  
  94.    public void setTabsOnBottom(boolean bTabsOnBottom) {
  95.       ((BaseTabbedPanel)this).setTabsInfo(bTabsOnBottom ? 1 : 0, bTabsOnBottom ? 1 : 0);
  96.       ((BaseTabbedPanel)this).layout();
  97.    }
  98.  
  99.    public boolean getTabsOnBottom() {
  100.       return ((BaseTabbedPanel)this).getTabsPosition() != 0;
  101.    }
  102.  
  103.    public synchronized void setTabPanel(String sLabel, boolean bEnabled, Component panel, int index) {
  104.       if (index >= 0 && index < this.vPanels.size()) {
  105.          if (index != ((BaseTabbedPanel)this).currentTabIndex() || bEnabled) {
  106.             try {
  107.                this.vPanels.setElementAt(panel, index);
  108.                ((BaseTabbedPanel)this).setTab(sLabel, bEnabled, index);
  109.             } catch (ArrayIndexOutOfBoundsException var5) {
  110.             }
  111.          }
  112.       }
  113.    }
  114.  
  115.    public synchronized Component getTabPanel(int index) {
  116.       if (index >= 0 && index < this.vPanels.size()) {
  117.          Component p = null;
  118.  
  119.          try {
  120.             p = (Component)this.vPanels.elementAt(index);
  121.          } catch (ArrayIndexOutOfBoundsException var3) {
  122.          }
  123.  
  124.          return p;
  125.       } else {
  126.          return null;
  127.       }
  128.    }
  129.  
  130.    public synchronized int getPanelTabIndex(Component panel) {
  131.       return this.vPanels.indexOf(panel);
  132.    }
  133.  
  134.    public synchronized void showTabPanel(int index) {
  135.       if (((BaseTabbedPanel)this).tabIsEnabled(index)) {
  136.          try {
  137.             Component p = (Component)this.vPanels.elementAt(index);
  138.             ((BaseTabbedPanel)this).showTab(index);
  139.             ((BaseTabbedPanel)this).showPanel(p);
  140.          } catch (ArrayIndexOutOfBoundsException var3) {
  141.          }
  142.       }
  143.    }
  144.  
  145.    public synchronized void enableTabPanel(boolean bEnable, int index) {
  146.       if (index >= 0 && index < this.vPanels.size() && index != super.curIndex) {
  147.          ((BaseTabbedPanel)this).enableTab(bEnable, index);
  148.       }
  149.    }
  150.  
  151.    public synchronized void removeTabPanel(int index) {
  152.       if (index >= 0 && index < this.vPanels.size() && index != super.curIndex) {
  153.          try {
  154.             Component p = (Component)this.vPanels.elementAt(index);
  155.             super.remove(p);
  156.             this.vPanels.removeElementAt(index);
  157.          } catch (ArrayIndexOutOfBoundsException var3) {
  158.          }
  159.  
  160.          ((BaseTabbedPanel)this).removeTab(index);
  161.       }
  162.    }
  163.  
  164.    public synchronized void removeAllTabPanels() {
  165.       this.vPanels = new Vector();
  166.       super.curIndex = -1;
  167.       ((BaseTabbedPanel)this).removeAllTabs();
  168.    }
  169.  
  170.    public int countTabs() {
  171.       return this.vPanels.size();
  172.    }
  173.  
  174.    public boolean handleEvent(Event evt) {
  175.       switch (evt.id) {
  176.          case 1001:
  177.             if (evt.target instanceof TabPanel && evt.target == this) {
  178.                this.showTabPanel(((BaseTabbedPanel)this).currentTabIndex());
  179.             }
  180.          default:
  181.             return super.handleEvent(evt);
  182.       }
  183.    }
  184.  
  185.    public Dimension preferredSize() {
  186.       Component pan = null;
  187.       Dimension d = null;
  188.       Dimension p = ((Component)this).size();
  189.       int s = this.vPanels.size();
  190.       Insets insets = ((BaseTabbedPanel)this).insets();
  191.       p.width -= insets.left + insets.right;
  192.       p.height -= insets.top + insets.bottom;
  193.       if (p.width < 0) {
  194.          p.width = 0;
  195.       }
  196.  
  197.       if (p.height < 0) {
  198.          p.height = 0;
  199.       }
  200.  
  201.       for(int x = 0; x < s; ++x) {
  202.          pan = (Component)this.vPanels.elementAt(x);
  203.          if (pan != null) {
  204.             d = pan.minimumSize();
  205.             if (d.width > p.width) {
  206.                p.width = d.width;
  207.             }
  208.  
  209.             if (d.height > p.height) {
  210.                p.height = d.height;
  211.             }
  212.  
  213.             d = pan.preferredSize();
  214.             if (d.width > p.width) {
  215.                p.width = d.width;
  216.             }
  217.  
  218.             if (d.height > p.height) {
  219.                p.height = d.height;
  220.             }
  221.          }
  222.       }
  223.  
  224.       p.width += insets.left + insets.right;
  225.       p.height += insets.top + insets.bottom;
  226.       return p;
  227.    }
  228.  
  229.    public Dimension minimumSize() {
  230.       Component pan = null;
  231.       Dimension d = null;
  232.       Dimension m = new Dimension(0, 0);
  233.       int s = this.vPanels.size();
  234.  
  235.       for(int x = 0; x < s; ++x) {
  236.          pan = (Component)this.vPanels.elementAt(x);
  237.          if (pan != null) {
  238.             d = pan.minimumSize();
  239.             if (d.width > m.width) {
  240.                m.width = d.width;
  241.             }
  242.  
  243.             if (d.height > m.height) {
  244.                m.height = d.height;
  245.             }
  246.          }
  247.       }
  248.  
  249.       Insets insets = ((BaseTabbedPanel)this).insets();
  250.       m.width += insets.left + insets.right;
  251.       m.height += insets.top + insets.bottom;
  252.       return m;
  253.    }
  254. }
  255.