home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 1998 October / DPPCPRO1098.ISO / Hotdog / files / snagpack.exe / WARP.CLASS (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-21  |  4.8 KB  |  244 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Dimension;
  5. import java.awt.Event;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10.  
  11. public class warp extends Applet implements Runnable {
  12.    // $FF: renamed from: s java.lang.String
  13.    private String field_0;
  14.    private int stringLength;
  15.    private Thread engineThread;
  16.    private boolean userPause;
  17.    private boolean readyToPaint = true;
  18.    private int x_coord = 2;
  19.    private int y_coord = 2;
  20.    private String speed;
  21.    private boolean threadSuspended;
  22.    private boolean debug;
  23.    private String fontstring;
  24.    private int fontsize = 20;
  25.    private int newFontSize = 20;
  26.    private int fontstyle;
  27.    private int changeSize = 1;
  28.    private int focalSize = 1;
  29.    private int sleepTime;
  30.    private Color stringColor;
  31.    private Color backColor;
  32.    private Image offImage;
  33.    private Graphics offGraphics;
  34.    private Dimension offScrSize;
  35.    private Font font;
  36.    private boolean matched;
  37.    private boolean unreg = true;
  38.    private boolean toSmall = true;
  39.  
  40.    public void stop() {
  41.       if (this.engineThread != null && this.engineThread.isAlive()) {
  42.          this.engineThread.stop();
  43.       }
  44.  
  45.       this.engineThread = null;
  46.    }
  47.  
  48.    private synchronized void updateFont() {
  49.       this.font = new Font(this.fontstring, this.fontstyle, this.newFontSize);
  50.    }
  51.  
  52.    public synchronized void prePaint(Graphics var1) {
  53.       var1.setColor(this.backColor);
  54.       var1.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  55.       var1.setFont(this.font);
  56.       var1.setColor(this.stringColor);
  57.       this.centerString(var1);
  58.       if (this.debug) {
  59.          System.out.println(this.newFontSize);
  60.       }
  61.  
  62.       var1.drawString(this.field_0, this.x_coord, this.y_coord);
  63.       this.newFontSize = this.toSmall ? this.newFontSize - this.changeSize : this.newFontSize + this.changeSize;
  64.       if (this.newFontSize == 27) {
  65.          this.newFontSize = this.toSmall ? this.newFontSize - this.changeSize : this.newFontSize + this.changeSize;
  66.       }
  67.  
  68.       if (this.newFontSize <= this.focalSize) {
  69.          this.toSmall = false;
  70.          this.newFontSize = this.focalSize;
  71.       } else if (this.newFontSize >= this.fontsize) {
  72.          this.toSmall = true;
  73.       }
  74.  
  75.    }
  76.  
  77.    public void paint(Graphics var1) {
  78.       if (this.engineThread != null) {
  79.          if (this.offGraphics != null) {
  80.             this.prePaint(this.offGraphics);
  81.             var1.drawImage(this.offImage, 0, 0, this);
  82.          } else {
  83.             this.prePaint(var1);
  84.          }
  85.       }
  86.  
  87.    }
  88.  
  89.    private void dbg(String var1) {
  90.       if (this.debug) {
  91.          System.out.println(var1);
  92.       }
  93.  
  94.    }
  95.  
  96.    public synchronized void update(Graphics var1) {
  97.       Dimension var2 = ((Component)this).size();
  98.       if (this.offImage == null || var2.width != this.offScrSize.width || var2.height != this.offScrSize.height) {
  99.          this.offImage = ((Component)this).createImage(var2.width, var2.height);
  100.          this.offGraphics = this.offImage.getGraphics();
  101.          this.offGraphics.setFont(((Component)this).getFont());
  102.          this.offScrSize = var2;
  103.       }
  104.  
  105.       if (this.readyToPaint) {
  106.          this.paint(var1);
  107.       }
  108.  
  109.    }
  110.  
  111.    private synchronized void centerString(Graphics var1) {
  112.       FontMetrics var2 = var1.getFontMetrics();
  113.       if (var2 != null) {
  114.          this.x_coord = ((Component)this).size().width / 2 - var2.stringWidth(this.field_0) / 2;
  115.          this.y_coord = ((Component)this).size().height / 2 + var2.getAscent() / 2;
  116.       }
  117.  
  118.    }
  119.  
  120.    public void start() {
  121.       if (this.engineThread == null) {
  122.          this.engineThread = new Thread(this);
  123.       }
  124.  
  125.       this.engineThread.start();
  126.    }
  127.  
  128.    public String getAppletInfo() {
  129.       return "Swami - warp.class v1.0 Copyright (c) Sausage SoftWare 1996";
  130.    }
  131.  
  132.    public void run() {
  133.       Thread.currentThread().setPriority(1);
  134.  
  135.       while(true) {
  136.          if (this.unreg) {
  137.             ((Applet)this).getAppletContext().showStatus("Unregistered version. Copyright (c) Sausage Software 1996");
  138.          }
  139.  
  140.          ((Component)this).repaint();
  141.  
  142.          try {
  143.             Thread.sleep((long)this.sleepTime);
  144.          } catch (Exception var1) {
  145.          }
  146.  
  147.          this.readyToPaint = false;
  148.          this.updateFont();
  149.          this.readyToPaint = true;
  150.       }
  151.    }
  152.  
  153.    public void init() {
  154.       String var1 = ((Applet)this).getParameter("font");
  155.       this.fontstring = null;
  156.       this.fontstring = myFont.getFontName(var1);
  157.       this.dbg(this.fontstring);
  158.       var1 = ((Applet)this).getParameter("fontsize");
  159.       if (var1 != null) {
  160.          this.fontsize = this.newFontSize = Integer.parseInt(var1);
  161.       }
  162.  
  163.       var1 = ((Applet)this).getParameter("style");
  164.       this.fontstyle = myFont.getFontStyle(var1);
  165.       var1 = ((Applet)this).getParameter("focalSize");
  166.       if (var1 != null) {
  167.          this.focalSize = Integer.parseInt(var1);
  168.       }
  169.  
  170.       this.field_0 = ((Applet)this).getParameter("text");
  171.       if (this.field_0 == null) {
  172.          this.field_0 = "Sausage Software";
  173.       }
  174.  
  175.       this.stringLength = this.field_0.length();
  176.       String var2 = ((Applet)this).getParameter("reguser");
  177.       if (var2 == null) {
  178.          ver.NotRegistered();
  179.       }
  180.  
  181.       if (var2.toLowerCase().equals("unregistered")) {
  182.          this.unreg = true;
  183.       } else {
  184.          this.unreg = false;
  185.       }
  186.  
  187.       String var3 = ((Applet)this).getParameter("serialid");
  188.       if (var3 == null) {
  189.          ver.NotRegistered();
  190.       }
  191.  
  192.       ver var4 = new ver(var2, var3);
  193.       this.matched = var4.verifyUser(this.field_0);
  194.       if (!this.matched) {
  195.          ver.NotRegistered();
  196.       }
  197.  
  198.       this.speed = ((Applet)this).getParameter("sizeChange");
  199.       if (this.field_0 != null) {
  200.          this.changeSize = Integer.valueOf(this.speed);
  201.       }
  202.  
  203.       var1 = ((Applet)this).getParameter("speed");
  204.       if (var1 != null) {
  205.          this.sleepTime = Integer.parseInt(var1);
  206.       }
  207.  
  208.       var1 = ((Applet)this).getParameter("color");
  209.       if (var1 != null) {
  210.          createColor var5 = new createColor(var1, ",");
  211.          this.stringColor = var5.getColor();
  212.       } else {
  213.          this.stringColor = new Color(255, 0, 0);
  214.       }
  215.  
  216.       var1 = ((Applet)this).getParameter("background");
  217.       if (var1 != null) {
  218.          createColor var12 = new createColor(var1, ",");
  219.          this.backColor = var12.getColor();
  220.       } else {
  221.          this.backColor = new Color(0, 0, 0);
  222.       }
  223.  
  224.       this.dbg("finish init");
  225.    }
  226.  
  227.    public boolean handleEvent(Event var1) {
  228.       if (var1.id == 501) {
  229.          if (this.userPause) {
  230.             this.engineThread.resume();
  231.          } else {
  232.             this.engineThread.suspend();
  233.          }
  234.  
  235.          this.userPause = !this.userPause;
  236.       } else if (var1.id == 201) {
  237.          this.stop();
  238.          System.exit(0);
  239.       }
  240.  
  241.       return true;
  242.    }
  243. }
  244.