home *** CD-ROM | disk | FTP | other *** search
Java Source | 1996-08-14 | 3.8 KB | 151 lines |
- /*---------------------------------------------------------------------------
-
- Written by the Personal Journal developers of Dow Jones & Company, Inc.
-
- Dow Jones makes no representations or warranties about
- the suitability of this software, either express or
- implied, including but not limited to the implied warranties
- of merchantability, fitness for a particular purpose,
- or non-infringement. Dow Jones will not be liable for
- any damages suffered by a user as a result of using,
- modifying or distributing this software or its derivatives.
-
-
- @(#)GifCanvas.java 0.00 17-Jan-96
-
- A canvas that displays a GIF image.
-
- Authors:
-
- rphall Rick Hall
- jlee James Lee
- Ted S. Ted Skolnick
-
- Version Ident:
-
- $Header$
-
- History:
-
- 17-Jan-96 rphall Initial Creation
- 21-Jan-96 jlee Added resize
- 24-Jan-96 jlee Deleted resize, added dynamic resizing functionality.
- 27-Mar-96 Ted S. Allow for changing of image.
- ---------------------------------------------------------------------------*/
-
- package pj.awt;
-
- import java.awt.Canvas;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.Rectangle;
-
- /**
- * A canvas that displays a GIF image.
- *
- * @version 0.00 17-Jan-96
- * @author rphall, jlee
- */
- public class GifCanvas extends Canvas
- {
-
-
-
- // --- Instance variables
-
- /** The specification for this instance */
-
- private Image image;
- private Rectangle repaintrect = new Rectangle();
- private final static long UPDATERATE = 100;
- private boolean fullrepaint = false;
-
-
- // --- Public constructor
-
- /**
- * Construct a GIF canvas
- * @param i A GIF image.
- */
- public GifCanvas(Image i)
- {
- image = i;
- checkSize();
- }
-
-
-
- /**
- * Construct a GIF canvas before image is known, only to be used by derived class.
- */
- protected GifCanvas()
- {
- }
-
-
- /**
- * Change the image in use.
- * @param i A GIF image.
- */
- public void setImage( Image i )
- {
- image = i;
- checkSize();
- }
-
-
- // --- Public operations
-
- /**
- * Handle updates from images being loaded.
- *
- * @return true if image needs more update, false otherwise.
- */
- public boolean imageUpdate(Image img, int infoflags, int x, int y, int width, int height)
- {
- if ((infoflags & (WIDTH | HEIGHT)) != 0)
- {
- checkSize();
- }
- if ((infoflags & (SOMEBITS | FRAMEBITS | ALLBITS)) != 0)
- {
- repaint( ((infoflags & (FRAMEBITS | ALLBITS)) != 0) ? 0 : UPDATERATE, x, y, width, height );
- }
- return (infoflags & (ALLBITS | ERROR)) == 0;
- }
-
-
- /**
- * Paint the canvas with the GIF image. If the image
- * is null, paint the canvas with the default background color.
- */
- public void paint(Graphics g)
- {
- if (image == null)
- super.paint(g);
- else
- g.drawImage(image,0,0,this);
- }
-
- // --- Private operations
-
- /**
- * Check the size of this canvas while the image is being loaded.
- */
- private synchronized void checkSize()
- {
- int w = image.getWidth(this);
- int h = image.getHeight(this);
- if (w > 0 && h > 0)
- {
- resize(w, h);
- repaintrect.x = repaintrect.y = 0;
- repaintrect.width = w;
- repaintrect.height = h;
- fullrepaint = true;
- repaint();
- }
- }
-
- } // GifCanvas
-