Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/flexstor/common/awt/Help.java


1   /*
2    * Help.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:32 $ FLEXSTOR.net Inc.
5    *
6    * This work is licensed for use and distribution under license terms found at
7    * http://www.flexstor.org/license.html
8    *
9    */
10  
11  package com.flexstor.common.awt;
12  
13  import com.flexstor.common.awt.dialogs.MessageBox;
14  import com.flexstor.common.settings.Settings;
15  import com.flexstor.common.util.Diagnostic;
16  
17  /**
18    * The class <B>Help</B> implements HelpHandlerI and
19    * provides one method named <I>showHelp</I>.
20    * showHelp creates a new browser window to display an HTML help file.
21    *
22    * Window identifiers are defined in FlexFrame.<BR>
23    * <BR>
24    * Example call: <pre>
25    *
26    *   static final int iWndId = WNDID_MAIN;  // constant defined in FlexFrame
27    *   ...
28    *   private HelpHandlerI helpHandler = new Help();
29    *   ...
30    *   void bHelp_Clicked(Event event)
31    *   {
32    *      // if applicable, check for focus here and set fieldId
33    *      // correspondingly
34    *      int iFldId = 0;   // field id zero for window level help
35    *      helpHandler.showHelp(this.iWndId, iFldId);
36    *   }
37    *   </pre>
38    * @author Raimund Dettmer
39    * @version 3.0
40    * @see com.flexstor.common.awt.FlexFrame
41    */
42  public class Help
43     implements HelpHandlerI
44  {
45    // MKS macro expander
46    public final static String IDENTIFIER = "$Id: Help.java,v 1.4 2003/08/11 02:22:32 aleric Exp $";
47  
48     private static final int    HLP_DEFAULT_ID  = 0000;           // id for contents help file
49     private static       HelpFileMapper fileMapper;             // helper class to read the map file
50  
51    /**
52      * This method shows an HTML help file in a browser window.
53      *
54      * @param windowId Window for which help is requested (id defined in FlexFrame)
55      * @param fieldId  Field for which help is requested (id defined in window)
56      * @return true if sucessfull.
57      *
58      * @see com.flexstor.client.resource.HelpResources
59      * @see com.flexstor.client.awt.FlexFrame
60      */
61     public void showHelp(int iWndId, int iFldId)
62     {
63        String sHelpFile = null;
64        int    iHelpId   = 0;
65  
66        if (fileMapper == null)
67        {
68           try
69           {
70              fileMapper = new HelpFileMapper();
71           }
72           catch(Exception e)
73           {
74              Diagnostic.trace(Diagnostic.CAT_PROCESS, "Help: unable to read help file map: " + e.toString());
75              MessageBox.showMessageDialog(null, 5962);
76              return;
77           }
78        }
79  
80        // map help id to file name (URL)
81        // first 2 digits = window id, last 2 digits = field id
82        iHelpId = iWndId * 100 + iFldId;
83  
84        // get help file for original request
85        sHelpFile = fileMapper.getFile( iHelpId );
86        if (sHelpFile == null || sHelpFile.length() == 0)
87        // if not found, check main window help (field id zero)
88        {
89           iHelpId = iWndId * 100 + 0;
90           sHelpFile = fileMapper.getFile( iHelpId );
91        }
92        // no context help available, show contents
93        if (sHelpFile == null || sHelpFile.length() == 0)
94        {
95           sHelpFile = fileMapper.getFile( HLP_DEFAULT_ID );
96        }
97  
98        Diagnostic.trace(Diagnostic.CAT_PROCESS, "HelpFile: " + sHelpFile);
99  
100       HTMLLauncher.openHTML ( Settings.getString(Settings.HELP_LOCATION) + sHelpFile );
101       return;
102    }  // end of showHelp
103 
104 
105 /* for unit test
106 
107    public static void main(String[] args)
108    {
109       try
110       {
111          Settings.registerDataSource ( Settings.CONFIG,
112             new com.flexstor.common.settings.datasource.ConfigDataSource(
113             new com.flexstor.common.settings.datasource.ConfigSettingsLoader().loadSettings ( args[0] + ServicesI.CONFIG_DIR + '/' + ServicesI.PROPERTIES_FILE )
114          ) );
115          Settings.registerDataSource ( Settings.RUNTIME,
116             new com.flexstor.common.settings.datasource.RuntimeDataSource());
117          Settings.registerDataSource ( Settings.USER,
118             new com.flexstor.common.settings.datasource.UserDataSource(new java.util.Hashtable()));
119          Settings.registerDataSource ( Settings.MACHINE,
120             new com.flexstor.common.settings.datasource.MachineDataSource(new com.flexstor.common.data.ejb.machine.MachineData("206.147.164.136")));
121          com.flexstor.common.util.Diagnostic.addOutputDevice(System.out);
122          com.flexstor.common.util.Diagnostic.addTraceCategory(com.flexstor.common.util.Diagnostic.CAT_PROCESS);
123          com.flexstor.common.util.Diagnostic.setTraceLevel(1);
124          com.flexstor.common.util.Diagnostic.enableOutput(true);
125          // Set the initial resource data source
126          String sResourceFile = Settings.getString(Settings.RESOURCE_LOCATION) + "Resources.en";
127          try
128          {
129             com.flexstor.common.resources.Resources.registerDataSource( new com.flexstor.common.resources.FileDataSource( sResourceFile ) );
130          }
131          catch ( Exception e )
132          {
133          }
134 
135          (new Help()).showHelp(1,1);
136       }
137       catch(Exception e)
138       {
139          e.printStackTrace();
140       }
141       finally
142       {
143          //try{System.in.read();}catch(Exception e){}
144          System.exit(0);
145       }
146    }
147 */
148 
149 } // end of Help class
150