Package javax.swing.text

Examples of javax.swing.text.StyledDocument


        if (log.isDebugEnabled()) {
            log.debug("valueChanged : selected node - " + node);
        }

        StyledDocument statsDoc = stats.getStyledDocument();
        try {
            statsDoc.remove(0, statsDoc.getLength());
            sampleDataField.setText(""); // $NON-NLS-1$
            results.setText(""); // $NON-NLS-1$
            if (node != null) {
                Object userObject = node.getUserObject();
                if(userObject instanceof SampleResult) {
                    SampleResult res = (SampleResult) userObject;

                    // We are displaying a SampleResult
                    setupTabPaneForSampleResult();

                    if (log.isDebugEnabled()) {
                        log.debug("valueChanged1 : sample result - " + res);
                    }

                    // load time label

                    log.debug("valueChanged1 : load time - " + res.getTime());
                    String sd = res.getSamplerData();
                    if (sd != null) {
                        String rh = res.getRequestHeaders();
                        if (rh != null) {
                            StringBuffer sb = new StringBuffer(sd.length() + rh.length()+20);
                            sb.append(sd);
                            sb.append("\n"); //$NON-NLS-1$
                            sb.append(JMeterUtils.getResString("view_results_request_headers")); //$NON-NLS-1$
                            sb.append("\n"); //$NON-NLS-1$
                            sb.append(rh);
                            sd = sb.toString();
                        }
                        sampleDataField.setText(sd);
                    }

                    StringBuffer statsBuff = new StringBuffer(200);
                    statsBuff.append(JMeterUtils.getResString("view_results_thread_name")).append(res.getThreadName()).append(NL); //$NON-NLS-1$
                    String startTime = dateFormat.format(new Date(res.getStartTime()));
                    statsBuff.append(JMeterUtils.getResString("view_results_sample_start")).append(startTime).append(NL); //$NON-NLS-1$
                    statsBuff.append(JMeterUtils.getResString("view_results_load_time")).append(res.getTime()).append(NL); //$NON-NLS-1$
                    statsBuff.append(JMeterUtils.getResString("view_results_latency")).append(res.getLatency()).append(NL); //$NON-NLS-1$
                    statsBuff.append(JMeterUtils.getResString("view_results_size_in_bytes")).append(res.getBytes()).append(NL); //$NON-NLS-1$
                    statsBuff.append(JMeterUtils.getResString("view_results_sample_count")).append(res.getSampleCount()).append(NL); //$NON-NLS-1$
                    statsBuff.append(JMeterUtils.getResString("view_results_error_count")).append(res.getErrorCount()).append(NL); //$NON-NLS-1$
                    statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
                    statsBuff = new StringBuffer(); //reset for reuse

                    String responseCode = res.getResponseCode();
                    log.debug("valueChanged1 : response code - " + responseCode);

                    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;
                    }

                    statsBuff.append(JMeterUtils.getResString("view_results_response_code")).append(responseCode).append(NL); //$NON-NLS-1$
                    statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), style);
                    statsBuff = new StringBuffer(100); //reset for reuse

                    // response message label
                    String responseMsgStr = res.getResponseMessage();

                    log.debug("valueChanged1 : response message - " + responseMsgStr);
                    statsBuff.append(JMeterUtils.getResString("view_results_response_message")).append(responseMsgStr).append(NL); //$NON-NLS-1$

                    statsBuff.append(NL);
                    statsBuff.append(JMeterUtils.getResString("view_results_response_headers")).append(NL); //$NON-NLS-1$
                    statsBuff.append(res.getResponseHeaders()).append(NL);
                    statsBuff.append(NL);
                    final String samplerClass = res.getClass().getName();
                    statsBuff.append(samplerClass.substring(1+samplerClass.lastIndexOf('.'))).append(" " + JMeterUtils.getResString("view_results_fields")).append(NL); //$NON-NLS-1$
                    statsBuff.append("ContentType: ").append(res.getContentType()).append(NL);
                    statsBuff.append("DataEncoding: ").append(res.getDataEncodingNoDefault()).append(NL);
                    statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
                    statsBuff = null; // Done

                    // get the text response and image icon
                    // to determine which is NOT null
                    if ((SampleResult.TEXT).equals(res.getDataType())) // equals(null) is OK
                    {
                        String response = getResponseAsString(res);
                        if (command.equals(TEXT_COMMAND)) {
                            showTextResponse(response);
                        } else if (command.equals(HTML_COMMAND)) {
                            showRenderedResponse(response, res);
                        } else if (command.equals(JSON_COMMAND)) {
                            showRenderJSONResponse(response);
                        } else if (command.equals(XML_COMMAND)) {
                            showRenderXMLResponse(res);
                        }
                    } else {
                        byte[] responseBytes = res.getResponseData();
                        if (responseBytes != null) {
                            showImage(new ImageIcon(responseBytes)); //TODO implement other non-text types
                        }
                    }
                }
                else if(userObject instanceof AssertionResult) {
                    AssertionResult res = (AssertionResult) userObject;

                    // We are displaying an AssertionResult
                    setupTabPaneForAssertionResult();

                    if (log.isDebugEnabled()) {
                        log.debug("valueChanged1 : sample result - " + res);
                    }

                    StringBuffer statsBuff = new StringBuffer(100);
                    statsBuff.append(JMeterUtils.getResString("view_results_assertion_error")).append(res.isError()).append(NL); //$NON-NLS-1$
                    statsBuff.append(JMeterUtils.getResString("view_results_assertion_failure")).append(res.isFailure()).append(NL); //$NON-NLS-1$
                    statsBuff.append(JMeterUtils.getResString("view_results_assertion_failure_message")).append(res.getFailureMessage()).append(NL); //$NON-NLS-1$
                    statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
                    statsBuff = null;
                }
            }
        } catch (BadLocationException exc) {
            log.error("Error setting statistics text", exc);
View Full Code Here


        stats = new JTextPane();
        stats.setEditable(false);
        stats.setBackground(getBackground());

        // Add styles to use for different types of status messages
        StyledDocument doc = (StyledDocument) stats.getDocument();

        Style style = doc.addStyle(STYLE_REDIRECT, null);
        StyleConstants.setForeground(style, REDIRECT_COLOR);

        style = doc.addStyle(STYLE_CLIENT_ERROR, null);
        StyleConstants.setForeground(style, CLIENT_ERROR_COLOR);

        style = doc.addStyle(STYLE_SERVER_ERROR, null);
        StyleConstants.setForeground(style, SERVER_ERROR_COLOR);

        JScrollPane pane = makeScrollPane(stats);
        pane.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
        return pane;
View Full Code Here

        if (log.isDebugEnabled())
        {
            log.debug("valueChanged : selected node - " + node);
        }

        StyledDocument statsDoc = stats.getStyledDocument();
        try {
            statsDoc.remove(0, statsDoc.getLength());
            if (node != null) {
                SampleResult res = (SampleResult) node.getUserObject();

                if (log.isDebugEnabled()) {
                    log.debug("valueChanged1 : sample result - " + res);
                }

                if (res != null) {
                    // load time label

                    log.debug("valueChanged1 : load time - " + res.getTime());
                    if (res != null && res.getSamplerData() != null) {
                        sampleDataField.setText(res.getSamplerData().trim());
                    }

                    statsDoc.insertString(
                        statsDoc.getLength(),
                        "Load time: " + res.getTime() + "\n",
                        null);

                    String responseCode = res.getResponseCode();
                    log.debug(
                        "valueChanged1 : response code - " + responseCode);

                    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("Redirect");
                            break;
                        case 4 :
                            style = statsDoc.getStyle("ClientError");
                            break;
                        case 5 :
                            style = statsDoc.getStyle("ServerError");
                            break;
                    }
                    statsDoc.insertString(
                        statsDoc.getLength(),
                        "HTTP response code: " + responseCode + "\n",
                        style);

                    // response message label
                    String responseMsgStr = res.getResponseMessage();

                    log.debug(
                        "valueChanged1 : response message - " + responseMsgStr);
                    statsDoc.insertString(
                        statsDoc.getLength(),
                        "HTTP response message: " + responseMsgStr + "\n",
                        null);

                    // get the text response and image icon
                    // to determine which is NOT null
View Full Code Here

        stats = new JTextPane();
        stats.setEditable(false);
        stats.setBackground(getBackground());

        // Add styles to use for different types of status messages       
        StyledDocument doc = (StyledDocument)stats.getDocument();

        Style style = doc.addStyle("Redirect", null);
        StyleConstants.setForeground(style, REDIRECT_COLOR);

        style = doc.addStyle("ClientError", null);
        StyleConstants.setForeground(style, CLIENT_ERROR_COLOR);
       
        style = doc.addStyle("ServerError", null);
        StyleConstants.setForeground(style, SERVER_ERROR_COLOR);
               

        JScrollPane pane = makeScrollPane(stats);
        pane.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
View Full Code Here

                    dataString = BytesUtil.toDisplayHexString(dataByte);
                    indexPane.setText(dataIndex);
                    dataPane.setText(dataString);
                }
                try {
                    StyledDocument doc = dataPane.getStyledDocument();
                    doc.setCharacterAttributes(0, doc.getLength(), notSelected, true);
                    doc.setCharacterAttributes(offset, end - offset, selected, true);
                    dataPane.select(offset, end);//let auto scroll
                } catch (Exception ex) {
                    ex.printStackTrace();
                }
            }
View Full Code Here

    return cardId;
  }
   
  private void drawText(java.util.List<String> strings) {
    text.setText("");
    StyledDocument doc = text.getStyledDocument();

    try {
      for (String line: strings) {
        doc.insertString(doc.getLength(), line + "\n", doc.getStyle("regular"));
      }
    } catch (BadLocationException ble) { }
    text.setCaretPosition(0);
  }
View Full Code Here

    this.bigCard = bigCard;
    small = new BufferedImage(Config.dimensions.frameWidth, Config.dimensions.frameHeight, BufferedImage.TYPE_INT_RGB);
    backgroundName = getBackgroundName();
    background = ImageHelper.getBackground(card, backgroundName);
   
    StyledDocument doc = text.getStyledDocument();
        Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
        Style regular = doc.addStyle("regular", def);
        StyleConstants.setFontFamily(def, "arial");
        Style s = doc.addStyle("small", regular);
        StyleConstants.setFontSize(s, 9);

    addMouseListener(this);
    text.addMouseListener(this);
      addFocusListener(this);
View Full Code Here

    return sb.toString();
  }

  protected void drawText() {
    text.setText("");
    StyledDocument doc = text.getStyledDocument();

    try {
      for (String rule: getRules())
        doc.insertString(doc.getLength(), rule + "\n", doc.getStyle("small"));
    } catch (BadLocationException e) {}

    text.setCaretPosition(0);
  }
View Full Code Here

    return cardId;
  }
   
  private void drawText(java.util.List<String> strings) {
    text.setText("");
    StyledDocument doc = text.getStyledDocument();

    try {
      for (String line: strings) {
        doc.insertString(doc.getLength(), line + "\n", doc.getStyle("regular"));
      }
    } catch (BadLocationException ble) { }
    text.setCaretPosition(0);
  }
View Full Code Here

        if( tpane==null )return;

        if( clearStyle==null )
            clearStyle = tpane.getStyledDocument().addStyle(null, null);

        StyledDocument sdoc = tpane.getStyledDocument();
        int len = sdoc.getLength();
        if( len>0 )
        {
            sdoc.setCharacterAttributes(0, len, clearStyle, true);
        }
    }
View Full Code Here

TOP

Related Classes of javax.swing.text.StyledDocument

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.