Search in sources :

Example 1 with FilePanel

use of org.apache.jmeter.gui.util.FilePanel in project jmeter by apache.

the class RespTimeGraphVisualizer method actionPerformed.

@Override
public void actionPerformed(ActionEvent event) {
    boolean forceReloadData = false;
    final Object eventSource = event.getSource();
    if (eventSource == displayButton) {
        actionMakeGraph();
    } else if (eventSource == saveGraph) {
        saveGraphToFile = true;
        try {
            ActionRouter.getInstance().getAction(ActionNames.SAVE_GRAPHICS, SaveGraphics.class.getName()).doAction(new ActionEvent(this, event.getID(), ActionNames.SAVE_GRAPHICS));
        } catch (Exception e) {
            log.error(e.getMessage());
        }
    } else if (eventSource == syncWithName) {
        graphTitle.setText(namePanel.getName());
    } else if (eventSource == dynamicGraphSize) {
        enableDynamicGraph(dynamicGraphSize.isSelected());
    } else if (eventSource == samplerSelection) {
        enableSamplerSelection(samplerSelection.isSelected());
        if (!samplerSelection.isSelected()) {
            // Force reload data
            forceReloadData = true;
        }
    }
    // Not 'else if' because forceReloadData 
    if (eventSource == applyFilterBtn || eventSource == intervalButton || forceReloadData) {
        if (eventSource == intervalButton) {
            intervalValue = Integer.parseInt(intervalField.getText());
        }
        if (eventSource == applyFilterBtn && samplerSelection.isSelected() && samplerMatchLabel.getText() != null && samplerMatchLabel.getText().length() > 0) {
            pattern = createPattern(samplerMatchLabel.getText());
        } else if (forceReloadData) {
            pattern = null;
        }
        if (getFile() != null && getFile().length() > 0) {
            // Reload data from file
            clearData();
            FilePanel filePanel = (FilePanel) getFilePanel();
            filePanel.actionPerformed(event);
        } else {
            // Reload data form internal list of results
            synchronized (lockInterval) {
                if (internalList.size() >= 2) {
                    List<RespTimeGraphDataBean> tempList = new ArrayList<>();
                    tempList.addAll(internalList);
                    this.clearData();
                    for (RespTimeGraphDataBean data : tempList) {
                        SampleResult sr = new SampleResult(data.getStartTime(), data.getTime());
                        sr.setSampleLabel(data.getSamplerLabel());
                        this.add(sr);
                    }
                }
            }
        }
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) FilePanel(org.apache.jmeter.gui.util.FilePanel) SampleResult(org.apache.jmeter.samplers.SampleResult) SaveGraphics(org.apache.jmeter.gui.action.SaveGraphics) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 2 with FilePanel

use of org.apache.jmeter.gui.util.FilePanel in project jmeter by apache.

the class HTMLAssertionGui method init.

/**
     * Inits the GUI.
     */
private void init() {
    // WARNING: called from ctor so must not be overridden (i.e. must be private or final)
    setLayout(new BorderLayout(0, 10));
    setBorder(makeBorder());
    add(makeTitlePanel(), BorderLayout.NORTH);
    JPanel mainPanel = new JPanel(new BorderLayout());
    // USER_INPUT
    VerticalPanel assertionPanel = new VerticalPanel();
    assertionPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Tidy Settings"));
    // doctype
    HorizontalPanel docTypePanel = new HorizontalPanel();
    docTypeBox = new JComboBox<>(new String[] { "omit", "auto", "strict", "loose" });
    // docTypePanel.add(new
    // JLabel(JMeterUtils.getResString("duration_assertion_label"))); //$NON-NLS-1$
    docTypePanel.add(new JLabel("Doctype:"));
    docTypePanel.add(docTypeBox);
    assertionPanel.add(docTypePanel);
    // format (HTML, XHTML, XML)
    VerticalPanel formatPanel = new VerticalPanel();
    formatPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "Format"));
    //$NON-NLS-1$
    htmlRadioButton = new JRadioButton("HTML", true);
    //$NON-NLS-1$
    xhtmlRadioButton = new JRadioButton("XHTML", false);
    //$NON-NLS-1$
    xmlRadioButton = new JRadioButton("XML", false);
    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(htmlRadioButton);
    buttonGroup.add(xhtmlRadioButton);
    buttonGroup.add(xmlRadioButton);
    formatPanel.add(htmlRadioButton);
    formatPanel.add(xhtmlRadioButton);
    formatPanel.add(xmlRadioButton);
    assertionPanel.add(formatPanel);
    // errors only
    errorsOnly = new JCheckBox("Errors only", false);
    errorsOnly.addActionListener(this);
    assertionPanel.add(errorsOnly);
    // thresholds
    HorizontalPanel thresholdPanel = new HorizontalPanel();
    thresholdPanel.add(new JLabel("Error threshold:"));
    // $NON-NLS-1$
    errorThresholdField = new JTextField("0", 5);
    errorThresholdField.setName(ERROR_THRESHOLD_FIELD);
    errorThresholdField.addKeyListener(this);
    thresholdPanel.add(errorThresholdField);
    thresholdPanel.add(new JLabel("Warning threshold:"));
    // $NON-NLS-1$
    warningThresholdField = new JTextField("0", 5);
    warningThresholdField.setName(WARNING_THRESHOLD_FIELD);
    warningThresholdField.addKeyListener(this);
    thresholdPanel.add(warningThresholdField);
    assertionPanel.add(thresholdPanel);
    // file panel
    //$NON-NLS-1$ //$NON-NLS-2$
    filePanel = new FilePanel(JMeterUtils.getResString("html_assertion_file"), ".txt");
    assertionPanel.add(filePanel);
    mainPanel.add(assertionPanel, BorderLayout.NORTH);
    add(mainPanel, BorderLayout.CENTER);
}
Also used : JCheckBox(javax.swing.JCheckBox) JPanel(javax.swing.JPanel) VerticalPanel(org.apache.jmeter.gui.util.VerticalPanel) JRadioButton(javax.swing.JRadioButton) BorderLayout(java.awt.BorderLayout) ButtonGroup(javax.swing.ButtonGroup) HorizontalPanel(org.apache.jmeter.gui.util.HorizontalPanel) JLabel(javax.swing.JLabel) FilePanel(org.apache.jmeter.gui.util.FilePanel) JTextField(javax.swing.JTextField)

Example 3 with FilePanel

use of org.apache.jmeter.gui.util.FilePanel in project jmeter by apache.

the class StatGraphVisualizer method actionPerformed.

@Override
public void actionPerformed(ActionEvent event) {
    boolean forceReloadData = false;
    final Object eventSource = event.getSource();
    if (eventSource == displayButton) {
        actionMakeGraph();
    } else if (eventSource == saveGraph) {
        saveGraphToFile = true;
        try {
            ActionRouter.getInstance().getAction(ActionNames.SAVE_GRAPHICS, SaveGraphics.class.getName()).doAction(new ActionEvent(this, event.getID(), ActionNames.SAVE_GRAPHICS));
        } catch (Exception e) {
            log.error("Error saving to file", e);
        }
    } else if (eventSource == saveTable) {
        //$NON-NLS-1$
        JFileChooser chooser = FileDialoger.promptToSaveFile("statistics.csv");
        if (chooser == null) {
            return;
        }
        try (FileOutputStream fo = new FileOutputStream(chooser.getSelectedFile());
            OutputStreamWriter writer = new OutputStreamWriter(fo, Charset.forName("UTF-8"))) {
            CSVSaveService.saveCSVStats(getAllTableData(model, getFormatters()), writer, saveHeaders.isSelected() ? getLabels(COLUMNS) : null);
        } catch (IOException e) {
            // NOSONAR Error is reported in GUI
            JMeterUtils.reportErrorToUser(e.getMessage(), "Error saving data");
        }
    } else if (eventSource == chooseForeColor) {
        Color color = JColorChooser.showDialog(null, //$NON-NLS-1$
        JMeterUtils.getResString("aggregate_graph_choose_color"), colorBarGraph);
        if (color != null) {
            colorForeGraph = color;
        }
    } else if (eventSource == syncWithName) {
        graphTitle.setText(namePanel.getName());
    } else if (eventSource == dynamicGraphSize) {
        // if use dynamic graph size is checked, we disable the dimension fields
        if (dynamicGraphSize.isSelected()) {
            graphWidth.setEnabled(false);
            graphHeight.setEnabled(false);
        } else {
            graphWidth.setEnabled(true);
            graphHeight.setEnabled(true);
        }
    } else if (eventSource == columnSelection) {
        if (columnSelection.isSelected()) {
            columnMatchLabel.setEnabled(true);
            applyFilterBtn.setEnabled(true);
            caseChkBox.setEnabled(true);
            regexpChkBox.setEnabled(true);
        } else {
            columnMatchLabel.setEnabled(false);
            applyFilterBtn.setEnabled(false);
            caseChkBox.setEnabled(false);
            regexpChkBox.setEnabled(false);
            // Force reload data
            forceReloadData = true;
        }
    }
    // Not 'else if' because forceReloadData 
    if (eventSource == applyFilterBtn || forceReloadData) {
        if (columnSelection.isSelected() && columnMatchLabel.getText() != null && columnMatchLabel.getText().length() > 0) {
            pattern = createPattern(columnMatchLabel.getText());
        } else if (forceReloadData) {
            pattern = null;
        }
        if (getFile() != null && getFile().length() > 0) {
            clearData();
            FilePanel filePanel = (FilePanel) getFilePanel();
            filePanel.actionPerformed(event);
        }
    } else if (eventSource instanceof JButton) {
        // Changing color for column
        JButton btn = (JButton) eventSource;
        if (btn.getName() != null) {
            try {
                BarGraph bar = eltList.get(Integer.parseInt(btn.getName()));
                Color color = JColorChooser.showDialog(null, bar.getLabel(), bar.getBackColor());
                if (color != null) {
                    bar.setBackColor(color);
                    btn.setBackground(bar.getBackColor());
                }
            } catch (NumberFormatException nfe) {
            // nothing to do
            }
        }
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) Color(java.awt.Color) JButton(javax.swing.JButton) FilePanel(org.apache.jmeter.gui.util.FilePanel) IOException(java.io.IOException) PatternSyntaxException(java.util.regex.PatternSyntaxException) IOException(java.io.IOException) JFileChooser(javax.swing.JFileChooser) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) SaveGraphics(org.apache.jmeter.gui.action.SaveGraphics)

Aggregations

FilePanel (org.apache.jmeter.gui.util.FilePanel)3 ActionEvent (java.awt.event.ActionEvent)2 PatternSyntaxException (java.util.regex.PatternSyntaxException)2 SaveGraphics (org.apache.jmeter.gui.action.SaveGraphics)2 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 ButtonGroup (javax.swing.ButtonGroup)1 JButton (javax.swing.JButton)1 JCheckBox (javax.swing.JCheckBox)1 JFileChooser (javax.swing.JFileChooser)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 JRadioButton (javax.swing.JRadioButton)1 JTextField (javax.swing.JTextField)1 HorizontalPanel (org.apache.jmeter.gui.util.HorizontalPanel)1 VerticalPanel (org.apache.jmeter.gui.util.VerticalPanel)1