Tuesday Jan 31, 2012

Managing BTI Networks on the NetBeans Platform

Let's drop by BTI Systems, with a development team split between Belfast and Ottawa, with a NetBeans Platform application that’s about two years old now. The application is a GUI front end for BTI's proNX Server Manager product, which is part of the proNX Management Suite. It provides a modular and scalable management solution for BTI networks and integrates seamlessly into any operating environment, providing maximum flexibility and ease-of-use.

Below is a screenshot which shows a small network of BTI equipment under management. You can see the discovered devices, how they are grouped, alarms, and in the center an Ethernet Service. All of this is data mined from the hardware over SNMP by the server component of the product. The client then displays the network, and draws the topology of the services without the user needing to layout the elements manually. The Ethernet Service in this screenshot is having some performance metrics being gathered on it, as you can see in the bottom right.

Quite a range of NetBeans Platform features are used here, including the visual library to draw optical and ethernet services, and all the core libraries to show an up to date network state and allow management functions to be performed against discovered equipment.

Monday Jan 30, 2012

Formatting & Highlighting of Javadoc Comments

Here's a completely new set of options in NetBeans IDE 7.1 for javadoc comments:

Wrapping the javadoc comments to justify them with the right editor margin is now also possible, so this very popular issue is now fixed:


The entire tab that you see above is new in 7.1. This new feature is also mentioned in the New & Noteworthy for NetBeans IDE 7.1.

Friday Jan 27, 2012

Hidden NetBeans Feature: Export Shortcuts to HTML

Here's another incredibly hidden NetBeans feature. If you go to Help | Keyboard Shortcuts Card, a PDF document pops up, listing all the keyboard shortcuts predefined in NetBeans. However, what happens when you change one of those keyboard shortcuts? Now that PDF document is out of date. Wouldn't it be handy if you could export the currently defined keyboard shortcuts to an HTML file? Then you'd have that as your reference document, rather than the statically defined PDF document that NetBeans provides.

Well, here you go, map this action to a keyboard shortcut and then you can print out all the current keyboard shortcuts:

So, specify a keyboard shortcut for "Export Shortcuts to HTML". Then, press the key combination you defined, and go to the user directory, i.e., ".netbeans/7.1" or whatever it is in your case. There, in the "config" subfolder, you'll find an HTML file has been created:

Open the "shortcuts.html" file and there you'll find all the current definitions of the keyboard shortcuts. Of course, if you've been reading this blog since 2005, where I blogged about this, then all this is not really news to you.

Thursday Jan 26, 2012

Upcoming NetBeans Feature: Generate Implementing/Extending Class!

Another upcoming NetBeans IDE feature, already in the daily builds, is this hint, which appears when you put the cursor in a class declaration:


When the hint is invoked, the new class, with all its required methods, is automatically generated, as a separate class (a dialog pops up letting you specify the name of the class and the package where the class should be created).

How handy these small enhancements can be!

This particular enhancement was included for 7.2 specifically because of a remark Arun Gupta made during Devoxx last year. That small discussion in a hallway resulted in this issue being highlighted and implemented:


Just pointing this out as yet further evidence that we're really listening to users and, between balancing the various requirements coming in from various sides, are making very sure that user requests are taken extremely seriously.

Wednesday Jan 25, 2012

Upcoming NetBeans Feature: Multi-Row Editor Tabs!

Several NetBeans users have been asking, for a long time already, for multi-row tabs in the NetBeans editor.

Read the list of use cases and requests around this area in the issue:


Today, Stan Aubrecht, the NetBeans Platform window system engineer, closed the above issue. Why? Because he fixed it. And it is part of NetBeans IDE 7.2. In the Options window, you'll see several new options in the Appearance tab:

Above, the "Tabs placement" and "Multi-row tabs" options did not exist before today. As you can see, not only will you be able to set multi-row tabs, but you'll also be able to set where the tabs should appear, whether they're multi-tab or not.

Here you see multi-row tabs, with "top" tab placement:

Multi-row tabs, with "bottom" tab placement:

Multi-row tabs, with "right" tab placement:

Of course, anyone creating their applications on the NetBeans Platform will automatically inherit this behavior too, if they're creating document-centric NetBeans Platform applications.

With this new level of flexibility, you're able to get even more comfortable in your development environment than before.

Thanks, Stan!

Tuesday Jan 24, 2012

Syntax Coloring for Clojure

Someone reading yesterday's blog entry might have thought: "OK. So you're not only able to create syntax coloring for some kind of trivial DSL. Yes, you're also able to do it for a real language, in this case, Ceylon. However, you caught a lucky break in that case, it's unlikely you'll be able to do it again for another real language."

Well, OK, take a look at this, my hypothetically sceptical imaginary friend:

What you see here is syntax coloring for Clojure (via the Clojure.g ANTLR file), created in about 45 minutes (Clojure turns out to have a lot less tokens than Ceylon), together with HTML embedding within Clojure comments. However, note that the embedding only supports syntax coloring, not code completion, not sure if that is possible nor how to do that.

Here's my embedding definition, i.e., this is all, no more or less than this:

@ServiceProvider(service = LanguageProvider.class)
public class HTMLEmbeddingLanguageProvider extends LanguageProvider {

    private Language embeddedLanguage;

    public Language<?> findLanguage(String mimeType) {
	return ClojureTokenId.getLanguage();

    public LanguageEmbedding<?> findLanguageEmbedding(Token<?> token, LanguagePath languagePath, InputAttributes inputAttributes) {
	if (11 == token.id().ordinal()) { //11 is the token ordinal in Clojure for comments
	    return LanguageEmbedding.create(embeddedLanguage, 0, 0);
	return null;

    private void initLanguage() {
	embeddedLanguage = MimeLookup.getLookup("text/html").lookup(Language.class);
	if (embeddedLanguage == null) {
	    throw new NullPointerException("Can't find language for embedding");


Soon I'll be working on a tutorial showing how to create syntax coloring for the Movie Query DSL I showed over the last two days.

Monday Jan 23, 2012

Syntax Coloring for Ceylon

Yesterday's blog entry was a "smoke test" for generating syntax coloring and anyone reading it might have thought: "Big deal. Syntax coloring for a trivial query language is trivial. Call us again when you've provided syntax coloring for a real language."

And, justifiably so, since the DSL used yesterday is obviously, and appropriately, pretty simplistic:

OK, fine. So how about this. Syntax coloring for Ceylon (http://ceylon-lang.org/), which is one of the new JVM languages, (read about it here on Wikipedia):

(I literally know nothing about Ceylon, copied the code shown above from here.)

What's handy about Ceylon is that you don't even need to generate the lexer. The ANTLR-based lexer (and the parser) is already in the com.redhat.ceylon.typechecker-0.1.jar. So then it's a question of weaving the Ceylon lexer with the NetBeans APIs, which [as I pointed out yesterday] is actually a trivial task.

And it's even a trivial task for a real language, as you can see. I spent about 2 hours on this and only because Ceylon has a lot more tokens than my simple 'smoke test' of yesterday did. And a lot of those two hours was spent getting the coloring right, i.e., I wanted the colors to have exactly the right shade of purple, green, etc, which took a bit of experimentation. You don't like my colors? Also fine. Change them in the Options window:

So, since I imagine there's now even more interest in this topic than there was yesterday, I'm going to make a screencast that shows how to do this, with an accompanying tutorial, and a list of references that especially focuses on the existing implementations of these NetBeans APIs, which are extremely useful when you need to customize your implementations slightly and diverge from the standard path.

Sunday Jan 22, 2012

Generate Syntax Colors for a Domain Specific Language

In about 15 minutes of work, without typing a single line of actual code, I created syntax coloring for the domain specific language described here.

The result in a JEditorPane (and notice the non-printable characters are displayed, optionally, too) is as follows:

The user of the application is able to customize the colors:

Again, I did not type a single line of code to create the above. It was all as simple as using a lexer generator (JavaCC in this case) and then connecting the generated files into 100% standard NetBeans Lexer API implementations. I.e., all copy and paste stuff, together with a small bit of configuration and tweaking.

If anyone is interested in step by step instructions for getting to the above, again, without doing any actual coding at all, please leave a message and, based on whether there is some demand for this, I'll write a tutorial describing the procedure for this particular domain specific language.

Update: Here is a YouTube movie describing step by step how to do the above, which I created because of comments below asking for a tutorial: http://www.youtube.com/watch?v=aOwdeoOlZ7E

Friday Jan 20, 2012

Hidden NetBeans Feature: Drag/Drop to Create HTML Snippets

Here's another super hidden NetBeans feature. Because of the inherent functioning of this feature, it is completely hidden and undiscoverable from the point of view of the NetBeans user interface.

The scenario is that you've got an HTML file open and you're typing something in there. The 'something' is something that you're likely to reuse within the same HTML file or other files, such as the META tags that you see highlighted below:

Now, as you can see, I have the part of the file that I'd like to reuse highlighted.

And then... I drag my mouse into the palette, i.e., the palette that you see on the right of the image above. And then, guess what? This dialog automatically pops up:

The "Content" section above is automatically filled in, based on what I dragged. The other fields and icons are things I fill in myself. Then I click "Add to Palette", at which point the HTML snippet is added into the palette, from where it can then be dragged into an HTML file, like any other snippet in the palette.

Handy, isn't it? And really hidden. (I blogged about this before here in 2008, where you also see a Java file equivalent.)

In other news. There are two excellent new NetBeans blogs out there! The first is NetBeans Ruminations by Hermien Pellissier from South Africa and the other is the NetBeans category of Crazy Java Hacking by Martin Skurla from Slovakia. Check them out! Their blog entries are also going to be visible in the NetBeans welcome screen, because they've been included in the planetnetbeans.org aggregator. You have a NetBeans related blog too? Leave a message here. And if you don't have a NetBeans blog too, why not start one?

Wednesday Jan 18, 2012

Hidden NetBeans Feature: Show Spaces in Editor

A really cool feature that I didn't know about until a few hours ago. Go to the main NetBeans menu bar and choose "View | Show Non-printable Characters". And now I can see the spaces in the editor:

The above is in the Java editor. Here is the HTML editor, with spaces:

Really handy to see the spaces (and the carriage returns, as well as the tabs). I made the above discovery while e-mailing with NetBeans Dream Team member Ryan de Laplante. He said that IntelliJ IDEA shows the spaces in the editor, while NetBeans doesn't. Some googling later, I found that NetBeans does, after all, have this support.

It appears that the spaces are visible in the editor for the first time in NetBeans IDE 7.1. At least, I invoked the same action as described above in 7.0.1 and then saw the carriage returns, but not the spaces. (And here's someone else who's found the same thing to be true.)

It's also possible to change the color of the non-printable characters, i.e., you could make them light grey. (But non-printable characters in HTML files do not change color as specified, so that's a bug.) Go to Tools | Options | Fonts & Colors and then go down the Category list until you find "Whitespace". Ryan commented on this that in IntelliJ IDEA "the non-printable characters are shown in a very light shade of grey so I can leave the feature turned on all the time and barely notice it unless I specifically want to look at it. In NetBeans I was able to change the color of the whitespace characters to a light grey too. That would be a nice default."

A second point that Ryan makes about the IntelliJ IDEA implementation of this feature is: "They don't show the line break character… they know that I'm only interested in whitespace characters. Maybe instead of enabling a 'Show non-printable characters' feature, I could enable a 'Show whitespace characters' feature."

And, finally, thus far, I've been unable to distinguish an EOL character from a carriage return (as also pointed out here).

But, clearly, aside from these quibbles, which I think would be nice enhancements for an upcoming release (see the list of issues I added in the comments to this blog entry), it's really great to see the spaces visibly in the editor. Makes it much easier to align one line with the next.

Other support for spaces include Tools | Options | General | Remove Trailing Whitespace, where you can specify under which condition (Never, Always, From Modified Lines Only) the last space, if any, should automatically be removed when the file is saved. Also, if you go to Tools | Options | Formatting | Java | Spaces, you can specify where a space should automatically be entered. (There's a similar option there where you can specify where a blank line, tabs, and indents should automatically be added, e.g., before/after methods, etc.)

NetBeans IDE: where the perfectly customized editor is only a space away...

Hidden NetBeans Feature: Search In Editor Selection

Probably this is obvious to many people, but when I first discovered it I was quite (pleasantly) surprised. When you select a section of code in an editor, you can search within that particular selection:

Here I selected a paragraph (which could have been anything, e.g., a block of code in the Java editor or a subset of words within a paragraph), then pressed Ctrl-F (which is "Find"), which puts my cursor in the small Find area in the bottom left of the screenshot above. Then I type "if", since that's the word I want to find and now, only within the selected text (e.g., not the "if" in the next paragraph above, since that paragraph wasn't selected), all the instances of the word "if" are found and then I can toggle forwards and backwards with F3/Shift-F3.

And all within whatever was selected when Ctrl-F was pressed. Then you can do a replace of all found items, i.e., only within a particular selection.

Tried and failed to do the same thing in IntelliJ IDEA Community Edition 10.5, while in Eclipse Indigo a Find/Replace dialog pops up with the "Scope" automatically set to "Selected Lines". So, in that respect, Eclipse appears to be better than IntelliJ IDEA, though I still prefer not having to use a dialog, which is what NetBeans supports, i.e., the Find/Search bar is integrated into the editor itself, as can be seen from the screenshot above.

Monday Jan 16, 2012

Ruby Development in NetBeans IDE 7.1

Yesterday Tom Enebo announced the availability of the community Ruby plugin for NetBeans IDE 7.1.

Installs without a hitch. Seems to work as one would expect. Here you see the Projects window showing a structured view of a Ruby sample project, together with the Ruby editor:

As always, start your development work by going to File | New Project and then select one of the Ruby or Ruby on Rails templates that have been registered there by the plugin.

Sunday Jan 15, 2012

Including a Native Terminal Window in a Java Desktop Application

A terminal window is handy to have in an application. Here's what you need to select in the "ide" cluster of your NetBeans Platform application:

Then click the Resolve button. Run your application and you'll see the new menu item highlighted below, which opens the terminal window, as can be seen here:

Friday Jan 13, 2012

Javeleon 2.0 Beta 3: Try It Today!

The NetBeans/Jmol project (which I've blogged about a few times already this week) has already proven its value! I was using Javeleon with it, discovered several problems, and reported them to Allan and the Javeleon guys. They downloaded the NetBeans/Jmol project and reproduced the bugs I had encountered.

Install Javeleon today, working for NetBeans IDE 7.1 and JDK 7:


Make sure you see this in your Plugin Manager, i.e., the plugin must be at version 2.0 Beta 3:

The bugs identified via the NetBeans/Jmol project have been incorporated into the above version of the plugin. For example, I can now change the annotation of a "position" attribute for a menu item for opening a TopComponent, i.e., this is an annotation in the TopComponent, reload the module, and then see the repositioned menu item. Another thing that the plugin is useful for is when you quickly want to prune some items from a layer file and want to immediately see the changes without going through the boring process of starting up your application all over again.

If you're a NetBeans Platform developer, whether on Ant or Maven, please try this plugin now, especially if you've tried it before, just to experience the improvements and report on other bugs you might encounter.

Wednesday Jan 11, 2012

NetBeans IDE 7.1 Community Translations

From today, go to the NetBeans IDE download page, make very sure to refresh (i.e., drop your browser cache), and you will see the list of supported languages for NetBeans IDE 7.1:

Note that also the community supported languages, e.g., German, are now in the list, in addition to the official languages supported.

If you choose German, or any other community supported language, you'll get one big download that includes all the localized JARs for all the translations (i.e., regardless of what you choose, you'll get all the languages), and then use "locale", e.g., "locale de" for German, at startup, and then you'll have your IDE start up in the language of your choosing, translated to the extent that it's been translated. For example, here's my German NetBeans IDE 7.1. Click to enlarge the image:

This should be pretty good news, among others for NetBeans Platform developers, who need to deliver their applications in multiple different languages.

Me on NetBeans in YouTube Video & Java Spotlight Podcast

About NetBeans IDE 7.1, its highlights and a discussion on its main features, and related topics, I was interviewed recently during JavaOne Latin America by Tori from the Oracle Technology Network:

And by Roger from the Java Spotlight Podcast:


Tuesday Jan 10, 2012

From JavaCC Grammar to NetBeans Code Editor

You can get pretty far without much coding, if you start off with a JavaCC grammar file and want to end up with an editor for your language, as these two new tutorials show:



These tutorials are based on some notes in the Wiki, created by various NetBeans Platform developers. That document should now be considered obsolete and the above two documents replace them.

More features will be described and the features described so far will be expanded. An ANTLR version of these tutorials is also in the works, though the majority of the above two tutorials, i.e., the parts describing integration with NetBeans editor features, is the same regardless of the parser/lexer generator you choose to use.

Though some parts are a bit basic, a lot of it has never been documented before. If there are parts that you know how to add in the context of the tutorials, please let me know and I will pass the sources on to you so that you can expand on them. Feedback is extremely welcome.

Update: Here's a YouTube movie to help you get started with the above!

Monday Jan 09, 2012

Jmol Gets a Window System and Loosely Coupled Capabilities

As you can see below, Jmol now has a window system, so that multiple molecules can be open simultaneously. Handy for viewing (e.g., the windows can be undocked from the frame of the application and moved around, also outside of the frame onto other monitors) and possibly also for molecular comparisons of various kinds:

But what's even cooler than that is the way the explorers on the left (i.e., the data providers) interact with the editor windows (i.e., the Jmol viewers). Here I've implemented the "capability pattern", which enables the two sides of the relationship to not need to know anything about each other, aside from the capabilities that one side publishes and to which the other side is subscribed.

So, I have two capabilities involved in this particular scenario:

package org.netbeans.jmol.api;
public interface LoadScriptCapability { 
    String getName();
    String getScript();
package org.netbeans.jmol.api;
public interface OpenCapability { 
    void open();

The above two interfaces are in an API module, which the other modules all depend on.

And here's the definition of one of the Nodes you see on the left hand side, i.e., a data provider leaf node representating a single molecule:

public class ProteinNode extends BeanNode {
    private ProteinLoadScriptCapability plsc = new ProteinLoadScriptCapability(); 
    public ProteinNode(String bean) throws IntrospectionException { 
       this(bean, new InstanceContent());
    public ProteinNode(String bean, final InstanceContent ic) throws IntrospectionException {
        super(bean, Children.LEAF, new AbstractLookup(ic)); 
        ic.add(new OpenCapability() { 
            public void open() { 
                 StatusDisplayer.getDefault().setStatusText("Opened: " + getDisplayName());
    private class ProteinLoadScriptCapability implements LoadScriptCapability {
        public String getScript() {
            return "var xid = _modelTitle; if (xid.length != 4) { xid = '"
                    + getDisplayName()
                    + "'};load @{'=' + xid}";

       @Override         public String getName() {             return getDisplayName();         }     } @Override     public Action[] getActions(boolean context) {         List<? extends Action> jmolActions = Utilities.actionsForPath("Actions/JMol/Leaf");        return jmolActions.toArray(new Action[jmolActions.size()]);     } }

So, as you can see below, the Action (which is on the Node above) will be enabled because its context, which is the Node, has an OpenCapability in its Lookup. When the "open" method is invoked,  which is when the ProteinLoadScriptCapability is added to the Lookup of the Node, which is the selected Node, which thus publishes that capability, which is the capability that the display TopComponent (i.e., the Jmol viewer) is listening for, the display TopComponent is able to get hold of the published Jmol script provided by the capability and can then render it.

So "opening", below, means nothing more than publishing a capability which the display TopComponent is prepared to handle. And as soon as the capability is published, it needs to be removed again from the Node's Lookup, otherwise when you scroll up and down and get back to that same Node (i.e., you select that same Node again), it will be rendered all over again, which is not what you want in this scenario, since here the Action, and only the Action, should cause the rendering to take place.

@ActionID(category = "JMol/Leaf",
id = "org.netbeans.jmol.explorer.LoadScriptAction") 
@ActionRegistration(displayName = "#CTL_LoadScriptAction")
@Messages("CTL_LoadScriptAction=Load Script")
public final class LoadScriptAction implements ActionListener {  
    private final OpenCapability context;
    public LoadScriptAction(OpenCapability context) {
        this.context = context; 
    public void actionPerformed(ActionEvent ev) {

What you end up with is a cascading set of capabilities—once the OpenCapability is retrieved from the Lookup and "open" is called, the ProteinLoadScriptCapability is added to the Lookup, at which point the loosely coupled display TopComponent receives a notification that it needs to open itself and render a script. It's really powerful and simple and results in a loosely coupled viewer/editor relationship.

Sunday Jan 08, 2012

Pluggable Data Providers for Jmol

Wouldn't it be cool if you could plug new windows into Jmol, each providing access to a different database, or any other kind of data source, from which the provider would create its own Jmol script? One data source could provide a list of proteins, another a list of generic molecules, and yet another some other kind of subset of data relevant to Jmol. Then, the display window would detect when a new item in a data provider has been selected, which would result in the publication of a new script provided by the data provider for the selected item. Receiving notification of the published script, the display window (with its backing code for processing scripts) would process the script and render it. 

The above concept is now part of the Jmol/NetBeans application that I'm working on. Below, you see two data providers, one is the Protein Data Bank (rcsb.org) and the other is from a list of modules extracted from reciprocal.net. (You can also see that the Jmol output is shown in the Output Window of the new Jmol application below.) 

I have put the sources here, but you cannot access it, yet, at the time of writing, because the project has not been approved and published yet by java.net:


Once the site is approved, you can create your own data providers, which need to somehow provide a Jmol script, at which point the selected item will be rendered in the display area in the main part of the application.

Saturday Jan 07, 2012

Jmol on NetBeans Platform

Here's Jmol, an open-source Java viewer for chemical structures in 3D, on the NetBeans Platform, benefiting from its module system, extensibility, loose coupling, windowing management, and ecosystem (e.g., now you can install space invaders from plugins.netbeans.org into Jmol). And I imagine that other NetBeans Platform applications, such as Instant JChem, might find it interesting to have Jmol plugged into their application too, which is now completely possible. 

The left hand side, i.e., the list of proteins, is obtained live from the Protein Data Bank, which is what we did during the recent NetBeans Platform course in Amsterdam. Then I continued working on it via the old POV-Ray tutorial, which I am updating to NetBeans Platform 7.1. (It is still currently on Sang Shin's Javapassion.com page, but will eventually be removed from there once it has been updated on netbeans.org). Then I ended up abandoning that approach since Jmol has embedded POV-Ray, so that the whole process of downloading POV-Ray and running it externally isn't necessary at all. So then it was a question of embedding the JMolPanel in a TopComponent and passing the name of the Node to the Jmol script.

Still a lot of cleaning up to do. Once the architecture is reasonably stable, I'll set up a hacking session in an Amsterdam pub, where all the participants can each work (or in pairs) on various features which can all be contributed via independent modules. For example, Jmol has heaps of export formats and renderers, so each of those could be developed independently once a general architecture has been set up.


Geertjan Wielenga (@geertjanw) is a Principal Product Manager in the Oracle Developer Tools group living & working in Amsterdam. He is a Java technology enthusiast, evangelist, trainer, speaker, and writer. He blogs here daily.

The focus of this blog is mostly on NetBeans (a development tool primarily for Java programmers), with an occasional reference to NetBeans, and sometimes diverging to topics relating to NetBeans. And then there are days when NetBeans is mentioned, just for a change.


« January 2012 »