Monday July 09, 2007
Two Classes Every NetBeans API User Should Know
There are two NetBeans API classes that are extremely important to know. They are useful in a very wide variety of scenarios. Here they are:
- org.openide.filesystems.FileUtil. Provides countless useful methods that you absolutely cannot do without when creating NetBeans modules. Without question, my two favorites are FileUtil.toFile(FileObject fo) and FileUtil.toFileObject(File file). But, right now, since looking at that whole javadoc page, I see there's also a FileUtil.normalizeFile(File file), which seems pretty handy. Not to forget, of course, are the methods FileUtil.createData and FileUtil.createFolder, both of which can accept either a File or a FileObject as arguments. But, how about findFreeFileName and findFreeFolderName? No need to iterate through folders, looking for free file names, once you know these methods exist... and, more likely, no more ending up with files that are named "foo_1.java", because "foo.java" already exists. Anyway, that's what I assume will be avoidable with these methods.
- org.openide.text.NbDocument. Without knowing about this class, you won't know about crucial editor methods such as NbDocument.findLineNumber(StyledDocument doc, int offset), which is vital when working with, for example, annotations. The methods runAtomic and runAtomicAsUser, used in various places in the "Rich Client Programming: Plugging into the NetBeans Platform" book, also come from this class, as do the methods for adding and removing annotations.
Various other utility classes are available for various areas, such as for code completion and code folding. Are there any specific NetBeans API classes or methods that you, NetBeans API enthusiast and reader of this blog, have found particularly useful? Has there been a moment where you thought: "Wow. Until I knew about this method, I was really doing things the hard way"? If so, I'd be happy to hear about it—leave a comment at the end of this blog entry and share your NetBeans API insights, large and small.
In other news. Jacek Furmankiewicz has created two extremely interesting looking plugins for OpenLaszlo and Echo2 in NetBeans IDE: nbopenlaszlosupport.dev.java.net and https://nbecho2support.dev.java.net. Congratulations Jacek, I am looking forward to trying them out!
Jul 09 2007, 10:02:14 AM PDT Permalink


