home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.awt;
-
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Insets;
- import java.util.Vector;
- import symantec.beans.Beans;
-
- public strictfp class TabPanel extends BaseTabbedPanel {
- Vector vPanels;
- String[] labels;
- boolean bOsHack;
-
- public TabPanel() {
- this(0, 0);
- }
-
- public TabPanel(boolean bTabsOnTop) {
- this(bTabsOnTop ? 0 : 1, bTabsOnTop ? 0 : 1);
- }
-
- public TabPanel(int tabsPostion, int tabsStyle) {
- super(tabsPostion, tabsStyle);
- this.vPanels = new Vector();
- String sOS = System.getProperty("os.name");
- if (sOS.equals("Windows 95")) {
- this.bOsHack = true;
- } else {
- this.bOsHack = false;
- }
- }
-
- public int addTabPanel(String sLabel, boolean bEnabled, Component panel) {
- this.vPanels.addElement(panel);
- return ((BaseTabbedPanel)this).addTab(sLabel, bEnabled);
- }
-
- public int getCurrentPanelNdx() {
- return super.curIndex;
- }
-
- public void setCurrentPanelNdx(int index) {
- this.showTabPanel(index);
- if (!Beans.isDesignTime()) {
- super.curIndex = index;
- }
-
- }
-
- public Component add(Component comp) {
- return this.add(comp, -1);
- }
-
- private String createDefaultLabel(int i) {
- String name = "tab - ";
- name = name + String.valueOf(i);
- return name;
- }
-
- public synchronized Component add(Component comp, int pos) {
- int newIndex = this.addTabPanel(this.createDefaultLabel(this.vPanels.size()), true, comp);
- if (newIndex == super.curIndex || Beans.isDesignTime()) {
- this.showTabPanel(newIndex);
- }
-
- this.updatePanelLabels();
- return comp;
- }
-
- public synchronized Component add(String name, Component comp) {
- return comp;
- }
-
- public synchronized void remove(Component comp) {
- int i = this.getPanelTabIndex(comp);
- if (this.countTabs() == 1) {
- this.removeAllTabPanels();
- } else {
- if (i == 0) {
- this.showTabPanel(1);
- } else {
- this.showTabPanel(i - 1);
- }
-
- this.removeTabPanel(i);
- }
- }
-
- public void setPanelLabels(String[] sLabels) {
- this.labels = sLabels;
- this.updatePanelLabels();
- }
-
- public String[] getPanelLabels() {
- return this.labels;
- }
-
- public void updatePanelLabels() {
- try {
- for(int i = 0; i < this.vPanels.size(); ++i) {
- String newlabel;
- if (this.labels != null) {
- try {
- newlabel = this.labels[i];
- } catch (ArrayIndexOutOfBoundsException var3) {
- newlabel = this.createDefaultLabel(i);
- }
- } else {
- newlabel = this.createDefaultLabel(i);
- }
-
- ((BaseTabbedPanel)this).setLabel(newlabel, i);
- }
-
- } catch (Throwable var4) {
- }
- }
-
- public void setTabsOnBottom(boolean bTabsOnBottom) {
- ((BaseTabbedPanel)this).setTabsInfo(bTabsOnBottom ? 1 : 0, bTabsOnBottom ? 1 : 0);
- ((BaseTabbedPanel)this).layout();
- }
-
- public boolean getTabsOnBottom() {
- return ((BaseTabbedPanel)this).getTabsPosition() != 0;
- }
-
- public synchronized void setTabPanel(String sLabel, boolean bEnabled, Component panel, int index) {
- if (index >= 0 && index < this.vPanels.size()) {
- if (index != ((BaseTabbedPanel)this).currentTabIndex() || bEnabled) {
- try {
- this.vPanels.setElementAt(panel, index);
- ((BaseTabbedPanel)this).setTab(sLabel, bEnabled, index);
- } catch (ArrayIndexOutOfBoundsException var5) {
- }
- }
- }
- }
-
- public synchronized Component getTabPanel(int index) {
- if (index >= 0 && index < this.vPanels.size()) {
- Component p = null;
-
- try {
- p = (Component)this.vPanels.elementAt(index);
- } catch (ArrayIndexOutOfBoundsException var3) {
- }
-
- return p;
- } else {
- return null;
- }
- }
-
- public synchronized int getPanelTabIndex(Component panel) {
- return this.vPanels.indexOf(panel);
- }
-
- public synchronized void showTabPanel(int index) {
- if (((BaseTabbedPanel)this).tabIsEnabled(index)) {
- try {
- Component p = (Component)this.vPanels.elementAt(index);
- ((BaseTabbedPanel)this).showTab(index);
- ((BaseTabbedPanel)this).showPanel(p);
- } catch (ArrayIndexOutOfBoundsException var3) {
- }
- }
- }
-
- public synchronized void enableTabPanel(boolean bEnable, int index) {
- if (index >= 0 && index < this.vPanels.size() && index != super.curIndex) {
- ((BaseTabbedPanel)this).enableTab(bEnable, index);
- }
- }
-
- public synchronized void removeTabPanel(int index) {
- if (index >= 0 && index < this.vPanels.size() && index != super.curIndex) {
- try {
- Component p = (Component)this.vPanels.elementAt(index);
- super.remove(p);
- this.vPanels.removeElementAt(index);
- } catch (ArrayIndexOutOfBoundsException var3) {
- }
-
- ((BaseTabbedPanel)this).removeTab(index);
- }
- }
-
- public synchronized void removeAllTabPanels() {
- this.vPanels = new Vector();
- super.curIndex = -1;
- ((BaseTabbedPanel)this).removeAllTabs();
- }
-
- public int countTabs() {
- return this.vPanels.size();
- }
-
- public boolean handleEvent(Event evt) {
- switch (evt.id) {
- case 1001:
- if (evt.target instanceof TabPanel && evt.target == this) {
- this.showTabPanel(((BaseTabbedPanel)this).currentTabIndex());
- }
- default:
- return super.handleEvent(evt);
- }
- }
-
- public Dimension preferredSize() {
- Component pan = null;
- Dimension d = null;
- Dimension p = ((Component)this).size();
- int s = this.vPanels.size();
- Insets insets = ((BaseTabbedPanel)this).insets();
- p.width -= insets.left + insets.right;
- p.height -= insets.top + insets.bottom;
- if (p.width < 0) {
- p.width = 0;
- }
-
- if (p.height < 0) {
- p.height = 0;
- }
-
- for(int x = 0; x < s; ++x) {
- pan = (Component)this.vPanels.elementAt(x);
- if (pan != null) {
- d = pan.minimumSize();
- if (d.width > p.width) {
- p.width = d.width;
- }
-
- if (d.height > p.height) {
- p.height = d.height;
- }
-
- d = pan.preferredSize();
- if (d.width > p.width) {
- p.width = d.width;
- }
-
- if (d.height > p.height) {
- p.height = d.height;
- }
- }
- }
-
- p.width += insets.left + insets.right;
- p.height += insets.top + insets.bottom;
- return p;
- }
-
- public Dimension minimumSize() {
- Component pan = null;
- Dimension d = null;
- Dimension m = new Dimension(0, 0);
- int s = this.vPanels.size();
-
- for(int x = 0; x < s; ++x) {
- pan = (Component)this.vPanels.elementAt(x);
- if (pan != null) {
- d = pan.minimumSize();
- if (d.width > m.width) {
- m.width = d.width;
- }
-
- if (d.height > m.height) {
- m.height = d.height;
- }
- }
- }
-
- Insets insets = ((BaseTabbedPanel)this).insets();
- m.width += insets.left + insets.right;
- m.height += insets.top + insets.bottom;
- return m;
- }
- }
-