home *** CD-ROM | disk | FTP | other *** search
/ Computer Shopper 201 / DPCS1104.ISO / data1.cab / Internet_Extensions / Java / SerifMarquee / Animation.class (.txt) next >
Encoding:
Java Class File  |  2004-08-11  |  2.8 KB  |  87 lines

  1. import java.awt.Color;
  2. import java.awt.Dimension;
  3. import java.awt.Graphics;
  4. import java.awt.Image;
  5. import java.awt.Rectangle;
  6. import java.util.StringTokenizer;
  7.  
  8. public final class Animation {
  9.    public int m_fps = 20;
  10.    public Color m_background;
  11.    public AnimationEvent m_head;
  12.    public AnimationEvent m_tail;
  13.    public Dimension m_size;
  14.  
  15.    public Animation() {
  16.       this.m_background = Color.black;
  17.       this.m_head = null;
  18.       this.m_size = new Dimension();
  19.    }
  20.  
  21.    public void addEvent(AnimationEvent event) {
  22.       if (this.m_head == null) {
  23.          this.m_head = event;
  24.          this.m_tail = event;
  25.       } else {
  26.          this.m_tail.m_next = event;
  27.          event.m_prev = this.m_tail;
  28.          this.m_tail = event;
  29.       }
  30.  
  31.    }
  32.  
  33.    public void drawFrame(Image im) {
  34.       Graphics grImage = im.getGraphics();
  35.       grImage.setColor(this.m_background);
  36.       grImage.fillRect(0, 0, this.m_size.width, this.m_size.height);
  37.  
  38.       for(AnimationEvent event = this.m_head; event != null; event = event.m_next) {
  39.          event.drawFrame(grImage);
  40.       }
  41.  
  42.       grImage.dispose();
  43.    }
  44.  
  45.    public void initFromParams(String params) {
  46.       StringTokenizer st = new StringTokenizer(params, ";");
  47.  
  48.       while(st.hasMoreTokens()) {
  49.          String szToken = st.nextToken();
  50.          int nColon = szToken.indexOf(58);
  51.          if (nColon != -1) {
  52.             String szName = szToken.substring(0, nColon).toUpperCase();
  53.             String szValue = szToken.substring(nColon + 1);
  54.             if (szName.equals("FPS")) {
  55.                this.m_fps = Integer.valueOf(szValue);
  56.             } else if (szName.equals("BACKGROUND")) {
  57.                this.m_background = Misc.initColour(szValue);
  58.             }
  59.          }
  60.       }
  61.  
  62.    }
  63.  
  64.    public void setSize(Rectangle bounds) {
  65.       this.m_size.width = bounds.width;
  66.       this.m_size.height = bounds.height;
  67.    }
  68.  
  69.    public String getUrl(int x, int y) {
  70.       for(AnimationEvent event = this.m_tail; event != null; event = event.m_prev) {
  71.          String url = event.getUrl(x, y);
  72.          if (url != null) {
  73.             return url;
  74.          }
  75.       }
  76.  
  77.       return null;
  78.    }
  79.  
  80.    public void incFrame() {
  81.       for(AnimationEvent event = this.m_head; event != null; event = event.m_next) {
  82.          event.incFrame();
  83.       }
  84.  
  85.    }
  86. }
  87.