home *** CD-ROM | disk | FTP | other *** search
/ Popular Software (Premium Edition) / mycd.iso / INTERNET / PFRONT98 / DATA.Z / fprotate.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-09-26  |  7.7 KB  |  288 lines

  1. import java.applet.Applet;
  2. import java.awt.Component;
  3. import java.awt.Event;
  4. import java.awt.Graphics;
  5. import java.awt.Image;
  6. import java.awt.MediaTracker;
  7. import java.awt.Rectangle;
  8. import java.awt.image.FilteredImageSource;
  9. import java.awt.image.ImageFilter;
  10. import java.awt.image.ImageObserver;
  11. import java.awt.image.ImageProducer;
  12. import java.net.MalformedURLException;
  13. import java.net.URL;
  14.  
  15. public class fprotate extends Applet implements Runnable {
  16.    private Thread m_fprotate;
  17.    private Graphics m_Graphics;
  18.    private Image[] m_Images;
  19.    private int m_nCurrImage;
  20.    private int m_nNextImage;
  21.    private int[] m_nImgWidth;
  22.    private int[] m_nImgHeight;
  23.    private boolean m_fAllLoaded;
  24.    private int m_numImages;
  25.    private String[] m_imageString;
  26.    private URL m_docUrl;
  27.    private int m_transitionSteps = 4;
  28.    private Image m_transImage1;
  29.    private Image m_transImage2;
  30.    private Image[] m_transImage;
  31.    private int m_transitionTime;
  32.    private String m_url;
  33.    private String m_target;
  34.    private int m_time;
  35.    private String m_effectString;
  36.    private String m_image;
  37.    private int m_effect;
  38.    private final String PARAM_time;
  39.    private final String PARAM_effect;
  40.    private final String PARAM_image;
  41.    private final String PARAM_url;
  42.    private final String PARAM_target;
  43.  
  44.    public void stop() {
  45.       if (this.m_fprotate != null) {
  46.          this.m_fprotate.stop();
  47.          this.m_fprotate = null;
  48.       }
  49.  
  50.    }
  51.  
  52.    public boolean mouseEnter(Event evt, int x, int y) {
  53.       ((Applet)this).showStatus(this.m_url);
  54.       return true;
  55.    }
  56.  
  57.    public boolean mouseExit(Event evt, int x, int y) {
  58.       ((Applet)this).showStatus("");
  59.       return true;
  60.    }
  61.  
  62.    public void paint(Graphics g) {
  63.       if (this.m_fAllLoaded) {
  64.          Rectangle r = g.getClipRect();
  65.          g.clearRect(r.x, r.y, r.width, r.height);
  66.          this.displayImage(g, this.m_Images[this.m_nCurrImage], this.m_nImgWidth[this.m_nCurrImage], this.m_nImgHeight[this.m_nCurrImage]);
  67.       }
  68.  
  69.    }
  70.  
  71.    public boolean mouseUp(Event evt, int x, int y) {
  72.       return true;
  73.    }
  74.  
  75.    public String[][] getParameterInfo() {
  76.       String[][] info = new String[][]{{"time", "int", "Display time in seconds"}, {"rotatoreffect", "String", "Transition effect"}, {"image" + 1, "String", "Image number 1"}, {"image" + 2, "String", "Image number 2"}, {"url", "String", "Url"}, {"target", "String", "Target frame"}};
  77.       return info;
  78.    }
  79.  
  80.    public void destroy() {
  81.    }
  82.  
  83.    private void displayImage(Graphics g, Image image, int w, int h) {
  84.       if (this.m_fAllLoaded) {
  85.          g.drawImage(image, (((Component)this).size().width - w) / 2, (((Component)this).size().height - h) / 2, (ImageObserver)null);
  86.       }
  87.    }
  88.  
  89.    public fprotate() {
  90.       this.m_transImage = new Image[this.m_transitionSteps];
  91.       this.m_url = "";
  92.       this.m_target = "";
  93.       this.m_time = 3;
  94.       this.m_effectString = "";
  95.       this.m_image = "";
  96.       this.m_effect = 3;
  97.       this.PARAM_time = "time";
  98.       this.PARAM_effect = "rotatoreffect";
  99.       this.PARAM_image = "image";
  100.       this.PARAM_url = "url";
  101.       this.PARAM_target = "target";
  102.    }
  103.  
  104.    public void start() {
  105.       if (this.m_fprotate == null) {
  106.          this.m_fprotate = new Thread(this);
  107.          this.m_fprotate.start();
  108.       }
  109.  
  110.    }
  111.  
  112.    public String getAppletInfo() {
  113.       return "Name: fprotate\r\n" + "Author: Microsoft FrontPage\r\n" + "Created with Microsoft Visual J++ Version 1.1";
  114.    }
  115.  
  116.    public boolean mouseDown(Event evt, int x, int y) {
  117.       if (!this.m_url.equalsIgnoreCase("") && this.m_docUrl != null) {
  118.          if (this.m_target.equalsIgnoreCase("")) {
  119.             ((Applet)this).getAppletContext().showDocument(this.m_docUrl);
  120.          } else {
  121.             ((Applet)this).getAppletContext().showDocument(this.m_docUrl, this.m_target);
  122.          }
  123.       }
  124.  
  125.       return true;
  126.    }
  127.  
  128.    public void run() {
  129.       this.m_nCurrImage = 0;
  130.       if (!this.m_fAllLoaded) {
  131.          ((Component)this).repaint();
  132.          this.m_Graphics = ((Component)this).getGraphics();
  133.          this.m_Images = new Image[this.m_numImages];
  134.          this.m_nImgWidth = new int[this.m_numImages];
  135.          this.m_nImgHeight = new int[this.m_numImages];
  136.          MediaTracker tracker = new MediaTracker(this);
  137.  
  138.          for(int i = 0; i < this.m_numImages; ++i) {
  139.             this.m_Images[i] = ((Applet)this).getImage(((Applet)this).getDocumentBase(), this.m_imageString[i]);
  140.             tracker.addImage(this.m_Images[i], 0);
  141.          }
  142.  
  143.          try {
  144.             tracker.waitForAll();
  145.             this.m_fAllLoaded = !tracker.isErrorAny();
  146.          } catch (InterruptedException var21) {
  147.          }
  148.  
  149.          if (!this.m_fAllLoaded) {
  150.             this.stop();
  151.             return;
  152.          }
  153.  
  154.          for(int i = 0; i < this.m_numImages; ++i) {
  155.             this.m_nImgWidth[i] = this.m_Images[i].getWidth(this);
  156.             this.m_nImgHeight[i] = this.m_Images[i].getHeight(this);
  157.          }
  158.       } else {
  159.          ((Component)this).repaint();
  160.       }
  161.  
  162.       while(true) {
  163.          try {
  164.             int currWidth = this.m_nImgWidth[this.m_nCurrImage];
  165.             int currHeight = this.m_nImgHeight[this.m_nCurrImage];
  166.             int wCurrOffset = (((Component)this).size().width - currWidth) / 2;
  167.             int hCurrOffset = (((Component)this).size().height - currHeight) / 2;
  168.             this.m_nNextImage = this.m_nCurrImage + 1;
  169.             if (this.m_nNextImage == this.m_numImages) {
  170.                this.m_nNextImage = 0;
  171.             }
  172.  
  173.             int nextWidth = this.m_nImgWidth[this.m_nNextImage];
  174.             int nextHeight = this.m_nImgHeight[this.m_nNextImage];
  175.             int wNextOffset = (((Component)this).size().width - nextWidth) / 2;
  176.             int hNextOffset = (((Component)this).size().height - nextHeight) / 2;
  177.             int width = Math.max(currWidth, nextWidth);
  178.             int height = Math.max(currHeight, nextHeight);
  179.             int wTransOffset = (((Component)this).size().width - width) / 2;
  180.             int hTransOffset = (((Component)this).size().height - height) / 2;
  181.             this.m_transImage1 = ((Component)this).createImage(width, height);
  182.             Graphics g1 = this.m_transImage1.getGraphics();
  183.             int wOffset = wCurrOffset - wTransOffset;
  184.             int hOffset = hCurrOffset - hTransOffset;
  185.             g1.drawImage(this.m_Images[this.m_nCurrImage], wOffset, hOffset, (ImageObserver)null);
  186.             int steps = this.m_effect == 0 ? 1 : this.m_transitionSteps;
  187.  
  188.             for(int i = 0; i < steps; ++i) {
  189.                this.m_transImage[i] = ((Component)this).createImage(width, height);
  190.             }
  191.  
  192.             this.m_transImage2 = ((Component)this).createImage(width, height);
  193.             Graphics g2 = this.m_transImage2.getGraphics();
  194.             wOffset = wNextOffset - wTransOffset;
  195.             hOffset = hNextOffset - hTransOffset;
  196.             g2.drawImage(this.m_Images[this.m_nNextImage], wOffset, hOffset, (ImageObserver)null);
  197.             this.displayImage(this.m_Graphics, this.m_transImage1, width, height);
  198.  
  199.             for(int var24 = 0; var24 < steps; ++var24) {
  200.                this.applyEffect(var24, this.m_transitionSteps, width, height, this.m_effect);
  201.             }
  202.  
  203.             int nDelay = this.m_time * 1000;
  204.             if (this.m_time == 0) {
  205.                nDelay = 50;
  206.             }
  207.  
  208.             Thread.sleep((long)nDelay);
  209.  
  210.             for(int var25 = 0; var25 < steps; ++var25) {
  211.                this.displayImage(this.m_Graphics, this.m_transImage[var25], width, height);
  212.                if (this.m_transitionTime > 0) {
  213.                   Thread.sleep((long)this.m_transitionTime);
  214.                }
  215.             }
  216.  
  217.             this.m_nCurrImage = this.m_nNextImage;
  218.          } catch (InterruptedException var22) {
  219.             this.stop();
  220.          }
  221.       }
  222.    }
  223.  
  224.    public void init() {
  225.       String param = ((Applet)this).getParameter("time");
  226.       if (param != null) {
  227.          this.m_time = Integer.parseInt(param);
  228.       }
  229.  
  230.       param = ((Applet)this).getParameter("rotatoreffect");
  231.       if (param != null) {
  232.          this.m_effectString = param;
  233.       }
  234.  
  235.       if (this.m_effectString.equalsIgnoreCase("none")) {
  236.          this.m_effect = 0;
  237.       }
  238.  
  239.       if (this.m_effectString.equalsIgnoreCase("blindsHorizontal")) {
  240.          this.m_effect = 1;
  241.       } else if (this.m_effectString.equalsIgnoreCase("blindsVertical")) {
  242.          this.m_effect = 2;
  243.       } else if (this.m_effectString.equalsIgnoreCase("dissolve")) {
  244.          this.m_effect = 3;
  245.       } else if (this.m_effectString.equalsIgnoreCase("boxIn")) {
  246.          this.m_effect = 4;
  247.       } else if (this.m_effectString.equalsIgnoreCase("boxOut")) {
  248.          this.m_effect = 5;
  249.       }
  250.  
  251.       this.m_numImages = 0;
  252.       this.m_imageString = new String[100];
  253.       int i = 1;
  254.  
  255.       do {
  256.          param = ((Applet)this).getParameter("image" + i);
  257.          if (param == null) {
  258.             break;
  259.          }
  260.  
  261.          this.m_imageString[this.m_numImages++] = param;
  262.          ++i;
  263.       } while(i <= 99);
  264.  
  265.       param = ((Applet)this).getParameter("url");
  266.       if (param != null) {
  267.          this.m_url = param;
  268.       }
  269.  
  270.       param = ((Applet)this).getParameter("target");
  271.       if (param != null) {
  272.          this.m_target = param;
  273.       }
  274.  
  275.       try {
  276.          this.m_docUrl = new URL(((Applet)this).getDocumentBase(), this.m_url);
  277.       } catch (MalformedURLException var4) {
  278.       }
  279.  
  280.    }
  281.  
  282.    public void applyEffect(int i, int n, int width, int height, int effect) {
  283.       ImageFilter filter = new fprotatx(i, n, width, height, effect);
  284.       ImageProducer producer = new FilteredImageSource(this.m_transImage2.getSource(), filter);
  285.       this.m_transImage[i] = ((Component)this).createImage(producer);
  286.    }
  287. }
  288.