My entry for Geertjan’s first annual “Will Code HTML for food” competition
Archiv für die Kategorie ‘clippy’
Will Code HTML for food
Samstag, 26. April 2008Porting Kirk Pepperdine to the NetBeans Platform
Samstag, 14. Juli 2007I just returned from the Münchner Viktualienmarkt Biergarten where I had met Geertjan. He really is a Sun guy: he didn’t even want a table in the shadow when it was like 35 degrees celsius. Geertjan has started to port Kirk Pepperdine to the NetBeans Platform, and I think this is a great project, so I decided to contribute. Geertjan has already found a perfect name for my subproject. So say goodbye Clippy, for here comes PEPPy ( obviously this is an acronym for Performance Enhancement Personal Pundit)!
update: I confess, this is a pure backronym
Lets create the module (New Project-> Netbeans Plug-in Modules -> Module Project). Make it a standalone and add a Window component (New File -> NetBeans Module Development -> Window Component). We will use this window to launch Peppy. In the designer of your TopComponent (mine is called “SomeTopComponent”) add a JTextArea, select it and go to events. Click on the keytyped, and add a new Handler (call it “PepperdineHandler”).
To show Peppy above all other components in NetBeans we will need to get hold of the glasspane. In Winston Prakash’s blog I found information on how to get hold of the glasspane in NetBeans. So first we will create a GlassPane. You can take any component for this. We will use a JPanel (New File-> Java GUI Forms -> JPanel Form). Add a JLabel to the lower right corner with an image of a performance guru like this one:
and a second one just above to display a message:

You can change the second one to display a different message, or add a more elaborate component, but for a first shot this will be fine. Set your JPanel to be transparent by adding this to the constructor:
/** Creates new form PeppyPane */
public PeppyPane() {
initComponents();
setOpaque(false);
}
Now we will add this as the GlassPane to NetBeans, add this variable to your TopComponent:
private static PeppyPane glassPane = new PeppyPane();
and set it as the GlassPane in the constructor:
private SomeTopComponent() {
initComponents();
final JFrame mainWin = (JFrame) WindowManager.getDefault().getMainWindow();
mainWin.setGlassPane(glassPane);
setName(NbBundle.getMessage(SomeTopComponent.class, "CTL_SomeTopComponent"));
setToolTipText(NbBundle.getMessage(SomeTopComponent.class, "HINT_SomeTopComponent"));
// setIcon(Utilities.loadImage(ICON_PATH, true));
}
As you know the Microsoft Assistant had a very elaborate AI to pop up exactly when you need it, and only then. So it must be hard to model this behavior, right? Believe it or not: Sun has already implemented this exact behaviour in the java language
. So all you’ve got to do is add one variable to the TopComponent:
private Random randomGenerator = new Random(System.currentTimeMillis());
and implement your PepperdineHandler method:
private void PepperdineHandler(java.awt.event.KeyEvent evt) {
if (randomGenerator.nextInt()%37==0)
glassPane.setVisible(!glassPane.isVisible());
}
And here we are, Kirk Pepperdine at your service:

Be sure to tune in next time when captain Kirk says “It looks like you’re tuning an application. Do you need help?”
