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;
}
//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)
);
} 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