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.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.GuiPackage;
032: import org.apache.jmeter.swing.HtmlPane;
033: import org.apache.jmeter.util.JMeterUtils;
034: import org.apache.jorphan.gui.ComponentUtil;
035: import org.apache.jorphan.logging.LoggingManager;
036: import org.apache.log.Logger;
037:
038: /**
039: *
040: * @version $Revision: 493779 $ $Date: 2007-01-07 17:46:38 +0000 (Sun, 07 Jan 2007) $
041: */
042: public class Help implements Command {
043: private static final Logger log = LoggingManager
044: .getLoggerForClass();
045:
046: private static Set commands = new HashSet();
047:
048: private static final String HELP_DOCS = "file:///" // $NON-NLS-1$
049: + JMeterUtils.getJMeterHome()
050: + "/printable_docs/usermanual/"; // $NON-NLS-1$
051:
052: private static final String HELP_PAGE = HELP_DOCS
053: + "component_reference.html"; // $NON-NLS-1$
054:
055: public static final String HELP_FUNCTIONS = HELP_DOCS
056: + "functions.html"; // $NON-NLS-1$
057:
058: private static JDialog helpWindow;
059:
060: private static HtmlPane helpDoc;
061:
062: private static JScrollPane scroller;
063:
064: private static String currentPage;
065:
066: static {
067: commands.add(ActionNames.HELP);
068: helpDoc = new HtmlPane();
069: scroller = new JScrollPane(helpDoc);
070: helpDoc.setEditable(false);
071: try {
072: helpDoc.setPage(HELP_PAGE);
073: currentPage = HELP_PAGE;
074: } catch (IOException err) {
075: String msg = "Couldn't load help file " + err.toString();
076: log.error(msg);
077: currentPage = "";// Avoid NPE in resetPage() // $NON-NLS-1$
078: }
079: }
080:
081: /**
082: * @see org.apache.jmeter.gui.action.Command#doAction(ActionEvent)
083: */
084: public void doAction(ActionEvent e) {
085: if (helpWindow == null) {
086: helpWindow = new JDialog(new Frame(),// independent frame to
087: // allow it to be overlaid
088: // by the main frame
089: JMeterUtils.getResString("help"),//$NON-NLS-1$
090: false);
091: helpWindow.getContentPane().setLayout(new GridLayout(1, 1));
092: ComponentUtil.centerComponentInWindow(helpWindow, 60);
093: }
094: helpWindow.getContentPane().removeAll();
095: helpWindow.getContentPane().add(scroller);
096: helpWindow.show();
097: if (e.getSource() instanceof String[]) {
098: String[] source = (String[]) e.getSource();
099: resetPage(source[0]);
100: helpDoc.scrollToReference(source[1]);
101: } else {
102: resetPage(HELP_PAGE);
103: helpDoc.scrollToReference(GuiPackage.getInstance()
104: .getTreeListener().getCurrentNode().getDocAnchor());
105:
106: }
107: }
108:
109: private void resetPage(String source) {
110: if (!currentPage.equals(source)) {
111: try {
112: helpDoc.setPage(source);
113: currentPage = source;
114: } catch (IOException err) {
115: log.error(err.toString());
116: JMeterUtils
117: .reportErrorToUser("Problem loading a help page - see log for details");
118: currentPage = ""; // $NON-NLS-1$
119: }
120: }
121: }
122:
123: /**
124: * @see org.apache.jmeter.gui.action.Command#getActionNames()
125: */
126: public Set getActionNames() {
127: return commands;
128: }
129: }
|