1 /********************************************************************************
2 * InternetCafe is a software solution that helps the management of Cybercafes
3 * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005.
4 * Copyright (C) 2006 Guido Angelo Ingenito
5
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 *******************************************************************************/
20
21 package ui.help;
22
23 import java.io.File;
24 import java.net.URL;
25
26 import javax.help.CSH;
27 import javax.help.HelpBroker;
28 import javax.help.HelpSet;
29 import javax.swing.JMenuItem;
30
31 import org.apache.log4j.Logger;
32
33 @SuppressWarnings("serial")
34 public class HelpMenuItem extends JMenuItem{
35
36 private static final transient Logger logger = Logger.getLogger(HelpMenuItem.class.getName());
37
38 /***The protocol can be one between http, file, etc...**/
39 public static final String URL_PROTOCOL="file";
40 /***The local machine.**/
41 public static final String URL_HOST="localhost";
42 /***This specifies the default port to use in the protocol.**/
43 public static final int URL_PORT=-1;
44
45 public HelpMenuItem(String menuName) {
46 super(menuName);
47 initialize();
48 }
49
50 protected void initialize(){
51
52 File file = new File("help"+File.separatorChar+"InternetCafe.hs");
53 if(!file.exists())
54 {
55 logger.debug("The Help Set File named: "+file + " doesn't exists!");
56 return;
57 }else logger.debug("The Help Set File named: "+file + " exists!");
58
59 HelpSet helpSet = getHelpSet(file.getAbsolutePath());
60 HelpBroker helpBroker = helpSet.createHelpBroker();
61
62 CSH.setHelpIDString(this, getName());
63
64 this.addActionListener(new CSH.DisplayHelpFromSource(helpBroker));
65 }
66
67 /***
68 * find the helpset file and create a HelpSet object
69 */
70 public HelpSet getHelpSet(String helpsetfile) {
71 HelpSet helpSet = null;
72 try {
73 URL hsURL = new URL(URL_PROTOCOL,URL_HOST,URL_PORT,helpsetfile);
74 helpSet = new HelpSet(this.getClass().getClassLoader(), hsURL);
75 } catch(Exception ex) {
76 ex.printStackTrace();
77 logger.error("HelpSet: "+ex.getMessage());
78 logger.error("HelpSet: "+ helpsetfile + " not found");
79 }
80 return helpSet;
81 }
82 }
83