home *** CD-ROM | disk | FTP | other *** search
/ PC Users 1998 November / Cd users extra 14.iso / prog / inst / scroll / scroll.exe / ScrollTextVert.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-09-15  |  6.3 KB  |  453 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. import java.io.DataInputStream;
  11. import java.io.InputStream;
  12.  
  13. public class ScrollTextVert extends Applet implements Runnable {
  14.    Thread scrollThread;
  15.    int bannerHeight = 20;
  16.    int maxWidth;
  17.    int maxHeight;
  18.    public String message;
  19.    int messageX = 5;
  20.    int messageY = 5;
  21.    int messageW;
  22.    // $FF: renamed from: X int
  23.    int field_0;
  24.    // $FF: renamed from: Y int
  25.    int field_1 = 2;
  26.    int scrollUnit = 1;
  27.    int sleepTime;
  28.    public Dimension lastS;
  29.    public Font messageF;
  30.    Image textImage;
  31.    Graphics textGC;
  32.    static boolean loaded;
  33.    // $FF: renamed from: f java.io.InputStream
  34.    InputStream field_2;
  35.    // $FF: renamed from: df java.io.DataInputStream
  36.    DataInputStream field_3;
  37.    Image bannerImage;
  38.    Graphics bannerGraphic;
  39.    boolean flag = true;
  40.    int color;
  41.    int bkcolor = 3;
  42.    Color backgroundColor;
  43.    Color textColor;
  44.    Color lineColor;
  45.    int fontH;
  46.    int fontName;
  47.    int fontL;
  48.    String strLine;
  49.    String curFont;
  50.    boolean load_flag;
  51.    int load_count;
  52.    Font curTTF;
  53.    int vertScrollIndex;
  54.    boolean vertScrollFlag;
  55.    int fastScrollIndex;
  56.    boolean fastScrollFlag;
  57.    boolean needFastScroll;
  58.    int horScrollIndex;
  59.    String horScrollStr;
  60.    boolean horScrollFlag;
  61.    boolean horF;
  62.    int lineSleepTime;
  63.    int charSleepTime;
  64.    int pageSleepTime;
  65.    boolean onlineFlag;
  66.    boolean offlineFlag;
  67.  
  68.    public void init() {
  69.       Dimension var1 = ((Component)this).size();
  70.       this.maxWidth = var1.width - 4;
  71.       this.maxHeight = var1.height;
  72.       this.bannerImage = ((Component)this).createImage(this.maxWidth, this.maxHeight);
  73.       this.bannerGraphic = this.bannerImage.getGraphics();
  74.       this.textImage = ((Component)this).createImage(this.maxWidth, this.maxHeight);
  75.       this.textGC = this.textImage.getGraphics();
  76.       this.lastS = new Dimension(1, 1);
  77.       ((Component)this).setBackground(Color.white);
  78.       this.message = "123";
  79.       this.createBannerParams();
  80.       ((Component)this).repaint();
  81.    }
  82.  
  83.    public void start() {
  84.       if (this.scrollThread == null) {
  85.          this.scrollThread = new Thread(this);
  86.          this.scrollThread.start();
  87.          loaded = true;
  88.          this.offlineFlag = true;
  89.       }
  90.  
  91.       ((Applet)this).showStatus(this.getAppletInfo());
  92.    }
  93.  
  94.    public void stop() {
  95.       if (this.scrollThread != null && this.scrollThread.isAlive()) {
  96.          this.scrollThread.stop();
  97.       }
  98.  
  99.       loaded = false;
  100.       this.onlineFlag = true;
  101.       ((Component)this).repaint();
  102.       this.scrollThread = null;
  103.    }
  104.  
  105.    public void run() {
  106.       Thread var1 = Thread.currentThread();
  107.       var1.setPriority(1);
  108.       ((Component)this).repaint();
  109.  
  110.       while(this.scrollThread == var1) {
  111.          while(loaded) {
  112.             this.nextPos();
  113.  
  114.             try {
  115.                Thread.sleep((long)this.sleepTime);
  116.             } catch (InterruptedException var2) {
  117.             }
  118.          }
  119.       }
  120.  
  121.    }
  122.  
  123.    public synchronized String readText() {
  124.       String var1 = null;
  125.       if (!this.load_flag) {
  126.          try {
  127.             var1 = ((Applet)this).getParameter("Font" + this.load_count);
  128.          } catch (Exception var7) {
  129.          }
  130.  
  131.          if (var1 != null) {
  132.             this.curFont = var1;
  133.          }
  134.  
  135.          try {
  136.             var1 = ((Applet)this).getParameter("Layout" + this.load_count);
  137.          } catch (Exception var6) {
  138.          }
  139.  
  140.          if (var1 != null) {
  141.             this.fontL = Integer.parseInt(var1);
  142.          }
  143.  
  144.          try {
  145.             var1 = ((Applet)this).getParameter("FHeight" + this.load_count);
  146.          } catch (Exception var5) {
  147.          }
  148.  
  149.          if (var1 != null) {
  150.             this.fontH = Integer.parseInt(var1);
  151.          }
  152.  
  153.          this.curTTF = new Font(this.curFont, this.fontL, this.fontH);
  154.  
  155.          try {
  156.             var1 = ((Applet)this).getParameter("backgroundcolor" + this.load_count);
  157.          } catch (Exception var4) {
  158.          }
  159.  
  160.          if (var1 != null) {
  161.             this.backgroundColor = this.decodeColor(var1);
  162.          }
  163.  
  164.          try {
  165.             var1 = ((Applet)this).getParameter("color" + this.load_count);
  166.          } catch (Exception var3) {
  167.          }
  168.  
  169.          if (var1 != null) {
  170.             this.textColor = this.decodeColor(var1);
  171.          }
  172.  
  173.          try {
  174.             var1 = ((Applet)this).getParameter("Text" + this.load_count);
  175.             ++this.load_count;
  176.          } catch (Exception var2) {
  177.          }
  178.  
  179.          if (var1 == null) {
  180.             this.load_flag = true;
  181.             this.load_count = 0;
  182.          }
  183.       }
  184.  
  185.       if (this.load_flag) {
  186.          var1 = " ";
  187.       }
  188.  
  189.       return var1;
  190.    }
  191.  
  192.    synchronized Color decodeColor(String var1) {
  193.       int var2 = 0;
  194.  
  195.       try {
  196.          if (var1.startsWith("0x")) {
  197.             var2 = Integer.parseInt(var1.substring(2), 16);
  198.          } else if (var1.startsWith("#")) {
  199.             var2 = Integer.parseInt(var1.substring(1), 16);
  200.          } else if (var1.startsWith("0") && var1.length() > 1) {
  201.             var2 = Integer.parseInt(var1.substring(1), 8);
  202.          } else {
  203.             var2 = Integer.parseInt(var1, 10);
  204.          }
  205.  
  206.          return new Color(var2);
  207.       } catch (NumberFormatException var3) {
  208.          return null;
  209.       }
  210.    }
  211.  
  212.    public synchronized void paint(Graphics var1) {
  213.    }
  214.  
  215.    public synchronized void update(Graphics var1) {
  216.       if (this.onlineFlag) {
  217.          var1.setColor(this.lineColor);
  218.          var1.drawRect(0, 0, this.maxWidth, this.maxHeight - 2);
  219.          this.onlineFlag = false;
  220.       }
  221.  
  222.       if (this.offlineFlag) {
  223.          var1.setColor(this.backgroundColor);
  224.          var1.drawRect(0, 0, this.maxWidth, this.maxHeight - 2);
  225.          this.offlineFlag = false;
  226.       }
  227.  
  228.       if (loaded) {
  229.          if (!this.needFastScroll) {
  230.             if (!this.vertScrollFlag && !this.horScrollFlag) {
  231.                var1.setColor(this.backgroundColor);
  232.                this.textGC.setColor(this.backgroundColor);
  233.                this.textGC.fillRect(0, 0, this.maxWidth, this.maxHeight);
  234.                var1.fillRect(0, 0, this.maxWidth, this.maxHeight);
  235.                var1.setColor(this.textColor);
  236.                this.textGC.setColor(this.textColor);
  237.                this.load_flag = false;
  238.             } else {
  239.                this.drawText(var1);
  240.             }
  241.          } else {
  242.             var1.clipRect(5, 5, this.maxWidth - 5, this.maxHeight - 5);
  243.             var1.drawImage(this.textImage, 0, this.fastScrollIndex, this);
  244.  
  245.             try {
  246.                Thread.sleep((long)(this.lineSleepTime + this.fastScrollIndex / (int)((double)this.maxHeight + 0.1)));
  247.             } catch (InterruptedException var2) {
  248.             }
  249.          }
  250.       }
  251.    }
  252.  
  253.    public synchronized void drawText(Graphics var1) {
  254.       if (this.horF) {
  255.          this.textGC.setColor(this.textColor);
  256.          this.textGC.clipRect(5, 5, this.maxWidth - 10, this.maxHeight - 5);
  257.          this.textGC.setFont(this.curTTF);
  258.          this.textGC.drawString(this.horScrollStr, this.field_0 + this.messageX + 2, this.field_1 + this.messageY + 2 + this.vertScrollIndex * this.fontH);
  259.       }
  260.  
  261.       var1.setColor(this.textColor);
  262.       var1.clipRect(5, 5, this.maxWidth - 10, this.maxHeight - 5);
  263.       var1.setFont(this.curTTF);
  264.       var1.drawString(this.horScrollStr.substring(0, this.horScrollIndex), this.field_0 + this.messageX + 2, this.field_1 + this.messageY + 2 + this.vertScrollIndex * this.fontH);
  265.  
  266.       try {
  267.          Thread.sleep((long)this.charSleepTime);
  268.       } catch (InterruptedException var2) {
  269.       }
  270.    }
  271.  
  272.    public synchronized void nextPos() {
  273.       if (this.horScrollFlag) {
  274.          if (this.horScrollIndex < this.horScrollStr.length()) {
  275.             ++this.horScrollIndex;
  276.             this.horScrollFlag = true;
  277.             this.horF = false;
  278.          } else {
  279.             this.horScrollFlag = false;
  280.             this.vertScrollFlag = true;
  281.             this.horScrollIndex = 0;
  282.             this.horF = true;
  283.          }
  284.       } else if (!this.needFastScroll) {
  285.          if (this.vertScrollIndex < (this.maxHeight - 10 - this.fontH) / this.fontH && this.flag) {
  286.             this.horScrollStr = this.readText();
  287.             ++this.vertScrollIndex;
  288.             this.vertScrollFlag = false;
  289.             this.horScrollFlag = true;
  290.          } else {
  291.             this.vertScrollFlag = false;
  292.             this.vertScrollIndex = -1;
  293.             this.needFastScroll = true;
  294.  
  295.             try {
  296.                Thread.sleep((long)this.pageSleepTime);
  297.             } catch (InterruptedException var1) {
  298.             }
  299.          }
  300.       } else if (this.fastScrollIndex > -this.maxHeight) {
  301.          --this.fastScrollIndex;
  302.          this.fastScrollFlag = true;
  303.       } else {
  304.          this.fastScrollFlag = false;
  305.          this.fastScrollIndex = 0;
  306.          this.needFastScroll = false;
  307.       }
  308.  
  309.       ((Component)this).repaint();
  310.    }
  311.  
  312.    public void createBannerParams() {
  313.       String var1 = "";
  314.       this.lastS.width = 300;
  315.       this.lastS.height = 20;
  316.  
  317.       try {
  318.          var1 = ((Applet)this).getParameter("lineColor");
  319.       } catch (Exception var15) {
  320.       }
  321.  
  322.       if (var1 != null) {
  323.          this.lineColor = this.decodeColor(var1);
  324.       }
  325.  
  326.       try {
  327.          var1 = ((Applet)this).getParameter("color");
  328.       } catch (Exception var14) {
  329.       }
  330.  
  331.       if (var1 != null) {
  332.          this.textColor = this.decodeColor(var1);
  333.       }
  334.  
  335.       try {
  336.          var1 = ((Applet)this).getParameter("backgroundcolor");
  337.       } catch (Exception var13) {
  338.       }
  339.  
  340.       if (var1 != null) {
  341.          this.backgroundColor = this.decodeColor(var1);
  342.       }
  343.  
  344.       try {
  345.          var1 = ((Applet)this).getParameter("Font");
  346.       } catch (Exception var12) {
  347.       }
  348.  
  349.       if (var1 != null) {
  350.          this.curFont = var1;
  351.       }
  352.  
  353.       try {
  354.          var1 = ((Applet)this).getParameter("Layout");
  355.       } catch (Exception var11) {
  356.       }
  357.  
  358.       if (var1 != null) {
  359.          this.fontL = Integer.parseInt(var1);
  360.       }
  361.  
  362.       try {
  363.          var1 = ((Applet)this).getParameter("FHeight");
  364.       } catch (Exception var10) {
  365.       }
  366.  
  367.       if (var1 != null) {
  368.          this.fontH = Integer.parseInt(var1);
  369.       }
  370.  
  371.       try {
  372.          var1 = ((Applet)this).getParameter("charSleepTime");
  373.       } catch (Exception var9) {
  374.       }
  375.  
  376.       if (var1 != null) {
  377.          this.charSleepTime = Integer.parseInt(var1);
  378.       }
  379.  
  380.       try {
  381.          var1 = ((Applet)this).getParameter("lineSleepTime");
  382.       } catch (Exception var8) {
  383.       }
  384.  
  385.       if (var1 != null) {
  386.          this.lineSleepTime = Integer.parseInt(var1);
  387.       }
  388.  
  389.       try {
  390.          var1 = ((Applet)this).getParameter("pageSleepTime");
  391.       } catch (Exception var7) {
  392.       }
  393.  
  394.       if (var1 != null) {
  395.          this.pageSleepTime = Integer.parseInt(var1);
  396.       }
  397.  
  398.       int var2 = this.fontH;
  399.       Font var3 = new Font(this.curFont, this.fontL, this.fontH);
  400.       this.curTTF = var3;
  401.       ((Component)this).setFont(var3);
  402.       FontMetrics var4 = ((Component)this).getFontMetrics(var3);
  403.       int var5 = var4.getHeight();
  404.       var5 = var2 * 18 / var5;
  405.       this.messageF = new Font("TimesRoman", 0, var5);
  406.       FontMetrics var6 = ((Component)this).getFontMetrics(this.messageF);
  407.       var5 = var6.getHeight();
  408.       this.messageY = (20 - var5 >> 1) + var6.getAscent();
  409.    }
  410.  
  411.    public String getAppletInfo() {
  412.       return "Text Scroller v. 0.1 by Alex Vlasenko, 1997";
  413.    }
  414.  
  415.    public boolean handleEvent(Event var1) {
  416.       switch (var1.id) {
  417.          case 504:
  418.             ((Applet)this).showStatus(this.getAppletInfo());
  419.             this.stop();
  420.             return true;
  421.          case 505:
  422.             this.start();
  423.             ((Applet)this).showStatus(" ");
  424.             return true;
  425.          default:
  426.             return true;
  427.       }
  428.    }
  429.  
  430.    public ScrollTextVert() {
  431.       this.backgroundColor = Color.white;
  432.       this.textColor = Color.black;
  433.       this.lineColor = Color.red;
  434.       this.fontH = 14;
  435.       this.fontName = 1;
  436.       this.strLine = "";
  437.       this.curFont = "TimesRoman";
  438.       this.load_flag = false;
  439.       this.vertScrollIndex = -1;
  440.       this.vertScrollFlag = false;
  441.       this.fastScrollFlag = false;
  442.       this.needFastScroll = false;
  443.       this.horScrollStr = "";
  444.       this.horScrollFlag = false;
  445.       this.horF = false;
  446.       this.lineSleepTime = 4;
  447.       this.charSleepTime = 15;
  448.       this.pageSleepTime = 500;
  449.       this.onlineFlag = false;
  450.       this.offlineFlag = false;
  451.    }
  452. }
  453.