Java Code Examples for java.awt.Image#getProperty()

The following examples show how to use java.awt.Image#getProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JavaNode.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Image prefferImage(Image computed, Image parent, int type) {
    if (computed == null) {
        return parent;
    }
    if (!ALWAYS_PREFFER_COMPUTED_ICON) {
        final Object attrValue = parent.getProperty("url", null);   //NOI18N
        if (attrValue instanceof URL) {
            final String url = attrValue.toString();
            if (!(isJavaSource ? url.endsWith(JAVA_ICON_BASE) : url.endsWith(CLASS_ICON_BASE))) {
                return parent;
            }
        }
    }
    try {
        final FileObject fo = getDataObject().getPrimaryFile ();
        computed = FileUIUtils.getImageDecorator(fo.getFileSystem ()).annotateIcon (
            computed,
            type,
            Collections.singleton(fo));
    } catch (FileStateInvalidException e) {
        // no fs, do nothing
    }
    return computed;
}
 
Example 2
Source File: ImageUtilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static ToolTipImage createNew(String toolTipText, Image image, URL url) {
    ImageUtilities.ensureLoaded(image);
    boolean bitmask = (image instanceof Transparency) && ((Transparency) image).getTransparency() != Transparency.TRANSLUCENT;
    ColorModel model = colorModel(bitmask ? Transparency.BITMASK : Transparency.TRANSLUCENT);
    int w = image.getWidth(null);
    int h = image.getHeight(null);
    if (url == null) {
        Object value = image.getProperty("url", null);
        url = (value instanceof URL) ? (URL) value : null;
    }            
    Icon icon = (image instanceof ToolTipImage)
            ? ((ToolTipImage) image).getDelegateIcon() : null;
    ToolTipImage newImage = new ToolTipImage(
        toolTipText,
        icon,
        model,
        model.createCompatibleWritableRaster(w, h),
        model.isAlphaPremultiplied(), null, url
    );

    java.awt.Graphics g = newImage.createGraphics();
    g.drawImage(image, 0, 0, null);
    g.dispose();
    return newImage;
}
 
Example 3
Source File: ImageUtilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public Object getProperty(String name, ImageObserver observer) {
    if ("url".equals(name)) { // NOI18N
        /* In some cases it might strictly be more appropriate to return
        Image.UndefinedProperty rather than null (see Javadoc spec for this method), but
        retain the existing behavior and use null instead here. That way there won't be a
        ClassCastException if someone tries to cast to URL. */
        if (url != null) {
            return url;
        } else if (!(delegateIcon instanceof ImageIcon)) {
            return null;
        } else {
            Image image = ((ImageIcon) delegateIcon).getImage();
            if (image == this || image == null) {
                return null;
            }
            return image.getProperty("url", observer);
        }
    }
    return super.getProperty(name, observer);
}
 
Example 4
Source File: ImageUtilities.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static final ToolTipImage doMergeImages(Image image1, Image image2, int x, int y) {
    ensureLoaded(image1);
    ensureLoaded(image2);

    int w = Math.max(image1.getWidth(null), x + image2.getWidth(null));
    int h = Math.max(image1.getHeight(null), y + image2.getHeight(null));
    boolean bitmask = (image1 instanceof Transparency) && ((Transparency)image1).getTransparency() != Transparency.TRANSLUCENT
            && (image2 instanceof Transparency) && ((Transparency)image2).getTransparency() != Transparency.TRANSLUCENT;

    StringBuilder str = new StringBuilder(image1 instanceof ToolTipImage ? ((ToolTipImage)image1).toolTipText : "");
    if (image2 instanceof ToolTipImage) {
        String toolTip = ((ToolTipImage)image2).toolTipText;
        if (str.length() > 0 && toolTip.length() > 0) {
            str.append(TOOLTIP_SEPAR);
        }
        str.append(toolTip);
    }
    Object firstUrl = image1.getProperty("url", null);
    
    ColorModel model = colorModel(bitmask? Transparency.BITMASK: Transparency.TRANSLUCENT);
    // Provide a delegate Icon for scalable rendering.
    Icon delegateIcon = new MergedIcon(image2Icon(image1), image2Icon(image2), x, y);
    ToolTipImage buffImage = new ToolTipImage(str.toString(), delegateIcon,
            model, model.createCompatibleWritableRaster(w, h), model.isAlphaPremultiplied(), null, firstUrl instanceof URL ? (URL)firstUrl : null
        );

    // Also provide an Image-based rendering for backwards-compatibility.
    java.awt.Graphics g = buffImage.createGraphics();
    g.drawImage(image1, 0, 0, null);
    g.drawImage(image2, x, y, null);
    g.dispose();

    return buffImage;
}
 
Example 5
Source File: ImageUtilitiesTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testConvertNullImageIcon() {
    // A corner case which occured during development.
    ImageIcon imageIcon = new ImageIcon();
    Image image = ImageUtilities.icon2Image(imageIcon);
    if (image == null) {
        throw new AssertionError(
                "icon2Image should work even with an ImageIcon for which the image is null");
    }
    // Just ensure there are no NPEs.
    image.getProperty("url", null);
}
 
Example 6
Source File: MultiResolutionCachedImageTest.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {

        Image image = new TestMultiResolutionCachedImage(100);

        image.getWidth(null);
        image.getHeight(null);
        image.getProperty("comment", null);

        int scaledSize = 50;
        Image scaledImage = image.getScaledInstance(scaledSize, scaledSize,
                Image.SCALE_SMOOTH);

        if (!(scaledImage instanceof BufferedImage)) {
            throw new RuntimeException("Wrong scaled image!");
        }

        BufferedImage buffScaledImage = (BufferedImage) scaledImage;

        if (buffScaledImage.getWidth() != scaledSize
                || buffScaledImage.getHeight() != scaledSize) {
            throw new RuntimeException("Wrong scaled image!");
        }

        if (buffScaledImage.getRGB(scaledSize / 2, scaledSize / 2) != TEST_COLOR.getRGB()) {
            throw new RuntimeException("Wrong scaled image!");
        }
    }
 
Example 7
Source File: MultiResolutionCachedImageTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {

        Image image = new TestMultiResolutionCachedImage(100);

        image.getWidth(null);
        image.getHeight(null);
        image.getProperty("comment", null);

        int scaledSize = 50;
        Image scaledImage = image.getScaledInstance(scaledSize, scaledSize,
                Image.SCALE_SMOOTH);

        if (!(scaledImage instanceof BufferedImage)) {
            throw new RuntimeException("Wrong scaled image!");
        }

        BufferedImage buffScaledImage = (BufferedImage) scaledImage;

        if (buffScaledImage.getWidth() != scaledSize
                || buffScaledImage.getHeight() != scaledSize) {
            throw new RuntimeException("Wrong scaled image!");
        }

        if (buffScaledImage.getRGB(scaledSize / 2, scaledSize / 2) != TEST_COLOR.getRGB()) {
            throw new RuntimeException("Wrong scaled image!");
        }
    }
 
Example 8
Source File: UnitDetails.java    From netbeans with Apache License 2.0 4 votes vote down vote up
private void buildUnitText(Unit u, StringBuilder text, boolean collectDependencies) {
    if (u instanceof Unit.Available) {
        Unit.Available u1 = (Unit.Available) u;
        Image c = u1.getSourceIcon();
        Object url = c.getProperty("url", null);
        String categoryName = u1.getSourceDescription();
        text.append("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr>");
        if (url instanceof URL) {
            text.append("<td><img src=\"").append(url).append("\"></img></td>");
        }
        text.append("<td></td>");
        text.append("<td>&nbsp;&nbsp;</td>");
        text.append("<td><b>").append(categoryName).append("</b></td>");
        text.append("</tr></table><br>");
    }

    if (Utilities.modulesOnly() || Utilities.showExtendedDescription()) {
        text.append("<b>").append(getBundle("UnitDetails_Plugin_CodeName")).append("</b>").append(u.updateUnit.getCodeName()); // NOI18N
        text.append("<br>");

    }
    String desc = null;
    if (u instanceof Unit.Update) {
        Unit.Update uu = ((Unit.Update) u);
        text.append("<b>").append(getBundle("UnitDetails_Plugin_InstalledVersion")).append("</b>").append(uu.getInstalledVersion()).append("<br>"); // NOI18N
        text.append("<b>").append(getBundle("UnitDetails_Plugin_AvailableVersion")).append("</b>").append(uu.getAvailableVersion()).append("<br>"); // NOI18N
        desc = getDependencies(uu, collectDependencies);
    } else {
        text.append("<b>").append(getBundle("UnitDetails_Plugin_Version")).append("</b>").append(u.getDisplayVersion()).append("<br>"); // NOI18N
    }
    if (u.getAuthor() != null && u.getAuthor().length() > 0) {
        text.append("<b>").append(getBundle("UnitDetails_Plugin_Author")).append("</b>").append(u.getAuthor()).append("<br>"); // NOI18N
    }
    if (u.getDisplayDate() != null && u.getDisplayDate().length() > 0) {
        text.append("<b>").append(getBundle("UnitDetails_Plugin_Date")).append("</b>").append(u.getDisplayDate()).append("<br>"); // NOI18N
    }
    text.append("<b>").append(getBundle("UnitDetails_Plugin_Source")).append("</b>").append(u.getSource()).append("<br>"); // NOI18N

    if (u.getHomepage() != null && u.getHomepage().length() > 0) {
        text.append("<b>").append(getBundle("UnitDetails_Plugin_Homepage")).append("</b><a href=\"").append(u.getHomepage()).append("\">").append(u.getHomepage()).append("</a><br>"); // NOI18N
    }

    if (u.getNotification() != null && u.getNotification().length() > 0) {
        text.append("<br><h3>").append(getBundle("UnitDetails_Plugin_Notification")).append("</h3>"); // NOI18N
        text.append("<font color=\"red\">"); // NOI18N
        text.append(u.getNotification());
        text.append("</font><br>");  // NOI18N
    }

    if (u.getDescription() != null && u.getDescription().length() > 0) {
        text.append("<br><h3>").append(getBundle("UnitDetails_Plugin_Description")).append("</h3>"); // NOI18N
        String description = u.getDescription();
        if(description.toLowerCase().startsWith("<html>")) {
            text.append(description.substring(6));
        } else {
            text.append(description);
        }
    }
    if (desc != null && desc.length() > 0) {
        text.append("<br><br><h4>").append(getBundle("Unit_InternalUpdates_Title")).append("</h4>"); // NOI18N
        text.append(desc);
    }
}