home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 25 / nopv25.iso / 046A / COOBAR.ZIP / COMMON.CLA (.txt) < prev    next >
Encoding:
Java Class File  |  1997-07-02  |  9.8 KB  |  420 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Frame;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.awt.MediaTracker;
  9. import java.net.MalformedURLException;
  10. import java.net.URL;
  11. import java.util.Date;
  12. import java.util.Random;
  13.  
  14. class common {
  15.    static int soundOff;
  16.    static int whichStep;
  17.    static Color[] theColors = new Color[13];
  18.    static String teststring;
  19.    static boolean inAd;
  20.    int clientX;
  21.    int clientY;
  22.    int clientW;
  23.    int clientH;
  24.    int whichBase;
  25.    String background;
  26.    String bgcolor;
  27.    AudioClip[] hideSound;
  28.    int numHideSound;
  29.    String[] hideSoundName = new String[50];
  30.    int delayLoadAudio = 100;
  31.    String target;
  32.    Applet m_parent;
  33.    int bState;
  34.    String action = "URL";
  35.    int releaseLevel;
  36.    int TheShareware = 2;
  37.    int TheAdware = 1;
  38.    int TheDemo;
  39.    String Name;
  40.    int showAd = 1000;
  41.    int showAdCount;
  42.    // $FF: renamed from: wb int
  43.    int field_0;
  44.    // $FF: renamed from: hb int
  45.    int field_1;
  46.    // $FF: renamed from: w int
  47.    int field_2;
  48.    // $FF: renamed from: h int
  49.    int field_3;
  50.    String mmmm;
  51.    Graphics gBufBK;
  52.    Image bufBK;
  53.    boolean bBackgroundOK = false;
  54.    Color colForeground;
  55.    String colForegroundName = "STATIC";
  56.    Color colBackground;
  57.    String colBackgroundName;
  58.    Color fixCaptionColor;
  59.    String fixCaptionColorName = "STATIC";
  60.    Image imgBackground;
  61.    // $FF: renamed from: rr java.util.Random
  62.    Random field_4;
  63.    // $FF: renamed from: dd java.util.Date
  64.    static Date field_5 = new Date();
  65.    int disableLevel = 2;
  66.    static String myAd = "GO Coolshare!! You will explore COOL: Free Java applets, the best screen savers in the world, Cool resource to build your web pages, date through the Web, and more!! Go http://www.aimnet.com/~markqian to get them!!";
  67.    static String myAddress = "http://www.coolshare.com";
  68.    String whatWare = "evaluateShareware";
  69.    String homeURL;
  70.    URL uhomeURL;
  71.    String TheStatus;
  72.    String aboutMe = "Go http://www.coolshare.com  to get COOL shareware, applets, and more COOL stuff!!";
  73.    MediaTracker tracker;
  74.  
  75.    public common(Applet _parent) {
  76.       this.m_parent = _parent;
  77.       theColors[0] = Color.black;
  78.       theColors[1] = Color.blue;
  79.       theColors[2] = Color.cyan;
  80.       theColors[3] = Color.darkGray;
  81.       theColors[4] = Color.gray;
  82.       theColors[5] = Color.green;
  83.       theColors[6] = Color.lightGray;
  84.       theColors[7] = Color.magenta;
  85.       theColors[8] = Color.orange;
  86.       theColors[9] = Color.pink;
  87.       theColors[10] = Color.red;
  88.       theColors[11] = Color.white;
  89.       theColors[12] = Color.yellow;
  90.       this.field_4 = new Random();
  91.       this.field_4.setSeed((long)(field_5.getMinutes() * field_5.getSeconds()));
  92.    }
  93.  
  94.    public void turnSoundOff(int action) {
  95.       soundOff = action;
  96.    }
  97.  
  98.    public void doSound(int which) {
  99.       if (soundOff != 1 && which <= this.numHideSound && which >= 1) {
  100.          if (this.hideSound[which] != null) {
  101.             this.hideSound[which].play();
  102.          } else {
  103.             System.out.println("hideSound[" + which + "]=null");
  104.          }
  105.       }
  106.    }
  107.  
  108.    public void drawButtonBorder(int bState, Graphics g, int w, int h, int wb, int hb) {
  109.       int[] tri_x = new int[6];
  110.       int[] tri_y = new int[6];
  111.       if (bState == 0) {
  112.          g.setColor(Color.white);
  113.       } else {
  114.          g.setColor(Color.darkGray);
  115.       }
  116.  
  117.       tri_x[0] = 0;
  118.       tri_y[0] = 0;
  119.       tri_x[1] = 0;
  120.       tri_y[1] = h;
  121.       tri_x[2] = wb;
  122.       tri_y[2] = h - hb;
  123.       tri_x[3] = wb;
  124.       tri_y[3] = hb;
  125.       tri_x[4] = w - wb;
  126.       tri_y[4] = hb;
  127.       tri_x[5] = w;
  128.       tri_y[5] = 0;
  129.       g.fillPolygon(tri_x, tri_y, 6);
  130.       if (bState == 1) {
  131.          g.setColor(Color.white);
  132.       } else {
  133.          g.setColor(Color.darkGray);
  134.       }
  135.  
  136.       g.drawPolygon(tri_x, tri_y, 6);
  137.       if (bState == 0) {
  138.          g.setColor(Color.darkGray);
  139.       } else {
  140.          g.setColor(Color.white);
  141.       }
  142.  
  143.       g.fillRect(wb, hb, w, h);
  144.       g.setColor(Color.lightGray);
  145.       g.fillRect(wb, hb, w - 2 * wb, h - 2 * hb);
  146.       g.drawLine(0, 0, wb, hb);
  147.       if (bState == 0) {
  148.          g.setColor(Color.darkGray);
  149.       } else {
  150.          g.setColor(Color.white);
  151.       }
  152.  
  153.       tri_x[0] = w;
  154.       tri_y[0] = h;
  155.       tri_x[1] = 0;
  156.       tri_y[1] = h;
  157.       tri_x[2] = wb;
  158.       tri_y[2] = h - hb;
  159.       tri_x[3] = w - wb;
  160.       tri_y[3] = h - hb;
  161.       tri_x[4] = w - wb;
  162.       tri_y[4] = hb;
  163.       tri_x[5] = w;
  164.       tri_y[5] = 0;
  165.       g.fillPolygon(tri_x, tri_y, 6);
  166.       g.drawLine(0, 0, wb, hb);
  167.       if (bState == 1) {
  168.          g.setColor(Color.darkGray);
  169.       } else {
  170.          g.setColor(Color.white);
  171.       }
  172.  
  173.       g.drawPolygon(tri_x, tri_y, 6);
  174.       if (bState == 0) {
  175.          g.setColor(Color.white);
  176.       } else {
  177.          g.setColor(Color.darkGray);
  178.       }
  179.  
  180.       g.drawLine(w - wb, h - hb, w, h);
  181.       g.setColor(Color.lightGray);
  182.       tri_x[0] = wb;
  183.       tri_y[0] = hb;
  184.       tri_x[1] = w - wb;
  185.       tri_y[1] = hb;
  186.       tri_x[2] = w - wb;
  187.       tri_y[2] = h - hb;
  188.       tri_x[3] = wb;
  189.       tri_y[3] = h - hb;
  190.       g.fillPolygon(tri_x, tri_y, 4);
  191.    }
  192.  
  193.    Color getColorFromParam(String szParam, Color col_default) {
  194.       int offset = 0;
  195.       String szColor;
  196.       if ((szColor = this.m_parent.getParameter(szParam)) != null && !szColor.equals("")) {
  197.          if (szColor.startsWith("#")) {
  198.             offset = 1;
  199.          }
  200.  
  201.          int Red;
  202.          int Blue;
  203.          int Green;
  204.          try {
  205.             Red = Integer.parseInt(szColor.substring(offset, 2 + offset), 16);
  206.             Green = Integer.parseInt(szColor.substring(2 + offset, 4 + offset), 16);
  207.             Blue = Integer.parseInt(szColor.substring(4 + offset, 6 + offset), 16);
  208.          } catch (Exception var8) {
  209.             System.out.println("parseInt failed: szParam=" + szColor);
  210.             return col_default;
  211.          }
  212.  
  213.          return new Color(Red, Green, Blue);
  214.       } else {
  215.          return col_default;
  216.       }
  217.    }
  218.  
  219.    public void iniCommon() {
  220.       Date dd = new Date();
  221.       this.field_4.setSeed((long)(dd.getMinutes() * dd.getSeconds()));
  222.       String at = this.m_parent.getParameter("whatWare");
  223.       this.whatWare = at != null ? at : "evaluateShareware";
  224.       if (!this.whatWare.equalsIgnoreCase("evaluateShareware") && !this.whatWare.equalsIgnoreCase("AdWare")) {
  225.          this.whatWare = "evaluateShareware";
  226.       }
  227.  
  228.       if (this.releaseLevel == this.TheShareware) {
  229.          this.disableLevel = 0;
  230.       } else if (this.whatWare.equalsIgnoreCase("AdWare")) {
  231.          this.disableLevel = 1;
  232.       } else if ((dd.getHours() < 7 || dd.getHours() > 18) && this.releaseLevel <= this.TheShareware && this.releaseLevel >= this.TheAdware) {
  233.          this.disableLevel = 0;
  234.       } else {
  235.          this.disableLevel = 2;
  236.       }
  237.  
  238.       this.tracker = new MediaTracker(this.m_parent);
  239.       at = this.m_parent.getParameter("action");
  240.       this.action = at != null ? at : "URL";
  241.       this.target = this.m_parent.getParameter("target");
  242.       if (!this.action.equalsIgnoreCase("URL") && !this.action.equalsIgnoreCase("SoundSwitch")) {
  243.          this.action = "URL";
  244.       }
  245.  
  246.       at = this.m_parent.getParameter("nice");
  247.       if (at != null) {
  248.          this.showAd *= 2;
  249.       }
  250.  
  251.       at = this.m_parent.getParameter("status_text");
  252.       if (this.disableLevel > 0) {
  253.          this.TheStatus = this.aboutMe;
  254.       }
  255.  
  256.       at = this.m_parent.getParameter("on_click");
  257.       if (this.disableLevel == 2) {
  258.          this.homeURL = myAddress;
  259.       } else {
  260.          this.homeURL = at != null ? at : myAddress;
  261.       }
  262.  
  263.       try {
  264.          this.uhomeURL = new URL(this.homeURL);
  265.       } catch (MalformedURLException var4) {
  266.          this.uhomeURL = null;
  267.       }
  268.  
  269.       at = this.m_parent.getParameter("delayLoadAudio");
  270.       this.delayLoadAudio = at == null ? 100 : Integer.valueOf(at);
  271.       at = this.m_parent.getParameter("whichBase");
  272.       this.whichBase = at == null ? 0 : Integer.valueOf(at);
  273.       int i = 0;
  274.  
  275.       do {
  276.          ++i;
  277.          this.hideSoundName[i] = this.m_parent.getParameter("hideSound" + i);
  278.       } while(this.hideSoundName[i] != null);
  279.  
  280.       this.numHideSound = i - 1;
  281.       if (this.numHideSound > 0) {
  282.          this.hideSound = new AudioClip[this.numHideSound + 1];
  283.  
  284.          for(int var13 = 1; var13 <= this.numHideSound; ++var13) {
  285.             this.hideSound[var13] = null;
  286.          }
  287.       }
  288.  
  289.       at = this.m_parent.getParameter("borderWidth");
  290.       this.field_0 = at == null ? 0 : Integer.valueOf(at);
  291.       at = this.m_parent.getParameter("borderHeight");
  292.       this.field_1 = at == null ? 0 : Integer.valueOf(at);
  293.       if (this.m_parent.size().width > 0 && this.m_parent.size().height > 0) {
  294.          this.clientW = this.m_parent.size().width - 2 * this.field_0;
  295.          this.clientH = this.m_parent.size().height - 2 * this.field_1;
  296.          this.clientX = this.field_0;
  297.          this.clientY = this.field_1;
  298.          this.bufBK = this.m_parent.createImage(this.m_parent.size().width, this.m_parent.size().height);
  299.          this.gBufBK = this.bufBK.getGraphics();
  300.       } else {
  301.          this.clientW = 0;
  302.       }
  303.  
  304.       this.setColors("bgcolor");
  305.       this.setColors("fgcolor");
  306.       this.background = this.m_parent.getParameter("background");
  307.       if (this.background != null && !this.background.equals("")) {
  308.          if (this.whichBase == 0) {
  309.             this.imgBackground = this.m_parent.getImage(this.m_parent.getDocumentBase(), this.background);
  310.          } else {
  311.             this.imgBackground = this.m_parent.getImage(this.m_parent.getCodeBase(), this.background);
  312.          }
  313.       }
  314.  
  315.       if (this.imgBackground != null) {
  316.          this.bBackgroundOK = true;
  317.          this.tracker.addImage(this.imgBackground, 0);
  318.       }
  319.  
  320.    }
  321.  
  322.    public void loadHideSound() {
  323.       if (this.numHideSound > 0) {
  324.          for(int i = 1; i <= this.numHideSound; ++i) {
  325.             if (this.whichBase == 0) {
  326.                this.hideSound[i] = this.m_parent.getAudioClip(this.m_parent.getDocumentBase(), this.hideSoundName[i]);
  327.             } else {
  328.                this.hideSound[i] = this.m_parent.getAudioClip(this.m_parent.getCodeBase(), this.hideSoundName[i]);
  329.             }
  330.          }
  331.       }
  332.  
  333.    }
  334.  
  335.    public void maintainBK() {
  336.       int iBackWidth = 0;
  337.       int iBackHeight = 0;
  338.       if (this.bBackgroundOK && this.imgBackground != null) {
  339.          if ((iBackWidth = this.imgBackground.getWidth(this.m_parent)) > 0 && (iBackHeight = this.imgBackground.getHeight(this.m_parent)) > 0) {
  340.             for(int bx = 0; bx < this.bufBK.getWidth(this.m_parent); bx += iBackWidth) {
  341.                for(int by = 0; by < this.bufBK.getHeight(this.m_parent); by += iBackHeight) {
  342.                   this.gBufBK.drawImage(this.imgBackground, bx, by, this.m_parent);
  343.                }
  344.             }
  345.  
  346.             return;
  347.          }
  348.       } else {
  349.          Color cc;
  350.          if (this.colBackgroundName.equalsIgnoreCase("vary")) {
  351.             Date dd = new Date();
  352.             this.field_4.setSeed((long)(dd.getMinutes() * dd.getSeconds()));
  353.             float tt = this.field_4.nextFloat();
  354.             cc = theColors[(int)(tt * 12.0F)];
  355.          } else {
  356.             cc = this.colBackground;
  357.          }
  358.  
  359.          this.gBufBK.setColor(cc);
  360.          this.gBufBK.fillRect(0, 0, this.bufBK.getWidth(this.m_parent), this.bufBK.getHeight(this.m_parent));
  361.       }
  362.  
  363.    }
  364.  
  365.    public Color getTheColor(String ColorName, int which) {
  366.       if (ColorName.equalsIgnoreCase("vary")) {
  367.          return theColors[(int)(this.field_4.nextFloat() * 12.0F)];
  368.       } else if (which == 0) {
  369.          return this.colForeground;
  370.       } else {
  371.          return which == 1 ? this.colBackground : this.fixCaptionColor;
  372.       }
  373.    }
  374.  
  375.    public void setColors(String what) {
  376.       String at = null;
  377.       at = this.m_parent.getParameter(what);
  378.       if (what.equalsIgnoreCase("fgcolor")) {
  379.          if (at != null && at.equalsIgnoreCase("null")) {
  380.             at = null;
  381.          }
  382.  
  383.          this.colForegroundName = at != null ? at : "STATIC";
  384.          if (!this.colForegroundName.equalsIgnoreCase("STATIC") && !this.colForegroundName.equalsIgnoreCase("vary")) {
  385.             this.colForeground = this.getColorFromParam("fgcolor", Color.black);
  386.             return;
  387.          }
  388.       } else if (what.equalsIgnoreCase("bgcolor")) {
  389.          if (at != null && (at.equalsIgnoreCase("null") || at.equalsIgnoreCase(""))) {
  390.             at = null;
  391.          }
  392.  
  393.          this.bgcolor = at;
  394.          this.colBackgroundName = at != null ? at : "STATIC";
  395.          if (!this.colBackgroundName.equalsIgnoreCase("STATIC") && !this.colBackgroundName.equalsIgnoreCase("vary")) {
  396.             this.colBackground = this.getColorFromParam(what, Color.pink);
  397.             return;
  398.          }
  399.       } else if (what.equalsIgnoreCase("fixCaptionColor")) {
  400.          if (at != null && at.equalsIgnoreCase("null")) {
  401.             at = null;
  402.          }
  403.  
  404.          this.fixCaptionColorName = at != null ? at : "STATIC";
  405.          if (!this.fixCaptionColorName.equalsIgnoreCase("STATIC") && !this.fixCaptionColorName.equalsIgnoreCase("vary")) {
  406.             this.fixCaptionColor = this.getColorFromParam(what, Color.black);
  407.          }
  408.       }
  409.  
  410.    }
  411.  
  412.    public void setTheCursor(int whatCursor) {
  413.       Object frame;
  414.       for(frame = this.m_parent.getParent(); !(frame instanceof Frame); frame = ((Component)frame).getParent()) {
  415.       }
  416.  
  417.       ((Frame)frame).setCursor(whatCursor);
  418.    }
  419. }
  420.