samples/extensibleicon/src/org/apidesign/extensibleicon/Icon2Image.java
author Jaroslav Tulach <jtulach@netbeans.org>
Sat, 14 Jun 2008 09:53:51 +0200
changeset 89 06f2e2a3d986
child 132 3bc4c54f4bcc
permissions -rw-r--r--
review2: ExtIcon example used to demonstrate the beauty of query pattern. two sections merged into one, a bit of reordering. Please review.
     1 package org.apidesign.extensibleicon;
     2 
     3 import java.awt.Image;
     4 import java.awt.image.BufferedImage;
     5 
     6 public class Icon2Image {
     7     private Icon2Image() {}
     8     
     9     // BEGIN: ext.icon2image
    10     public static Image toImage(ExtIcon icon) {
    11         Image img = icon.getLookup().lookup(Image.class);
    12         if (img != null) {
    13             return img;
    14         }
    15         BufferedImage buf = new BufferedImage(icon.getIconWidth(), icon.getIconHeight(), BufferedImage.TYPE_INT_RGB);
    16         icon.paintIcon(null, buf.getGraphics(), 0, 0);
    17         return buf;
    18     }
    19     // END: ext.icon2image
    20 }