home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2002 March / PCWMAR02.iso / software / windowsxp / ftgateoffice / ftgateoffice.exe / Main / webhelp.jar / hhapplet / TabButton.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-11-07  |  4.6 KB  |  239 lines

  1. package hhapplet;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.Event;
  7. import java.awt.Font;
  8. import java.awt.FontMetrics;
  9. import java.awt.Graphics;
  10. import java.awt.Rectangle;
  11. import java.awt.image.ImageObserver;
  12.  
  13. public class TabButton extends CanvasButton {
  14.    protected String label;
  15.    protected int x_offset = -1;
  16.    protected int y_offset = -1;
  17.    protected Font active;
  18.    protected Font inactive;
  19.    protected int tab_x;
  20.    protected int tab_y;
  21.    protected int tab_width;
  22.    protected int tab_height;
  23.    protected boolean m_bDrawLeft = true;
  24.    protected boolean m_bDrawRight = true;
  25.    protected boolean m_bActive = false;
  26.    protected boolean m_bFocused = false;
  27.    protected TabManagerAdaper m_manager = null;
  28.    protected boolean m_bCenterBroken = false;
  29.  
  30.    protected void centerText(Font var1) {
  31.       Rectangle var2 = ((Component)this).bounds();
  32.       FontMetrics var3 = ((Component)this).getFontMetrics(var1);
  33.       int var4 = var3.stringWidth(this.label);
  34.       int var5 = var3.getMaxAscent();
  35.       this.y_offset = var2.height - var5;
  36.       this.y_offset = this.y_offset / 2 + var5;
  37.       this.x_offset = var2.width - var4;
  38.       this.x_offset /= 2;
  39.       if (this.m_bCenterBroken && this.isActived()) {
  40.          this.x_offset += 3;
  41.       }
  42.  
  43.    }
  44.  
  45.    public void reshape(int var1, int var2, int var3, int var4) {
  46.       super.reshape(var1, var2, var3, var4);
  47.       this.tab_x = var1;
  48.       this.tab_y = var2;
  49.       this.tab_width = var3;
  50.       this.tab_height = var4;
  51.       this.centerText(((Component)this).getFont());
  52.    }
  53.  
  54.    public void disactive() {
  55.       if (this.isActived()) {
  56.          ((Component)this).setFont(this.inactive);
  57.          super.reshape(this.tab_x, this.tab_y, this.tab_width, this.tab_height);
  58.          this.centerText(this.inactive);
  59.          ((Component)this).repaint();
  60.          this.m_bActive = false;
  61.       }
  62.  
  63.    }
  64.  
  65.    public boolean isFocusTraversable() {
  66.       return this.isActived();
  67.    }
  68.  
  69.    public TabButton(String var1, TabManagerAdaper var2) {
  70.       this.m_manager = var2;
  71.       int var3 = BsscFontFixPatch.GetFontSize();
  72.  
  73.       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)) {
  74.          ++var3;
  75.       }
  76.  
  77.       this.inactive = new Font(BsscFontFixPatch.GetFontName(), 0, var3);
  78.       ((Component)this).setFont(this.inactive);
  79.       this.label = var1;
  80.       if (System.getProperty("java.vendor").startsWith("Netscape") && System.getProperty("os.name").startsWith("Windows 95")) {
  81.          try {
  82.             String var4 = System.getProperty("java.version");
  83.             if (var4.startsWith("1.02")) {
  84.                this.m_bCenterBroken = true;
  85.             }
  86.  
  87.             Integer var5 = new Integer(var4.substring(0, 1));
  88.             Integer var6 = new Integer(var4.substring(2, 3));
  89.             Integer var7 = new Integer(var4.substring(4, 5));
  90.             if (var5 <= 1 && var6 <= 1 && var7 <= 2) {
  91.                this.m_bCenterBroken = true;
  92.                return;
  93.             }
  94.          } catch (Exception var8) {
  95.             ((Throwable)var8).printStackTrace();
  96.          }
  97.       }
  98.  
  99.    }
  100.  
  101.    public void paint(Graphics var1) {
  102.       try {
  103.          var1.setColor(((Component)this).getBackground());
  104.          var1.fillRect(0, 0, ((Component)this).bounds().width, ((Component)this).bounds().height);
  105.          if (super.img != null) {
  106.             var1.drawImage(super.img, 2, 2, (ImageObserver)null);
  107.          } else if (this.label != null) {
  108.             this.centerText(((Component)this).getFont());
  109.             var1.setColor(((Component)this).getForeground());
  110.             var1.setFont(((Component)this).getFont());
  111.             var1.drawString(this.label, this.x_offset, this.y_offset);
  112.             if (this.m_bFocused) {
  113.                var1.drawRect(3, 3, ((Component)this).bounds().width - 7, ((Component)this).bounds().height - 7);
  114.             }
  115.          }
  116.  
  117.          this.paintBorderOut(var1);
  118.       } catch (Exception var3) {
  119.          ((Throwable)var3).printStackTrace();
  120.       }
  121.    }
  122.  
  123.    public boolean isActived() {
  124.       return this.m_bActive;
  125.    }
  126.  
  127.    public void paintBorderOut(Graphics var1) {
  128.       Rectangle var2 = ((Component)this).bounds();
  129.       if (this.isActived()) {
  130.          var1.setColor(Color.white);
  131.          var1.drawLine(2, 0, var2.width - 3, 0);
  132.          var1.drawLine(1, 1, 1, 1);
  133.          var1.drawLine(0, 2, 0, var2.height - 1);
  134.          var1.setColor(Color.white);
  135.          var1.drawLine(2, 0, var2.width - 3, 0);
  136.       } else if (this.m_bDrawLeft) {
  137.          var1.setColor(Color.white);
  138.          var1.drawLine(2, 3, var2.width - 3, 3);
  139.          var1.drawLine(1, 4, 1, 4);
  140.          var1.drawLine(0, 5, 0, var2.height - 1);
  141.       } else {
  142.          var1.setColor(Color.white);
  143.          var1.drawLine(0, 3, var2.width - 3, 3);
  144.       }
  145.  
  146.       if (this.isActived()) {
  147.          var1.setColor(Color.darkGray);
  148.          var1.drawLine(var2.width - 2, 2, var2.width - 2, var2.height - 1);
  149.          var1.setColor(Color.black);
  150.          var1.drawLine(var2.width - 2, 1, var2.width - 2, 1);
  151.          var1.drawLine(var2.width - 1, 2, var2.width - 1, var2.height - 1);
  152.       } else if (this.m_bDrawRight) {
  153.          var1.setColor(Color.darkGray);
  154.          var1.drawLine(var2.width - 2, 5, var2.width - 2, var2.height - 1);
  155.          var1.setColor(Color.black);
  156.          var1.drawLine(var2.width - 2, 4, var2.width - 2, 4);
  157.          var1.drawLine(var2.width - 1, 5, var2.width - 1, var2.height - 1);
  158.       } else {
  159.          var1.setColor(Color.white);
  160.          var1.drawLine(2, 3, var2.width - 1, 3);
  161.       }
  162.  
  163.       if (!this.isActived()) {
  164.          var1.setColor(Color.white);
  165.          var1.drawLine(0, var2.height - 1, var2.width - 1, var2.height - 1);
  166.          var1.setColor(((Component)this).getBackground());
  167.          var1.drawLine(0, 0, var2.width - 1, 0);
  168.          var1.drawLine(0, 1, var2.width - 1, 1);
  169.          var1.drawLine(0, 2, var2.width - 1, 2);
  170.       }
  171.  
  172.    }
  173.  
  174.    public void active() {
  175.       if (!this.isActived()) {
  176.          ((Component)this).setFont(this.active);
  177.          super.reshape(this.tab_x, this.tab_y, this.tab_width, this.tab_height);
  178.          this.centerText(this.active);
  179.          ((Component)this).repaint();
  180.          this.m_bActive = true;
  181.       }
  182.  
  183.    }
  184.  
  185.    public void SetDrawRight(boolean var1) {
  186.       this.m_bDrawRight = var1;
  187.       ((Component)this).repaint();
  188.    }
  189.  
  190.    public Dimension preferredSize() {
  191.       try {
  192.          if (super.img != null) {
  193.             return new Dimension(super.img.getWidth(this) + 4, super.img.getHeight(this) + 4);
  194.          } else if (this.label != null) {
  195.             FontMetrics var1 = ((Component)this).getFontMetrics(this.active);
  196.             FontMetrics var2 = ((Component)this).getFontMetrics(this.inactive);
  197.             int var3 = var1.stringWidth(this.label) > var2.stringWidth(this.label) ? var1.stringWidth(this.label) : var2.stringWidth(this.label);
  198.             int var4 = var1.getMaxAscent() > var2.getMaxAscent() ? var1.stringWidth(this.label) : var2.stringWidth(this.label);
  199.             int var5 = var1.getDescent() > var2.getDescent() ? var1.getDescent() : var2.getDescent();
  200.             var3 += 20;
  201.             var4 += 8 + var5;
  202.             return new Dimension(var3, var4);
  203.          } else {
  204.             return new Dimension(20, 20);
  205.          }
  206.       } catch (Exception var6) {
  207.          ((Throwable)var6).printStackTrace();
  208.          return new Dimension(20, 20);
  209.       }
  210.    }
  211.  
  212.    public boolean handleEvent(Event var1) {
  213.       if (var1.target == this) {
  214.          if (var1.id == 501) {
  215.             ((Component)this).requestFocus();
  216.          } else if (var1.id == 1005) {
  217.             this.m_bFocused = false;
  218.             ((Component)this).repaint();
  219.          } else if (var1.id == 1004) {
  220.             this.m_bFocused = true;
  221.             ((Component)this).repaint();
  222.          } else if (var1.key == 1006 && var1.id == 403) {
  223.             if (this.m_manager != null) {
  224.                return this.m_manager.GoPrev(this);
  225.             }
  226.          } else if (var1.key == 1007 && var1.id == 403 && this.m_manager != null) {
  227.             return this.m_manager.GoNext(this);
  228.          }
  229.       }
  230.  
  231.       return super.handleEvent(var1);
  232.    }
  233.  
  234.    public void SetDrawLeft(boolean var1) {
  235.       this.m_bDrawLeft = var1;
  236.       ((Component)this).repaint();
  237.    }
  238. }
  239.