home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / main.bin / TabPanel.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-08-04  |  6.7 KB  |  281 lines

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