home *** CD-ROM | disk | FTP | other *** search
- import java.awt.Color;
- import java.awt.Dimension;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Rectangle;
- import java.util.StringTokenizer;
-
- public final class Animation {
- public int m_fps = 20;
- public Color m_background;
- public AnimationEvent m_head;
- public AnimationEvent m_tail;
- public Dimension m_size;
-
- public Animation() {
- this.m_background = Color.black;
- this.m_head = null;
- this.m_size = new Dimension();
- }
-
- public void addEvent(AnimationEvent event) {
- if (this.m_head == null) {
- this.m_head = event;
- this.m_tail = event;
- } else {
- this.m_tail.m_next = event;
- event.m_prev = this.m_tail;
- this.m_tail = event;
- }
-
- }
-
- public void drawFrame(Image im) {
- Graphics grImage = im.getGraphics();
- grImage.setColor(this.m_background);
- grImage.fillRect(0, 0, this.m_size.width, this.m_size.height);
-
- for(AnimationEvent event = this.m_head; event != null; event = event.m_next) {
- event.drawFrame(grImage);
- }
-
- grImage.dispose();
- }
-
- public void initFromParams(String params) {
- StringTokenizer st = new StringTokenizer(params, ";");
-
- while(st.hasMoreTokens()) {
- String szToken = st.nextToken();
- int nColon = szToken.indexOf(58);
- if (nColon != -1) {
- String szName = szToken.substring(0, nColon).toUpperCase();
- String szValue = szToken.substring(nColon + 1);
- if (szName.equals("FPS")) {
- this.m_fps = Integer.valueOf(szValue);
- } else if (szName.equals("BACKGROUND")) {
- this.m_background = Misc.initColour(szValue);
- }
- }
- }
-
- }
-
- public void setSize(Rectangle bounds) {
- this.m_size.width = bounds.width;
- this.m_size.height = bounds.height;
- }
-
- public String getUrl(int x, int y) {
- for(AnimationEvent event = this.m_tail; event != null; event = event.m_prev) {
- String url = event.getUrl(x, y);
- if (url != null) {
- return url;
- }
- }
-
- return null;
- }
-
- public void incFrame() {
- for(AnimationEvent event = this.m_head; event != null; event = event.m_next) {
- event.incFrame();
- }
-
- }
- }
-