Friday Feb 08, 2013

Display JavaHelp In Browser Instead Of JavaHelp Window

Thanks to Henry Arousell and Jaroslav Havlin:

import java.net.URL;
import javax.swing.event.ChangeListener;
import org.netbeans.api.javahelp.Help;
import org.openide.awt.HtmlBrowser.URLDisplayer;
import org.openide.util.HelpCtx;
import org.openide.util.lookup.ServiceProvider;
import org.openide.util.lookup.ServiceProviders;

@ServiceProviders({
    @ServiceProvider(service = HelpCtx.Displayer.class,
            supersedes = {"org.netbeans.modules.javahelp.JavaHelp"}),
    @ServiceProvider(service = Help.class,
            supersedes = {"org.netbeans.modules.javahelp.JavaHelp"})
})
public class BrowserHelpDisplayer extends Help implements HelpCtx.Displayer {

    @Override
    public boolean display(HelpCtx hc) {
        try {
            URLDisplayer.getDefault().showURL(
                    new URL("http://www.google.com?q=" 
                    + hc.getHelpID()));
        } catch (Exception ex) {
            return false;
        }
        return true;
    }

    @Override
    public Boolean isValidID(String id, boolean force) {
        return true;
    }

    @Override
    public void showHelp(HelpCtx ctx, boolean showmaster) {
        display(ctx);
    }

    @Override
    public void addChangeListener(ChangeListener l) {
    }

    @Override
    public void removeChangeListener(ChangeListener l) {
    }
    
}

The above puts the help ID into Google search. Not helpful in itself, but a starting point for publishing help topics on line, instead of in the JavaHelp window.

About

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.

Search

Archives
« February 2013 »
SunMonTueWedThuFriSat
     
3
4
5
6
10
11
12
14
15
16
17
27
28
  
       
Today