A JavaHelp Class

With my helpset prepared as described in the last post I am ready to launch the javahelp viewer.

Given the opacity of the api pdf files, I decided that I needed to first implement a Java class that would open a help dialog. Once I have defined the required methods, it will be easier to recode in Clojure. It has been >10 years since I last thought about Java code so getting back in the swing (hah!) won’t be easy. When I last worked with the language generics and enums were yet to be defined.

I call my class OpenHelpDialog and don’t bother putting it in a package.

OpenHelpDialog.java
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
31
32
33
34

import javax.help.*;
import java.net.URL;

public class OpenHelpDialog {

public static HelpSet hs;
public static HelpBroker hb;
public static String helpHS;
public static URL hsURL;

public OpenHelpDialog(){
helpHS = "../pmhelpset/pmhelp.hs";

ClassLoader cl = OpenHelpDialog.class.getClassLoader();

try {
hsURL = HelpSet.findHelpSet(cl, helpHS);
hs = new HelpSet(null, hsURL);
} catch (Exception ee) {
// Say what the exception really is
System.out.println( "HelpSet " + ee.getMessage());
System.out.println("HelpSet "+ helpHS +" not found");
}
hb = hs.createHelpBroker();
hb.setCurrentID("assaytype");
hb.setDisplayed(true);
}

public static void main(String [ ] args){
new OpenHelpDialog();
}
}

I navigate to its directory which is “/home/mbc/plate-manager/jws/pm/pmhelpclasses” and:

compile.sh
1
2
3

javac -cp /home/mbc/plate-manager/jws/pm/pm/helpclasses:/home/mbc/plate-manager/jws/pm/pmhelpset:/home/mbc/plate-manager/jws/pm/resources/javahelp-2.0.05.jar OpenHelpDialog.java

Note that I include the helpset directory in the classpath, as well as the helpclasses. Then run:

run.sh
1
2
java -cp /home/mbc/plate-manager/jws/pm/pmhelpclasses:/home/mbc/plate-manager/jws/pm/pmhelpset:/home/mbc/jh2.0/javahelp/lib/jhall.jar OpenHelpDialog

Looks good. By default a MainWindow is displayed.

From the api pdf it looks like the main function of the HelpBroker is to enable objects (menu items, buttons, etc.) with the ability to launch the help viewer when a HelpActionListener is activated. Looking through the methods on HelpBroker I see hb.setDisplayed(true), which allows me to launch the viewer directly. A prior version of OpenHelpDialog had a button that was activated with the HelpBroker.enableHelpOnButton() method. If I were writing in Java, that may be the preferred method, but I was uncertain how to utilize the HelpBroker that way in Clojure, given that I have another layer of abstraction between clojure and java - the seesaw gui classes.

Share