Search in sources :

Example 1 with ActionRouter

use of org.apache.jmeter.gui.action.ActionRouter in project jmeter by apache.

the class JMeter method startGui.

/**
     * Starts up JMeter in GUI mode
     */
private void startGui(String testFile) {
    //NOSONAR
    System.out.println("================================================================================");
    //NOSONAR
    System.out.println("Don't use GUI mode for load testing, only for Test creation and Test debugging !");
    //NOSONAR
    System.out.println("For load testing, use NON GUI Mode:");
    //NOSONAR
    System.out.println("   jmeter -n -t [jmx file] -l [results file] -e -o [Path to output folder]");
    //NOSONAR
    System.out.println("& adapt Java Heap to your test requirements:");
    //NOSONAR
    System.out.println("   Modify HEAP=\"-Xms512m -Xmx512m\" in the JMeter batch file");
    //NOSONAR
    System.out.println("================================================================================");
    SplashScreen splash = new SplashScreen();
    splash.showScreen();
    String jMeterLaf = LookAndFeelCommand.getJMeterLaf();
    try {
        UIManager.setLookAndFeel(jMeterLaf);
    } catch (Exception ex) {
        log.warn("Could not set LAF to: {}", jMeterLaf, ex);
    }
    splash.setProgress(10);
    JMeterUtils.applyHiDPIOnFonts();
    PluginManager.install(this, true);
    JMeterTreeModel treeModel = new JMeterTreeModel();
    splash.setProgress(30);
    JMeterTreeListener treeLis = new JMeterTreeListener(treeModel);
    final ActionRouter instance = ActionRouter.getInstance();
    instance.populateCommandMap();
    splash.setProgress(60);
    treeLis.setActionHandler(instance);
    GuiPackage.initInstance(treeLis, treeModel);
    splash.setProgress(80);
    MainFrame main = new MainFrame(treeModel, treeLis);
    splash.setProgress(100);
    ComponentUtil.centerComponentInWindow(main, 80);
    main.setVisible(true);
    instance.actionPerformed(new ActionEvent(main, 1, ActionNames.ADD_ALL));
    if (testFile != null) {
        try {
            File f = new File(testFile);
            log.info("Loading file: {}", f);
            FileServer.getFileServer().setBaseForScript(f);
            HashTree tree = SaveService.loadTree(f);
            GuiPackage.getInstance().setTestPlanFile(f.getAbsolutePath());
            Load.insertLoadedTree(1, tree);
        } catch (ConversionException e) {
            log.error("Failure loading test file", e);
            JMeterUtils.reportErrorToUser(SaveService.CEtoString(e));
        } catch (Exception e) {
            log.error("Failure loading test file", e);
            JMeterUtils.reportErrorToUser(e.toString());
        }
    } else {
        JTree jTree = GuiPackage.getInstance().getMainFrame().getTree();
        TreePath path = jTree.getPathForRow(0);
        jTree.setSelectionPath(path);
        FocusRequester.requestFocus(jTree);
    }
    splash.setProgress(100);
    splash.close();
}
Also used : ConversionException(com.thoughtworks.xstream.converters.ConversionException) HashTree(org.apache.jorphan.collections.HashTree) ActionEvent(java.awt.event.ActionEvent) ActionRouter(org.apache.jmeter.gui.action.ActionRouter) ConfigurationException(org.apache.jmeter.report.config.ConfigurationException) JMeterException(org.apache.jorphan.util.JMeterException) FileNotFoundException(java.io.FileNotFoundException) ConversionException(com.thoughtworks.xstream.converters.ConversionException) SocketException(java.net.SocketException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) IllegalUserActionException(org.apache.jmeter.exceptions.IllegalUserActionException) GenerationException(org.apache.jmeter.report.dashboard.GenerationException) MainFrame(org.apache.jmeter.gui.MainFrame) JMeterTreeModel(org.apache.jmeter.gui.tree.JMeterTreeModel) JTree(javax.swing.JTree) TreePath(javax.swing.tree.TreePath) JMeterTreeListener(org.apache.jmeter.gui.tree.JMeterTreeListener) File(java.io.File)

Example 2 with ActionRouter

use of org.apache.jmeter.gui.action.ActionRouter in project jmeter by apache.

the class JMeterTreeListener method keyPressed.

@Override
public void keyPressed(KeyEvent e) {
    String actionName = null;
    if (KeyStrokes.matches(e, KeyStrokes.COPY)) {
        actionName = ActionNames.COPY;
    } else if (KeyStrokes.matches(e, KeyStrokes.PASTE)) {
        actionName = ActionNames.PASTE;
    } else if (KeyStrokes.matches(e, KeyStrokes.CUT)) {
        actionName = ActionNames.CUT;
    } else if (KeyStrokes.matches(e, KeyStrokes.DUPLICATE)) {
        actionName = ActionNames.DUPLICATE;
    } else if (KeyStrokes.matches(e, KeyStrokes.ALT_UP_ARROW)) {
        actionName = ActionNames.MOVE_UP;
    } else if (KeyStrokes.matches(e, KeyStrokes.ALT_DOWN_ARROW)) {
        actionName = ActionNames.MOVE_DOWN;
    } else if (KeyStrokes.matches(e, KeyStrokes.ALT_LEFT_ARROW)) {
        actionName = ActionNames.MOVE_LEFT;
    } else if (KeyStrokes.matches(e, KeyStrokes.ALT_RIGHT_ARROW)) {
        actionName = ActionNames.MOVE_RIGHT;
    } else if (KeyStrokes.matches(e, KeyStrokes.SHIFT_LEFT_ARROW)) {
        actionName = ActionNames.COLLAPSE;
    } else if (KeyStrokes.matches(e, KeyStrokes.SHIFT_RIGHT_ARROW)) {
        actionName = ActionNames.EXPAND;
    }
    if (actionName != null) {
        final ActionRouter actionRouter = ActionRouter.getInstance();
        actionRouter.doActionNow(new ActionEvent(e.getSource(), e.getID(), actionName));
        e.consume();
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) ActionRouter(org.apache.jmeter.gui.action.ActionRouter)

Aggregations

ActionEvent (java.awt.event.ActionEvent)2 ActionRouter (org.apache.jmeter.gui.action.ActionRouter)2 ConversionException (com.thoughtworks.xstream.converters.ConversionException)1 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 SocketException (java.net.SocketException)1 JTree (javax.swing.JTree)1 TreePath (javax.swing.tree.TreePath)1 IllegalUserActionException (org.apache.jmeter.exceptions.IllegalUserActionException)1 MainFrame (org.apache.jmeter.gui.MainFrame)1 JMeterTreeListener (org.apache.jmeter.gui.tree.JMeterTreeListener)1 JMeterTreeModel (org.apache.jmeter.gui.tree.JMeterTreeModel)1 ConfigurationException (org.apache.jmeter.report.config.ConfigurationException)1 GenerationException (org.apache.jmeter.report.dashboard.GenerationException)1 HashTree (org.apache.jorphan.collections.HashTree)1 JMeterException (org.apache.jorphan.util.JMeterException)1