View Javadoc

1   package com.explosion.expf.help;
2   
3   /* =============================================================================
4    *       
5    *     Copyright 2004 Stephen Cowx
6    *
7    *     Licensed under the Apache License, Version 2.0 (the "License");
8    *     you may not use this file except in compliance with the License.
9    *     You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   *     Unless required by applicable law or agreed to in writing, software
14   *     distributed under the License is distributed on an "AS IS" BASIS,
15   *     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   *     See the License for the specific language governing permissions and
17   *     limitations under the License.
18   * 
19   * =============================================================================
20   */
21  
22  import java.awt.BorderLayout;
23  
24  import javax.help.HelpBroker;
25  import javax.help.HelpSet;
26  import javax.help.JHelpContentViewer;
27  import javax.help.JHelpNavigator;
28  import javax.swing.JLabel;
29  import javax.swing.JPanel;
30  import javax.swing.JSplitPane;
31  import javax.swing.JTabbedPane;
32  
33  import com.explosion.expf.Application;
34  import com.explosion.utilities.exception.EnhancedException;
35  import com.explosion.utilities.exception.ExceptionManagerFactory;
36  
37  /***
38   * @author Stephen Cowx
39   * Date created:@29-Jan-2003
40   */
41  public class HelpPane extends JSplitPane
42  {
43    private HelpSet apiHS = null;
44    private JHelpContentViewer viewer1 = null;
45    private JHelpNavigator tocNav = null;
46    private JHelpNavigator indexNav = null;
47    private JHelpNavigator searchNav = null;
48    
49    private JTabbedPane tabbedPane = new JTabbedPane();
50    private JPanel contentPanel = new JPanel();
51    private String startID = "";
52      
53    
54    /***
55     * Constructor
56     */
57    public HelpPane(String startID) throws Exception
58    {
59      super(JSplitPane.HORIZONTAL_SPLIT);
60      this.startID = startID;
61      init();
62    }  
63    
64    /***
65     * This method sets out the look and feel for this component
66     */
67    private void init() throws Exception
68    {
69    	
70    	/* Use the same model for both the content pane and navigator components (viewer1) 
71  	 * so changes generated by one component are reflected in the other component. Note 
72  	 * that the TOC can be created using either the HelpSet getNavigatorView() method or 
73  	 * the JavaHelpNavigator getNavigatorView() method. Both methods produce the same 
74  	 * results, however using HelpSet reduces the dependency on the GUI.  */
75  	
76  	HelpBroker hb = null;
77      try
78      {
79        hb = Application.getHelpBroker();
80      }
81      catch (Exception e)
82      {
83        ExceptionManagerFactory.getExceptionManager().manageException(e,EnhancedException.getStackTrace(e));
84      }
85  		
86  	if (hb != null)
87      {
88      	apiHS = hb.getHelpSet();
89          viewer1 = new JHelpContentViewer(apiHS);
90          
91  	    if (apiHS.getNavigatorView("TOC") != null)
92      	    tocNav = (JHelpNavigator) apiHS.getNavigatorView("TOC").createNavigator(viewer1.getModel());
93  	    
94  	    if (apiHS.getNavigatorView("Index") != null)
95  	      indexNav = (JHelpNavigator) apiHS.getNavigatorView("Index").createNavigator(viewer1.getModel());
96  	      
97  	    if (apiHS.getNavigatorView("Search") != null)  
98     	      searchNav = (JHelpNavigator) apiHS.getNavigatorView("Search").createNavigator(viewer1.getModel());
99  	      
100 	    if (!startID.trim().equals(""))
101 	       viewer1.setCurrentID(startID);
102 	     
103 		if (tocNav != null)
104 		   tabbedPane.addTab("Contents",tocNav);
105 		   
106 		if (indexNav != null)   
107 		   tabbedPane.addTab("Index",indexNav);
108 		   
109 		if (searchNav != null)
110 		   tabbedPane.addTab("Search",searchNav);
111 		   
112 		tabbedPane.setSelectedIndex(0);
113 			
114 	    contentPanel.setLayout(new BorderLayout());
115 	    contentPanel.setDoubleBuffered(true);
116 	    contentPanel.add(viewer1, "Center");
117 	    
118 		this.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
119 	    this.setLeftComponent(tabbedPane);
120 	    this.setRightComponent(contentPanel);
121 	    this.setResizeWeight(0.2);
122     }
123     else
124     {
125        contentPanel.add(new JLabel("No help could be found for this application."));
126        //this.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
127 	   this.add(contentPanel);
128     }   
129   }
130 
131 }