home *** CD-ROM | disk | FTP | other *** search
- package hhapplet;
-
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Event;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Rectangle;
- import java.awt.image.ImageObserver;
-
- public class TabButton extends CanvasButton {
- protected String label;
- protected int x_offset = -1;
- protected int y_offset = -1;
- protected Font active;
- protected Font inactive;
- protected int tab_x;
- protected int tab_y;
- protected int tab_width;
- protected int tab_height;
- protected boolean m_bDrawLeft = true;
- protected boolean m_bDrawRight = true;
- protected boolean m_bActive = false;
- protected boolean m_bFocused = false;
- protected TabManagerAdaper m_manager = null;
- protected boolean m_bCenterBroken = false;
-
- protected void centerText(Font var1) {
- Rectangle var2 = ((Component)this).bounds();
- FontMetrics var3 = ((Component)this).getFontMetrics(var1);
- int var4 = var3.stringWidth(this.label);
- int var5 = var3.getMaxAscent();
- this.y_offset = var2.height - var5;
- this.y_offset = this.y_offset / 2 + var5;
- this.x_offset = var2.width - var4;
- this.x_offset /= 2;
- if (this.m_bCenterBroken && this.isActived()) {
- this.x_offset += 3;
- }
-
- }
-
- public void reshape(int var1, int var2, int var3, int var4) {
- super.reshape(var1, var2, var3, var4);
- this.tab_x = var1;
- this.tab_y = var2;
- this.tab_width = var3;
- this.tab_height = var4;
- this.centerText(((Component)this).getFont());
- }
-
- public void disactive() {
- if (this.isActived()) {
- ((Component)this).setFont(this.inactive);
- super.reshape(this.tab_x, this.tab_y, this.tab_width, this.tab_height);
- this.centerText(this.inactive);
- ((Component)this).repaint();
- this.m_bActive = false;
- }
-
- }
-
- public boolean isFocusTraversable() {
- return this.isActived();
- }
-
- public TabButton(String var1, TabManagerAdaper var2) {
- this.m_manager = var2;
- int var3 = BsscFontFixPatch.GetFontSize();
-
- for(this.active = new Font(BsscFontFixPatch.GetFontName(), 1, var3); this.active.getSize() != var3 && var3 < BsscFontFixPatch.GetFontSize() + 10; this.active = new Font(BsscFontFixPatch.GetFontName(), 1, var3)) {
- ++var3;
- }
-
- this.inactive = new Font(BsscFontFixPatch.GetFontName(), 0, var3);
- ((Component)this).setFont(this.inactive);
- this.label = var1;
- if (System.getProperty("java.vendor").startsWith("Netscape") && System.getProperty("os.name").startsWith("Windows 95")) {
- try {
- String var4 = System.getProperty("java.version");
- if (var4.startsWith("1.02")) {
- this.m_bCenterBroken = true;
- }
-
- Integer var5 = new Integer(var4.substring(0, 1));
- Integer var6 = new Integer(var4.substring(2, 3));
- Integer var7 = new Integer(var4.substring(4, 5));
- if (var5 <= 1 && var6 <= 1 && var7 <= 2) {
- this.m_bCenterBroken = true;
- return;
- }
- } catch (Exception var8) {
- ((Throwable)var8).printStackTrace();
- }
- }
-
- }
-
- public void paint(Graphics var1) {
- try {
- var1.setColor(((Component)this).getBackground());
- var1.fillRect(0, 0, ((Component)this).bounds().width, ((Component)this).bounds().height);
- if (super.img != null) {
- var1.drawImage(super.img, 2, 2, (ImageObserver)null);
- } else if (this.label != null) {
- this.centerText(((Component)this).getFont());
- var1.setColor(((Component)this).getForeground());
- var1.setFont(((Component)this).getFont());
- var1.drawString(this.label, this.x_offset, this.y_offset);
- if (this.m_bFocused) {
- var1.drawRect(3, 3, ((Component)this).bounds().width - 7, ((Component)this).bounds().height - 7);
- }
- }
-
- this.paintBorderOut(var1);
- } catch (Exception var3) {
- ((Throwable)var3).printStackTrace();
- }
- }
-
- public boolean isActived() {
- return this.m_bActive;
- }
-
- public void paintBorderOut(Graphics var1) {
- Rectangle var2 = ((Component)this).bounds();
- if (this.isActived()) {
- var1.setColor(Color.white);
- var1.drawLine(2, 0, var2.width - 3, 0);
- var1.drawLine(1, 1, 1, 1);
- var1.drawLine(0, 2, 0, var2.height - 1);
- var1.setColor(Color.white);
- var1.drawLine(2, 0, var2.width - 3, 0);
- } else if (this.m_bDrawLeft) {
- var1.setColor(Color.white);
- var1.drawLine(2, 3, var2.width - 3, 3);
- var1.drawLine(1, 4, 1, 4);
- var1.drawLine(0, 5, 0, var2.height - 1);
- } else {
- var1.setColor(Color.white);
- var1.drawLine(0, 3, var2.width - 3, 3);
- }
-
- if (this.isActived()) {
- var1.setColor(Color.darkGray);
- var1.drawLine(var2.width - 2, 2, var2.width - 2, var2.height - 1);
- var1.setColor(Color.black);
- var1.drawLine(var2.width - 2, 1, var2.width - 2, 1);
- var1.drawLine(var2.width - 1, 2, var2.width - 1, var2.height - 1);
- } else if (this.m_bDrawRight) {
- var1.setColor(Color.darkGray);
- var1.drawLine(var2.width - 2, 5, var2.width - 2, var2.height - 1);
- var1.setColor(Color.black);
- var1.drawLine(var2.width - 2, 4, var2.width - 2, 4);
- var1.drawLine(var2.width - 1, 5, var2.width - 1, var2.height - 1);
- } else {
- var1.setColor(Color.white);
- var1.drawLine(2, 3, var2.width - 1, 3);
- }
-
- if (!this.isActived()) {
- var1.setColor(Color.white);
- var1.drawLine(0, var2.height - 1, var2.width - 1, var2.height - 1);
- var1.setColor(((Component)this).getBackground());
- var1.drawLine(0, 0, var2.width - 1, 0);
- var1.drawLine(0, 1, var2.width - 1, 1);
- var1.drawLine(0, 2, var2.width - 1, 2);
- }
-
- }
-
- public void active() {
- if (!this.isActived()) {
- ((Component)this).setFont(this.active);
- super.reshape(this.tab_x, this.tab_y, this.tab_width, this.tab_height);
- this.centerText(this.active);
- ((Component)this).repaint();
- this.m_bActive = true;
- }
-
- }
-
- public void SetDrawRight(boolean var1) {
- this.m_bDrawRight = var1;
- ((Component)this).repaint();
- }
-
- public Dimension preferredSize() {
- try {
- if (super.img != null) {
- return new Dimension(super.img.getWidth(this) + 4, super.img.getHeight(this) + 4);
- } else if (this.label != null) {
- FontMetrics var1 = ((Component)this).getFontMetrics(this.active);
- FontMetrics var2 = ((Component)this).getFontMetrics(this.inactive);
- int var3 = var1.stringWidth(this.label) > var2.stringWidth(this.label) ? var1.stringWidth(this.label) : var2.stringWidth(this.label);
- int var4 = var1.getMaxAscent() > var2.getMaxAscent() ? var1.stringWidth(this.label) : var2.stringWidth(this.label);
- int var5 = var1.getDescent() > var2.getDescent() ? var1.getDescent() : var2.getDescent();
- var3 += 20;
- var4 += 8 + var5;
- return new Dimension(var3, var4);
- } else {
- return new Dimension(20, 20);
- }
- } catch (Exception var6) {
- ((Throwable)var6).printStackTrace();
- return new Dimension(20, 20);
- }
- }
-
- public boolean handleEvent(Event var1) {
- if (var1.target == this) {
- if (var1.id == 501) {
- ((Component)this).requestFocus();
- } else if (var1.id == 1005) {
- this.m_bFocused = false;
- ((Component)this).repaint();
- } else if (var1.id == 1004) {
- this.m_bFocused = true;
- ((Component)this).repaint();
- } else if (var1.key == 1006 && var1.id == 403) {
- if (this.m_manager != null) {
- return this.m_manager.GoPrev(this);
- }
- } else if (var1.key == 1007 && var1.id == 403 && this.m_manager != null) {
- return this.m_manager.GoNext(this);
- }
- }
-
- return super.handleEvent(var1);
- }
-
- public void SetDrawLeft(boolean var1) {
- this.m_bDrawLeft = var1;
- ((Component)this).repaint();
- }
- }
-