< prev index next >

src/share/classes/sun/awt/SunToolkit.java

Print this page




 698         AWTAccessor.getComponentAccessor().setBackgroundEraseDisabled(component, true);
 699     }
 700 
 701     /**
 702      * Returns the value of "sun.awt.noerasebackground" property. Default
 703      * value is {@code false}.
 704      */
 705     public static boolean getSunAwtNoerasebackground() {
 706         return AccessController.doPrivileged(new GetBooleanAction("sun.awt.noerasebackground"));
 707     }
 708 
 709     /**
 710      * Returns the value of "sun.awt.erasebackgroundonresize" property. Default
 711      * value is {@code false}.
 712      */
 713     public static boolean getSunAwtErasebackgroundonresize() {
 714         return AccessController.doPrivileged(new GetBooleanAction("sun.awt.erasebackgroundonresize"));
 715     }
 716 
 717 
 718     static final SoftCache imgCache = new SoftCache();


 719 
 720     static Image getImageFromHash(Toolkit tk, URL url) {
 721         checkPermissions(url);
 722         synchronized (imgCache) {
 723             Image img = (Image)imgCache.get(url);

 724             if (img == null) {
 725                 try {
 726                     img = tk.createImage(new URLImageSource(url));
 727                     imgCache.put(url, img);
 728                 } catch (Exception e) {
 729                 }
 730             }
 731             return img;
 732         }
 733     }
 734 
 735     static Image getImageFromHash(Toolkit tk,
 736                                                String filename) {
 737         checkPermissions(filename);
 738         synchronized (imgCache) {
 739             Image img = (Image)imgCache.get(filename);
 740             if (img == null) {
 741                 try {
 742                     img = tk.createImage(new FileImageSource(filename));
 743                     imgCache.put(filename, img);
 744                 } catch (Exception e) {
 745                 }
 746             }
 747             return img;
 748         }
 749     }
 750 
 751     public Image getImage(String filename) {
 752         return getImageFromHash(this, filename);
 753     }
 754 
 755     public Image getImage(URL url) {
 756         return getImageFromHash(this, url);
 757     }
 758 
 759     protected Image getImageWithResolutionVariant(String fileName,
 760             String resolutionVariantName) {
 761         synchronized (imgCache) {
 762             Image image = getImageFromHash(this, fileName);
 763             if (image instanceof MultiResolutionImage) {
 764                 return image;
 765             }
 766             Image resolutionVariant = getImageFromHash(this, resolutionVariantName);
 767             image = createImageWithResolutionVariant(image, resolutionVariant);
 768             imgCache.put(fileName, image);
 769             return image;
 770         }
 771     }
 772 
 773     protected Image getImageWithResolutionVariant(URL url,
 774             URL resolutionVariantURL) {
 775         synchronized (imgCache) {
 776             Image image = getImageFromHash(this, url);
 777             if (image instanceof MultiResolutionImage) {
 778                 return image;
 779             }
 780             Image resolutionVariant = getImageFromHash(this, resolutionVariantURL);
 781             image = createImageWithResolutionVariant(image, resolutionVariant);
 782             imgCache.put(url, image);

 783             return image;
 784         }
 785     }
 786 
 787 
 788     public Image createImage(String filename) {
 789         checkPermissions(filename);
 790         return createImage(new FileImageSource(filename));
 791     }
 792 
 793     public Image createImage(URL url) {
 794         checkPermissions(url);
 795         return createImage(new URLImageSource(url));
 796     }
 797 
 798     public Image createImage(byte[] data, int offset, int length) {
 799         return createImage(new ByteArrayImageSource(data, offset, length));
 800     }
 801 
 802     public Image createImage(ImageProducer producer) {


 867                 rvImage, rvw, rvh,
 868                 MultiResolutionToolkitImage.getResolutionVariantObserver(
 869                         img, o, w, h, rvw, rvh, true));
 870     }
 871 
 872     private static int getRVSize(int size){
 873         return size == -1 ? -1 : 2 * size;
 874     }
 875 
 876     private static ToolkitImage getResolutionVariant(Image image) {
 877         if (image instanceof MultiResolutionToolkitImage) {
 878             Image resolutionVariant = ((MultiResolutionToolkitImage) image).
 879                     getResolutionVariant();
 880             if (resolutionVariant instanceof ToolkitImage) {
 881                 return (ToolkitImage) resolutionVariant;
 882             }
 883         }
 884         return null;
 885     }
 886 
 887     protected static boolean imageCached(Object key) {
 888         return imgCache.containsKey(key);





 889     }
 890 
 891     protected static boolean imageExists(String filename) {
 892         if (filename != null) {
 893             checkPermissions(filename);
 894             return new File(filename).exists();
 895         }
 896         return false;
 897     }
 898 
 899     @SuppressWarnings("try")
 900     protected static boolean imageExists(URL url) {
 901         if (url != null) {
 902             checkPermissions(url);
 903             try (InputStream is = url.openStream()) {
 904                 return true;
 905             }catch(IOException e){
 906                 return false;
 907             }
 908         }




 698         AWTAccessor.getComponentAccessor().setBackgroundEraseDisabled(component, true);
 699     }
 700 
 701     /**
 702      * Returns the value of "sun.awt.noerasebackground" property. Default
 703      * value is {@code false}.
 704      */
 705     public static boolean getSunAwtNoerasebackground() {
 706         return AccessController.doPrivileged(new GetBooleanAction("sun.awt.noerasebackground"));
 707     }
 708 
 709     /**
 710      * Returns the value of "sun.awt.erasebackgroundonresize" property. Default
 711      * value is {@code false}.
 712      */
 713     public static boolean getSunAwtErasebackgroundonresize() {
 714         return AccessController.doPrivileged(new GetBooleanAction("sun.awt.erasebackgroundonresize"));
 715     }
 716 
 717 
 718     static final SoftCache fileImgCache = new SoftCache();
 719 
 720     static final SoftCache urlImgCache = new SoftCache();
 721 
 722     static Image getImageFromHash(Toolkit tk, URL url) {
 723         checkPermissions(url);
 724         synchronized (urlImgCache) {
 725             String key = url.toString();
 726             Image img = (Image)urlImgCache.get(key);
 727             if (img == null) {
 728                 try {
 729                     img = tk.createImage(new URLImageSource(url));
 730                     urlImgCache.put(key, img);
 731                 } catch (Exception e) {
 732                 }
 733             }
 734             return img;
 735         }
 736     }
 737 
 738     static Image getImageFromHash(Toolkit tk,
 739                                                String filename) {
 740         checkPermissions(filename);
 741         synchronized (fileImgCache) {
 742             Image img = (Image)fileImgCache.get(filename);
 743             if (img == null) {
 744                 try {
 745                     img = tk.createImage(new FileImageSource(filename));
 746                     fileImgCache.put(filename, img);
 747                 } catch (Exception e) {
 748                 }
 749             }
 750             return img;
 751         }
 752     }
 753 
 754     public Image getImage(String filename) {
 755         return getImageFromHash(this, filename);
 756     }
 757 
 758     public Image getImage(URL url) {
 759         return getImageFromHash(this, url);
 760     }
 761 
 762     protected Image getImageWithResolutionVariant(String fileName,
 763             String resolutionVariantName) {
 764         synchronized (fileImgCache) {
 765             Image image = getImageFromHash(this, fileName);
 766             if (image instanceof MultiResolutionImage) {
 767                 return image;
 768             }
 769             Image resolutionVariant = getImageFromHash(this, resolutionVariantName);
 770             image = createImageWithResolutionVariant(image, resolutionVariant);
 771             fileImgCache.put(fileName, image);
 772             return image;
 773         }
 774     }
 775 
 776     protected Image getImageWithResolutionVariant(URL url,
 777             URL resolutionVariantURL) {
 778         synchronized (urlImgCache) {
 779             Image image = getImageFromHash(this, url);
 780             if (image instanceof MultiResolutionImage) {
 781                 return image;
 782             }
 783             Image resolutionVariant = getImageFromHash(this, resolutionVariantURL);
 784             image = createImageWithResolutionVariant(image, resolutionVariant);
 785             String key = url.toString();
 786             urlImgCache.put(key, image);
 787             return image;
 788         }
 789     }
 790 
 791 
 792     public Image createImage(String filename) {
 793         checkPermissions(filename);
 794         return createImage(new FileImageSource(filename));
 795     }
 796 
 797     public Image createImage(URL url) {
 798         checkPermissions(url);
 799         return createImage(new URLImageSource(url));
 800     }
 801 
 802     public Image createImage(byte[] data, int offset, int length) {
 803         return createImage(new ByteArrayImageSource(data, offset, length));
 804     }
 805 
 806     public Image createImage(ImageProducer producer) {


 871                 rvImage, rvw, rvh,
 872                 MultiResolutionToolkitImage.getResolutionVariantObserver(
 873                         img, o, w, h, rvw, rvh, true));
 874     }
 875 
 876     private static int getRVSize(int size){
 877         return size == -1 ? -1 : 2 * size;
 878     }
 879 
 880     private static ToolkitImage getResolutionVariant(Image image) {
 881         if (image instanceof MultiResolutionToolkitImage) {
 882             Image resolutionVariant = ((MultiResolutionToolkitImage) image).
 883                     getResolutionVariant();
 884             if (resolutionVariant instanceof ToolkitImage) {
 885                 return (ToolkitImage) resolutionVariant;
 886             }
 887         }
 888         return null;
 889     }
 890 
 891     protected static boolean imageCached(String fileName) {
 892         return fileImgCache.containsKey(fileName);
 893     }
 894 
 895     protected static boolean imageCached(URL url) {
 896         String key = url.toString();
 897         return urlImgCache.containsKey(key);
 898     }
 899 
 900     protected static boolean imageExists(String filename) {
 901         if (filename != null) {
 902             checkPermissions(filename);
 903             return new File(filename).exists();
 904         }
 905         return false;
 906     }
 907 
 908     @SuppressWarnings("try")
 909     protected static boolean imageExists(URL url) {
 910         if (url != null) {
 911             checkPermissions(url);
 912             try (InputStream is = url.openStream()) {
 913                 return true;
 914             }catch(IOException e){
 915                 return false;
 916             }
 917         }


< prev index next >