Wednesday Sep 30, 2009

NetBeans tip: Notifications using the Dialogs API

The standard code used to display a dialog in NetBeans is:

DialogDescriptor dd = new DialogDescriptor(new UIPanel(), "UI Panel" ) ;
Dialog dlg = DialogDisplayer.getDefault().createDialog(dd);
dlg.setVisible(true);

This uses the DialogDescriptor and DialogDisplayer classes from the Dialogs API. You end up a dialog which looks like the image below.

Standard UI Panel

However, what if you want to display some notification messages to the user? NotificationLineSupport to the rescue. Just create a notification line (code highlighted below) and add your message.

DialogDescriptor dd = new DialogDescriptor(new UIPanel(), "UI Panel" ) ;
NotificationLineSupport supp = dd.createNotificationLineSupport();
Dialog dlg = DialogDisplayer.getDefault().createDialog(dd);
supp.setInformationMessage("Sample Information Message" ) ;
dlg.setVisible(true);

The result is a dialog like the one shown below:

UI Panel with notifications

You can show informational messages, error messages and warning messages. However, displaying an error or a warning message does not disable the OK button. For that you will have to call the setValid() method.

Saturday Jul 25, 2009

How to display the NetBeans font chooser.

Since I have been going after some low hanging fruits in fixing some Python support related issues in NetBeans, strictly over weekends (without the knowledge of my wife who prefers my MacBook Pro being 2000 miles away from me on weekends), I ran into an interesting issue where I had to display the NetBeans font chooser instead of a custom font chooser being used in the code. Unable to find the proper API (perhaps I am dumb), I waded into the NetBeans sources, and found the way out. Blogging about this here to save some poor soul some time when the need arises.

PropertyEditor pe = PropertyEditorManager.findEditor (Font.class);
DialogDescriptor dd = new DialogDescriptor (
    pe.getCustomEditor(),
    "Some Title"  // NOI18N
);

DialogDisplayer.getDefault ().createDialog (dd).setVisible (true);
if (dd.getValue () == DialogDescriptor.OK_OPTION) {
    font = (Font) pe.getValue ();
}

It just boils down to getting a property editor for Font and then wrapping the panel inside a dialog box using the NetBeans DialogDisplayer API.


Tuesday Jun 24, 2008

A better look

I am a big Ubuntu fan, and always feel a bit sad when I have to upload my new and noteworthy screenshots next to the swanky and sleek screenshots of people on a Mac on the NetBeans wiki (look at the Spring framwork support section here).

However after some digging around I finally got a font combination that looks pretty neat to my eyes. Here's a screenshot with the default font in NetBeans 6.1 running on Ubuntu 8.04:

And here's after I changed the font to Bitstream Vera Sans Mono 12 pt:

The second one is much better for my eyes (atleast). Any other good combinations out there folks?

Font Settings:


Monday Apr 07, 2008

Some nifty XML editing add-ons

It was a long weekend here in India, and that provided me some time to add some shortcuts which will help users who author XML documents using NetBeans. I wrote a plugin which will add some context sensitive actions to the XML editor. I have just managed to add one action (Delete current attribute), but more are on the way. Actions planned are:

  • Jump to parent tag
  • Jump to next sibling tag
  • Jump to previous sibling tag
  • Jump to end tag (if at start tag)
  • Jump to start tag (if at end tag)
  • Jump to next attribute in a tag
  • Jump to previous attribute in a tag
  • Delete current tag (alongwith children)
  • Delete current attribute (alongwith it's value)
  • Delete value
  • Expand a short tag <a/> into the longer form <a></a>
  • Condense an empty tag <a></a> into it's shorter form <a/>

I am planning to upload the module on the Plugin portal soon. For now, here's a screen shot:

Before the action was selected:

After the action was selected (notice the name attribute is gone):


Monday Feb 25, 2008

XML and NetBeans

NetBeans never boasted of a good editor as compared to IntelliJ IDEA and Eclipse, but things took a complete turn when NetBeans 6.0 came out. And now that NetBeans has conquered Java developers with the shining new editor, NetBeans is going gung-ho for Groovy, Scala, Erlang and what not. Though I totally agree to Groovy and Scala becoming first class citizens in the NetBeans world, I personally feel that NetBeans needs to do something about nicely editing a 10 year old thing - XML.

Why, you might ask. Well, whatever web frameworks I have dealt with, Struts, Struts2, Spring MVC, JSF, require reasonable amount of configuration in XML. Hell, even many non web applications seem to use Spring and it's XML configuration files. Though the deal is now seeming in favor of POJOs with annotations, I don't think developer authored XML is dead, by any means.

In a series of upcoming posts, I plan to compare the XML editing landscape in Eclipse, IntelliJ IDEA and NetBeans. IMO, NetBeans has the weakest XML editor story, but I plan to make a wishlist out of this, hopefully someone will come along and take XML editing in NetBeans to new heights.
 

Tuesday Dec 11, 2007

NetBeans Module: XML Breadcrumbs

I was trying out IntelliJ IDEA 7.0 and came across the XML breadcrumbs feature. The breadcrumbs bar tracks the current position of the cursor in the XML tag hierarchy.

 

It would be so nice to have this in NetBeans. So here it is (sources to be uploaded soon):
 

Friday Nov 30, 2007

A smarter XML completion in NetBeans - Part II

After my last adventure with XML code completion, I am ready for one more nifty add-on. This one is straight from Eclipse XML editor. When you request completion for an attribute in an XML tag, you might want to add the default value (by default). Such a thing is not provided by NetBeans. However, as with yesterday's hack, this one is mighty easy to do.

If you have followed yesterday's post, you know where the sources of the schema aware code completion module reside. When we type CTRL+SPACE for invoking code completion for attributes of a tag, we get a list of org.netbeans.modules.xml.schema.completion.AttributeResultItem objects, each one representing a possible attribute that can belong at the position where completion was invoked. I make the following modifications to the code.

First, I need to find if there is a default value for the particular attribute. So, I add the following code to the constructor of AttributeResultItem:

 

The getDefaultValue() method is as given below: 

 

 One final thing. The getReplacementText() method needs to be modified.

 

That's it. Now, when you invoke code completion for attributes (after you have compiled your changes and re-run the development IDE), you can see the attributes with their default values.

 

 

More XML completion fun to come in the next post! 

Wednesday Nov 28, 2007

A smarter XML completion in NetBeans - Part I

If you are used to heavily editing XML files in NetBeans, you would have wished for the code completion assistance to be a bit smarter. As an example, let us take the case of editing a Spring Framework Beans Configuration file. I want to add an <alias> tag to the XML configuration file. This tag has two required attributes: name and alias. It all starts by invoking the code completion assistance by typing in '<'. The following dialog shows up:

 

When I select the alias tag and hit Enter, the completion assistance just puts in the tag name:

To insert the attributes I have to again press CTRL + SPACE:

 

If the code completion were a bit smarter, it would insert the required attributes as well. I mean, why will anyone use a tag without using the required attributes? Anyway, NetBeans doesn't offer this feature, so I decided to do some hacking.

I downloaded the NetBeans sources and opened up the module project for the Schema based code completion in NetBeans (NB_SRC_ROOT/xml/schema/completion)

 

 

The items displayed in the completion assistance popup are implemented in ElementResultItem.java and AttributeResultItem.java. Since I want additional text to be added when the user wants to add a new XML tag (element), I will modify the ElementResultItem.java. I modified the constructors of the class to add the additional text:

 

I needed to override a method to return the new text to the completion infrastructure.

 

That's it. Now I built NetBeans, and run the same scenario for code completion, and here's what I see:

 

Notice the required attributes appearing alongwith the end tag (another nifty thing which the current XML code completion misses). Now pressing Enter gives me the tag complete with it's required attributes and end tag.

 

The hack still needs some work, but you can see the point. If there is something you want in NetBeans, just dig through the sources and modify it and contribute it back to the community. This in my mind is the single most advantage of using an Open Source tool.

 

Monday Nov 26, 2007

NetBeans Module: Close other projects

Many a times, we have many projects open in the IDE and we want to close all of them, except one. The usual way in such a case is to select all the project nodes using CTRL+A and right click and select "Close XX Projects" action and then re-open the project that you wanted to keep open. Or else, you can select all projects using CTRL + A and then unselect the project you want to keep open and then invoke "Close Projects" action.

 

I am a programmer, I am supposed to be lazy. So here's my little creation, an action which lets you close all other projects apart from the selected one. Select a project which you want to keep open, and click File -> Close other projects.

 

I have uploaded it to the Plugin Portal, and you can download the sources from here.

If you are like me, developing NetBeans modules, then you will like this module. I developed this one in 10 minutes!

Sunday Sep 02, 2007

NetBeans 6.0 Beta 1 - soon!

I have been waiting for this for a long time. I was at http://www.netbeans.org downloading another nightly build and what do I see? Look at the red rectangle. The links don't work (yet).

 

The intrepid Netbeans.org guys are at work :)
 
The Beta 1 is coming soon! Hurray!

Sunday Aug 26, 2007

Netbeans 6.0 getting an identity of it's own

I have been playing around with the nightly builds of NetBeans 6.0 for about a month now, mainly to keep my Struts2 plugin code up to date with the changes in Netbeans 6.0. I tried out the latest nightly and was pleasantly surprised to find some cool UI upgradations in Netbeans. Netbeans 6.0 is definitely getting a look of it's own, and identity separate from it's ancestors (Netbeans 5.x). I absolutely love the new UI work, though it resembles Vista in some ways. But it's real good nonetheless. Here are some major areas that have been "upgraded" (apart from the well known by now, Welcome Screen):

1. The about dialog. 

 

2. The application icon (in the window and in the tray). 5.x carried a rather dull improper resolution icon for Netbeans. This one is pretty neat. 


 

 

3. The splash screen. What a terrific mix of colors. Really good stuff 

 

 

 

4. The installer looks really neat. 

 

 

 

 

 

 

Tuesday Mar 13, 2007

Dilbert in Netbeans!

Out of profound imagination (or the sheer lack of it), I have created a plugin in Netbeans for reading the Daily Dilbert strip from http://www.dilbert.com. Here's what it looks like:

This module reads the Dilbert Daily archive and does some HTML scrapping to retrieve the images. Counting the total time taken for trial and error, it took me an hour to get it in shape.

After doing some basic code cleanup and implementing a couple of 'features', I will post the modules here for my programmer brethren.

 

Enjoy! :)

Dilbert Plugin

About

Rohan Ranade's musings on anything and everything.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today