Open source Java projects: NetBeans plugins

Five plugins to enhance your NetBeans development experience

The NetBeans IDE is pretty good on its own, but even handier once you start extending it with plugins specific to your needs. In this installment of Open source Java projects, Jeff Friesen introduces you to NetBeans plugins that let you view the NetBeans filesystem, explore pictures on Windows systems, check code for standards compliance, add properties to Java classes, and make OpenGL development easier. All that is just a start, though, as you'll also learn how to create your own NetBeans plugin for accessing the NetBeans API Javadoc. Level: Intermediate.

Earlier this year, I used NetBeans IDE 6.1 with JavaFX (part of the Sun Microsystems JavaFX Preview SDK) to develop the examples for my Jump into JavaFX series on JavaWorld. While playing with the IDE, I encountered the topic of plugins -- modules that install themselves into NetBeans to extend it with new features such as a Google search toolbar.

This article introduces you to five of the many open source NetBeans plugins that you can download from the NetBeans Plugin Portal. You'll discover each plugin's purpose, its open source license, and the platforms that the plugin targets. You'll also briefly tour each plugin in NetBeans IDE 6.5, which I assume you've installed. Lastly, you will see how to create your own plugin for accessing the NetBeans API Javadoc.

At the end of this article you will have learned about five useful plugins. Moreover, you'll be familiar with the NetBeans plugin architecture and with the steps for creating your own plugins.

File System Displayer: View the NetBeans filesystem

The NetBeans system filesystem is the central repository for NetBeans configuration data. The File System Displayer plugin, created by NetBeans expert Geertjan Wielenga, lets you view the NetBeans system filesystem from within the IDE. This plugin is licensed under the Common Development and Distribution License (CDDL) and targets the Solaris, Linux, Mac OS X, and Windows platforms.

The module foundation

NetBeans is based on modules -- software components for providing applications or the IDE with various features. These components are distributed as NetBeans Module (NBM) files, which are JAR files containing sets of classes that provide the features, as well as manifest information for identifying these archives to NetBeans as modules.

Download the 1226158890776_org-demo-fsdisplayer.nbm module file by clicking the Download button on the File System Displayer detail page. Then start NetBeans 6.5 (if the IDE isn't already running), and complete the following steps to install this plugin into the IDE:

  1. Select Tools > Plugins from the main menu to open the Plugins dialog box.
  2. Switch to the Downloaded tab on the Plugins dialog box.
  3. Click the Add Plugins button.
  4. In the Add Plugins file chooser, navigate to the folder containing the downloaded 1226158890776_org-demo-fsdisplayer.nbm file. Select this file and click Open. The File System Displayer plugin will show up in the list of plugins to be installed.
  5. Click the Plugins dialog's Install button.
  6. On the resulting NetBeans IDE Install dialog box, click the Next button, followed by the Install button. You should see a Validation Warning dialog box stating that the plugin is unsigned. Skip this warning by clicking the dialog's Continue button.
  7. Once installation completes, click the Finish button on the NetBeans IDE Install dialog, followed by the Close button on the Plugins dialog.

After installation, NetBeans presents the plugin's FsDisplayer Window explorer window component, which displays the hierarchy of configuration data that appears in Figure 1.

FsDisplayer Window appears alongside the Projects, Files, and Services tabs.
Figure 1. FsDisplayer Window appears alongside the Projects, Files, and Services tabs. (Click to enlarge.)

At runtime, the filesystem is composed of information located in each module's XML-based layer file. A layer file defines folders and files to be merged into the system filesystem. Other modules can store files or objects in these folders; the defining module can scan each folder's contents and do whatever it likes with the contents.

PicturesExplorer: View images on Windows

Kunal Modi's PicturesExplorer plugin lets users of Windows XP (and presumably other Windows versions) view the contents of their My Pictures folder within NetBeans; you don't need to leave the IDE to open a picture viewer. This plugin is licensed under version 2 of the GNU General Public License (GPL).

Download PicturesExplorer's 1202697173670_org-modules-sack-picturesexplorer.nbm module file by clicking the Download button on the PicturesExplorer detail page. Then install this plugin via the same steps for installing File System Displayer. Once it's installed, select Pictures from the Window menu to display the Pictures Window with its My Pictures contents.

You can zoom into the currently displayed picture by clicking the zoom bar's plus (+) button and zoom out by clicking the minus (-) button, as shown in Figure 2.

Use the zoom bar to zoom into or out of a picture.
Figure 2. Use the zoom bar to zoom into or out of a picture. (Click to enlarge.)

Additional buttons let you restore the picture to its original size (1:1), select a zoom-out or zoom-in preset (1:3 through 7:1), select a custom zoom level (X:Y), and display a grid when zooming in (#).

Checkstyle 4.3 plugin: Check code for standards compliance/h2>

Checkstyle helps you write Java source code that obeys a given coding standard. This tool automates the task of checking code for standards compliance, relieving you of the tedium of manually performing this task. Checkstyle is available to NetBeans via Andrea Matsunaga's Checkstyle 4.3 plugin, which is licensed under GPL version 2. It targets the Solaris, Linux, Mac OS X, and Windows platforms.

Open source licenses

Each of the open source Java projects covered in this series is subject to a license, which you should understand before integrating the project with your own projects. In the case of this article, each NetBeans plugin has its own license.

From the Checkstyle 4.3 detail page, click the Download button to download the 42267_com-ammatsun-checkstyle4nb-4.3.1.nbm module file. Then install the plugin via the same steps you used for the previous two plugins. Once it's installed, select any Java source file and click the Checkstyle icon (the main toolbar's rightmost icon) to check this code, as shown in Figure 3.

Click the Checkstyle icon to check the style of the current Java source file.
Figure 3. Click the Checkstyle icon to check the style of the current Java source file. (Click to enlarge.)

Although Checkstyle defaults to Sun's Java code conventions, you can make Checkstyle support a different coding standard by selecting Tools > Options, and then selecting the appropriate Checkstyle configuration and properties files from the Options dialog box's Checkstyle tab. For information on developing new coding standards in Checkstyle, take a look at the Checkstyle documentation.

Add Property: Add properties to Java classes

Many developers expect Java SE 7 to introduce new language features, and one possibility is properties. If you perform a Google search for "java 7 property" you'll discover that this topic has been widely discussed, and that ideas abound about what form the syntax should take. While we wait to see what happens with properties support in Java SE 7, check out Sandip V. Chitale's Add Property plugin.

Add Property is licensed under the CDDL and targets the Solaris, Linux, Mac OS X, and Windows platforms. It simplifies adding properties to Java classes. Visit this plugin's detail page, and click the Download button to download the 1198476035439_org-netbeans-modules-java-addproperty.nbm module file. Follow the same steps as before to install this plugin.

Let's play with Add Property. Start the New Project wizard and introduce a new Java application project named Employee. Leave the project's package set to employee and the main class set to Main. The resulting skeletal application code is similar to that shown in Figure 3.

Next you'll introduce a name property for the employee's name. Select Source >Add Property, and then specify name in the Name field of the resulting Add Property dialog box. Figure 4 presents this dialog box, which reveals what the generated property's code looks like.

The property type defaults to String.
Figure 4. The property type defaults to String. (Click to enlarge.)

Click OK to insert the code at the caret position. If the caret position is located outside of the class, the resulting code won't compile. In that case, you'll need to undo the insert via Edit > Undo, reposition the caret, launch the Add Property dialog box, and click its OK button. This dialog box remembers the previous settings.

Add Property lets you perform a wide range of customizations. For example, you can create a bound property. If you require a special customization that's not supported (perhaps you wish to prefix your property declarations with a certain annotation), you'll need to modify the boilerplate template. Follow these steps to access this template:

  1. Select Tools > Templates.
  2. In the resulting Template Manager dialog box, select and expand the org.netbeans.modules.java.addproperty template category folder.
  3. Select the AddProperty.freemarker template under this folder, and click the Open in Editor button.

Figure 5 shows a portion of the template.

The template includes special ${identifier} placeholders and HTML-like <#if> tag blocks.
Figure 5. The template includes special ${identifier} placeholders and HTML-like <#if> tag blocks. (Click to enlarge.)

Figure 5 reveals various ${identifier} placeholders, where identifier names a special variable. Each placeholder's value is inserted into the generated code. For example, the String value in the Type field of Figure 4's dialog box would be inserted into the generated code via the ${type} placeholder.

Figure 5 also reveals various <#if identifier> tags, where identifier names a special variable. The variable's value is used in a Boolean expression to determine if the code between <#if identifier> and </#if> should be inserted into the generated code. For example, <#if static >static </#if> inserts static into the generated code if the static checkbox is selected.

Although Figure 5's template is fairly easy to follow, here are a few more examples to facilitate your understanding:

  • ${access} inserts the selected private, protected, or public radio button's name into the generated code. Nothing is inserted if package is selected.
  • The following example inserts Javadoc into the generated code whenever the Generate javadoc checkbox is clicked. Each of the two occurrences of ${name} within the Javadoc is expanded to the name of the property (as entered into the Name field):
    <#if generateJavadoc >
        /**
         * Get the value of ${name}
         *
         * @return the value of ${name}
         */
    </#if>
    
  • return <#if !static >this.</#if>${name}; inserts the this. prefix (if the static checkbox is not selected), followed by the property's name and a semicolon, into the generated code.

NetBeans OpenGL Pack: Ease OpenGL development

My previous article in this series, "Open source Java projects: Java Binding for OpenGL (JOGL)," introduced 3D graphics by way of Sun's JOGL technology. While writing that article, I developed my JOGL demos at the command line. If I had known about the NetBeans OpenGL Pack plugin, I would have developed them in NetBeans instead.

Michael Bien introduced NetBeans OpenGL Pack to provide an easy-to-use OpenGL development environment that's integrated into NetBeans. This plugin provides several modules, such as an OpenGL Shading Language (GLSL) shader editor and an OpenGL capabilities viewer, It also includes ready-to-run JOGL demos and all OpenGL samples from the OpenGL Programming Guide (also known as the Red Book). NetBeans OpenGL Pack is licensed under the GPLv2 with Classpath Exception license. It targets the Solaris, Linux, Mac OS X, and Windows platforms.

Download NetBeans OpenGL Pack's 227048417356_netbeans-opengl-pack_0.5.3.zip archive by clicking the Download button on the NetBeans OpenGL Pack detail page. After unzipping this archive, you'll discover several NBM files. You must select all these modules before installing them, as shown in Figure 6.

Click the Install button to start installing all of the selected modules.
Figure 6. Click the Install button to start installing all of the selected modules. (Click to enlarge.)

After installing NetBeans OpenGL Pack, you can immediately try out any of the OpenGL demos in NetBeans. For example, start the New Project wizard and (as shown in Figure 7) expand the OpenGL category folder, select the Demos subcategory folder, and select the JOGL Hardware Shadow Mapping Demo project.

Select a JOGL demo and then click the Next button.
Figure 7. Select a JOGL demo and then click the Next button. (Click to enlarge.)

After you click Next and (on the subsequent panel) Finish, NetBeans creates a new project based on the selected demo. As Figure 8 reveals, you can view and edit the demo's source code, and compile and run the demo (by clicking the green triangle button in the main tool bar, or by pressing the F6 function key).

You can easily edit, compile, and run JOGL demos in NetBeans.
Figure 8. You can easily edit, compile, and run JOGL demos in NetBeans. (Click to enlarge.)

Roll your own plugins

After trying out the previously discussed NetBeans plugins and others that you download from the NetBeans Plugins Portal, you'll probably want to create your own. If you're new to this task, you might find it somewhat intimidating. Fortunately, NetBeans greatly simplifies plugin development.

1 2 Page
Recommended
Join the discussion
Be the first to comment on this article. Our Commenting Policies
See more