* Revert BF[2736995]

- incorrect fix and introduce recursive call
* BF[2736995]
- Change File.toURL() to File.toURI().toURL() as per the recommendation in the File.toURL javadoc
* loadImage(String path)
- added null check for the path parameter
This commit is contained in:
Heng Sin Low 2009-04-16 17:46:29 +00:00
parent 0bf6befbab
commit 3b97e31b67
1 changed files with 29 additions and 23 deletions

View File

@ -32,12 +32,13 @@ import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.logging.Logger;
import javax.swing.JComponent;
import com.sun.enterprise.naming.java.javaURLContext;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageDecoder;
@ -46,7 +47,6 @@ import com.sun.image.codec.jpeg.JPEGImageDecoder;
*
* @author Jorg Janke
* @version $Id: AdempiereUtils.java,v 1.2 2006/07/30 00:52:23 jjanke Exp $
* @author Michael Judd BF [ 2736995 ] - toURL() in java.io.File has been deprecated
*/
public class CompiereUtils
{
@ -56,7 +56,7 @@ public class CompiereUtils
/**
* Fill Background with Color.
* (Usually called from update methods)
* (Ususlly called from update methods)
*
* @param g2D Graphics
* @param c Component
@ -240,21 +240,25 @@ public class CompiereUtils
* @param path location of image file in local file system
* - otherwise relative to class
* @return loaded image at path or url
* @see java.io.File#toURL()
* @see java.io.File#toURI()
* @see java.net.URI#toURL()
*/
public static synchronized Image loadImage(String path)
{
Image image = null;
if (path != null)
{
try
{
File file = new File(path);
URI url = file.toURI();
image = loadImage(url.toString());
URL url = file.toURI().toURL();
image = loadImage(url);
}
catch (SecurityException e)
catch (MalformedURLException e)
{
log.severe("Path= " + path + " - " + e.getMessage());
}
}
return image;
} // loadImage
@ -263,7 +267,7 @@ public class CompiereUtils
*
* @param url URL where the image file is located.
* @return loaded image at path or url
* @see java.io.File#toURL()
* @see java.io.File#toURI()
*/
public static synchronized Image loadImage(URL url)
{
@ -321,10 +325,10 @@ public class CompiereUtils
BufferedImage image = null;
try
{
URI url = file.toURI();
image = loadBufferedImage(url.toString(), imageType);
URL url = file.toURI().toURL();
image = loadBufferedImage(url, imageType);
}
catch (SecurityException e)
catch (MalformedURLException e)
{
log.severe("File: " + file + " - " + e.getMessage());
}
@ -341,6 +345,8 @@ public class CompiereUtils
* @param imageType one of the image type defined in the BufferedImage class.
* @return loaded image at path or url
* @see java.awt.image.BufferedImage
* @see java.io.File#toURI()
* @see java.net.URI#toURL()
*/
public static synchronized BufferedImage loadBufferedImage(String path, int imageType)
{
@ -348,10 +354,10 @@ public class CompiereUtils
BufferedImage image = null;
try
{
URI url = file.toURI();
image = loadBufferedImage(url.toString(), imageType);
URL url = file.toURI().toURL();
image = loadBufferedImage(url, imageType);
}
catch (SecurityException e)
catch (MalformedURLException e)
{
log.severe("Path: " + path + " - " + e.getMessage());
}