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

The following are Jave code examples for showing how to use getProperty() of the java.awt.Image class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: incubator-netbeans   File: ImageUtilities.java   View Source Code Vote up 6 votes
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;
    }            
    ToolTipImage newImage = new ToolTipImage(
        toolTipText,
        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 2
Project: incubator-netbeans   File: JavaNode.java   View Source Code Vote up 6 votes
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 3
Project: incubator-netbeans   File: ImageUtilities.java   View Source Code Vote up 5 votes
private static final Image 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);
    ToolTipImage buffImage = new ToolTipImage(str.toString(), 
            model, model.createCompatibleWritableRaster(w, h), model.isAlphaPremultiplied(), null, firstUrl instanceof URL ? (URL)firstUrl : null
        );

    java.awt.Graphics g = buffImage.createGraphics();
    g.drawImage(image1, 0, 0, null);
    g.drawImage(image2, x, y, null);
    g.dispose();

    return buffImage;
}
 
Example 4
Project: openjdk-jdk10   File: MultiResolutionCachedImageTest.java   View Source Code Vote up 5 votes
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 5
Project: incubator-netbeans   File: UnitDetails.java   View Source Code Vote up 4 votes
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);
    }
}