Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Quaqua questions




On 06.12.2006, at 07:28, Werner Randelshofer wrote:
All the code is in method createApplicationIconImage in class QuaquaIconFactory. If you (or someone else) finds the time to rewrite it, that would be great. :)
[...]
public static BufferedImage createApplicationIconImage() {
[...]

Oops, there is second method in the same class, that is used to generate the large file icon in the preview column of the FileChooser. I attached the code at the bottom.

Contact me, if you (or someone else) is interested in rewriting these two methods to JNI-Code.

Best regards,
Werner

public static BufferedImage createFileIconImage(File file, int iconWidth, int iconHeight) {
if (! file.exists() ||
QuaquaManager.getProperty("java.version").startsWith ("1.3")) {
return null;
}


Integer myPool = null;
BufferedImage image = null;
try {
myPool = (Integer) Methods.invokeStatic(
"com.apple.cocoa.foundation.NSAutoreleasePool","push"
);


Object nsWorkspace = Methods.invokeStatic(
"com.apple.cocoa.application.NSWorkspace", "sharedWorkspace"
);


            //Now we'll get an NSImage of applicationIconImage
            Object fileIconImage = Methods.invoke(
                    nsWorkspace, "iconForFile", file.getPath()
                    );

// Scale the icon to 128x128
Class nsSize = Class.forName ("com.apple.cocoa.foundation.NSSize");
Object size = Methods.newInstance(
nsSize,
new Class[] {Float.TYPE, Float.TYPE},
new Object[] { new Float(iconWidth), new Float (iconHeight) }
);
Methods.invoke(fileIconImage, "setSize", nsSize, size);



//Now we'll get an NSData as TIFF Object data = Methods.invoke( fileIconImage, "TIFFRepresentation" );

//Get the length of the NSData
int dataLength = Methods.invokeGetter(data, "length", -1);
//Now we'll get an byte array from the NSData
byte[] bytes = (byte[]) Methods.invoke(
data, "bytes",
new Class[] { int.class, int.class },
new Object[] { new Integer(0), new Integer (dataLength)}
);


Class imageIOClazz = Class.forName ("javax.imageio.ImageIO");
Object imageInputStream = Methods.invokeStatic (imageIOClazz,
"createImageInputStream", Object.class, new ByteArrayInputStream(bytes)
);


Object imageReader = ((Iterator) Methods.invokeStatic (imageIOClazz,
"getImageReadersByFormatName", String.class, "tiff")
).next();


Methods.invoke(imageReader, "setInput", Object.class, imageInputStream);

image = (BufferedImage) Methods.invoke(imageReader, "read", 0);

} catch (Exception e) {
System.err.println("Warning "+QuaquaIconFactory.class+" couldn't access Java for Cocoa. Please make sure that /System/Library/ Java is in the class path.");
e.printStackTrace();
return null;
} finally {
if (myPool != null) {
try {
Methods.invokeStatic ("com.apple.cocoa.foundation.NSAutoreleasePool","pop", Integer.TYPE, myPool);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
}
}
return image;
}



_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: Quaqua questions (From: Doug Zwick <email@hidden>)
 >Re: Quaqua questions (From: Werner Randelshofer <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.