How to provide context-sensitive help when the user presses the F1 key and how to customize the way help is presented.
You can run this technique code from:
| |
See the section on context-sensitive help in the advanced form techniques chapter in the Programmer's Guide |
The example frmHelpTest has help information for the form as well as specific help for several controls. When the user presses F1, a page from the database is displayed in the browser or in a custom help dialog.
The table lists the form and controls, and their help pages. These pages are specified for the Help Page property in the Property Inspector.
It also provides two ways to display the help:
The custom dialog is a form called dialogHelp
. It is a simple alternative to the default browser. You can program a custom help system for your application by implementing the processHelp()
method in the form.
This code for the valueChanged event of the list box changes the help page according to the item in the list that the user has selected. These help topics are called pgHelpItem1.html, pgHelpItem2.html, and so on. This event does not display the help; it changes the help page to be displayed when the user presses F1.
private void handle_List1_valueChanged(AgoPropertyChangeEvent evt) { int index = List1.getSelectedIndex(); if (index > -1) { int item = index + 1; List1.setHelpInfo("pgHelpItem" + item + ".html"); } else { List1.setHelpInfo("pgHelpListBox.html"); } }
When the custom help radio button is selected and the user presses F1, this method displays a dialog with and editor pane that displays the help page. The example avoids displaying more than one version of the dialog. If the user doesn't close the dialog, then when the user asks for help again, the code substitutes a new help page into the dialog.
public boolean processHelp(Object obj, String sHelpPage) { if (b_defaultHelp == true) return false; if (sHelpPage == null) return false; try { if (dlgHelp == null) { dlgHelp = (com.sssw.gen.forms.dialogHelp) agDialog.getForm("dialogHelp"); } dlgHelp.EditorPane1.setPage( agGeneral.getDatabaseURL().toString() + "SilverStream/Pages/" + sHelpPage); dlgHelp.EditorPane1.setEditable(false); if (b_dlgHelpVisible == false) { agDialog.showForm("Help", dlgHelp, agDialog.FORM_MODELESS, true, 50,50); set_dlgHelpVisible(true); } return true; } catch (java.io.IOException e) { ... } }
b_defaultHelp
) is true (meaning the default help radio button is selected), processHelp()
returns false. Default help processing occurs if the help manager can't find an implementation of processHelp()
that returns true.
sHelpPage
is null), processHelp()
also returns false. Eventually if help information is found, default help processing will occur. In this example, sHelpPage
should never be null; the help page for the form is displayed for any controls that have no help information.
dlgHelp
is an instance variable. Its type is the form class dialogHelp
.
public dialogHelp dlgHelp;
dlgHelp
is null). The code calls getForm()
to instantiate it, then calls setPage()
and showForm(
).
b_dlgHelpVisible
is false). The code calls setPage()
and showForm()
.
b_dlgHelpVisible
is true). The code calls setPage()
, but not showForm()
.
b_dlgHelpVisible
is initialized to false. When this code calls showForm()
, it also sets the variable to true. When the user closes the dialog, a method in the windowClosing event of the dialogHelp form sets it to false again.
public void windowClosing(WindowEvent event) { ((frmHelpTest)getParentForm()).set_dlgHelpVisible(false); }