Coverage details for ui.help.HelpMenuItem

LineHitsSource
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  *******************************************************************************/
200 
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;
300 
310import org.apache.log4j.Logger;
320 
33 @SuppressWarnings("serial") //$NON-NLS-1$
340public class HelpMenuItem extends JMenuItem{
35     
360    private static final transient Logger logger = Logger.getLogger(HelpMenuItem.class.getName());
370 
38     /**The protocol can be one between http, file, etc...**/
390    public static final String URL_PROTOCOL="file"; //$NON-NLS-1$
400    /**The local machine.**/
410    public static final String URL_HOST="localhost"; //$NON-NLS-1$
42     /**This specifies the default port to use in the protocol.**/
430    public static final int URL_PORT=-1;
440    
45     public HelpMenuItem(String menuName) {
460        super(menuName);
470        initialize();
480    }
490    
500    protected void initialize(){
510        // 1. create HelpSet and HelpBroker objects
520        File file = new File("help"+File.separatorChar+"InternetCafe.hs"); //$NON-NLS-1$ //$NON-NLS-2$
530        if(!file.exists())
54         {
550            logger.debug("The Help Set File named: "+file + " doesn't exists!"); //$NON-NLS-1$ //$NON-NLS-2$
560            return;
570        }else logger.debug("The Help Set File named: "+file + " exists!"); //$NON-NLS-1$ //$NON-NLS-2$
580            
590        HelpSet helpSet = getHelpSet(file.getAbsolutePath());
600        HelpBroker helpBroker = helpSet.createHelpBroker();
610        // 2. assign help to components
620        CSH.setHelpIDString(this, getName());
630        // 3. handle events
640        this.addActionListener(new CSH.DisplayHelpFromSource(helpBroker));
650    }
66     
670    /**
680     * find the helpset file and create a HelpSet object
69      */
70     public HelpSet getHelpSet(String helpsetfile) {
710        HelpSet helpSet = null;
72         try {
730            URL hsURL = new URL(URL_PROTOCOL,URL_HOST,URL_PORT,helpsetfile);
740            helpSet = new HelpSet(this.getClass().getClassLoader(), hsURL);
750        } catch(Exception ex) {
760            ex.printStackTrace();
770            logger.error("HelpSet: "+ex.getMessage()); //$NON-NLS-1$
780            logger.error("HelpSet: "+ helpsetfile + " not found"); //$NON-NLS-1$ //$NON-NLS-2$
790        }
800        return helpSet;
810    }
82 }
830 

this report was generated by version 1.0.5 of jcoverage.
visit www.jcoverage.com for updates.

copyright © 2003, jcoverage ltd. all rights reserved.
Java is a trademark of Sun Microsystems, Inc. in the United States and other countries.