01: /*
02: * Copyright (C) 2005 Jeff Tassin
03: *
04: * This library is free software; you can redistribute it and/or
05: * modify it under the terms of the GNU Lesser General Public
06: * License as published by the Free Software Foundation; either
07: * version 2.1 of the License, or (at your option) any later version.
08: *
09: * This library is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12: * Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public
15: * License along with this library; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: */
18:
19: package com.jeta.swingbuilder.help;
20:
21: import java.awt.event.ActionEvent;
22: import java.awt.event.ActionListener;
23:
24: /**
25: * Helper class for handling application Help support
26: *
27: * @author Jeff Tassin
28: */
29: public class HelpUtils {
30:
31: /**
32: * Adds an action listener to the button to invoke help when the button is
33: * pressed.
34: */
35: public static void enableHelpOnButton(
36: javax.swing.AbstractButton btn, String id) {
37: try {
38: /**
39: * from CSH source
40: *
41: * @see CSH.setHelpIDString( btn, id ); We don't call CSH here
42: * because we don't want to load the classes until the user
43: * actually presses the help button
44: */
45:
46: setHelpIDString(btn, id);
47: btn.addActionListener(new HelpListener());
48: } catch (Exception e) {
49: e.printStackTrace();
50: }
51: }
52:
53: public static void setHelpIDString(javax.swing.AbstractButton btn,
54: String id) {
55: btn.putClientProperty("HelpID", id);
56: }
57:
58: /**
59: * This is a lazy action listener for the help system. We don't want to load
60: * the helpset unless the user explicitly presses the help button. It is
61: * hoped that this would improve startup performance because it is one less
62: * thing that has to be loaded; however no tests were run to prove that this
63: * actually helps.
64: */
65: static class HelpListener implements ActionListener {
66: /** the delegate action handler that actually displays the help */
67: private HelpDelegator m_delegate;
68:
69: public void actionPerformed(ActionEvent evt) {
70: if (m_delegate == null) {
71: m_delegate = new HelpDelegator();
72: }
73: m_delegate.actionPerformed(evt);
74: }
75: }
76: }
|