home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.awt;
-
- import java.awt.Canvas;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Container;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Insets;
- import java.awt.LayoutManager;
- import java.awt.Panel;
- import java.awt.Polygon;
- import java.awt.Rectangle;
- import java.util.Vector;
-
- public abstract strictfp class BaseTabbedPanel extends Panel {
- public static final int TOP = 0;
- public static final int BOTTOM = 1;
- public static final int ROUNDED = 0;
- public static final int SQUARE = 1;
- private int TF_LEFT;
- private int TF_RIGHT;
- private int TF_TOP;
- private int TF_BOTTOM;
- private int TF_BTN_HEIGHT;
- private Vector vLabels;
- private Vector vEnabled;
- private Vector vPolys;
- protected int curIndex;
- private Font fReg;
- private Font fSel;
- private Component userPanel;
- private int iTabsPosition;
- private int iTabsStyle;
- private int osAdjustment;
- private int firstVisibleTab;
- private DirectionButton dbLeft;
- private DirectionButton dbRight;
- private Polygon nullPoly;
- private int lastWidth;
- private Insets btpInsets;
-
- public BaseTabbedPanel() {
- this(0, 0);
- }
-
- public BaseTabbedPanel(boolean bTabsOnTop) {
- this(bTabsOnTop ? 0 : 1, bTabsOnTop ? 0 : 1);
- }
-
- public BaseTabbedPanel(int tabsPostion, int tabsStyle) {
- this.TF_LEFT = 9;
- this.TF_RIGHT = -9;
- this.TF_TOP = 30;
- this.TF_BOTTOM = -9;
- this.TF_BTN_HEIGHT = 20;
- this.curIndex = -1;
- this.iTabsPosition = 0;
- this.iTabsStyle = 0;
- this.lastWidth = -1;
- this.vLabels = new Vector();
- this.vEnabled = new Vector();
- this.vPolys = new Vector();
- this.btpInsets = new Insets(0, 0, 0, 0);
- this.setTabsInfo(tabsPostion, tabsStyle);
- this.fReg = new Font("Helvetica", 0, 12);
- this.fSel = new Font("Helvetica", 1, 12);
- if (System.getProperty("os.name").startsWith("S")) {
- this.osAdjustment = -1;
- } else {
- this.osAdjustment = 0;
- }
-
- super.setLayout((LayoutManager)null);
- this.dbLeft = new DirectionButton(0);
- this.dbRight = new DirectionButton(1);
- this.dbLeft.setShowFocus(false);
- this.dbRight.setShowFocus(false);
- this.dbLeft.shrinkTriangle(1, 1, 0, 1);
- this.dbRight.shrinkTriangle(1, 1, 0, 1);
- super.add(this.dbLeft, -1);
- super.add(this.dbRight, -1);
- this.nullPoly = new Polygon();
- this.nullPoly.addPoint(0, 0);
- this.nullPoly.addPoint(1, 1);
- this.nullPoly.addPoint(0, 0);
- }
-
- public void setTabsPosition(int tabsPosition) {
- if (this.iTabsPosition != tabsPosition) {
- this.setTabsInfo(tabsPosition, this.iTabsStyle);
- }
-
- }
-
- public int getTabsPosition() {
- return this.iTabsPosition;
- }
-
- public void setTabsStyle(int tabsStyle) {
- if (this.iTabsStyle != tabsStyle) {
- this.setTabsInfo(this.iTabsPosition, tabsStyle);
- }
-
- }
-
- public int getTabsStyle() {
- return this.iTabsStyle;
- }
-
- public void setTabsInfo(int tabsPosition, int tabsStyle) {
- this.iTabsPosition = tabsPosition;
- if (this.iTabsPosition == 0) {
- this.iTabsStyle = 0;
- } else {
- this.iTabsStyle = tabsStyle;
- }
-
- if (this.iTabsStyle == 0) {
- this.TF_BTN_HEIGHT = 20;
- } else {
- this.TF_BTN_HEIGHT = 17;
- }
-
- ((Component)this).repaint();
- }
-
- public void setPanel(Component p) {
- this.removeAll();
- this.userPanel = p;
- if (this.userPanel != null) {
- super.add(this.userPanel, -1);
- this.userPanel.requestFocus();
- }
-
- }
-
- public void showPanel(Component p) {
- if (this.userPanel != null) {
- this.userPanel.hide();
- }
-
- this.userPanel = p;
- if (this.userPanel != null) {
- Component[] comps = ((Container)this).getComponents();
- int l = comps.length;
-
- int x;
- for(x = 0; x < l && comps[x] != this.userPanel; ++x) {
- }
-
- if (x == l) {
- super.add(this.userPanel, -1);
- }
-
- this.userPanel.show();
- this.userPanel.requestFocus();
- ((Container)this).validate();
- ((Component)this).repaint();
- }
-
- }
-
- public int addTab(String sLabel, boolean bEnabled) {
- this.vLabels.addElement(sLabel);
- this.vEnabled.addElement(new Boolean(bEnabled));
- int index = this.vLabels.size() - 1;
- if (this.curIndex == -1 && bEnabled) {
- this.showTab(index);
- }
-
- return index;
- }
-
- public synchronized void setTab(String sLabel, boolean bEnabled, int index) {
- if (index >= 0 && index < this.vLabels.size()) {
- if (index != this.curIndex || bEnabled) {
- try {
- this.vLabels.setElementAt(sLabel, index);
- this.vEnabled.setElementAt(new Boolean(bEnabled), index);
- ((Component)this).repaint();
- } catch (ArrayIndexOutOfBoundsException var4) {
- }
- }
- }
- }
-
- public synchronized void setLabel(String sLabel, int index) {
- if (index >= 0 && index < this.vLabels.size()) {
- try {
- this.vLabels.setElementAt(sLabel, index);
- ((Component)this).repaint();
- } catch (ArrayIndexOutOfBoundsException var3) {
- }
- }
- }
-
- public synchronized String getLabel(int index) {
- if (index >= 0 && index < this.vLabels.size()) {
- try {
- return (String)this.vLabels.elementAt(index);
- } catch (ArrayIndexOutOfBoundsException var2) {
- return "";
- }
- } else {
- return "";
- }
- }
-
- public synchronized void setEnabled(boolean bEnabled, int index) {
- if (index >= 0 && index < this.vLabels.size()) {
- if (index != this.curIndex || bEnabled) {
- try {
- this.vEnabled.setElementAt(new Boolean(bEnabled), index);
- ((Component)this).repaint();
- } catch (ArrayIndexOutOfBoundsException var3) {
- }
- }
- }
- }
-
- public void showTab(int index) {
- if (index >= 0 && index < this.vLabels.size() && index != this.curIndex) {
- if (this.tabIsEnabled(index)) {
- this.curIndex = index;
- ((Container)this).invalidate();
- ((Container)this).validate();
- ((Component)this).repaint();
- ((Component)this).postEvent(new Event(this, 1001, (Object)null));
- }
-
- }
- }
-
- public boolean tabIsEnabled(int index) {
- if (index >= 0 && index < this.vLabels.size()) {
- try {
- Boolean bool = (Boolean)this.vEnabled.elementAt(index);
- if (bool) {
- return true;
- }
- } catch (ArrayIndexOutOfBoundsException var3) {
- }
-
- return false;
- } else {
- return false;
- }
- }
-
- public int currentTabIndex() {
- return this.curIndex;
- }
-
- public void enableTab(boolean bEnable, int index) {
- if (index >= 0 && index < this.vEnabled.size() && index != this.curIndex) {
- try {
- this.vEnabled.setElementAt(new Boolean(bEnable), index);
- ((Component)this).repaint();
- } catch (ArrayIndexOutOfBoundsException var3) {
- }
- }
- }
-
- public void removeTab(int index) {
- if (index >= 0 && index < this.vEnabled.size() && index != this.curIndex) {
- try {
- this.vLabels.removeElementAt(index);
- this.vEnabled.removeElementAt(index);
- ((Component)this).repaint();
- } catch (ArrayIndexOutOfBoundsException var2) {
- }
- }
- }
-
- public void removeAllTabs() {
- this.vLabels = new Vector();
- this.vEnabled = new Vector();
- this.vPolys = new Vector();
- this.curIndex = -1;
- this.firstVisibleTab = 0;
- this.lastWidth = -1;
- this.removeAll();
- ((Component)this).repaint();
- }
-
- public void layout() {
- Rectangle r = ((Component)this).bounds();
- int width = r.width - this.TF_LEFT + this.TF_RIGHT;
- if (width >= 0) {
- int height = r.height - this.TF_TOP + this.TF_BOTTOM;
- if (height >= 0) {
- int col = this.TF_LEFT;
- int row = 0;
- if (this.iTabsPosition == 0) {
- row = this.TF_TOP;
- } else {
- row = this.TF_TOP - this.TF_BTN_HEIGHT;
- }
-
- if (this.userPanel != null) {
- this.userPanel.reshape(col + 3, row + 3, width - 6, height - 5);
- this.userPanel.invalidate();
- this.userPanel.validate();
- if (this.userPanel instanceof Canvas || this.userPanel instanceof Panel) {
- this.userPanel.repaint();
- return;
- }
-
- ((Component)this).repaint();
- }
-
- }
- }
- }
-
- public synchronized void paint(Graphics g) {
- Rectangle r = ((Component)this).bounds();
- int width = r.width - this.TF_LEFT + this.TF_RIGHT;
- if (width >= 0) {
- int height = r.height - this.TF_TOP + this.TF_BOTTOM;
- if (height >= 0) {
- if (r.width > this.lastWidth) {
- this.firstVisibleTab = 0;
- }
-
- this.lastWidth = r.width;
- int col = this.TF_LEFT;
- Color c = g.getColor();
- g.setColor(((Component)this).getBackground());
- g.fillRect(0, 0, r.width, r.height);
- int row;
- if (this.iTabsPosition == 0) {
- row = this.TF_TOP;
- } else {
- row = this.TF_TOP - this.TF_BTN_HEIGHT;
- }
-
- g.setColor(Color.white);
- g.drawLine(col, row, col + width - 1, row);
- g.drawLine(col, row, col, row + height - 1);
- g.setColor(Color.gray);
- g.drawLine(col + 2, row + height - 2, col + width - 2, row + height - 2);
- g.drawLine(col + width - 2, row + 2, col + width - 2, row + height - 2);
- g.setColor(Color.black);
- g.drawLine(col + 1, row + height - 1, col + width - 1, row + height - 1);
- g.drawLine(col + width - 1, row + 1, col + width - 1, row + height - 1);
- int x2 = this.TF_LEFT + 8;
- int x3 = 0;
- int x4 = this.TF_LEFT;
- int sze = this.vLabels.size();
- this.vPolys.removeAllElements();
- Font f = g.getFont();
- FontMetrics fm = ((Component)this).getFontMetrics(this.fReg);
- FontMetrics fms = ((Component)this).getFontMetrics(this.fSel);
- int labelWidth = 0;
-
- int w;
- for(w = 0; w < this.firstVisibleTab; ++w) {
- this.vPolys.addElement(this.nullPoly);
- }
-
- if (w > 0) {
- x4 += 2;
- }
-
- for(; w < sze; ++w) {
- Polygon p = new Polygon();
-
- try {
- String sLabel = (String)this.vLabels.elementAt(w);
- if (w == this.curIndex) {
- labelWidth = fms.stringWidth(sLabel);
- } else {
- labelWidth = fm.stringWidth(sLabel);
- }
-
- int y1;
- int y2;
- if (this.iTabsPosition == 0) {
- y1 = this.TF_TOP - this.TF_BTN_HEIGHT;
- y2 = this.TF_TOP - 1;
- } else {
- y1 = r.height + this.TF_BOTTOM + 1;
- y2 = r.height + this.TF_BOTTOM - this.TF_BTN_HEIGHT;
- }
-
- int x1;
- if (this.iTabsStyle == 0) {
- x1 = x4 + 2;
- x2 = x1 + labelWidth + 13;
- } else {
- x1 = x2 - 7;
- x2 = x1 + labelWidth + 28;
- }
-
- if (x2 + 36 - this.TF_RIGHT > r.width) {
- break;
- }
-
- if (this.iTabsPosition == 0) {
- if (w == this.curIndex) {
- y1 -= 3;
- x1 -= 2;
- }
-
- g.setColor(Color.white);
- if (this.curIndex == w + 1) {
- g.drawLine(x1 + 2, y1, x2 - 2, y1);
- } else {
- g.drawLine(x1 + 2, y1, x2, y1);
- }
-
- if (this.curIndex != w - 1) {
- g.drawLine(x1, y1 + 2, x1, y2);
- x3 = x1;
- } else {
- x3 = x1 + 1;
- }
-
- g.drawLine(x1 + 1, y1 + 1, x1 + 1, y1 + 1);
- if (this.curIndex != w + 1) {
- g.setColor(Color.gray);
- g.drawLine(x2, y1, x2, y2);
- g.setColor(Color.black);
- g.drawLine(x2 + 1, y1 + 2, x2 + 1, y2);
- x4 = x2;
- } else {
- x4 = x2 - 1;
- }
- } else if (this.iTabsStyle != 1) {
- if (w == this.curIndex) {
- y1 += 3;
- x1 -= 2;
- }
-
- g.setColor(Color.white);
- if (this.curIndex == w + 1) {
- g.drawLine(x1 + 2, y1, x2 - 2, y1);
- } else {
- g.drawLine(x1 + 2, y1, x2, y1);
- }
-
- if (this.curIndex != w - 1) {
- g.drawLine(x1, y1 - 2, x1, y2);
- x3 = x1;
- } else {
- x3 = x1 + 1;
- }
-
- g.drawLine(x1 + 1, y1 - 1, x1 + 1, y1 - 1);
- if (this.curIndex != w + 1) {
- g.setColor(Color.gray);
- g.drawLine(x2, y1, x2, y2);
- g.setColor(Color.black);
- g.drawLine(x2 + 1, y1 - 2, x2 + 1, y2);
- x4 = x2;
- } else {
- x4 = x2 - 1;
- }
- } else {
- g.setColor(Color.gray);
- g.drawLine(x1 + 9, y1, x2 - 9, y1);
- g.setColor(Color.black);
- if (w != 0 && w != this.curIndex) {
- g.drawLine(x1 + 4, y1 - 9, x1 + 9, y1);
- p.addPoint(x1 + 9, y2);
- p.addPoint(x1 + 4, y1 - 9);
- } else {
- g.drawLine(x1, y2, x1 + 9, y1);
- p.addPoint(x1, y2);
- }
-
- p.addPoint(x1 + 9, y1);
- p.addPoint(x2 - 9, y1);
- if (w + 1 == this.curIndex) {
- g.drawLine(x2 - 5, y1 - 9, x2 - 9, y1);
- p.addPoint(x2 - 5, y1);
- p.addPoint(x2 - 9, y2);
- } else {
- g.drawLine(x2, y2, x2 - 9, y1);
- p.addPoint(x2, y2);
- }
-
- if (w != 1 && w != this.curIndex) {
- p.addPoint(x1 + 9, y2);
- } else {
- p.addPoint(x1, y2);
- }
- }
-
- if (w == this.curIndex) {
- if (this.iTabsPosition == 0) {
- ++y2;
- } else {
- --y2;
- }
-
- g.setColor(((Component)this).getBackground());
- g.drawLine(x1 + 1, y2, x2, y2);
- if (this.iTabsPosition == 1) {
- g.drawLine(x1 + 1, y2 - 1, x2, y2 - 1);
- }
-
- g.setFont(this.fSel);
- } else {
- g.setFont(this.fReg);
- }
-
- if (this.iTabsStyle == 0) {
- p.addPoint(x3, y2);
- p.addPoint(x4, y2);
- p.addPoint(x4, y1);
- p.addPoint(x3, y1);
- p.addPoint(x3, y2);
- }
-
- this.vPolys.addElement(p);
- Boolean bool = (Boolean)this.vEnabled.elementAt(w);
- if (bool) {
- g.setColor(Color.black);
- } else {
- g.setColor(Color.gray);
- }
-
- if (this.iTabsPosition == 0) {
- g.drawString(sLabel, x1 + 8, y1 + 15 + this.osAdjustment);
- } else if (this.iTabsStyle == 0) {
- g.drawString(sLabel, x1 + 8, y1 - 6 + this.osAdjustment);
- } else {
- g.drawString(sLabel, x1 + 14, y1 - 4 + this.osAdjustment);
- }
- } catch (ArrayIndexOutOfBoundsException var23) {
- }
- }
-
- if (this.firstVisibleTab <= 0 && w >= sze) {
- this.dbLeft.hide();
- this.dbRight.hide();
- } else {
- this.dbLeft.show();
- this.dbRight.show();
- if (this.firstVisibleTab > 0) {
- this.dbLeft.enable();
- } else {
- this.dbLeft.disable();
- }
-
- if (w < sze) {
- this.dbRight.enable();
- } else {
- this.dbRight.disable();
- }
-
- if (this.iTabsPosition == 0) {
- this.dbLeft.reshape(r.width - 33 + this.TF_RIGHT, this.TF_TOP - 16, 16, 15);
- this.dbRight.reshape(r.width - 16 + this.TF_RIGHT, this.TF_TOP - 16, 16, 15);
- } else {
- this.dbLeft.reshape(r.width - 33 + this.TF_RIGHT, r.height + this.TF_BOTTOM - this.TF_BTN_HEIGHT, 16, 15);
- this.dbRight.reshape(r.width - 16 + this.TF_RIGHT, r.height + this.TF_BOTTOM - this.TF_BTN_HEIGHT, 16, 15);
- }
- }
-
- while(w < sze) {
- this.vPolys.addElement(this.nullPoly);
- ++w;
- }
-
- g.setFont(f);
- g.setColor(c);
- }
- }
- }
-
- public boolean handleEvent(Event evt) {
- switch (evt.id) {
- case 501:
- int sizeR = this.vPolys.size();
-
- for(int x = 0; x < sizeR; ++x) {
- try {
- Polygon p = (Polygon)this.vPolys.elementAt(x);
- if (p != this.nullPoly && p.inside(evt.x, evt.y)) {
- this.showTab(x);
- return true;
- }
- } catch (ArrayIndexOutOfBoundsException var5) {
- }
- }
- break;
- case 1001:
- if (evt.target == this.dbLeft) {
- if (--this.firstVisibleTab < 0) {
- this.firstVisibleTab = 0;
- } else {
- ((Component)this).repaint();
- }
-
- return true;
- }
-
- if (evt.target == this.dbRight) {
- int sze = this.vLabels.size();
- if (++this.firstVisibleTab == sze) {
- --this.firstVisibleTab;
- } else {
- ((Component)this).repaint();
- }
-
- return true;
- }
- }
-
- return super.handleEvent(evt);
- }
-
- public Component add(Component comp) {
- return comp;
- }
-
- public synchronized Component add(Component comp, int pos) {
- return comp;
- }
-
- public synchronized Component add(String name, Component comp) {
- return comp;
- }
-
- public synchronized void remove(Component comp) {
- if (comp != this.dbLeft && comp != this.dbRight) {
- super.remove(comp);
- if (comp == this.userPanel) {
- this.userPanel = null;
- }
-
- }
- }
-
- public synchronized void removeAll() {
- super.removeAll();
- super.add(this.dbLeft, -1);
- super.add(this.dbRight, -1);
- this.userPanel = null;
- }
-
- public void setLayout(LayoutManager mgr) {
- }
-
- public Insets insets() {
- this.btpInsets = super.insets();
- Insets var10000 = this.btpInsets;
- var10000.left += this.TF_LEFT + 3;
- var10000 = this.btpInsets;
- var10000.right += 6 - this.TF_RIGHT;
- if (this.iTabsPosition == 0) {
- var10000 = this.btpInsets;
- var10000.top += this.TF_TOP + 3;
- var10000 = this.btpInsets;
- var10000.bottom += 5 - this.TF_BOTTOM;
- } else {
- var10000 = this.btpInsets;
- var10000.top += this.TF_TOP - this.TF_BTN_HEIGHT + 3;
- var10000 = this.btpInsets;
- var10000.bottom += this.TF_BTN_HEIGHT + 5 - this.TF_BOTTOM;
- }
-
- return this.btpInsets;
- }
-
- public Dimension preferredSize() {
- Dimension s = ((Component)this).size();
- Dimension m = this.minimumSize();
- return new Dimension(Math.max(s.width, m.width), Math.max(s.height, m.height));
- }
-
- public Dimension minimumSize() {
- if (this.userPanel != null) {
- Dimension s = this.userPanel.minimumSize();
- return new Dimension(s.width + this.btpInsets.left + this.btpInsets.right, s.height + this.btpInsets.top + this.btpInsets.bottom);
- } else {
- return new Dimension(100, 100);
- }
- }
- }
-