/**
* @author Prakash G.R. (grprakash@gmail.com)
*
*/
@SuppressWarnings("restriction")
public class NSDockTile extends NSResponder {
private static final int sel_setBadgeLabel_ = OS.sel_registerName("setBadgeLabel:");
private static final int sel_dockTile_ = OS.sel_registerName("dockTile");
private static final int sel_display_ = OS.sel_registerName("display");
public NSDockTile(int id) {
super(id);
}
public static NSDockTile getApplicationDockTile() {
NSApplication sharedApplication = NSApplication.sharedApplication();
int id = OS.objc_msgSend(sharedApplication.id, sel_dockTile_);
NSDockTile dockTile = new NSDockTile(id);
return dockTile;
}
public void setBadgeLabel(String badgeLabel) {
NSString nsBadgeLabel = NSString.stringWith(badgeLabel);
OS.objc_msgSend(this.id, sel_setBadgeLabel_, nsBadgeLabel.id);
OS.objc_msgSend(this.id, sel_display_);
}
}
And a two line code to set the badge:
NSDockTile nsDockTile = NSDockTile.getApplicationDockTile();
nsDockTile.setBadgeLabel("6");
There you go in the dock icon and in the minimized window:
In case you were wondering how the GMail icon for the application is set, here is the code for that:
ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL(iconUrl); Image image = imageDescriptor.createImage(); NSApplication app = NSApplication.sharedApplication(); app.setApplicationIconImage(image.handle);
Oh, BTW, I've just started learning Objective C, Cocoa & related things. So stay tuned, you will see more Mac related posts here. Also what is your favourite Mac feature that you are missing in Eclipse?
Update 15-Mar-2010:
As of 3.6 M6, you don't have to do this hack. SWT has introduced a class TaskItem the API. See this SWT Snippet for usage.


8 comments: