home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2003 March / DPPCPRO0303.ISO / Extras / Content / Images / StockObjects / objects / java / ABanner / AMPERSANDSCROLL.CLASS (.txt) < prev    next >
Encoding:
Java Class File  |  1998-10-22  |  6.4 KB  |  280 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Font;
  5. import java.awt.Graphics;
  6. import java.awt.Image;
  7. import java.awt.image.FilteredImageSource;
  8. import java.net.URL;
  9.  
  10. public class AmpersandScroll extends Applet implements Runnable {
  11.    Thread animator;
  12.    Image image;
  13.    Image offscreen;
  14.    // $FF: renamed from: og java.awt.Graphics
  15.    Graphics field_0;
  16.    String text;
  17.    String correcthost;
  18.    Color backcolor;
  19.    Color textcolor;
  20.    Font textfont;
  21.    boolean istext;
  22.    boolean isimage;
  23.    boolean registered;
  24.    boolean dropshadow;
  25.    int sleep = 80;
  26.    int textinc = -2;
  27.    int imageinc = -1;
  28.    int imagewidth;
  29.    int imageheight;
  30.    int textwidth;
  31.    int inctext;
  32.    int imageX;
  33.    int width;
  34.    int height;
  35.    int textY;
  36.  
  37.    public void init() {
  38.       System.out.println("Scroller Applet");
  39.       System.out.println("Version 1.2");
  40.       System.out.println("Copyright 1997 Ampersand Internet All Rights Reserved");
  41.       System.out.println("http://www.powerup.com.au/~mgk");
  42.       this.correcthost = "http://www.powerup.com.au/~mgk";
  43.       String var1 = ((Applet)this).getDocumentBase().toString();
  44.       this.registered = true;
  45.       if (!var1.startsWith(this.correcthost)) {
  46.          System.out.println("Licensed for use at " + this.correcthost);
  47.          System.out.println("Contact mgk@powerup.com.au to obtain a license");
  48.          this.registered = false;
  49.       }
  50.  
  51.       this.textfont = ((Component)this).getFont();
  52.       String var2 = "HELVETICA";
  53.       int var3 = 14;
  54.       byte var4 = 0;
  55.       this.height = ((Component)this).size().height;
  56.       this.width = ((Component)this).size().width;
  57.       this.offscreen = ((Component)this).createImage(((Component)this).size().width, ((Component)this).size().height);
  58.       this.field_0 = this.offscreen.getGraphics();
  59.       if (((Applet)this).getParameter("sleep") != null) {
  60.          this.sleep = Integer.parseInt(((Applet)this).getParameter("sleep"));
  61.       }
  62.  
  63.       if (((Applet)this).getParameter("image") != null) {
  64.          this.image = this.loadimage(((Applet)this).getParameter("image"));
  65.          this.isimage = true;
  66.       }
  67.  
  68.       if (((Applet)this).getParameter("text") != null) {
  69.          this.text = ((Applet)this).getParameter("text");
  70.          if (((Applet)this).getParameter("pointsize") != null) {
  71.             var3 = Integer.parseInt(((Applet)this).getParameter("pointsize"));
  72.          }
  73.  
  74.          if (((Applet)this).getParameter("fontface") != null) {
  75.             var2 = ((Applet)this).getParameter("fontface");
  76.          }
  77.  
  78.          if (((Applet)this).getParameter("fontweight") != null) {
  79.             if (((Applet)this).getParameter("fontweight").equalsIgnoreCase("bold")) {
  80.                var4 = 1;
  81.             }
  82.  
  83.             if (((Applet)this).getParameter("fontweight").equalsIgnoreCase("italic")) {
  84.                var4 = 2;
  85.             }
  86.  
  87.             if (((Applet)this).getParameter("fontweight").equalsIgnoreCase("bolditalic")) {
  88.                var4 = 3;
  89.             }
  90.          }
  91.  
  92.          if (((Applet)this).getParameter("textinc") != null) {
  93.             this.textinc = Integer.parseInt(((Applet)this).getParameter("textinc"));
  94.          }
  95.  
  96.          this.textfont = new Font(var2, var4, var3);
  97.          this.inctext = this.width;
  98.          this.field_0.setFont(this.textfont);
  99.          this.textwidth = this.field_0.getFontMetrics().stringWidth(this.text);
  100.          String var5 = "center";
  101.          if (((Applet)this).getParameter("alignment") != null) {
  102.             var5 = ((Applet)this).getParameter("alignment");
  103.          }
  104.  
  105.          if (var5.equalsIgnoreCase("top")) {
  106.             this.textY = this.field_0.getFontMetrics().getLeading() + this.field_0.getFontMetrics().getAscent() - this.field_0.getFontMetrics().getDescent() + 1;
  107.          }
  108.  
  109.          if (var5.equalsIgnoreCase("center")) {
  110.             this.textY = (this.height + this.field_0.getFontMetrics().getHeight() - this.field_0.getFontMetrics().getAscent() / 2) / 2;
  111.          }
  112.  
  113.          if (var5.equalsIgnoreCase("bottom")) {
  114.             this.textY = ((Component)this).size().height - this.field_0.getFontMetrics().getDescent() - this.field_0.getFontMetrics().getLeading() - 1;
  115.          }
  116.  
  117.          if (((Applet)this).getParameter("dropshadow") != null && ((Applet)this).getParameter("dropshadow").equalsIgnoreCase("true")) {
  118.             this.dropshadow = true;
  119.          }
  120.  
  121.          this.istext = true;
  122.       }
  123.  
  124.       String var10 = ((Applet)this).getParameter("backcolor");
  125.       if (var10 == null) {
  126.          var10 = "#000000";
  127.       }
  128.  
  129.       String var6 = var10.substring(1, 3);
  130.       int var7 = Integer.valueOf(var6, 16);
  131.       var6 = var10.substring(3, 5);
  132.       int var8 = Integer.valueOf(var6, 16);
  133.       var6 = var10.substring(5, 7);
  134.       int var9 = Integer.valueOf(var6, 16);
  135.       this.backcolor = new Color(var7, var8, var9);
  136.       var10 = ((Applet)this).getParameter("textcolor");
  137.       if (var10 == null) {
  138.          var10 = "#ff0000";
  139.       }
  140.  
  141.       var6 = var10.substring(1, 3);
  142.       var7 = Integer.valueOf(var6, 16);
  143.       var6 = var10.substring(3, 5);
  144.       var8 = Integer.valueOf(var6, 16);
  145.       var6 = var10.substring(5, 7);
  146.       var9 = Integer.valueOf(var6, 16);
  147.       this.textcolor = new Color(var7, var8, var9);
  148.       ((Component)this).setBackground(this.backcolor);
  149.    }
  150.  
  151.    public void start() {
  152.       if (this.isimage) {
  153.          while(this.image.getWidth(this) < 0) {
  154.          }
  155.  
  156.          this.imagewidth = this.image.getWidth(this);
  157.  
  158.          while(this.image.getHeight(this) < 0) {
  159.          }
  160.  
  161.          this.imageheight = this.image.getWidth(this);
  162.       }
  163.  
  164.       if (this.animator == null) {
  165.          this.animator = new Thread(this);
  166.          this.animator.start();
  167.       }
  168.  
  169.    }
  170.  
  171.    public void stop() {
  172.       if (this.animator != null) {
  173.          this.animator.stop();
  174.          this.animator = null;
  175.       }
  176.  
  177.    }
  178.  
  179.    public void run() {
  180.       while(Thread.currentThread() == this.animator) {
  181.          long var1 = System.currentTimeMillis();
  182.          ((Component)this).repaint();
  183.          long var3 = System.currentTimeMillis();
  184.          long var5 = var1 - var3;
  185.          if (var5 > (long)this.sleep) {
  186.             var5 = (long)this.sleep;
  187.          }
  188.  
  189.          try {
  190.             Thread.sleep((long)this.sleep - var5);
  191.          } catch (InterruptedException var7) {
  192.          }
  193.       }
  194.  
  195.    }
  196.  
  197.    public synchronized void update(Graphics var1) {
  198.       this.paint(var1);
  199.       if (this.istext) {
  200.          this.inctext += this.textinc;
  201.          if (this.inctext < -this.textwidth) {
  202.             this.inctext = this.width;
  203.          }
  204.  
  205.          if (this.inctext > this.width) {
  206.             this.inctext = -this.textwidth;
  207.          }
  208.  
  209.          this.field_0.setColor(this.backcolor);
  210.          this.field_0.fillRect(0, 0, this.width, this.height);
  211.       }
  212.  
  213.       if (this.isimage) {
  214.          this.imageX += this.imageinc;
  215.          int var2 = this.imageX;
  216.          if (this.imageX > this.imagewidth || this.imageX < -this.imagewidth) {
  217.             this.imageX = 0;
  218.          }
  219.  
  220.          for(int var3 = -1; var2 + this.imagewidth * (var3 - 1) < this.width; ++var3) {
  221.             for(int var4 = 0; this.imageheight * (var4 - 1) < this.height; ++var4) {
  222.                this.field_0.drawImage(this.image, var2 + this.imagewidth * var3, this.imageheight * var4, this);
  223.             }
  224.          }
  225.       }
  226.  
  227.       if (this.istext) {
  228.          this.field_0.setFont(this.textfont);
  229.          if (this.dropshadow) {
  230.             this.field_0.setColor(Color.black);
  231.             this.field_0.drawString(this.text, this.inctext + 1, this.textY + 1);
  232.          }
  233.  
  234.          this.field_0.setColor(this.textcolor);
  235.          this.field_0.drawString(this.text, this.inctext, this.textY);
  236.       }
  237.  
  238.       if (!this.registered) {
  239.          this.field_0.setFont(new Font("arial", 1, 12));
  240.          this.field_0.setColor(Color.black);
  241.          this.field_0.drawString("Licensed for use at " + this.correcthost, 10, 12);
  242.          this.field_0.drawString("Contact mgk@powerup.com.au to obtain a license", 10, 24);
  243.          this.field_0.setColor(Color.white);
  244.          this.field_0.drawString("Licensed for use at " + this.correcthost, 9, 11);
  245.          this.field_0.drawString("Contact mgk@powerup.com.au to obtain a license", 9, 23);
  246.          this.field_0.setColor(this.backcolor);
  247.       }
  248.  
  249.       this.paint(this.field_0);
  250.    }
  251.  
  252.    public synchronized void paint(Graphics var1) {
  253.       var1.drawImage(this.offscreen, 0, 0, this);
  254.    }
  255.  
  256.    public Image loadimage(String var1) {
  257.       if (var1.toLowerCase().startsWith("http")) {
  258.          try {
  259.             Image var2 = ((Applet)this).getImage(new URL(var1));
  260.             FixDither var3 = new FixDither();
  261.             FilteredImageSource var4 = new FilteredImageSource(var2.getSource(), var3);
  262.             return ((Component)this).createImage(var4);
  263.          } catch (Exception var5) {
  264.             System.out.println(var5 + " loading image in Banner applet");
  265.          }
  266.       } else {
  267.          try {
  268.             Image var7 = ((Applet)this).getImage(((Applet)this).getDocumentBase(), var1);
  269.             FixDither var8 = new FixDither();
  270.             FilteredImageSource var9 = new FilteredImageSource(var7.getSource(), var8);
  271.             return ((Component)this).createImage(var9);
  272.          } catch (Exception var6) {
  273.             System.out.println(var6 + " loading image in Banner applet");
  274.          }
  275.       }
  276.  
  277.       return this.image;
  278.    }
  279. }
  280.