FileDocCategorySizeDatePackage
ImageArea.javaAPI DocJMF 2.1.1e3632Mon May 12 12:20:30 BST 2003jmapps.ui

ImageArea

public class ImageArea extends Canvas

Fields Summary
private Image
image
private Insets
insetsBorder
Constructors Summary
public ImageArea(Image image)


          
	this.image = image;
    
Methods Summary
public java.awt.DimensiongetPreferredSize()

        Dimension      dim;

        if ( image == null )
            dim = new Dimension ( 0, 0 );
        else
            dim = new Dimension ( image.getWidth(this), image.getHeight(this) );
        dim.width += insetsBorder.left + insetsBorder.right;
        dim.height += insetsBorder.top + insetsBorder.bottom;
        return ( dim );
    
public static java.awt.ImageloadImage(java.lang.String strFileName)

        Image               image = null;
        URL                 url;
        Toolkit             toolkit;
        Class               classObject;
        Object              objImageProducer;
        ImageProducer       imageProducer;
        BufferedInputStream streamImage;
        byte                arrImageBytes [];

        toolkit = Toolkit.getDefaultToolkit ();

        if ( strFileName == null )
            return ( null );
        if ( !strFileName.startsWith("/jmapps/images/") )
            strFileName = "/jmapps/images/" + strFileName;

        try {
            classObject = Class.forName ( "jmapps.ui.ImageArea" );
            url = classObject.getResource ( strFileName );
            if ( url != null ) {
                objImageProducer = url.getContent ();
                if ( objImageProducer instanceof ImageProducer ) {
                    imageProducer = (ImageProducer) objImageProducer;
                    image = toolkit.createImage ( imageProducer );
                }
                else if ( objImageProducer instanceof BufferedInputStream ) {
                    streamImage = (BufferedInputStream) objImageProducer;
                    arrImageBytes = new byte [streamImage.available()];
                    streamImage.read ( arrImageBytes );
                    image = toolkit.createImage ( arrImageBytes );
                }
            }
        }
        catch ( Exception exception ) {
//            exception.printStackTrace ();
        }

        return ( image );
    
public static java.awt.ImageloadImage(java.lang.String strFileName, java.awt.Component component, boolean boolWait)

        Image          image;
        MediaTracker   trackerMedia;

        image = loadImage ( strFileName );

        if ( image != null  &&  boolWait == true ) {
            trackerMedia = new MediaTracker ( component );
            trackerMedia.addImage ( image, 1001 );
            try {
                trackerMedia.waitForID ( 1001 );
            }
            catch ( Exception exception ) {
//                exception.printStackTrace ();
            }
        }
        return ( image );
    
public voidpaint(java.awt.Graphics g)

        Dimension       dim;

        dim = this.getSize ();
        dim.width -= insetsBorder.left + insetsBorder.right;
        dim.height -= insetsBorder.top + insetsBorder.bottom;
        g.drawImage ( image, insetsBorder.left, insetsBorder.top, dim.width, dim.height, this );
    
public voidsetImage(java.awt.Image image)

	this.image = image;
    
public voidsetInsets(int nLeft, int nTop, int nRight, int nBottom)

        insetsBorder.left = nLeft;
        insetsBorder.top = nTop;
        insetsBorder.right = nRight;
        insetsBorder.bottom = nBottom;