home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 24 / CDACTUAL24.iso / SHARE / os2 / edm2 / java / AdvertisementPanel.class (.txt) next >
Encoding:
Java Class File  |  1997-03-23  |  6.5 KB  |  244 lines

  1. import java.applet.Applet;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Event;
  5. import java.awt.Font;
  6. import java.awt.Graphics;
  7. import java.awt.Image;
  8. import java.net.MalformedURLException;
  9. import java.net.URL;
  10. import java.util.StringTokenizer;
  11. import java.util.Vector;
  12.  
  13. public class AdvertisementPanel extends Applet implements Runnable {
  14.    Image defaultImg;
  15.    Image currentImg;
  16.    String sCurrentEffect = "left";
  17.    String sCurrentDest = "";
  18.    long lCurrentDelay = 10000L;
  19.    // $FF: renamed from: t java.lang.Thread
  20.    public Thread field_0;
  21.    URL ImageURL;
  22.    int Totalheight;
  23.    int Totalwidth;
  24.    int width;
  25.    int height;
  26.    int Xtick;
  27.    int Ytick;
  28.    int nIndex;
  29.    boolean bUpdateEnabled = true;
  30.    Vector imgURLs;
  31.    Vector imgs;
  32.    Vector effects;
  33.    Vector delays;
  34.    Vector destURLs;
  35.    int nCount;
  36.  
  37.    public void init() {
  38.       this.Totalheight = ((Component)this).size().height;
  39.       this.Totalwidth = ((Component)this).size().width;
  40.       this.Xtick = this.Totalwidth / 10;
  41.       this.Ytick = this.Totalheight / 10;
  42.       this.defaultImg = ((Component)this).createImage(this.Totalwidth, this.Totalheight);
  43.       Graphics var1 = this.defaultImg.getGraphics();
  44.       var1.setColor(Color.black);
  45.       var1.fill3DRect(0, 0, this.Totalwidth, this.Totalheight, true);
  46.       var1.setColor(Color.white);
  47.       Font var2 = new Font("TimesRoman", 1, 16);
  48.       var1.setFont(var2);
  49.       var1.drawString("Loading images, please wait...", 20, this.Totalheight / 2 - 10);
  50.       this.currentImg = this.defaultImg;
  51.       ((Component)this).repaint();
  52.       this.bUpdateEnabled = false;
  53.       this.createParameters();
  54.       this.loadImages();
  55.    }
  56.  
  57.    void createParameters() {
  58.       String var1 = ((Applet)this).getParameter("count");
  59.       if (var1 == null) {
  60.          System.out.println("Please specify the count parameter");
  61.          System.exit(0);
  62.       } else {
  63.          this.nCount = Integer.valueOf(var1);
  64.       }
  65.  
  66.       Object var2 = null;
  67.       this.imgURLs = new Vector(this.nCount);
  68.       this.delays = new Vector(this.nCount);
  69.       this.effects = new Vector(this.nCount);
  70.       this.destURLs = new Vector(this.nCount);
  71.  
  72.       for(int var3 = 0; var3 < this.nCount; ++var3) {
  73.          var1 = ((Applet)this).getParameter("img" + var3);
  74.          StringTokenizer var4 = new StringTokenizer(var1, ",");
  75.  
  76.          try {
  77.             var7 = new URL(var4.nextToken());
  78.          } catch (MalformedURLException var5) {
  79.             System.out.println("Image URL malformed " + var3);
  80.             continue;
  81.          }
  82.  
  83.          this.imgURLs.addElement(var7);
  84.          this.delays.addElement(Long.valueOf(var4.nextToken()));
  85.          this.effects.addElement(var4.nextToken());
  86.          if (var4.hasMoreTokens()) {
  87.             this.destURLs.addElement(var4.nextToken());
  88.          } else {
  89.             this.destURLs.addElement("No target URL specified for this image");
  90.          }
  91.       }
  92.  
  93.    }
  94.  
  95.    public synchronized void paint(Graphics var1) {
  96.       var1.drawImage(this.currentImg, 0, 0, this.Totalwidth, this.Totalheight, this);
  97.    }
  98.  
  99.    public synchronized void update(Graphics var1) {
  100.    }
  101.  
  102.    public String getAppletInfo() {
  103.       return "AdvertisementPanel.class, copyrights 1996, Information Technology Solutions (ITS), http://its-idsc.gov.eg, contact: mnosseir@ritsec.com.eg";
  104.    }
  105.  
  106.    synchronized void loadImages() {
  107.       this.imgs = new Vector(this.imgURLs.size());
  108.  
  109.       for(int var1 = 0; var1 < this.imgURLs.size(); ++var1) {
  110.          this.imgs.addElement(((Applet)this).getImage((URL)this.imgURLs.elementAt(var1)));
  111.          ((Component)this).prepareImage((Image)this.imgs.elementAt(var1), this.Totalwidth, this.Totalheight, this);
  112.          if (this.imgs.elementAt(var1) == null) {
  113.             this.imgs.setElementAt(this.defaultImg, var1);
  114.             System.out.println("Can't prepare image. Loading default one");
  115.          }
  116.       }
  117.  
  118.       this.currentImg = (Image)this.imgs.elementAt(0);
  119.       this.sCurrentEffect = (String)this.effects.elementAt(0);
  120.       this.lCurrentDelay = (Long)this.delays.elementAt(0);
  121.       this.sCurrentDest = (String)this.destURLs.elementAt(0);
  122.    }
  123.  
  124.    synchronized void nextSlide() {
  125.       ++this.nIndex;
  126.       if (this.nIndex == this.nCount) {
  127.          this.nIndex = 0;
  128.       }
  129.  
  130.       this.currentImg = (Image)this.imgs.elementAt(this.nIndex);
  131.       this.sCurrentEffect = (String)this.effects.elementAt(this.nIndex);
  132.       this.lCurrentDelay = (Long)this.delays.elementAt(this.nIndex);
  133.       this.sCurrentDest = (String)this.destURLs.elementAt(this.nIndex);
  134.    }
  135.  
  136.    synchronized void drawImageGrow(int var1, int var2, int var3, int var4, int var5, int var6, int var7, int var8, long var9) {
  137.       Graphics var11 = ((Component)this).getGraphics();
  138.  
  139.       while(var3 <= this.Totalwidth && var3 >= 0 && var4 <= this.Totalheight && var4 >= 0 && this.field_0 != null) {
  140.          var11.drawImage(this.currentImg, var1, var2, var3, var4, this);
  141.          var1 += var5;
  142.          var2 += var6;
  143.          var3 += var7;
  144.          var4 += var8;
  145.  
  146.          try {
  147.             Thread.sleep(var9);
  148.          } catch (InterruptedException var12) {
  149.          }
  150.  
  151.          if (var3 > this.Totalwidth || var4 > this.Totalheight) {
  152.             var11.drawImage(this.currentImg, 0, 0, this.Totalwidth, this.Totalheight, this);
  153.          }
  154.       }
  155.  
  156.    }
  157.  
  158.    synchronized void displayImage(String var1) {
  159.       for(int var2 = 0; var2 < 10000 && !((Component)this).prepareImage(this.currentImg, this.Totalwidth, this.Totalheight, this); ++var2) {
  160.       }
  161.  
  162.       if (var1.equals("noeffect")) {
  163.          ((Component)this).getGraphics().drawImage(this.currentImg, 0, 0, this.Totalwidth, this.Totalheight, this);
  164.       } else if (var1.equals("left")) {
  165.          this.drawImageGrow(0, 0, 0, this.Totalheight, 0, 0, this.Xtick, 0, 25L);
  166.       } else if (var1.equals("right")) {
  167.          this.drawImageGrow(this.Totalwidth, 0, 0, this.Totalheight, -this.Xtick, 0, this.Xtick, 0, 25L);
  168.       } else if (var1.equals("top")) {
  169.          this.drawImageGrow(0, 0, this.Totalwidth, 0, 0, 0, 0, this.Ytick, 50L);
  170.       } else if (var1.equals("bottom")) {
  171.          this.drawImageGrow(0, this.Totalheight, this.Totalwidth, 0, 0, -this.Ytick, 0, this.Ytick, 50L);
  172.       } else if (var1.equals("center")) {
  173.          this.drawImageGrow(this.Totalwidth / 2 - this.Xtick / 2, this.Totalheight / 2 - this.Ytick / 2, this.Xtick, this.Ytick, -(this.Xtick / 2), -(this.Ytick / 2), this.Xtick, this.Ytick, 75L);
  174.       } else if (var1.equals("vcenter")) {
  175.          this.drawImageGrow(0, this.Totalheight / 2, this.Totalwidth, 0, 0, -(this.Ytick / 2), 0, this.Ytick, 50L);
  176.       } else if (var1.equals("hcenter")) {
  177.          this.drawImageGrow(this.Totalwidth / 2, 0, 0, this.Totalheight, -(this.Xtick / 2), 0, this.Xtick, 0, 25L);
  178.       } else if (var1.equals("lefttop")) {
  179.          this.drawImageGrow(0, 0, 0, 0, 0, 0, this.Xtick, this.Ytick, 50L);
  180.       } else if (var1.equals("leftbottom")) {
  181.          this.drawImageGrow(0, this.Totalheight, 0, 0, 0, -this.Ytick, this.Xtick, this.Ytick, 50L);
  182.       } else if (var1.equals("righttop")) {
  183.          this.drawImageGrow(this.Totalwidth, 0, 0, 0, -this.Xtick, 0, this.Xtick, this.Ytick, 50L);
  184.       } else {
  185.          if (var1.equals("rightbottom")) {
  186.             this.drawImageGrow(this.Totalwidth, this.Totalheight, 0, 0, -this.Xtick, -this.Ytick, this.Xtick, this.Ytick, 50L);
  187.          }
  188.  
  189.       }
  190.    }
  191.  
  192.    public void run() {
  193.       Graphics var1 = ((Component)this).getGraphics();
  194.       var1.drawImage(this.defaultImg, 0, 0, this.Totalwidth, this.Totalheight, this);
  195.  
  196.       for(; this.field_0 != null; this.nextSlide()) {
  197.          this.displayImage(this.sCurrentEffect);
  198.  
  199.          try {
  200.             Thread.sleep(this.lCurrentDelay);
  201.          } catch (InterruptedException var2) {
  202.          }
  203.       }
  204.  
  205.    }
  206.  
  207.    public void start() {
  208.       if (this.field_0 == null) {
  209.          this.field_0 = new Thread(this);
  210.          this.field_0.start();
  211.       }
  212.  
  213.    }
  214.  
  215.    public void stop() {
  216.       if (this.field_0 != null) {
  217.          this.field_0.stop();
  218.          this.field_0 = null;
  219.       }
  220.  
  221.    }
  222.  
  223.    public boolean mouseUp(Event var1, int var2, int var3) {
  224.       Object var4 = null;
  225.  
  226.       try {
  227.          var6 = new URL(this.sCurrentDest);
  228.       } catch (MalformedURLException var5) {
  229.          return true;
  230.       }
  231.  
  232.       if (var6 != null) {
  233.          ((Applet)this).getAppletContext().showDocument(var6);
  234.       }
  235.  
  236.       return true;
  237.    }
  238.  
  239.    public boolean mouseMove(Event var1, int var2, int var3) {
  240.       ((Applet)this).showStatus(this.sCurrentDest);
  241.       return true;
  242.    }
  243. }
  244.