Search in sources :

Example 86 with BadLocationException

use of javax.swing.text.BadLocationException 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 87 with BadLocationException

use of javax.swing.text.BadLocationException in project chipKIT32-MAX by chipKIT32.

the class CompositionTextManager method processCompositionText.

/**
   * Called when a user processing input characters and
   * select candidates from input method.
   * 
   * @param text Text from InputMethodEvent.
   * @param commited_count Numbers of committed characters in text. 
   */
public void processCompositionText(AttributedCharacterIterator text, int committed_count) {
    int layoutCaretPosition = initialCaretPosition + committed_count;
    CompositionTextPainter compositionPainter = textArea.getPainter().getCompositionTextpainter();
    compositionPainter.setComposedTextLayout(getTextLayout(text, committed_count), layoutCaretPosition);
    int textLength = text.getEndIndex() - text.getBeginIndex() - committed_count;
    StringBuffer unCommitedStringBuf = new StringBuffer(textLength);
    char c;
    for (c = text.setIndex(committed_count); c != AttributedCharacterIterator.DONE && textLength > 0; c = text.next(), --textLength) {
        unCommitedStringBuf.append(c);
    }
    String unCommittedString = unCommitedStringBuf.toString();
    try {
        if (canRemovePreviousInput(committed_count)) {
            textArea.getDocument().remove(layoutCaretPosition, prevComposeString.length());
        }
        textArea.getDocument().insertString(layoutCaretPosition, unCommittedString, null);
        if (committed_count > 0) {
            initialCaretPosition = initialCaretPosition + committed_count;
        }
        prevComposeString = unCommittedString;
        prevCommittedCount = committed_count;
    } catch (BadLocationException e) {
        e.printStackTrace();
    }
}
Also used : AttributedString(java.text.AttributedString) Point(java.awt.Point) BadLocationException(javax.swing.text.BadLocationException)

Example 88 with BadLocationException

use of javax.swing.text.BadLocationException in project processdash by dtuma.

the class AssignedToComboBox method startTrackingChanges.

public void startTrackingChanges() {
    initialTrackedState = new ArrayList();
    List<Word> words = document.getWords();
    Word w = (words.isEmpty() ? null : words.get(0));
    while (w != null) {
        // build trackable items for each set of initials
        TrackableItem item = new TrackableItem();
        item.origInitials = document.getWordText(w);
        int itemEndPos = w.end;
        w = w.next;
        // if the initials are followed by a number, add it to our item info
        if (w != null && w.isNumber()) {
            item.origTime = document.getWordText(w);
            itemEndPos = w.end + 1;
            w = w.next;
        }
        // create a document Position to track the end of this item
        try {
            item.end = document.createPosition(itemEndPos);
            initialTrackedState.add(item);
        } catch (BadLocationException ble) {
        }
    }
}
Also used : Word(net.sourceforge.processdash.ui.lib.autocomplete.AssignedToDocument.Word) ArrayList(java.util.ArrayList) BadLocationException(javax.swing.text.BadLocationException)

Aggregations

BadLocationException (javax.swing.text.BadLocationException)88 Document (javax.swing.text.Document)24 Element (javax.swing.text.Element)13 Point (java.awt.Point)10 IOException (java.io.IOException)9 DefaultHighlighter (javax.swing.text.DefaultHighlighter)8 DefaultStyledDocument (javax.swing.text.DefaultStyledDocument)7 Highlighter (javax.swing.text.Highlighter)7 ArrayList (java.util.ArrayList)6 DocumentEvent (javax.swing.event.DocumentEvent)6 StyledDocument (javax.swing.text.StyledDocument)6 HighlightPainter (javax.swing.text.Highlighter.HighlightPainter)5 Dimension (java.awt.Dimension)4 Rectangle (java.awt.Rectangle)4 ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 File (java.io.File)4 Date (java.util.Date)4 Style (javax.swing.text.Style)4 HTMLDocument (javax.swing.text.html.HTMLDocument)4