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

  1. package hhapplet;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Graphics;
  6. import java.awt.Image;
  7. import java.awt.Panel;
  8. import java.awt.Rectangle;
  9. import java.awt.image.ImageObserver;
  10. import java.util.Vector;
  11.  
  12. public class BsscImagePanel extends Panel implements Runnable {
  13.    private Image m_bgImage;
  14.    private int m_nbgWidth;
  15.    private int m_nbgHeight;
  16.    private Image m_cachebgImage;
  17.    private int m_nOldWidth;
  18.    private int m_nOldHeight;
  19.    private boolean m_bBgUpdated;
  20.    private Image m_imgbackground;
  21.    private Vector m_vToDo;
  22.  
  23.    private Image getBackgroundImage() {
  24.       if (this.m_nbgWidth > 0 && this.m_nbgHeight > 0 && this.m_bgImage != null) {
  25.          Rectangle var1 = ((Component)this).getBounds();
  26.          if (var1.height == this.m_nOldHeight && var1.width == this.m_nOldWidth && !this.m_bBgUpdated) {
  27.             return this.m_cachebgImage;
  28.          } else {
  29.             this.m_nOldWidth = var1.width;
  30.             this.m_nOldHeight = var1.height;
  31.             this.m_cachebgImage = ((Component)this).createImage(var1.width, var1.height);
  32.             Graphics var2 = this.m_cachebgImage.getGraphics();
  33.             this.drawBackGround(var2);
  34.             return this.m_cachebgImage;
  35.          }
  36.       } else {
  37.          return null;
  38.       }
  39.    }
  40.  
  41.    public BsscImagePanel() {
  42.       if (ViewSkin.m_PaneColorBg != null) {
  43.          ((Component)this).setBackground(ViewSkin.m_PaneColorBg);
  44.       }
  45.  
  46.       if (ViewSkin.m_PaneImageBg != null) {
  47.          this.setBgImage(ViewSkin.m_PaneImageBg);
  48.       }
  49.  
  50.       this.m_vToDo = new Vector();
  51.    }
  52.  
  53.    public void paint(Graphics var1) {
  54.       try {
  55.          super.paint(var1);
  56.          Rectangle var2 = ((Component)this).getBounds();
  57.          Image var3 = ((Component)this).createImage(var2.width, var2.height);
  58.          Graphics var4 = var3.getGraphics();
  59.          this.m_imgbackground = this.getBackgroundImage();
  60.          if (this.m_imgbackground != null) {
  61.             var4.drawImage(this.m_imgbackground, 0, 0, this);
  62.          }
  63.  
  64.          var1.drawImage(var3, 0, 0, this);
  65.       } catch (Exception var5) {
  66.          ((Throwable)var5).printStackTrace();
  67.       }
  68.    }
  69.  
  70.    public void setBgImage(Image var1) {
  71.       this.m_bgImage = var1;
  72.       this.m_nbgHeight = this.m_bgImage.getHeight(this);
  73.       this.m_nbgWidth = this.m_bgImage.getWidth(this);
  74.    }
  75.  
  76.    public void dispatchToDo(String var1) {
  77.       if (var1 == "repaint") {
  78.          ((Component)this).repaint();
  79.       }
  80.  
  81.    }
  82.  
  83.    public boolean imageUpdate(Image var1, int var2, int var3, int var4, int var5, int var6) {
  84.       if (var1 == this.m_bgImage) {
  85.          this.m_nbgWidth = var5;
  86.          this.m_nbgHeight = var6;
  87.          this.m_bBgUpdated = true;
  88.          ((Component)this).repaint();
  89.          return false;
  90.       } else {
  91.          return true;
  92.       }
  93.    }
  94.  
  95.    public void drawBackGround(Graphics var1) {
  96.       if (this.m_nbgWidth > 0 && this.m_nbgHeight > 0 && this.m_bgImage != null) {
  97.          Rectangle var5 = ((Component)this).getBounds();
  98.  
  99.          for(int var6 = 0; var6 <= (var5.width - 1) / this.m_nbgWidth; ++var6) {
  100.             for(int var7 = 0; var7 <= (var5.height - 1) / this.m_nbgHeight; ++var7) {
  101.                if (!var1.drawImage(this.m_bgImage, var6 * this.m_nbgWidth, var7 * this.m_nbgHeight, this.m_nbgWidth, this.m_nbgHeight, (ImageObserver)null)) {
  102.                   this.setTimeout("repaint", 100);
  103.                   return;
  104.                }
  105.             }
  106.          }
  107.  
  108.          if (this.m_bBgUpdated) {
  109.             this.m_bBgUpdated = false;
  110.             return;
  111.          }
  112.       } else {
  113.          Color var2 = var1.getColor();
  114.          Color var3 = ((Component)this).getBackground();
  115.          var1.setColor(var3);
  116.          Rectangle var4 = ((Component)this).getBounds();
  117.          var1.fillRect(0, 0, var4.width, var4.height);
  118.          var1.setColor(var2);
  119.       }
  120.  
  121.    }
  122.  
  123.    public void update(Graphics var1) {
  124.       this.paint(var1);
  125.    }
  126.  
  127.    public void run() {
  128.       synchronized(this.m_vToDo){}
  129.  
  130.       ToDo var1;
  131.       try {
  132.          var1 = (ToDo)this.m_vToDo.elementAt(0);
  133.          this.m_vToDo.removeElementAt(0);
  134.       } catch (Throwable var8) {
  135.          throw var8;
  136.       }
  137.  
  138.       try {
  139.          Thread.sleep((long)var1.m_nMSec);
  140.          this.dispatchToDo(var1.m_sToDo);
  141.       } catch (InterruptedException var7) {
  142.          ((Throwable)var7).printStackTrace();
  143.       }
  144.    }
  145.  
  146.    public final void setTimeout(String var1, int var2) {
  147.       ToDo var3 = new ToDo(this, var1, var2);
  148.       synchronized(this.m_vToDo){}
  149.  
  150.       try {
  151.          this.m_vToDo.addElement(var3);
  152.       } catch (Throwable var8) {
  153.          throw var8;
  154.       }
  155.  
  156.       Thread var4 = new Thread(this);
  157.       var4.start();
  158.    }
  159. }
  160.