home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2004 May / DPPCPRO0504.ISO / May / Seatools / SeaTools.iso / tools / en / webhelp / webhelp.cab / hhapplet / BsscImageLabel.class (.txt) < prev    next >
Encoding:
Java Class File  |  2002-04-17  |  4.2 KB  |  215 lines

  1. package hhapplet;
  2.  
  3. import java.awt.Canvas;
  4. import java.awt.Color;
  5. import java.awt.Component;
  6. import java.awt.Dimension;
  7. import java.awt.Font;
  8. import java.awt.FontMetrics;
  9. import java.awt.Graphics;
  10. import java.awt.Image;
  11. import java.awt.Rectangle;
  12. import java.awt.image.ImageObserver;
  13. import java.util.Vector;
  14.  
  15. public class BsscImageLabel extends Canvas implements Runnable {
  16.    private Image m_bgImage;
  17.    private int m_nbgWidth;
  18.    private int m_nbgHeight;
  19.    private Image m_cachebgImage;
  20.    private int m_nOldWidth;
  21.    private int m_nOldHeight;
  22.    private boolean m_bBgUpdated;
  23.    private Image m_imgbackground;
  24.    private Vector m_vToDo;
  25.    private BsscFont m_bFont;
  26.    private String m_strValue;
  27.    private static int m_nHeading = 4;
  28.    private static int m_nEnding = 4;
  29.  
  30.    private Image getBackgroundImage() {
  31.       if (this.m_nbgWidth > 0 && this.m_nbgHeight > 0 && this.m_bgImage != null) {
  32.          Rectangle var1 = ((Component)this).getBounds();
  33.          if (var1.height == this.m_nOldHeight && var1.width == this.m_nOldWidth && !this.m_bBgUpdated) {
  34.             return this.m_cachebgImage;
  35.          } else {
  36.             this.m_nOldWidth = var1.width;
  37.             this.m_nOldHeight = var1.height;
  38.             this.m_cachebgImage = ((Component)this).createImage(var1.width, var1.height);
  39.             Graphics var2 = this.m_cachebgImage.getGraphics();
  40.             this.drawBackGround(var2);
  41.             return this.m_cachebgImage;
  42.          }
  43.       } else {
  44.          return null;
  45.       }
  46.    }
  47.  
  48.    public BsscImageLabel(String var1) {
  49.       this.m_strValue = var1;
  50.       if (ViewSkin.m_PaneColorBg != null) {
  51.          ((Component)this).setBackground(ViewSkin.m_PaneColorBg);
  52.       }
  53.  
  54.       if (ViewSkin.m_PaneImageBg != null) {
  55.          this.setBgImage(ViewSkin.m_PaneImageBg);
  56.       }
  57.  
  58.       if (ViewSkin.m_PaneFont != null) {
  59.          this.m_bFont = ViewSkin.m_PaneFont;
  60.       }
  61.  
  62.       this.m_vToDo = new Vector();
  63.    }
  64.  
  65.    public void paint(Graphics var1) {
  66.       try {
  67.          Rectangle var2 = ((Component)this).getBounds();
  68.          Image var3 = ((Component)this).createImage(var2.width, var2.height);
  69.          Graphics var4 = var3.getGraphics();
  70.          this.m_imgbackground = this.getBackgroundImage();
  71.          if (this.m_imgbackground != null) {
  72.             var4.drawImage(this.m_imgbackground, 0, 0, this);
  73.          }
  74.  
  75.          Object var5 = null;
  76.          Object var6 = null;
  77.          Font var12;
  78.          Color var13;
  79.          if (this.m_bFont != null) {
  80.             var12 = this.m_bFont.getFont();
  81.             var13 = this.m_bFont.getColor();
  82.          } else {
  83.             var12 = new Font(BsscFontFixPatch.GetFontName(), 0, BsscFontFixPatch.GetFontSize());
  84.             var13 = Color.black;
  85.          }
  86.  
  87.          FontMetrics var7 = var1.getFontMetrics(var12);
  88.          int var8 = var7.getAscent();
  89.          int var9 = var7.getLeading();
  90.          var4.getFont();
  91.          Color var10 = var4.getColor();
  92.          var4.setColor(var13);
  93.          var4.setFont(var12);
  94.          var4.drawString(this.m_strValue, 0, var8 + var9 + m_nHeading);
  95.          var4.setFont(var12);
  96.          var4.setColor(var10);
  97.          var1.drawImage(var3, 0, 0, this);
  98.       } catch (Exception var11) {
  99.          ((Throwable)var11).printStackTrace();
  100.       }
  101.    }
  102.  
  103.    public void setBgImage(Image var1) {
  104.       this.m_bgImage = var1;
  105.       this.m_nbgHeight = this.m_bgImage.getHeight(this);
  106.       this.m_nbgWidth = this.m_bgImage.getWidth(this);
  107.    }
  108.  
  109.    public void dispatchToDo(String var1) {
  110.       if (var1 == "repaint") {
  111.          ((Component)this).repaint();
  112.       }
  113.  
  114.    }
  115.  
  116.    public boolean imageUpdate(Image var1, int var2, int var3, int var4, int var5, int var6) {
  117.       if (var1 == this.m_bgImage) {
  118.          this.m_nbgWidth = var5;
  119.          this.m_nbgHeight = var6;
  120.          this.m_bBgUpdated = true;
  121.          ((Component)this).repaint();
  122.          return false;
  123.       } else {
  124.          return true;
  125.       }
  126.    }
  127.  
  128.    public void drawBackGround(Graphics var1) {
  129.       if (this.m_nbgWidth > 0 && this.m_nbgHeight > 0 && this.m_bgImage != null) {
  130.          Rectangle var5 = ((Component)this).getBounds();
  131.  
  132.          for(int var6 = 0; var6 <= (var5.width - 1) / this.m_nbgWidth; ++var6) {
  133.             for(int var7 = 0; var7 <= (var5.height - 1) / this.m_nbgHeight; ++var7) {
  134.                if (!var1.drawImage(this.m_bgImage, var6 * this.m_nbgWidth, var7 * this.m_nbgHeight, this.m_nbgWidth, this.m_nbgHeight, (ImageObserver)null)) {
  135.                   this.setTimeout("repaint", 100);
  136.                   return;
  137.                }
  138.             }
  139.          }
  140.  
  141.          if (this.m_bBgUpdated) {
  142.             this.m_bBgUpdated = false;
  143.             return;
  144.          }
  145.       } else {
  146.          Color var2 = var1.getColor();
  147.          Color var3 = ((Component)this).getBackground();
  148.          var1.setColor(var3);
  149.          Rectangle var4 = ((Component)this).getBounds();
  150.          var1.fillRect(0, 0, var4.width, var4.height);
  151.          var1.setColor(var2);
  152.       }
  153.  
  154.    }
  155.  
  156.    public void update(Graphics var1) {
  157.       this.paint(var1);
  158.    }
  159.  
  160.    public Dimension getPreferredSize() {
  161.       new Dimension();
  162.       Object var1 = null;
  163.       Font var6;
  164.       if (this.m_bFont != null) {
  165.          var6 = this.m_bFont.getFont();
  166.       } else {
  167.          var6 = new Font(BsscFontFixPatch.GetFontName(), 0, BsscFontFixPatch.GetFontSize());
  168.       }
  169.  
  170.       FontMetrics var2 = ((Component)this).getGraphics().getFontMetrics(var6);
  171.       char[] var3 = new char[this.m_strValue.length()];
  172.       this.m_strValue.getChars(0, this.m_strValue.length(), var3, 0);
  173.       int var4 = var2.charsWidth(var3, 0, this.m_strValue.length());
  174.       int var5 = var2.getHeight() + m_nHeading + m_nEnding;
  175.       return new Dimension(var4, var5);
  176.    }
  177.  
  178.    public void run() {
  179.       synchronized(this.m_vToDo){}
  180.  
  181.       ToDo var1;
  182.       try {
  183.          var1 = (ToDo)this.m_vToDo.elementAt(0);
  184.          this.m_vToDo.removeElementAt(0);
  185.       } catch (Throwable var8) {
  186.          throw var8;
  187.       }
  188.  
  189.       try {
  190.          Thread.sleep((long)var1.m_nMSec);
  191.          this.dispatchToDo(var1.m_sToDo);
  192.       } catch (InterruptedException var7) {
  193.          ((Throwable)var7).printStackTrace();
  194.       }
  195.    }
  196.  
  197.    public final void setTimeout(String var1, int var2) {
  198.       ToDo var3 = new ToDo(this, var1, var2);
  199.       synchronized(this.m_vToDo){}
  200.  
  201.       try {
  202.          this.m_vToDo.addElement(var3);
  203.       } catch (Throwable var8) {
  204.          throw var8;
  205.       }
  206.  
  207.       Thread var4 = new Thread(this);
  208.       var4.start();
  209.    }
  210.  
  211.    public void setText(String var1) {
  212.       this.m_strValue = var1;
  213.    }
  214. }
  215.