Monday March 12, 2007
Palette API and 6.0, Testing the Waters... (Part 1)
This morning I installed a daily development build of 6.0, to try out the new palette features. Previously, when I wanted to create a palette for an existing file type, such as Java files, I had to create an entirely new data object and editor, because the palette could only be created in the editor's constructor, by adding it to the editor's Lookup. That was a lot of work for little return. Now, as reported two days ago in this blog, life is a lot better in 6.0. The original approach still takes precedence, for backward compatibility, but now there is a new approach, as a much simpler alternative... just declare the palette for the MIME type, in the layer.xml, as shown below:
For the rest, everything is exactly the same. Create a new palette factory and refer to a folder in the System FileSystem:
As you can see above, my new palette item is now in the palette. No Java code was necessary to associate the palette with the editor, which means you're free to enrich someone else's support for a file type with one or more of your own palettes. Of course, the same approach works too for TopComponents.
And because of improvements to the palette item's DTD (it is now 1.1, instead of 1.0) the name and tooltip are declared in the palette item XML file. Before, they were set in a resource bundle, so that you couldn't (or, at least, not easily) let users add palette items at runtime. Look at the XML below and note the inline-description bit:
Unfortunately, it is too late to include this information in the forthcoming book, although a few footnotes have been added to point out to the reader that MIME type registration for palettes is possible in 6.0.
In other news. Have you contributed tutorials to netbeans.org yet? A very detailed program has been started recently. James Branam is the new owner of the NetBeans Community Docs Page. You can create as many new Wiki pages as you like, and create new tutorials in each. You can also indicate which tutorials you would like to see, and then others can create those. And so, the open sourcing of learning and documentation takes another step forward...
Mar 12 2007, 08:41:07 AM PDT Permalink


