ImageRef.java revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* ident "%Z%%M% %I% %E% SMI"
*
* Copyright (c) 2000 by Sun Microsystems, Inc.
* All rights reserved.
*/
/*
* Copyright (C) 1996 Active Software, Inc.
* All rights reserved.
*
* @(#) ImageRef.java 1.17 - last change made 08/07/96
*/
/**
* Stores an image and the URL or filename that it came from. This
* class is capable of converting a filename to a URL and will do so
* in order to load the image using a "file:" URL. The creation of
* the image is delayed until the image is requested.
*
* @see Image
* @version 1.17, 08/07/96
*/
public class ImageRef implements ImageObserver {
private boolean errorFlagged = false; // set in imageUpdate
/* JSTYLED */
private boolean disableErrorPrint = false; // allow println in imageUpdate
/**
* Constructs a new instance of ImageRef that use a
* URL to find the image when it is requested.
* The size of the image
* cannot be appended to the URL.
*/
}
/**
* Constructs a new instance of ImageRef given the name of a file
* for the image. The filename may be relative to the codebase or
* any of the directories in the classpath. The size of the image
* may be appended to the filename to help with initial layout of
* widgets containing images, like this: "imagefile.gif;24x48".
*/
if (index != -1) {
try {
int w, h;
} catch (Exception e) {
}
} else {
}
}
int imgHeight) {
}
/**
* Gets the image stored here (or referenced by the URL). */
try {
}
catch (VJException vje) {
return null;
}
return img;
}
/**
* Returns the width of the image. If the image is not yet loaded,
* then returns the expected width of the image.
*/
try {
}
catch (VJException vje) {
return 0;
}
return imgWidth;
}
/**
* Returns the height of the image. If the image is not
* yet loaded,
* then returns the expected height of the image.
*/
try {
}
catch (VJException vje) {
return 0;
}
return imgHeight;
}
/**
* Returns the URL stored here.
*/
return (url);
}
/**
* Returns the file name of the image.
*/
public String getFileName() {
else
return name;
}
/**
* Returns the preferred string representation of this
* image reference.
*/
String s = getFileName();
+ imgHeight;
return s;
}
/**
* Start loading the image if we haven't already.
* Attempt to cache the
* width and height of the image.
*/
throws VJException {
return;
/* BEGIN JSTYLED */
"sunsoft.jws.visual.rt.type.ImageRef.FMT.32",
/* END JSTYLED */
}
return;
if (w != -1)
imgWidth = w;
if (h != -1)
imgHeight = h;
}
/**
* Verifies that the image for this image ref loaded successfully,
* returns true if it does. Warning: will wait until image is
* loaded before returning, so you shouldn't make this call unless
* you are really interested in reporting an error message when
* images can't be loaded.
*/
disableErrorPrint = true;
// image has already been set up
if (errorFlagged)
return false;
return true;
} else {
// set up the image
try {
}
catch (VJException vje) {
return false;
}
return true;
}
// start loading the image and wait for it to finish
try {
}
catch (InterruptedException e) {
return false;
}
}
/**
* Gets called when an update of the image's width
* and height are available.
*/
if (!disableErrorPrint)
/* JSTYLED */
System.out.println(Global.getMsg("sunsoft.jws.visual.rt.type.ImageRef.Error-co-__could__not__loa.34")
errorFlagged = true;
}
gotWidth = true;
}
gotHeight = true;
}
}
}