Search in sources :

Example 16 with Style

use of javax.swing.text.Style in project jmeter by apache.

the class SamplerResultTab method setupTabPane.

@Override
@SuppressWarnings("boxing")
public void setupTabPane() {
    // Clear all data before display a new
    this.clearData();
    StyledDocument statsDoc = stats.getStyledDocument();
    try {
        if (userObject instanceof SampleResult) {
            sampleResult = (SampleResult) userObject;
            // We are displaying a SampleResult
            setupTabPaneForSampleResult();
            requestPanel.setSamplerResult(sampleResult);
            final String samplerClass = sampleResult.getClass().getName();
            String typeResult = samplerClass.substring(1 + samplerClass.lastIndexOf('.'));
            StringBuilder statsBuff = new StringBuilder(200);
            //$NON-NLS-1$
            statsBuff.append(JMeterUtils.getResString("view_results_thread_name")).append(sampleResult.getThreadName()).append(NL);
            String startTime = dateFormat.format(new Date(sampleResult.getStartTime()));
            //$NON-NLS-1$
            statsBuff.append(JMeterUtils.getResString("view_results_sample_start")).append(startTime).append(NL);
            //$NON-NLS-1$
            statsBuff.append(JMeterUtils.getResString("view_results_load_time")).append(sampleResult.getTime()).append(NL);
            //$NON-NLS-1$
            statsBuff.append(JMeterUtils.getResString("view_results_connect_time")).append(sampleResult.getConnectTime()).append(NL);
            //$NON-NLS-1$
            statsBuff.append(JMeterUtils.getResString("view_results_latency")).append(sampleResult.getLatency()).append(NL);
            //$NON-NLS-1$
            statsBuff.append(JMeterUtils.getResString("view_results_size_in_bytes")).append(sampleResult.getBytesAsLong()).append(NL);
            //$NON-NLS-1$
            statsBuff.append(JMeterUtils.getResString("view_results_sent_bytes")).append(sampleResult.getSentBytes()).append(NL);
            //$NON-NLS-1$
            statsBuff.append(JMeterUtils.getResString("view_results_size_headers_in_bytes")).append(sampleResult.getHeadersSize()).append(NL);
            //$NON-NLS-1$
            statsBuff.append(JMeterUtils.getResString("view_results_size_body_in_bytes")).append(sampleResult.getBodySizeAsLong()).append(NL);
            //$NON-NLS-1$
            statsBuff.append(JMeterUtils.getResString("view_results_sample_count")).append(sampleResult.getSampleCount()).append(NL);
            //$NON-NLS-1$
            statsBuff.append(JMeterUtils.getResString("view_results_error_count")).append(sampleResult.getErrorCount()).append(NL);
            //$NON-NLS-1$
            statsBuff.append(JMeterUtils.getResString("view_results_datatype")).append(sampleResult.getDataType()).append(NL);
            statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
            // reset for reuse
            statsBuff.setLength(0);
            String responseCode = sampleResult.getResponseCode();
            int responseLevel = 0;
            if (responseCode != null) {
                try {
                    responseLevel = Integer.parseInt(responseCode) / 100;
                } catch (NumberFormatException numberFormatException) {
                // no need to change the foreground color
                }
            }
            Style style = null;
            switch(responseLevel) {
                case 3:
                    style = statsDoc.getStyle(STYLE_REDIRECT);
                    break;
                case 4:
                    style = statsDoc.getStyle(STYLE_CLIENT_ERROR);
                    break;
                case 5:
                    style = statsDoc.getStyle(STYLE_SERVER_ERROR);
                    break;
                default:
                    // quieten Findbugs
                    break;
            }
            //$NON-NLS-1$
            statsBuff.append(JMeterUtils.getResString("view_results_response_code")).append(responseCode).append(NL);
            statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), style);
            // reset for reuse
            statsBuff.setLength(0);
            // response message label
            String responseMsgStr = sampleResult.getResponseMessage();
            //$NON-NLS-1$
            statsBuff.append(JMeterUtils.getResString("view_results_response_message")).append(responseMsgStr).append(NL);
            statsBuff.append(NL);
            //$NON-NLS-1$
            statsBuff.append(JMeterUtils.getResString("view_results_response_headers")).append(NL);
            statsBuff.append(sampleResult.getResponseHeaders()).append(NL);
            statsBuff.append(NL);
            //$NON-NLS-1$ $NON-NLS-2$
            statsBuff.append(typeResult + " " + JMeterUtils.getResString("view_results_fields")).append(NL);
            //$NON-NLS-1$
            statsBuff.append("ContentType: ").append(sampleResult.getContentType()).append(NL);
            //$NON-NLS-1$
            statsBuff.append("DataEncoding: ").append(sampleResult.getDataEncodingNoDefault()).append(NL);
            statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
            // NOSONAR Help gc
            statsBuff = null;
            // Tabbed results: fill table
            //$NON-NLS-1$
            resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_thread_name"), sampleResult.getThreadName()));
            //$NON-NLS-1$
            resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_sample_start"), startTime));
            //$NON-NLS-1$
            resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_load_time"), sampleResult.getTime()));
            //$NON-NLS-1$
            resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_connect_time"), sampleResult.getConnectTime()));
            //$NON-NLS-1$
            resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_latency"), sampleResult.getLatency()));
            //$NON-NLS-1$
            resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_in_bytes"), sampleResult.getBytesAsLong()));
            //$NON-NLS-1$
            resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_sent_bytes"), sampleResult.getSentBytes()));
            //$NON-NLS-1$
            resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_headers_in_bytes"), sampleResult.getHeadersSize()));
            //$NON-NLS-1$
            resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_body_in_bytes"), sampleResult.getBodySizeAsLong()));
            //$NON-NLS-1$
            resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_sample_count"), sampleResult.getSampleCount()));
            //$NON-NLS-1$
            resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_error_count"), sampleResult.getErrorCount()));
            //$NON-NLS-1$
            resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_response_code"), responseCode));
            //$NON-NLS-1$
            resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_response_message"), responseMsgStr));
            // Parsed response headers
            LinkedHashMap<String, String> lhm = JMeterUtils.parseHeaders(sampleResult.getResponseHeaders());
            Set<Entry<String, String>> keySet = lhm.entrySet();
            for (Entry<String, String> entry : keySet) {
                resHeadersModel.addRow(new RowResult(entry.getKey(), entry.getValue()));
            }
            // Fields table
            //$NON-NLS-1$
            resFieldsModel.addRow(new RowResult("Type Result ", typeResult));
            //not sure needs I18N?
            //$NON-NLS-1$
            resFieldsModel.addRow(new RowResult("ContentType", sampleResult.getContentType()));
            //$NON-NLS-1$
            resFieldsModel.addRow(new RowResult("DataEncoding", sampleResult.getDataEncodingNoDefault()));
            // Reset search
            if (activateSearchExtension) {
                searchTextExtension.resetTextToFind();
            }
        } else if (userObject instanceof AssertionResult) {
            assertionResult = (AssertionResult) userObject;
            // We are displaying an AssertionResult
            setupTabPaneForAssertionResult();
            StringBuilder statsBuff = new StringBuilder(100);
            //$NON-NLS-1$
            statsBuff.append(JMeterUtils.getResString("view_results_assertion_error")).append(assertionResult.isError()).append(NL);
            //$NON-NLS-1$
            statsBuff.append(JMeterUtils.getResString("view_results_assertion_failure")).append(assertionResult.isFailure()).append(NL);
            //$NON-NLS-1$
            statsBuff.append(JMeterUtils.getResString("view_results_assertion_failure_message")).append(assertionResult.getFailureMessage()).append(NL);
            statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
        }
        stats.setCaretPosition(1);
    } catch (BadLocationException exc) {
        stats.setText(exc.getLocalizedMessage());
    }
}
Also used : AssertionResult(org.apache.jmeter.assertions.AssertionResult) StyledDocument(javax.swing.text.StyledDocument) Date(java.util.Date) Entry(java.util.Map.Entry) Style(javax.swing.text.Style) SampleResult(org.apache.jmeter.samplers.SampleResult) BadLocationException(javax.swing.text.BadLocationException)

Example 17 with Style

use of javax.swing.text.Style in project sulky by huxi.

the class SwingLogging method appendStyles.

private static void appendStyles(StyleSheet styleSheet, StringBuilder msg) {
    Enumeration<?> styleNames = styleSheet.getStyleNames();
    while (styleNames.hasMoreElements()) {
        Object styleName = styleNames.nextElement();
        Style style = styleSheet.getStyle(String.valueOf(styleName));
        msg.append("StyleName: ").append(styleName).append("\nStyle: ").append(style).append("\n\n");
    }
    StyleSheet[] styleSheets = styleSheet.getStyleSheets();
    if (styleSheets != null && styleSheets.length > 0) {
        for (int i = 0; i < styleSheets.length; i++) {
            msg.append("Child #").append(i).append(':');
            StyleSheet ss = styleSheets[i];
            appendStyles(ss, msg);
        }
    }
}
Also used : StyleSheet(javax.swing.text.html.StyleSheet) Style(javax.swing.text.Style)

Aggregations

Style (javax.swing.text.Style)17 BadLocationException (javax.swing.text.BadLocationException)5 StyledDocument (javax.swing.text.StyledDocument)4 BaseType (com.google.security.zynamics.binnavi.disassembly.types.BaseType)3 HTMLDocument (javax.swing.text.html.HTMLDocument)3 StyleContext (javax.swing.text.StyleContext)2 StyleSheet (javax.swing.text.html.StyleSheet)2 TypeMember (com.google.security.zynamics.binnavi.disassembly.types.TypeMember)1 LoadingNode (com.intellij.ui.LoadingNode)1 BorderLayout (java.awt.BorderLayout)1 Date (java.util.Date)1 Entry (java.util.Map.Entry)1 JPanel (javax.swing.JPanel)1 JSplitPane (javax.swing.JSplitPane)1 JTabbedPane (javax.swing.JTabbedPane)1 JTable (javax.swing.JTable)1 JTextPane (javax.swing.JTextPane)1 AttributeSet (javax.swing.text.AttributeSet)1 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)1 AssertionResult (org.apache.jmeter.assertions.AssertionResult)1