View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  package org.xnap.gui.util;
20  
21  import javax.help.DefaultHelpBroker;
22  import javax.help.HelpSet;
23  import javax.help.Map;
24  import javax.swing.JComponent;
25  
26  import org.apache.log4j.Logger;
27  import org.xnap.gui.HelpDialog;
28  import org.xnap.gui.XNapFrame;
29  
30  /***
31   * Extends the DefaultHelpBroker to use XNap's own {@link HelpDialog} for a
32   * consisten look and feel.
33   */
34  public class XNapHelpBroker extends DefaultHelpBroker
35  {
36  	//--- Constant(s) ---
37  
38  	//--- Data field(s) ---
39  
40  	private HelpDialog dialog = null;
41  
42      private static Logger logger = Logger.getLogger(XNapHelpBroker.class);
43  	
44  		//--- Constructor(s) ---
45  
46      public XNapHelpBroker(HelpSet hs)
47  	{
48  		super(hs);
49  	}
50  
51      //--- Method(s) ---
52  
53  	public JComponent getHelp()
54  	{
55  		// workaround to call private createJHelp method of super class
56  		if (jhelp == null) {
57  			try {
58  				Map.ID id = Map.ID.create(null, getHelpSet());
59  				setCurrentID(id);
60  			}
61  			catch (Exception e) {
62  			}
63  		}
64  		return jhelp;
65  	}
66  
67  	public boolean isDisplayed()
68  	{
69  		return dialog != null && dialog.isShowing();
70  	}
71  
72  	public void setDisplayed(boolean b)
73  	{
74  		if (b) {
75  			if (dialog == null) {
76  				dialog = new HelpDialog();
77  			}
78  			dialog.show(XNapFrame.getInstance());
79  		}
80  		else {
81  			if (dialog != null) {
82  				dialog.close();
83  			}
84  		}
85  	}
86  }