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