KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > gui > action > Help


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/action/Help.java,v 1.21 2004/03/05 13:18:37 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.gui.action;
20 import java.awt.Frame JavaDoc;
21 import java.awt.GridLayout JavaDoc;
22 import java.awt.event.ActionEvent JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.util.HashSet JavaDoc;
25 import java.util.Set JavaDoc;
26
27 import javax.swing.JDialog JavaDoc;
28 import javax.swing.JScrollPane JavaDoc;
29
30 import org.apache.jmeter.gui.GuiPackage;
31 import org.apache.jmeter.swing.HtmlPane;
32 import org.apache.jmeter.util.JMeterUtils;
33 import org.apache.jorphan.gui.ComponentUtil;
34 import org.apache.jorphan.logging.LoggingManager;
35 import org.apache.log.Logger;
36
37 /**
38  *
39  * @author unattributed
40  * @version $Revision: 1.21 $ $Date: 2004/03/05 13:18:37 $
41  */

42 public class Help implements Command
43 {
44     transient private static Logger log = LoggingManager.getLoggerForClass();
45
46     public final static String JavaDoc HELP = "help";
47     private static Set JavaDoc commands = new HashSet JavaDoc();
48
49     public static final String JavaDoc HELP_DOCS =
50         "file:///"
51             + JMeterUtils.getJMeterHome()
52             + "/printable_docs/usermanual/";
53
54     public static final String JavaDoc HELP_PAGE =
55         HELP_DOCS + "component_reference.html";
56
57     public static final String JavaDoc HELP_FUNCTIONS =
58         HELP_DOCS + "functions.html";
59
60     private static JDialog JavaDoc helpWindow;
61     private static HtmlPane helpDoc;
62     private static JScrollPane JavaDoc scroller;
63     private static String JavaDoc currentPage;
64
65     static
66     {
67         commands.add(HELP);
68         helpDoc = new HtmlPane();
69         scroller = new JScrollPane JavaDoc(helpDoc);
70         helpDoc.setEditable(false);
71         try
72         {
73             helpDoc.setPage(HELP_PAGE);
74             currentPage = HELP_PAGE;
75         }
76         catch (IOException JavaDoc err)
77         {
78             String JavaDoc msg = "Couldn't load help file " + err.toString();
79             log.error(msg);
80             currentPage="";// Avoid NPE in resetPage()
81
}
82     }
83     
84     /**
85      * @see org.apache.jmeter.gui.action.Command#doAction(ActionEvent)
86      */

87     public void doAction(ActionEvent JavaDoc e)
88     {
89         if (helpWindow == null)
90         {
91             helpWindow =
92                 new JDialog JavaDoc(
93                     new Frame JavaDoc(),// independent frame to allow it to be overlaid by the main frame
94
JMeterUtils.getResString("help"),//$NON-NLS-1$
95
false);
96             helpWindow.getContentPane().setLayout(new GridLayout JavaDoc(1, 1));
97             ComponentUtil.centerComponentInWindow(helpWindow, 60);
98         }
99         helpWindow.getContentPane().removeAll();
100         helpWindow.getContentPane().add(scroller);
101         helpWindow.show();
102         if (e.getSource() instanceof String JavaDoc[])
103         {
104             String JavaDoc[] source = (String JavaDoc[]) e.getSource();
105             resetPage(source[0]);
106             helpDoc.scrollToReference(source[1]);
107         }
108         else
109         {
110             resetPage(HELP_PAGE);
111             helpDoc.scrollToReference(
112                 GuiPackage
113                     .getInstance()
114                     .getTreeListener()
115                     .getCurrentNode()
116                     .getDocAnchor());
117                     
118         }
119     }
120
121     private void resetPage(String JavaDoc source)
122     {
123         if (!currentPage.equals(source))
124         {
125             try
126             {
127                 helpDoc.setPage(source);
128                 currentPage = source;
129             }
130             catch (IOException JavaDoc err)
131             {
132                 log.error(err.toString());
133                 JMeterUtils.reportErrorToUser("Problem loading a help page - see log for details");
134                 currentPage="";
135             }
136         }
137     }
138
139     /**
140      * @see org.apache.jmeter.gui.action.Command#getActionNames()
141      */

142     public Set JavaDoc getActionNames()
143     {
144         return commands;
145     }
146 }
147
Popular Tags