Search in sources :

Example 16 with StyledDocument

use of javax.swing.text.StyledDocument 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 StyledDocument

use of javax.swing.text.StyledDocument in project pcgen by PCGen.

the class NotesView method handleBackspace.

//methods dealing with Key Events
private void handleBackspace() {
    // TODO: This sucks, clean it up
    Element elem;
    int pos = editor.getCaretPosition();
    StyledDocument htmlDoc = (ExtendedHTMLDocument) editor.getStyledDocument();
    try {
        if (pos > 0) {
            if ((editor.getSelectedText()) != null) {
                ExtendedHTMLEditorKit.delete(editor);
                return;
            }
            int sOffset = htmlDoc.getParagraphElement(pos).getStartOffset();
            if (sOffset == editor.getSelectionStart()) {
                if (ExtendedHTMLEditorKit.checkParentsTag(htmlDoc.getParagraphElement(editor.getCaretPosition()), HTML.Tag.LI)) {
                    elem = ExtendedHTMLEditorKit.getListItemParent(htmlDoc.getCharacterElement(editor.getCaretPosition()));
                    boolean content = false;
                    int so = elem.getStartOffset();
                    int eo = elem.getEndOffset();
                    if ((so + 1) < eo) {
                        char[] temp = editor.getText(so, eo - so).toCharArray();
                        for (char aTemp : temp) {
                            if (!Character.isWhitespace(aTemp)) {
                                content = true;
                            }
                        }
                    }
                    if (!content) {
                        elem.getParentElement();
                        ExtendedHTMLEditorKit.removeTag(editor, elem, true);
                        editor.setCaretPosition(sOffset - 1);
                        return;
                    }
                    editor.setCaretPosition(editor.getCaretPosition() - 1);
                    editor.moveCaretPosition(editor.getCaretPosition() - 2);
                    editor.replaceSelection("");
                    return;
                }
            }
            editor.replaceSelection("");
        }
    } catch (BadLocationException ble) {
        Logging.errorPrint(ble.getMessage(), ble);
    }
}
Also used : ExtendedHTMLDocument(gmgen.gui.ExtendedHTMLDocument) Element(javax.swing.text.Element) StyledDocument(javax.swing.text.StyledDocument) Point(java.awt.Point) BadLocationException(javax.swing.text.BadLocationException)

Example 18 with StyledDocument

use of javax.swing.text.StyledDocument in project enclojure by EricThorsen.

the class ClojureCodeCompletionItem method doSubstitute.

private void doSubstitute(final JTextComponent component, final String toAdd, final int backOffset) {
    final StyledDocument doc = (StyledDocument) component.getDocument();
    class AtomicChange implements Runnable {

        public void run() {
            int caretOffset = component.getCaretPosition();
            String cname = component.getClass().getName();
            Boolean _isReplPanel = false;
            if (cname.equals("javax.swing.JEditorPane"))
                _isReplPanel = true;
            String value = getText();
            String javaList = "";
            if (toAdd != null) {
                value += toAdd;
            }
            try {
                String c = component.getText(caretOffset - 1, 1);
                if (// java package containing the Class at the end
                !_isClojure && _isNamespaceOrPkg) {
                    value = setValueForClass(value, component);
                    javaList = getJavaImportListStr(value);
                    if ((javaList.contains("(")) && (!_isReplPanel)) {
                        int messageret = (JOptionPane.showConfirmDialog(component, "Do you want to add the import " + value + " to your ns imports?", "add import ?", 0));
                        if (messageret == 0) {
                            PersistentArrayMap entry = addImportList(component, javaList);
                            // component.setCaretPosition(caretOffset + javaList.length());
                            value = getClassPart(value);
                            if (entry != null) {
                                String origNS = (String) entry.get(Keyword.intern(Symbol.create("orignodestr")));
                                String newNS = (String) entry.get(Keyword.intern(Symbol.create("newnodestr")));
                                int insertOffset = newNS.length() - origNS.length();
                                _carretOffset = _carretOffset + insertOffset;
                                _dotOffset = _dotOffset + insertOffset;
                            }
                        }
                    }
                }
                if (!c.equals("/") && (_layout != backSlashAfterParen) && (_layout != backSlashNoParen)) {
                    switch(_layout) {
                        case LowercaseAfterParen:
                            doc.remove(_dotOffset, _carretOffset - _dotOffset);
                            break;
                        case UppercaseAfterParen:
                            doc.remove(_dotOffset, _carretOffset - _dotOffset);
                            break;
                        case UppercaseAfterParenWithDot:
                            if (// java method
                            _isMethodOrFunction && (!_isClojure)) {
                                if (_isConstructor) {
                                    value = "";
                                } else if (Character.isLetter(value.charAt(0))) {
                                    {
                                        doc.remove(_dotOffset, _carretOffset - _dotOffset);
                                        value = "." + value;
                                    }
                                }
                            } else
                                doc.remove(_dotOffset, _carretOffset - _dotOffset);
                            break;
                        case LowercaseAfterParenWithDot:
                            if (// java method
                            _isMethodOrFunction && (!_isClojure)) {
                                if (_isConstructor) {
                                    value = "";
                                } else if (Character.isLetter(value.charAt(0))) {
                                    {
                                        doc.remove(_dotOffset, _carretOffset - _dotOffset);
                                        value = "." + value;
                                    }
                                }
                            } else
                                doc.remove(_dotOffset, _carretOffset - _dotOffset);
                            break;
                        case backSlashAfterParen:
                            doc.remove(_dotOffset, _carretOffset - _dotOffset);
                            break;
                        case FirstDotAfterParen:
                            doc.remove(_dotOffset, _carretOffset - _dotOffset);
                            break;
                        case FirstDotNoParen:
                            doc.remove(_dotOffset, _carretOffset - _dotOffset);
                            break;
                        case UppercaseNoParen:
                            doc.remove(_dotOffset, _carretOffset - _dotOffset);
                            break;
                        case UppercaseNoParenWithDot:
                            if (// java method
                            _isMethodOrFunction && (!_isClojure)) {
                                if (_isConstructor) {
                                    value = "";
                                } else if (Character.isLetter(value.charAt(0))) {
                                    {
                                        doc.remove(_dotOffset, _carretOffset - _dotOffset);
                                        value = "." + value;
                                    }
                                }
                            } else
                                doc.remove(_dotOffset, _carretOffset - _dotOffset);
                            break;
                        case LowercaseNoParenWithDot:
                            if (// java method
                            _isMethodOrFunction && (!_isClojure)) {
                                if (_isConstructor) {
                                    value = "";
                                } else if (Character.isLetter(value.charAt(0))) {
                                    {
                                        doc.remove(_dotOffset, _carretOffset - _dotOffset);
                                        value = "." + value;
                                    }
                                }
                            } else
                                doc.remove(_dotOffset, _carretOffset - _dotOffset);
                            break;
                        case LowercaseNoParen:
                            doc.remove(_dotOffset, _carretOffset - _dotOffset);
                            break;
                    }
                    doc.insertString(_dotOffset, value, null);
                } else {
                    if (!c.equals("/")) {
                        int backSlashOffset = indexOfBackSlash(component);
                        if (backSlashOffset == -1)
                            backSlashOffset = caretOffset;
                        if (_isStatic || _layout == backSlashAfterParen || _layout == backSlashNoParen) {
                            if (_isClojure && _isMethodOrFunction) {
                                if (isInCurrentNamespace(_fullclassname, component)) {
                                    doc.remove(_dotOffset, _carretOffset - _dotOffset);
                                    doc.insertString(_dotOffset, setValue(value), null);
                                } else {
                                    doc.remove(backSlashOffset + 1, caretOffset - backSlashOffset - 1);
                                    doc.insertString(backSlashOffset + 1, value, null);
                                }
                            } else {
                                doc.remove(backSlashOffset + 1, caretOffset - backSlashOffset - 1);
                                doc.insertString(backSlashOffset + 1, value, null);
                            }
                        } else {
                            doc.remove(_dotOffset, _carretOffset - _dotOffset);
                            doc.insertString(_dotOffset, setValue(value), null);
                        }
                    } else if (_isStatic || _layout == backSlashAfterParen || _layout == backSlashNoParen)
                        if (_isClojure && _isMethodOrFunction) {
                            if (isInCurrentNamespace(_fullclassname, component)) {
                                doc.remove(_dotOffset, _carretOffset - _dotOffset);
                                doc.insertString(_dotOffset, setValue(value), null);
                            } else
                                doc.insertString(_carretOffset, value, null);
                        } else
                            doc.insertString(_carretOffset, value, null);
                    else {
                        doc.remove(_dotOffset, _carretOffset - _dotOffset);
                        doc.insertString(_dotOffset, setValue(value), null);
                    }
                }
                component.setCaretPosition(component.getCaretPosition() - backOffset);
            } catch (BadLocationException e) {
                LOG.log(Level.FINEST, e.getMessage());
            }
        }
    }
    AtomicChange change = new AtomicChange();
    try {
        NbDocument.runAtomicAsUser(doc, change);
    } catch (BadLocationException ex) {
        LOG.log(Level.FINEST, ex.getMessage());
    }
}
Also used : PersistentArrayMap(clojure.lang.PersistentArrayMap) StyledDocument(javax.swing.text.StyledDocument) BadLocationException(javax.swing.text.BadLocationException)

Example 19 with StyledDocument

use of javax.swing.text.StyledDocument in project vcell by virtualcell.

the class SimulationConsolePanel method appendToConsole.

private void appendToConsole(TaskCallbackMessage newCallbackMessage) {
    TaskCallbackStatus status = newCallbackMessage.getStatus();
    String string = newCallbackMessage.getText();
    StyledDocument doc = netGenConsoleText.getStyledDocument();
    SimpleAttributeSet keyWord = new SimpleAttributeSet();
    try {
        switch(status) {
            case // clean console, display task initialization message
            Clean:
                netGenConsoleText.setText("");
                break;
            case TaskStopped:
                StyleConstants.setForeground(keyWord, Color.RED);
                StyleConstants.setBold(keyWord, true);
                doc.insertString(doc.getLength(), "  " + string + "\n", keyWord);
                break;
            case // normal notification, just display the string
            Notification:
                doc.insertString(doc.getLength(), string + "\n", null);
                break;
            case // display this in red, bold
            Error:
                StyleConstants.setForeground(keyWord, Color.RED);
                StyleConstants.setBold(keyWord, true);
                doc.insertString(doc.getLength(), string + "\n", keyWord);
                break;
            case // display this in red
            Warning:
                StyleConstants.setForeground(keyWord, Color.RED);
                doc.insertString(doc.getLength(), string + "\n", keyWord);
                break;
            default:
                break;
        }
    } catch (Exception e) {
        System.out.println(e);
    }
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) StyledDocument(javax.swing.text.StyledDocument) TaskCallbackStatus(cbit.vcell.mapping.TaskCallbackMessage.TaskCallbackStatus)

Example 20 with StyledDocument

use of javax.swing.text.StyledDocument in project vcell by virtualcell.

the class MultiPurposeTextPanel method highlightKeywords.

private void highlightKeywords(String text, int position) {
    if (text == null || keywords.size() < 1) {
        return;
    }
    ArrayList<KeywordToken> tokenList = new ArrayList<KeywordToken>();
    int p0 = 0;
    StringTokenizer st = new StringTokenizer(text);
    while (st.hasMoreTokens()) {
        while (p0 < text.length()) {
            char ch = text.charAt(p0);
            if (ch == ' ' || ch == '\n' || ch == '\f' || ch == '\t' || ch == '\r') {
                p0++;
            } else {
                break;
            }
        }
        String token = st.nextToken();
        if (keywords.contains(token)) {
            tokenList.add(new KeywordToken(token, p0 + position));
        }
        if (Character.isJavaIdentifierStart(token.charAt(0)) && Character.isJavaIdentifierPart(token.charAt(token.length() - 1))) {
            fullAutoCompletionWords.add(token);
        }
        p0 = p0 + token.length();
    }
    for (KeywordToken kt : tokenList) {
        ((StyledDocument) getTextPane().getDocument()).setCharacterAttributes(kt.charBegin, kt.contents.length(), getKeywordStyle(), true);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) ArrayList(java.util.ArrayList) StyledDocument(javax.swing.text.StyledDocument) Point(java.awt.Point)

Aggregations

StyledDocument (javax.swing.text.StyledDocument)22 SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)7 BadLocationException (javax.swing.text.BadLocationException)6 Point (java.awt.Point)5 Style (javax.swing.text.Style)4 PersistentArrayMap (clojure.lang.PersistentArrayMap)2 ArrayList (java.util.ArrayList)2 TaskCallbackStatus (cbit.vcell.mapping.TaskCallbackMessage.TaskCallbackStatus)1 ColorSet (com.android.tools.sherpa.drawing.ColorSet)1 ExtendedHTMLDocument (gmgen.gui.ExtendedHTMLDocument)1 BorderLayout (java.awt.BorderLayout)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 AttributedString (java.text.AttributedString)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1