Reputation: 267
My question today is I have a GUI that interfaces another program. I have a text area within my GUI which I would like to display the class documentation of specific components that the user selects.
Example: User selects the 'Protocol' setting I want it to show the JavaDoc for that 'Protocol'.
How do I go about recognising the correct Javadoc and presenting it within the text area?
Upvotes: 1
Views: 1332
Reputation: 168835
..Javadoc.. presenting it within the text area?
Don't use a JTextArea
, but a JEditorPane
. The latter will render HTML.
Upvotes: 2
Reputation: 18303
I would suggest 3 possible approaches:
Example code from QDox:
JavaDocBuilder builder = new JavaDocBuilder();
builder.addSource(new FileReader("MyFile.java"));
Upvotes: 2
Reputation: 298459
The JavaDoc is not part of a Java program. So you have to bundle the resources with your program regardless of what approach you use.
So you have two possibilities:
Generate the documentation with javadoc and bundle the result. It is easy to see how to map from a class name to the html page by looking at the generated files. The JavaDoc documentation (the Default doclet’s documentation to be more precise) contains more detailed descriptions
If you want to generate the documentation on-the-fly you have to bundle the source code with your application. Further, your application have to run inside a JDK rather than a plain JRE to get hands on JavaDoc.
See http://docs.oracle.com/javase/7/docs/technotes/guides/javadoc/standard-doclet.html
Running the Standard Doclet Programmatically
The Javadoc tool has a programmatic interface with public methods for invoking the Javadoc tool from another program written in the Java language. These methods are located in class com.sun.tools.javadoc.Main in lib/tools.jar. …
public static int execute(String programName, PrintWriter errWriter, PrintWriter warnWriter, PrintWriter noticeWriter, String defaultDocletClassName, String[] args)
This execute method is overloaded with variants taking fewer parameters.
Upvotes: 1