001    /* 
002     * Copyright (c) Holger Pfaff - http://pfaff.ws
003     *
004     * This software maybe used for any purpose provided the
005     * above copyright notice is retained. It is supplied as is.
006     * No warranty expressed or implied - Use at your own risk.
007     */
008    
009    import java.awt.*;  
010    
011    /**
012      * (#)ImageCanvas.java
013      * @author   Holger Pfaff
014      * @version  3.2 19-Mar-2004<br><br> 
015      *
016      * A widget to hold an image
017      *
018      */
019    
020    public class ImageCanvas extends Awt {
021    
022      /**
023       * the actual image itself
024       */
025      private Image im;
026      
027      /**
028       * Construct a new ImageCanvas.
029       *
030       * @param   i the image to use
031       */
032      public ImageCanvas(Image i) {
033        if(i == null) {
034          return;
035        }
036        im = waitForImage(i);
037        setSize(i.getWidth(null), i.getHeight(null));
038      }
039      
040      /**
041       * Actually paint the image
042       *
043       * @param   g current Graphics context
044       */
045      public void paint(Graphics g) {
046        makeBim();
047        paintBackground(big);
048        big.drawImage(im, 0, 0, this);
049        paintBim(g);
050      }
051      
052      /**
053       * Return size needed for this widget
054       */
055      public Dimension measure() {
056        return new Dimension(im.getWidth(null), im.getHeight(null));
057      }
058    }