home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 192 / dpcs0204.iso / Serif / pp60 / Internet / Java / SerifMarquee / SerifMarquee.class (.txt) < prev    next >
Encoding:
Java Class File  |  2003-11-17  |  7.8 KB  |  230 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.Rectangle;
  7. import java.awt.image.ImageObserver;
  8. import java.net.MalformedURLException;
  9. import java.net.URL;
  10. import java.util.StringTokenizer;
  11.  
  12. public class SerifMarquee extends Applet implements Runnable {
  13.    Thread m_SerifMarquee;
  14.    Image m_backBuffer;
  15.    Animation m_animation = new Animation();
  16.    boolean m_haveMouse;
  17.    int m_mx;
  18.    int m_my;
  19.    private String m_Global = "LENGTH:10;FPS:20;BACKGROUND:0,0,0";
  20.    private String m_Event1 = "TYPE:TEXT;STARTIME:0;TEXT:TEXTSHOW 1;FONT:ARIAL;STYLE:BOLD;COLOUR:255,64,64;MOTION:LSLIDEIN;";
  21.    private String m_Event2 = "TYPE:TEXT;STARTIME:0;TEXT:TEXTSHOW 2;FONT:ARIAL;STYLE:BOLD;MOTION:LSLIDEIN;";
  22.    private String m_Event3 = "TYPE:TEXT;STARTIME:0;TEXT:TEXTSHOW 3;FONT:ARIAL;STYLE:BOLD;MOTION:LSLIDEIN;";
  23.    private String m_Event4 = "TYPE:TEXT;STARTIME:0;TEXT:TEXTSHOW 4;FONT:ARIAL;STYLE:BOLD;MOTION:LSLIDEIN;";
  24.    private String m_Event5 = "TYPE:TEXT;STARTIME:0;TEXT:TEXTSHOW 5;FONT:ARIAL;STYLE:BOLD;MOTION:LSLIDEIN;";
  25.    private String m_Event6 = "TYPE:TEXT;STARTIME:0;TEXT:TEXTSHOW 6;FONT:ARIAL;STYLE:BOLD;MOTION:LSLIDEIN;";
  26.    private String m_Event7 = "TYPE:TEXT;STARTIME:0;TEXT:TEXTSHOW 7;FONT:ARIAL;STYLE:BOLD;MOTION:LSLIDEIN;";
  27.    private String m_Event8 = "TYPE:TEXT;STARTIME:0;TEXT:TEXTSHOW 8;FONT:ARIAL;STYLE:BOLD;MOTION:LSLIDEIN;";
  28.    private String m_Event9 = "TYPE:TEXT;STARTIME:0;TEXT:TEXTSHOW 9;FONT:ARIAL;STYLE:BOLD;MOTION:LSLIDEIN;";
  29.    private String m_Event10 = "TYPE:TEXT;STARTIME:0;TEXT:TEXTSHOW 10;FONT:ARIAL;STYLE:BOLD;MOTION:LSLIDEIN;";
  30.    private final String PARAM_Global = "Global";
  31.    private final String PARAM_Event1 = "Event1";
  32.    private final String PARAM_Event2 = "Event2";
  33.    private final String PARAM_Event3 = "Event3";
  34.    private final String PARAM_Event4 = "Event4";
  35.    private final String PARAM_Event5 = "Event5";
  36.    private final String PARAM_Event6 = "Event6";
  37.    private final String PARAM_Event7 = "Event7";
  38.    private final String PARAM_Event8 = "Event8";
  39.    private final String PARAM_Event9 = "Event9";
  40.    private final String PARAM_Event10 = "Event10";
  41.  
  42.    public void stop() {
  43.       if (this.m_SerifMarquee != null) {
  44.          this.m_SerifMarquee.stop();
  45.          this.m_SerifMarquee = null;
  46.       }
  47.  
  48.    }
  49.  
  50.    public boolean mouseEnter(Event evt, int x, int y) {
  51.       this.m_haveMouse = true;
  52.       this.m_mx = x;
  53.       this.m_my = y;
  54.       return true;
  55.    }
  56.  
  57.    public boolean mouseExit(Event evt, int x, int y) {
  58.       this.m_haveMouse = false;
  59.       return true;
  60.    }
  61.  
  62.    public void paint(Graphics g) {
  63.       g.drawImage(this.m_backBuffer, 0, 0, (ImageObserver)null);
  64.    }
  65.  
  66.    public boolean mouseUp(Event evt, int x, int y) {
  67.       String urlStr = this.m_animation.getUrl(x, y);
  68.       if (urlStr == null) {
  69.          return false;
  70.       } else {
  71.          try {
  72.             URL url = new URL(urlStr);
  73.             ((Applet)this).getAppletContext().showDocument(url);
  74.             ((Applet)this).getAppletContext().showStatus("");
  75.          } catch (MalformedURLException var7) {
  76.          }
  77.  
  78.          return true;
  79.       }
  80.    }
  81.  
  82.    public String[][] getParameterInfo() {
  83.       String[][] info = new String[][]{{"Global", "String", "Global Animation Parameters"}, {"Event1", "String", "First Animation Event"}, {"Event2", "String", "Second Animation Event"}, {"Event3", "String", "Third Animation Event"}, {"Event4", "String", "Fourth Animation Event"}, {"Event5", "String", "Fifth Animation Event"}, {"Event6", "String", "Sixth Animation Event"}, {"Event7", "String", "Seventh Animation Event"}, {"Event8", "String", "Eighth Animation Event"}, {"Event9", "String", "Ninth Animation Event"}, {"Event10", "String", "Tenth Animation Event"}};
  84.       return info;
  85.    }
  86.  
  87.    public void destroy() {
  88.    }
  89.  
  90.    public AnimationEvent initEvent(String params) {
  91.       StringTokenizer st = new StringTokenizer(params, ";");
  92.       String szToken = st.nextToken();
  93.       int nColon = szToken.indexOf(58);
  94.       if (nColon != -1) {
  95.          String szName = szToken.substring(0, nColon).toUpperCase();
  96.          String szValue = szToken.substring(nColon + 1);
  97.          if (szName.equals("TYPE") && szValue.equals("TEXT")) {
  98.             return this.initTextEvent(params);
  99.          }
  100.       }
  101.  
  102.       return null;
  103.    }
  104.  
  105.    public void update(Graphics g) {
  106.       this.paint(g);
  107.    }
  108.  
  109.    public void start() {
  110.       if (this.m_SerifMarquee == null) {
  111.          this.m_SerifMarquee = new Thread(this);
  112.          this.m_SerifMarquee.start();
  113.       }
  114.  
  115.    }
  116.  
  117.    public String getAppletInfo() {
  118.       return "Name: SerifMarquee\r\n" + "Author: Paul Hempstock for Serif (Europe) Ltd.";
  119.    }
  120.  
  121.    void initEvents() {
  122.       String param = ((Applet)this).getParameter("Event1");
  123.       if (param != null) {
  124.          this.m_Event1 = param;
  125.          AnimationEvent event = this.initEvent(this.m_Event1);
  126.          this.m_animation.addEvent(event);
  127.          param = ((Applet)this).getParameter("Event2");
  128.          if (param != null) {
  129.             this.m_Event2 = param;
  130.             event = this.initEvent(this.m_Event2);
  131.             this.m_animation.addEvent(event);
  132.             param = ((Applet)this).getParameter("Event3");
  133.             if (param != null) {
  134.                this.m_Event3 = param;
  135.                event = this.initEvent(this.m_Event3);
  136.                this.m_animation.addEvent(event);
  137.                param = ((Applet)this).getParameter("Event4");
  138.                if (param != null) {
  139.                   this.m_Event4 = param;
  140.                   event = this.initEvent(this.m_Event4);
  141.                   this.m_animation.addEvent(event);
  142.                   param = ((Applet)this).getParameter("Event5");
  143.                   if (param != null) {
  144.                      this.m_Event5 = param;
  145.                      event = this.initEvent(this.m_Event5);
  146.                      this.m_animation.addEvent(event);
  147.                      param = ((Applet)this).getParameter("Event6");
  148.                      if (param != null) {
  149.                         this.m_Event6 = param;
  150.                         event = this.initEvent(this.m_Event6);
  151.                         this.m_animation.addEvent(event);
  152.                         param = ((Applet)this).getParameter("Event7");
  153.                         if (param != null) {
  154.                            this.m_Event7 = param;
  155.                            event = this.initEvent(this.m_Event7);
  156.                            this.m_animation.addEvent(event);
  157.                            param = ((Applet)this).getParameter("Event8");
  158.                            if (param != null) {
  159.                               this.m_Event8 = param;
  160.                               event = this.initEvent(this.m_Event8);
  161.                               this.m_animation.addEvent(event);
  162.                               param = ((Applet)this).getParameter("Event9");
  163.                               if (param != null) {
  164.                                  this.m_Event9 = param;
  165.                                  event = this.initEvent(this.m_Event9);
  166.                                  this.m_animation.addEvent(event);
  167.                                  param = ((Applet)this).getParameter("Event10");
  168.                                  if (param != null) {
  169.                                     this.m_Event10 = param;
  170.                                     event = this.initEvent(this.m_Event10);
  171.                                     this.m_animation.addEvent(event);
  172.                                  }
  173.                               }
  174.                            }
  175.                         }
  176.                      }
  177.                   }
  178.                }
  179.             }
  180.          }
  181.       }
  182.    }
  183.  
  184.    public void run() {
  185.       int sleepPerFrame = 1000 / this.m_animation.m_fps;
  186.  
  187.       while(true) {
  188.          try {
  189.             this.m_animation.drawFrame(this.m_backBuffer);
  190.             this.m_animation.incFrame();
  191.             ((Component)this).repaint();
  192.             if (this.m_haveMouse) {
  193.                String urlStr = this.m_animation.getUrl(this.m_mx, this.m_my);
  194.                ((Applet)this).getAppletContext().showStatus(urlStr);
  195.             }
  196.  
  197.             Thread.sleep((long)sleepPerFrame);
  198.          } catch (InterruptedException var4) {
  199.             return;
  200.          }
  201.       }
  202.    }
  203.  
  204.    public void init() {
  205.       Rectangle rec = ((Component)this).bounds();
  206.       this.m_backBuffer = ((Component)this).createImage(rec.width, rec.height);
  207.       this.m_animation.setSize(rec);
  208.       String param = ((Applet)this).getParameter("Global");
  209.       if (param != null) {
  210.          this.m_Global = param;
  211.          this.m_animation.initFromParams(param);
  212.       }
  213.  
  214.       this.initEvents();
  215.       this.m_animation.drawFrame(this.m_backBuffer);
  216.    }
  217.  
  218.    public AnimationEvent initTextEvent(String params) {
  219.       TextEvent event = new TextEvent(this, this.m_animation);
  220.       event.initFromParams(params);
  221.       return event;
  222.    }
  223.  
  224.    public boolean mouseMove(Event evt, int x, int y) {
  225.       this.m_mx = x;
  226.       this.m_my = y;
  227.       return true;
  228.    }
  229. }
  230.