home *** CD-ROM | disk | FTP | other *** search
/ Your Web Site Creator / Your Web Site Creator.iso / WebSite / data1.cab / Program_Executable_Files / Classes / TXTPCAN2.CLA (.txt) < prev    next >
Encoding:
Java Class File  |  1999-01-13  |  5.1 KB  |  199 lines

  1. import java.applet.Applet;
  2. import java.awt.Canvas;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10.  
  11. public class TextPulseCanvas2 extends Canvas implements Runnable {
  12.    Thread appThread;
  13.    Image osImage;
  14.    Graphics osg;
  15.    Color bkColor;
  16.    Image bkImage;
  17.    Font startFont;
  18.    Font endFont;
  19.    int growthIncrement;
  20.    String message;
  21.    Color fontColor;
  22.    int messageWidth;
  23.    int messageHeight;
  24.    // $FF: renamed from: x int
  25.    int field_0;
  26.    // $FF: renamed from: y int
  27.    int field_1;
  28.    int delayTime;
  29.    Font[] font;
  30.    // $FF: renamed from: fm java.awt.FontMetrics[]
  31.    FontMetrics[] field_2;
  32.    int fontIndex;
  33.    int numFonts;
  34.  
  35.    public TextPulseCanvas2(Applet var1, int var2) {
  36.       this.GetParameters(var1, var2);
  37.  
  38.       try {
  39.          this.Initialize();
  40.       } catch (Exception var4) {
  41.          System.out.println(((Throwable)var4).getMessage());
  42.       }
  43.    }
  44.  
  45.    void GetParameters(Applet var1, int var2) {
  46.       String var3 = var1.getParameter("textPulseBkColor" + var2);
  47.       this.bkColor = AppletParam2.GetColor(var3, (Color)null);
  48.       if (this.bkColor != null) {
  49.          ((Component)this).setBackground(this.bkColor);
  50.       }
  51.  
  52.       var3 = var1.getParameter("textPulseBkImage" + var2);
  53.       this.bkImage = var1.getImage(var1.getCodeBase(), var3);
  54.       var3 = var1.getParameter("textPulseStartFont" + var2);
  55.       this.startFont = AppletParam2.GetJavaFont(var3);
  56.       var3 = var1.getParameter("textPulseEndFont" + var2);
  57.       this.endFont = AppletParam2.GetJavaFont(var3);
  58.       var3 = var1.getParameter("textPulseGrowthIncrement" + var2);
  59.       this.growthIncrement = AppletParam2.GetInt(var3, 1);
  60.       var3 = var1.getParameter("textPulseColor" + var2);
  61.       this.fontColor = AppletParam2.GetColor(var3, Color.black);
  62.       var3 = var1.getParameter("textPulseMessage" + var2);
  63.       this.message = AppletParam2.GetString(var3, "Message");
  64.       var3 = var1.getParameter("textPulseIncrement" + var2);
  65.       this.delayTime = AppletParam2.GetInt(var3, 125);
  66.    }
  67.  
  68.    public void Start() {
  69.       this.appThread = new Thread(this);
  70.       this.appThread.start();
  71.    }
  72.  
  73.    public void Stop() {
  74.       this.appThread.stop();
  75.       this.appThread = null;
  76.    }
  77.  
  78.    public void update(Graphics var1) {
  79.       if (this.osImage == null) {
  80.          this.osImage = ((Component)this).createImage(((Component)this).size().width, ((Component)this).size().height);
  81.          this.osg = this.osImage.getGraphics();
  82.       }
  83.  
  84.       this.osg.setColor(((Component)this).getBackground());
  85.       this.osg.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  86.       if (this.bkImage != null) {
  87.          int var2 = this.bkImage.getWidth(this);
  88.          int var3 = this.bkImage.getHeight(this);
  89.          int var4 = ((Component)this).size().width / var2;
  90.          int var5 = ((Component)this).size().height / var3;
  91.          ++var4;
  92.          ++var5;
  93.  
  94.          for(int var6 = 0; var6 < var5; ++var6) {
  95.             for(int var7 = 0; var7 < var4; ++var7) {
  96.                this.osg.drawImage(this.bkImage, var7 * var2, var6 * var3, this);
  97.             }
  98.          }
  99.       }
  100.  
  101.       this.osg.setColor(this.fontColor);
  102.       this.osg.setFont(this.font[this.fontIndex]);
  103.       this.field_0 = ((Component)this).size().width / 2 - this.messageWidth / 2;
  104.       this.field_1 = ((Component)this).size().height / 2 + this.messageHeight / 2;
  105.       this.osg.drawString(this.message, this.field_0, this.field_1);
  106.       var1.drawImage(this.osImage, 0, 0, this);
  107.    }
  108.  
  109.    public void run() {
  110.       try {
  111.          while(true) {
  112.             ((Component)this).repaint();
  113.             this.UpdateFont();
  114.             Thread.sleep((long)this.delayTime);
  115.          }
  116.       } catch (InterruptedException var1) {
  117.       }
  118.    }
  119.  
  120.    public Dimension minimumSize() {
  121.       return new Dimension(10, 10);
  122.    }
  123.  
  124.    public Dimension preferredSize() {
  125.       return new Dimension(10, 10);
  126.    }
  127.  
  128.    public synchronized void reshape(int var1, int var2, int var3, int var4) {
  129.       super.reshape(var1, var2, var3, var4);
  130.       this.osImage = null;
  131.       this.osg = null;
  132.    }
  133.  
  134.    public boolean imageUpdate(Image var1, int var2, int var3, int var4, int var5, int var6) {
  135.       ((Component)this).repaint();
  136.       return true;
  137.    }
  138.  
  139.    void UpdateFont() {
  140.       if (this.growthIncrement > 0) {
  141.          ++this.fontIndex;
  142.       } else {
  143.          --this.fontIndex;
  144.       }
  145.  
  146.       if (this.fontIndex >= this.numFonts) {
  147.          this.fontIndex = this.numFonts - 1;
  148.          this.growthIncrement = -this.growthIncrement;
  149.       } else if (this.fontIndex < 0) {
  150.          this.fontIndex = 0;
  151.          this.growthIncrement = -this.growthIncrement;
  152.       }
  153.  
  154.       this.messageWidth = this.field_2[this.fontIndex].stringWidth(this.message);
  155.       this.messageHeight = this.field_2[this.fontIndex].getAscent();
  156.    }
  157.  
  158.    void Initialize() throws Exception {
  159.       if (this.startFont == null) {
  160.          throw new Exception("Start font not specified");
  161.       } else if (this.endFont == null) {
  162.          throw new Exception("End font not specified");
  163.       } else if (!this.startFont.getName().equals(this.endFont.getName())) {
  164.          throw new Exception("Start font and end font the same font");
  165.       } else if (this.startFont.getStyle() != this.endFont.getStyle()) {
  166.          throw new Exception("Start font and end font must be the same style");
  167.       } else if (this.startFont.getSize() == this.endFont.getSize()) {
  168.          throw new Exception("Start font and end font cannot be the same size.");
  169.       } else if (this.growthIncrement < 1) {
  170.          throw new Exception("Growth increment must be greater than 0.");
  171.       } else {
  172.          int var1 = this.startFont.getSize();
  173.          int var2 = this.endFont.getSize();
  174.          this.numFonts = 0;
  175.          if (var2 > var1) {
  176.             this.numFonts = (var2 - var1) / this.growthIncrement;
  177.             if ((var2 - var1) % this.growthIncrement != 0) {
  178.                ++this.numFonts;
  179.             }
  180.          } else {
  181.             this.numFonts = (var1 - var2) / this.growthIncrement;
  182.             if ((var1 - var2) % this.growthIncrement != 0) {
  183.                ++this.numFonts;
  184.             }
  185.          }
  186.  
  187.          this.font = new Font[this.numFonts];
  188.          this.field_2 = new FontMetrics[this.numFonts];
  189.  
  190.          for(int var3 = 0; var3 < this.numFonts; ++var3) {
  191.             this.font[var3] = new Font(this.startFont.getName(), this.startFont.getStyle(), this.startFont.getSize() + var3 * this.growthIncrement);
  192.             this.field_2[var3] = ((Component)this).getFontMetrics(this.font[var3]);
  193.          }
  194.  
  195.          this.fontIndex = 0;
  196.       }
  197.    }
  198. }
  199.