Porting Kirk Pepperdine to the NetBeans Platform III
In my day job I’m right now tuning a java library that performs statistical analysis on very large data sets, and it would be great to have Peppy around to speed this up. So let’s get started:
In the last part of this series we have added a resizeable Balloon panel. Now we want to display real hints. First we need to create a list of hints and add some hyperlinks for further readings. The simplest solution is to have a properties file. For a start I wanted to display random hints, so we are using numbers as the keys, so we can easily use a random number to choose from them. Here’s my file:
# Sample Tips properties file
0=It looks like you're tuning an application.<br><br><a href="http://www.javaperformancetuning.com/">Do you need help?</a>
1=Use the final modifier on instance-variable definitions to create immutable internally accessible objects.<br><a href="http://www.oreilly.com/catalog/javapt/chapter/ch04.html">more...</a>
2=Use private and static methods, and final classes, to encourage inlining by the compiler.<br><a href="http://www.oreilly.com/catalog/javapt/chapter/ch04.html">more...</a>
3=ArrayList is faster than Vector except when there is no lock acquisition required in HotSpot JVMs (when they have about the same performance).<br><a href="http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.html">more...</a>
4=Vector and ArrayList implementations have excellent performance for indexed access and update of elements, since there is no overhead beyond range checking.<br><a href="http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.html">more...</a>
5=Adding elements to, or deleting elements from the end of a Vector or ArrayList also gives excellent performance except when the capacity is exhausted and the internal array has to be expanded.<br><a href="http://www.onjava.com/pub/a/onjava/2001/05/30/optimization.html">more...</a>
I’ve put it in a resources folder in my sources. Now we need to have the functionality to let Peppy display these hints. So first lets load the properties file, modify PeppyPanes constructor and add two variables like this:
private Random randomGenerator;
private Properties hints;
/** Creates new form PeppyPane */
public PeppyPane() {
initComponents();
setOpaque(false);
hints = new Properties();
try {
hints.load(PeppyPane.class.getResourceAsStream("/de/eppleton/pepperdine/resources/hints.properties"));
} catch (IOException ex) {
ex.printStackTrace();
}
randomGenerator = new Random(System.currentTimeMillis());
}
We want to display a different tip everytime Peppy shows up, so lets override setVisible:
public void setVisible(boolean aFlag) {
if (aFlag) balloonPanel1.setText( hints.getProperty(""+randomGenerator.nextInt(hints.size())));
super.setVisible(aFlag);
}
Do you see how efficient this is done? We’re only changing the text, when aFlag is true. Dude, this is going to be fast as lightning… Now we only need to get these hyperlinks to work. Shouldn’t be that hard, as NetBeans ships with a URLDisplayer. In the constructor of balloonpanel add this after the call to setText:
advicePane.setText("<html background=#ffffc6>It looks like you're tuning an application.<br><br>Do you need help?</html>");
advicePane.addHyperlinkListener(new HyperlinkListener() {
public void hyperlinkUpdate(HyperlinkEvent e) {
try{
if (e.getEventType() == EventType.ACTIVATED)URLDisplayer.getDefault().showURL
(e.getURL());//NOI18N
} catch (Exception eee){
return;
}
}
});
And here we are, Peppy giving us useful tips on how to tune our applications:

Now you can follow the hyperlink to see the details in your browser.
Geertjan had some great ideas on how to go on with Peppy, like having other experts around for different tasks, like Roman Strobl giving you the tip of the day on how to use the IDE, or Greg Murray giving AJAX tips, or Heinz Kabutz could give tips from his Java Specialists’ newsletter… We even could have a framework to let people provide their own Peppys. Imagine James Gosling, Geertjan Wielenga and Romain Guy at your fingertips to help you programming. For a start, you now know the format, so if you would like to contribute: send me a gif (with transperency, the gimp is great for that) of your favorite programming guru and a properties file with some hints (in a zip-file to epple genomatix de), so I can try to create a framework and already include some Peppys right from the start :). And imagine the honor of receiving a “you’ve been ported” mail yourself :).






and a second one just above to display a message:


