001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.report.gui.action;
020:
021: import java.awt.Frame;
022: import java.awt.GridLayout;
023: import java.awt.event.ActionEvent;
024: import java.io.IOException;
025: import java.util.HashSet;
026: import java.util.Set;
027:
028: import javax.swing.JDialog;
029: import javax.swing.JScrollPane;
030:
031: import org.apache.jmeter.gui.ReportGuiPackage;
032: import org.apache.jmeter.swing.HtmlPane;
033: import org.apache.jmeter.util.JMeterUtils;
034: import org.apache.jmeter.gui.action.Command;
035: import org.apache.jorphan.gui.ComponentUtil;
036: import org.apache.jorphan.logging.LoggingManager;
037: import org.apache.log.Logger;
038:
039: /**
040: *
041: * @author unattributed
042: * @version $Revision: 493793 $ $Date: 2007-01-07 18:19:27 +0000 (Sun, 07 Jan 2007) $
043: */
044: public class ReportHelp implements Command {
045: transient private static Logger log = LoggingManager
046: .getLoggerForClass();
047:
048: public final static String HELP = "help";
049:
050: private static Set commands = new HashSet();
051:
052: public static final String HELP_DOCS = "file:///"
053: + JMeterUtils.getJMeterHome()
054: + "/printable_docs/usermanual/";
055:
056: public static final String HELP_PAGE = HELP_DOCS
057: + "component_reference.html";
058:
059: public static final String HELP_FUNCTIONS = HELP_DOCS
060: + "functions.html";
061:
062: private static JDialog helpWindow;
063:
064: private static HtmlPane helpDoc;
065:
066: private static JScrollPane scroller;
067:
068: private static String currentPage;
069:
070: static {
071: commands.add(HELP);
072: helpDoc = new HtmlPane();
073: scroller = new JScrollPane(helpDoc);
074: helpDoc.setEditable(false);
075: try {
076: helpDoc.setPage(HELP_PAGE);
077: currentPage = HELP_PAGE;
078: } catch (IOException err) {
079: String msg = "Couldn't load help file " + err.toString();
080: log.error(msg);
081: currentPage = "";// Avoid NPE in resetPage()
082: }
083: }
084:
085: /**
086: * @see org.apache.jmeter.gui.action.Command#doAction(ActionEvent)
087: */
088: public void doAction(ActionEvent e) {
089: if (helpWindow == null) {
090: helpWindow = new JDialog(new Frame(),// independent frame to
091: // allow it to be overlaid
092: // by the main frame
093: JMeterUtils.getResString("help"),//$NON-NLS-1$
094: false);
095: helpWindow.getContentPane().setLayout(new GridLayout(1, 1));
096: ComponentUtil.centerComponentInWindow(helpWindow, 60);
097: }
098: helpWindow.getContentPane().removeAll();
099: helpWindow.getContentPane().add(scroller);
100: helpWindow.show();
101: if (e.getSource() instanceof String[]) {
102: String[] source = (String[]) e.getSource();
103: resetPage(source[0]);
104: helpDoc.scrollToReference(source[1]);
105: } else {
106: resetPage(HELP_PAGE);
107: helpDoc.scrollToReference(ReportGuiPackage.getInstance()
108: .getTreeListener().getCurrentNode().getDocAnchor());
109:
110: }
111: }
112:
113: private void resetPage(String source) {
114: if (!currentPage.equals(source)) {
115: try {
116: helpDoc.setPage(source);
117: currentPage = source;
118: } catch (IOException err) {
119: log.error(err.toString());
120: JMeterUtils
121: .reportErrorToUser("Problem loading a help page - see log for details");
122: currentPage = "";
123: }
124: }
125: }
126:
127: /**
128: * @see org.apache.jmeter.gui.action.Command#getActionNames()
129: */
130: public Set getActionNames() {
131: return commands;
132: }
133: }
|