1 18 19 package org.apache.jmeter.gui.action; 20 import java.awt.Frame ; 21 import java.awt.GridLayout ; 22 import java.awt.event.ActionEvent ; 23 import java.io.IOException ; 24 import java.util.HashSet ; 25 import java.util.Set ; 26 27 import javax.swing.JDialog ; 28 import javax.swing.JScrollPane ; 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 42 public class Help implements Command 43 { 44 transient private static Logger log = LoggingManager.getLoggerForClass(); 45 46 public final static String HELP = "help"; 47 private static Set commands = new HashSet (); 48 49 public static final String HELP_DOCS = 50 "file:///" 51 + JMeterUtils.getJMeterHome() 52 + "/printable_docs/usermanual/"; 53 54 public static final String HELP_PAGE = 55 HELP_DOCS + "component_reference.html"; 56 57 public static final String HELP_FUNCTIONS = 58 HELP_DOCS + "functions.html"; 59 60 private static JDialog helpWindow; 61 private static HtmlPane helpDoc; 62 private static JScrollPane scroller; 63 private static String currentPage; 64 65 static 66 { 67 commands.add(HELP); 68 helpDoc = new HtmlPane(); 69 scroller = new JScrollPane (helpDoc); 70 helpDoc.setEditable(false); 71 try 72 { 73 helpDoc.setPage(HELP_PAGE); 74 currentPage = HELP_PAGE; 75 } 76 catch (IOException err) 77 { 78 String msg = "Couldn't load help file " + err.toString(); 79 log.error(msg); 80 currentPage=""; } 82 } 83 84 87 public void doAction(ActionEvent e) 88 { 89 if (helpWindow == null) 90 { 91 helpWindow = 92 new JDialog ( 93 new Frame (), JMeterUtils.getResString("help"), false); 96 helpWindow.getContentPane().setLayout(new GridLayout (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 []) 103 { 104 String [] source = (String []) 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 source) 122 { 123 if (!currentPage.equals(source)) 124 { 125 try 126 { 127 helpDoc.setPage(source); 128 currentPage = source; 129 } 130 catch (IOException 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 142 public Set getActionNames() 143 { 144 return commands; 145 } 146 } 147 | Popular Tags |