001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.core.gui.base;
019:
020: import java.awt.Component;
021: import java.awt.Dimension;
022: import java.awt.Graphics;
023: import java.awt.Image;
024: import java.awt.MediaTracker;
025:
026: /**
027: * Component containing an animated gif, which can be started and
028: * stopped.
029: *
030: * @author fdietz
031: */
032:
033: public class AnimatedGIFComponent extends Component {
034: private Image image;
035: private Image restImage;
036: private boolean stop = false;
037:
038: public AnimatedGIFComponent(Image image, Image restImage) {
039:
040: super ();
041:
042: this .image = image;
043: this .restImage = restImage;
044:
045: MediaTracker mt = new MediaTracker(this );
046: mt.addImage(image, 9);
047: try {
048: mt.waitForAll();
049: } catch (Exception e) {
050: e.printStackTrace();
051: }
052:
053: stop();
054: }
055:
056: public void paint(Graphics g) {
057: if (stop)
058: g.drawImage(restImage, 0, 0, this );
059: else
060: g.drawImage(image, 0, 0, this );
061: }
062:
063: public void update(Graphics g) {
064: paint(g);
065: }
066:
067: public boolean imageUpdate(Image img, int infoflags, int x, int y,
068: int width, int height) {
069: if (stop)
070: return false;
071:
072: if ((infoflags & FRAMEBITS) != 0) {
073: //repaint(x, y, width, height);
074:
075: javax.swing.SwingUtilities.invokeLater(new Runnable() {
076: public void run() {
077: repaint();
078: }
079: });
080:
081: }
082:
083: return true;
084: }
085:
086: public void stop() {
087: this .stop = true;
088:
089: javax.swing.SwingUtilities.invokeLater(new Runnable() {
090: public void run() {
091: repaint();
092: }
093: });
094: }
095:
096: public void go() {
097: this .stop = false;
098:
099: javax.swing.SwingUtilities.invokeLater(new Runnable() {
100: public void run() {
101: repaint();
102: }
103: });
104: }
105:
106: public boolean stopped() {
107: return this .stop;
108: }
109:
110: public Dimension getMinimumSize() {
111: return new Dimension(image.getWidth(this ), image
112: .getHeight(this ));
113: }
114:
115: public Dimension getPreferredSize() {
116: return getMinimumSize();
117: }
118:
119: }
|