home *** CD-ROM | disk | FTP | other *** search
/ Independent Newspaper 1999 / cdng1999.iso / ng / NGMotto.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-08-20  |  12.8 KB  |  535 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Container;
  5. import java.awt.Dimension;
  6. import java.awt.Event;
  7. import java.awt.Font;
  8. import java.awt.FontMetrics;
  9. import java.awt.Frame;
  10. import java.awt.Graphics;
  11. import java.awt.Image;
  12. import java.awt.LayoutManager;
  13. import java.awt.MediaTracker;
  14. import java.awt.Rectangle;
  15. import java.awt.Toolkit;
  16. import java.net.MalformedURLException;
  17. import java.net.URL;
  18. import java.util.Random;
  19. import java.util.Vector;
  20.  
  21. public class NGMotto extends Applet implements Runnable {
  22.    private static int PARAM_message;
  23.    private static int PARAM_direction = 1;
  24.    private static int PARAM_url = 2;
  25.    private static int PARAM_fontName = 3;
  26.    private static int PARAM_fontSize = 4;
  27.    private static int PARAM_fontStyle = 5;
  28.    private static int PARAM_fontPadding = 6;
  29.    private static int PARAM_background = 7;
  30.    private static int PARAM_foreground = 8;
  31.    private static int PARAM_image = 9;
  32.    private static int PARAM_imageAttribute = 10;
  33.    private static int PARAM_charEffects = 11;
  34.    private static int PARAM_seed = 12;
  35.    private static int PARAM_pause = 13;
  36.    private static int PARAM_rotationfactor = 14;
  37.    private static int PARAM_radius = 15;
  38.    private static int PARAM_x = 16;
  39.    private static int PARAM_y = 17;
  40.    private static double RAD = (180D / Math.PI);
  41.    private boolean random;
  42.    private boolean fixed;
  43.    private boolean clockwise;
  44.    private boolean center;
  45.    private boolean tile;
  46.    private boolean scale;
  47.    private boolean loaded;
  48.    private double rotationfactor;
  49.    private int pause;
  50.    private int message_beg;
  51.    private int increment;
  52.    // $FF: renamed from: cH int
  53.    private int field_0;
  54.    private int fontSize;
  55.    private int fontStyle;
  56.    private int randCount;
  57.    private int fontPadding;
  58.    private int parm_radius;
  59.    private int parm_x;
  60.    private int parm_y;
  61.    private int parm_seed;
  62.    private int imageWidth;
  63.    private int imageHeight;
  64.    private int centered_XCorner;
  65.    private int centered_YCorner;
  66.    // $FF: renamed from: mX int[]
  67.    private int[] field_1;
  68.    private Color background;
  69.    private Color foreground;
  70.    private Color[] randColors;
  71.    private Dimension appletSize;
  72.    // $FF: renamed from: fm java.awt.FontMetrics
  73.    private FontMetrics field_2;
  74.    private Frame browserFrame;
  75.    private Graphics bufferGraphics;
  76.    private Image buffer;
  77.    private Image image;
  78.    private MediaTracker tracker;
  79.    private Rectangle[] rectangles;
  80.    private String message;
  81.    private String fontName;
  82.    private String imageName;
  83.    // $FF: renamed from: m java.lang.String[]
  84.    private String[] field_3;
  85.    private Thread animator;
  86.    private URL url;
  87.    // $FF: renamed from: p java.lang.String[][]
  88.    public String[][] field_4 = new String[][]{{"message", "   ╨æ╨╡╨╖ ╨│╨╜╨╡╨▓╨░ ╨╕ ╨┐╤Ç╨╕╤ü╤é╤Ç╨░╤ü╤é╨╕╤Å   "}, {"direction", "counterclockwise"}, {"url", "http://ng.ru"}, {"fontname", "Courier"}, {"fontsize", "16"}, {"fontstyle", "BOLD"}, {"fontpadding", "0"}, {"background", "FFFFFF"}, {"foreground", "FFFFFF"}, {"image", "nglogosm.gif"}, {"imageattribute", "center"}, {"effects", "randomcolors"}, {"seed", "100"}, {"pause", "10"}, {"rotationfactor", "0"}, {"radius", "85"}, {"x", "100"}, {"y", ""}};
  89.  
  90.    public void init() {
  91.       ((Container)this).setLayout((LayoutManager)null);
  92.       this.appletSize = ((Component)this).size();
  93.  
  94.       try {
  95.          this.browserFrame = (Frame)((Component)this).getParent();
  96.       } catch (Exception var38) {
  97.          this.browserFrame = null;
  98.       }
  99.  
  100.       this.getParameters();
  101.       this.buffer = ((Component)this).createImage(this.appletSize.width, this.appletSize.height);
  102.       this.setBufferGraphics();
  103.       Dimension var1 = new Dimension(this.field_2.getMaxAdvance() + 2 * this.field_2.getLeading() + this.fontPadding, this.field_2.getMaxAscent() + this.field_2.getMaxDescent() + 2 * this.field_2.getLeading() + this.fontPadding);
  104.       int var2 = var1.width > var1.height ? var1.width : var1.height;
  105.       int var7 = this.appletSize.width > this.appletSize.height ? this.appletSize.height : this.appletSize.width;
  106.       int var4;
  107.       int var3 = var4 = var7 / 2;
  108.       if (this.parm_x != -1000000) {
  109.          var3 = this.parm_x;
  110.       }
  111.  
  112.       if (this.parm_y != -1000000) {
  113.          var4 = this.parm_y;
  114.       }
  115.  
  116.       double var5 = (double)(var3 - var7 / 4 / 2);
  117.       if (this.parm_radius > -1) {
  118.          var5 = (double)this.parm_radius;
  119.       }
  120.  
  121.       Vector var8 = Vrato.circle(var3, var4, var5, 1);
  122.       double var9 = Math.atan2((double)var2, var5) * RAD;
  123.       double var11 = (double)360.0F / var9;
  124.       double var13 = Math.atan2((double)var2 * this.rotationfactor, var5) * RAD;
  125.       double var15 = (double)360.0F / var13;
  126.       double var17 = (double)var8.size() / var15;
  127.       if (var17 < (double)1.0F) {
  128.          var17 = (double)1.0F;
  129.       }
  130.  
  131.       if (this.rotationfactor > (double)1.0F) {
  132.          var11 = var15;
  133.       }
  134.  
  135.       double var19 = (double)var1.width + (double)this.field_2.getLeading();
  136.       double var21 = (double)var1.height;
  137.       Rectangle[] var23 = new Rectangle[var8.size()];
  138.       int var24 = (int)Math.rint(((Dvoto)var8.lastElement()).x - var19 / (double)2.0F);
  139.       int var25 = (int)Math.rint(((Dvoto)var8.lastElement()).y - var21 / (double)2.0F);
  140.       int var28 = -1;
  141.       double var29 = var17;
  142.  
  143.       int var39;
  144.       for(var39 = 0; (int)var29 < var8.size() && (var39 = (int)Math.rint(var29)) < var8.size(); var29 += var17) {
  145.          int var26 = (int)Math.rint(((Dvoto)var8.elementAt(var39)).x - var19 / (double)2.0F);
  146.          int var27 = (int)Math.rint(((Dvoto)var8.elementAt(var39)).y - var21 / (double)2.0F);
  147.          if (var26 != var24 || var27 != var25) {
  148.             ++var28;
  149.             var23[var28] = new Rectangle(var26, var27, (int)var19, (int)var21);
  150.             var24 = var26;
  151.             var25 = var27;
  152.          }
  153.       }
  154.  
  155.       System.arraycopy(var23, 0, this.rectangles = new Rectangle[var28 + 1], 0, var28 + 1);
  156.       this.increment = this.rectangles.length / (int)var11;
  157.       if (this.message.length() > (int)var11) {
  158.          this.message = this.message.substring(0, (int)var11);
  159.       }
  160.  
  161.       this.message_beg = this.clockwise ? 0 : this.message.length() * this.increment - this.increment;
  162.       this.field_3 = new String[this.message.length()];
  163.       this.field_1 = new int[this.field_3.length];
  164.       int var32 = this.field_2.getMaxAscent();
  165.       this.field_0 = (var1.height - (var32 + this.field_2.getMaxDescent() + this.field_2.getLeading())) / 2 + var32;
  166.       char[] var33 = this.message.toCharArray();
  167.  
  168.       for(int var34 = 0; var34 < this.message.length(); ++var34) {
  169.          this.field_3[var34] = new String(var33, var34, 1);
  170.          this.field_1[var34] = (var1.width - this.field_2.charWidth(this.message.charAt(var34))) / 2;
  171.       }
  172.  
  173.       if (!this.field_4[PARAM_charEffects][1].equals("")) {
  174.          this.buildColorArray();
  175.       }
  176.  
  177.       if (!this.imageName.equals("")) {
  178.          this.tracker = new MediaTracker(this);
  179.          this.image = ((Applet)this).getImage(((Applet)this).getDocumentBase(), this.imageName);
  180.          this.tracker.addImage(this.image, 0);
  181.          this.loaded = false;
  182.       } else {
  183.          this.image = null;
  184.          this.loaded = false;
  185.       }
  186.  
  187.       if (this.image != null && !this.loaded) {
  188.          try {
  189.             this.tracker.waitForID(0);
  190.          } catch (InterruptedException var37) {
  191.          }
  192.  
  193.          if (this.tracker.isErrorID(0)) {
  194.             ((Applet)this).showStatus("Error loading image " + this.imageName + ", quitting.");
  195.             return;
  196.          }
  197.  
  198.          this.loaded = true;
  199.  
  200.          while((this.imageWidth = this.image.getWidth(this)) < 0) {
  201.             try {
  202.                Thread.sleep(100L);
  203.             } catch (InterruptedException var36) {
  204.             }
  205.          }
  206.  
  207.          while((this.imageHeight = this.image.getHeight(this)) < 0) {
  208.             try {
  209.                Thread.sleep(100L);
  210.             } catch (InterruptedException var35) {
  211.             }
  212.          }
  213.  
  214.          if (this.center) {
  215.             this.centered_XCorner = this.appletSize.width / 2 - this.imageWidth / 2;
  216.             if (this.centered_XCorner < 0) {
  217.                this.centered_XCorner = 0;
  218.             }
  219.  
  220.             this.centered_YCorner = this.appletSize.height / 2 - this.imageHeight / 2;
  221.             if (this.centered_YCorner < 0) {
  222.                this.centered_YCorner = 0;
  223.             }
  224.          }
  225.       }
  226.  
  227.    }
  228.  
  229.    private void setBufferGraphics() {
  230.       this.bufferGraphics = this.buffer.getGraphics();
  231.       this.field_2 = this.bufferGraphics.getFontMetrics(new Font(this.fontName, this.fontStyle, this.fontSize));
  232.       this.bufferGraphics.setFont(this.field_2.getFont());
  233.       this.bufferGraphics.setColor(this.background);
  234.       this.bufferGraphics.fillRect(0, 0, this.appletSize.width, this.appletSize.height);
  235.    }
  236.  
  237.    public void destroy() {
  238.    }
  239.  
  240.    public void update(Graphics var1) {
  241.       if (this.image != null) {
  242.          if (this.scale) {
  243.             this.bufferGraphics.drawImage(this.image, 0, 0, this.appletSize.width, this.appletSize.height, 0, 0, 100, 100, this);
  244.          } else if (this.tile) {
  245.             for(int var2 = 0; var2 < this.appletSize.width; var2 += this.imageWidth) {
  246.                for(int var3 = 0; var3 < this.appletSize.height; var3 += this.imageHeight) {
  247.                   this.bufferGraphics.drawImage(this.image, var2, var3, this);
  248.                }
  249.             }
  250.          } else if (this.center) {
  251.             this.bufferGraphics.setColor(this.background);
  252.             this.bufferGraphics.fillRect(0, 0, this.appletSize.width, this.appletSize.height);
  253.             this.bufferGraphics.drawImage(this.image, this.centered_XCorner, this.centered_YCorner, this);
  254.          } else {
  255.             this.bufferGraphics.setColor(this.background);
  256.             this.bufferGraphics.fillRect(0, 0, this.appletSize.width, this.appletSize.height);
  257.             this.bufferGraphics.drawImage(this.image, 0, 0, this);
  258.          }
  259.       } else {
  260.          this.bufferGraphics.setColor(this.background);
  261.          this.bufferGraphics.fillRect(0, 0, this.appletSize.width, this.appletSize.height);
  262.       }
  263.  
  264.       if (!this.random || !this.fixed) {
  265.          this.bufferGraphics.setColor(this.foreground);
  266.       }
  267.  
  268.       if (this.clockwise) {
  269.          int var5 = 0;
  270.  
  271.          for(int var7 = this.message_beg; var5 < this.field_3.length; var7 += this.increment) {
  272.             int var4 = var7 >= this.rectangles.length ? var7 - this.rectangles.length : var7;
  273.             if (this.random) {
  274.                this.bufferGraphics.setColor(this.randColors[this.randCount]);
  275.                if (this.randCount < this.randColors.length - 1) {
  276.                   ++this.randCount;
  277.                } else {
  278.                   this.randCount = 0;
  279.                }
  280.             }
  281.  
  282.             if (this.fixed) {
  283.                this.bufferGraphics.setColor(this.randColors[var5]);
  284.             }
  285.  
  286.             this.bufferGraphics.drawString(this.field_3[var5], this.rectangles[var4].x + this.field_1[var5], this.rectangles[var4].y + this.field_0);
  287.             ++var5;
  288.          }
  289.  
  290.          this.message_beg = this.message_beg + 1 >= this.rectangles.length ? 0 : this.message_beg + 1;
  291.       } else {
  292.          int var6 = this.message.length() - 1;
  293.  
  294.          for(int var8 = this.message_beg; var6 > -1; var8 -= this.increment) {
  295.             int var9 = var8 < 0 ? var8 + this.rectangles.length : var8;
  296.             if (this.random) {
  297.                this.bufferGraphics.setColor(this.randColors[this.randCount]);
  298.                if (this.randCount < this.randColors.length - 1) {
  299.                   ++this.randCount;
  300.                } else {
  301.                   this.randCount = 0;
  302.                }
  303.             }
  304.  
  305.             if (this.fixed) {
  306.                this.bufferGraphics.setColor(this.randColors[var6]);
  307.             }
  308.  
  309.             this.bufferGraphics.drawString(this.field_3[var6], this.rectangles[var9].x + this.field_1[var6], this.rectangles[var9].y + this.field_0);
  310.             --var6;
  311.          }
  312.  
  313.          this.message_beg = this.message_beg - 1 < 0 ? this.rectangles.length - 1 : this.message_beg - 1;
  314.       }
  315.  
  316.       this.paint(var1);
  317.    }
  318.  
  319.    public void paint(Graphics var1) {
  320.       var1.drawImage(this.buffer, 0, 0, this);
  321.       var1.dispose();
  322.    }
  323.  
  324.    public void start() {
  325.       if (this.animator == null) {
  326.          Thread var1 = Thread.currentThread();
  327.          var1.setPriority(2);
  328.          this.animator = new Thread(this);
  329.          this.animator.setPriority(1);
  330.          this.animator.start();
  331.       }
  332.  
  333.    }
  334.  
  335.    public void stop() {
  336.       if (this.animator != null) {
  337.          this.animator.stop();
  338.          this.animator = null;
  339.       }
  340.  
  341.    }
  342.  
  343.    public void run() {
  344.       while(this.animator != null) {
  345.          ((Component)this).repaint();
  346.  
  347.          try {
  348.             Thread.sleep((long)this.pause);
  349.          } catch (InterruptedException var1) {
  350.          }
  351.       }
  352.  
  353.    }
  354.  
  355.    public boolean mouseDown(Event var1, int var2, int var3) {
  356.       try {
  357.          if (this.url != null) {
  358.             ((Applet)this).getAppletContext().showDocument(this.url);
  359.          }
  360.       } catch (Exception var6) {
  361.       } finally {
  362.          ;
  363.       }
  364.  
  365.       return true;
  366.    }
  367.  
  368.    public boolean mouseEnter(Event var1, int var2, int var3) {
  369.       if (this.field_4[PARAM_url][1] != null && !this.field_4[PARAM_url][1].equals("")) {
  370.          ((Applet)this).showStatus(this.field_4[PARAM_url][1]);
  371.          if (this.browserFrame != null) {
  372.             this.browserFrame.setCursor(12);
  373.          }
  374.       }
  375.  
  376.       return true;
  377.    }
  378.  
  379.    public boolean mouseExit(Event var1, int var2, int var3) {
  380.       ((Applet)this).showStatus("");
  381.       return true;
  382.    }
  383.  
  384.    private void buildColorArray() {
  385.       Color[] var3 = new Color[]{Color.black, Color.black, Color.black, Color.black, Color.black, Color.red, Color.black, Color.black, Color.black, Color.black, Color.white};
  386.       this.randCount = 0;
  387.       boolean var5 = this.random = this.fixed = false;
  388.       String var7 = this.field_4[PARAM_charEffects][1].toUpperCase();
  389.       if (var7.equals("RANDOMPASTELS")) {
  390.          this.random = true;
  391.          var5 = true;
  392.       } else if (var7.equals("RANDOMCOLORS")) {
  393.          this.random = true;
  394.       } else if (var7.equals("FIXEDPASTELS")) {
  395.          this.fixed = true;
  396.          var5 = true;
  397.       } else if (var7.equals("FIXEDCOLORS")) {
  398.          this.fixed = true;
  399.       }
  400.  
  401.       this.randColors = new Color[this.random ? 100 : this.field_3.length];
  402.       boolean var4;
  403.       Random var6;
  404.       if (var4 = this.parm_seed != -1000000) {
  405.          var6 = new Random((long)this.parm_seed);
  406.       } else {
  407.          var6 = null;
  408.       }
  409.  
  410.       if (var5) {
  411.          for(int var10 = 0; var10 < this.randColors.length; ++var10) {
  412.             double var9 = var4 ? var6.nextDouble() : Math.random();
  413.             this.randColors[var10] = Color.getHSBColor((float)var9, 0.3F, 0.99F);
  414.          }
  415.  
  416.       } else {
  417.          for(int var8 = 0; var8 < this.randColors.length; ++var8) {
  418.             while(true) {
  419.                double var1 = var4 ? var6.nextDouble() : Math.random();
  420.                this.randColors[var8] = var3[(int)Math.ceil(var1 * (double)11.0F) - 1];
  421.                if (this.randColors[var8] != this.background) {
  422.                   break;
  423.                }
  424.             }
  425.          }
  426.  
  427.       }
  428.    }
  429.  
  430.    private void getParameters() {
  431.       for(int var2 = 0; var2 < this.field_4.length; ++var2) {
  432.          String var1 = ((Applet)this).getParameter(this.field_4[var2][0]);
  433.          if (var1 != null) {
  434.             this.field_4[var2][1] = var1;
  435.          }
  436.       }
  437.  
  438.       this.message = this.field_4[PARAM_message][1];
  439.       this.imageName = this.field_4[PARAM_image][1];
  440.       this.fontName = this.field_4[PARAM_fontName][1];
  441.       String[] var3 = Toolkit.getDefaultToolkit().getFontList();
  442.  
  443.       for(int var4 = 0; var4 < var3.length; ++var4) {
  444.          if (this.field_4[PARAM_fontName][1].equalsIgnoreCase(var3[var4])) {
  445.             this.fontName = var3[var4];
  446.             break;
  447.          }
  448.       }
  449.  
  450.       if (this.field_4[PARAM_fontStyle][1].equalsIgnoreCase("PLAIN")) {
  451.          this.fontStyle = 0;
  452.       } else if (this.field_4[PARAM_fontStyle][1].equalsIgnoreCase("BOLD")) {
  453.          this.fontStyle = 1;
  454.       } else if (this.field_4[PARAM_fontStyle][1].equalsIgnoreCase("ITALIC")) {
  455.          this.fontStyle = 2;
  456.       } else {
  457.          this.fontStyle = 0;
  458.       }
  459.  
  460.       this.fontSize = this.parse(this.field_4[PARAM_fontSize][1], 12);
  461.       this.pause = this.parse(this.field_4[PARAM_pause][1], 100);
  462.       this.rotationfactor = (double)this.parse(this.field_4[PARAM_rotationfactor][1], 100) * 0.01;
  463.       this.parm_radius = this.parse(this.field_4[PARAM_radius][1], -1);
  464.       this.fontPadding = this.parse(this.field_4[PARAM_fontPadding][1], 0);
  465.       this.parm_x = this.parse(this.field_4[PARAM_x][1], -1000000);
  466.       this.parm_y = this.parse(this.field_4[PARAM_y][1], -1000000);
  467.       this.parm_seed = this.parse(this.field_4[PARAM_seed][1], -1000000);
  468.       this.clockwise = this.field_4[PARAM_direction][1].equalsIgnoreCase("CLOCKWISE");
  469.       this.scale = this.field_4[PARAM_imageAttribute][1].equalsIgnoreCase("SCALE");
  470.       this.tile = this.field_4[PARAM_imageAttribute][1].equalsIgnoreCase("TILE");
  471.       this.center = this.field_4[PARAM_imageAttribute][1].equalsIgnoreCase("CENTER");
  472.       this.background = this.getColor(this.field_4[PARAM_background][1], Color.black);
  473.       this.foreground = this.getColor(this.field_4[PARAM_foreground][1], Color.white);
  474.  
  475.       try {
  476.          this.url = new URL(this.field_4[PARAM_url][1]);
  477.       } catch (MalformedURLException var5) {
  478.          this.url = null;
  479.       }
  480.    }
  481.  
  482.    private int parse(String var1, int var2) {
  483.       try {
  484.          return Integer.parseInt(var1);
  485.       } catch (NumberFormatException var3) {
  486.          return var2;
  487.       }
  488.    }
  489.  
  490.    private Color getColor(String var1, Color var2) {
  491.       try {
  492.          return new Color(this.HexToInt(var1.substring(0, 2)), this.HexToInt(var1.substring(2, 4)), this.HexToInt(var1.substring(4)));
  493.       } catch (Exception var3) {
  494.          return var2;
  495.       }
  496.    }
  497.  
  498.    public int HexToInt(String var1) {
  499.       int var2 = 0;
  500.       if (var1.substring(0, 1).equalsIgnoreCase("a")) {
  501.          var2 = 160;
  502.       } else if (var1.substring(0, 1).equalsIgnoreCase("b")) {
  503.          var2 = 176;
  504.       } else if (var1.substring(0, 1).equalsIgnoreCase("c")) {
  505.          var2 = 192;
  506.       } else if (var1.substring(0, 1).equalsIgnoreCase("d")) {
  507.          var2 = 208;
  508.       } else if (var1.substring(0, 1).equalsIgnoreCase("e")) {
  509.          var2 = 224;
  510.       } else if (var1.substring(0, 1).equalsIgnoreCase("f")) {
  511.          var2 = 240;
  512.       } else {
  513.          var2 = Integer.valueOf(var1.substring(0, 1)) * 16;
  514.       }
  515.  
  516.       if (var1.substring(1).equalsIgnoreCase("a")) {
  517.          var2 += 10;
  518.       } else if (var1.substring(1).equalsIgnoreCase("b")) {
  519.          var2 += 11;
  520.       } else if (var1.substring(1).equalsIgnoreCase("c")) {
  521.          var2 += 12;
  522.       } else if (var1.substring(1).equalsIgnoreCase("d")) {
  523.          var2 += 13;
  524.       } else if (var1.substring(1).equalsIgnoreCase("e")) {
  525.          var2 += 14;
  526.       } else if (var1.substring(1).equalsIgnoreCase("f")) {
  527.          var2 += 15;
  528.       } else {
  529.          var2 += Integer.valueOf(var1.substring(1));
  530.       }
  531.  
  532.       return var2;
  533.    }
  534. }
  535.