Package javax.swing.text

Examples of javax.swing.text.StyledDocument


        assertNull(null);
        assertEquals("TextPaneUI", textPane.getUIClassID());
    }

    public void testSetDocument() {
        StyledDocument doc = new DefaultStyledDocument();
        textPane.setDocument(doc);
        assertSame(doc, textPane.getDocument());
        testExceptionalCase(new IllegalArgumentCase() {
            @Override
            public void exceptionalAction() throws Exception {
View Full Code Here


            }
        });
    }

    public void testSetStyledDocument() {
        StyledDocument doc = new DefaultStyledDocument();
        textPane.setDocument(doc);
        assertSame(doc, textPane.getDocument());
        testExceptionalCase(new IllegalArgumentCase() {
            @Override
            public void exceptionalAction() throws Exception {
View Full Code Here

        assertTrue(StyleConstants.isStrikeThrough(textAttrs));
        assertEquals(StyleConstants.ALIGN_CENTER, StyleConstants.getAlignment(textAttrs));
    }

    public void testSetParagraphAttributes() {
        StyledDocument doc = textPane.getStyledDocument();
        AttributeSet textAttrs;
        // The attributes are applied to the paragraph at the current caret
        // position.
        textPane.setCaretPosition(1);
        StyleConstants.setSubscript(attrs, false);
        doc.setParagraphAttributes(0, doc.getLength(), attrs, false);
        textAttrs = textPane.getParagraphAttributes();
        assertFalse(StyleConstants.isSubscript(textAttrs));
        StyleConstants.setSubscript(attrs, true);
        textPane.setParagraphAttributes(attrs, true);
        textAttrs = textPane.getParagraphAttributes();
View Full Code Here

        assertEquals(StyleConstants.ALIGN_CENTER, StyleConstants.getAlignment(textAttrs));
        assertTrue(StyleConstants.isStrikeThrough(textAttrs));
    }

    public void testSetCharacterAttributes() {
        StyledDocument doc = textPane.getStyledDocument();
        // The attributes are applied to the paragraph at the current caret
        // position.
        textPane.setCaretPosition(1);
        StyleConstants.setSubscript(textPane.getInputAttributes(), false);
        assertFalse(StyleConstants.isSubscript(textPane.getCharacterAttributes()));
View Full Code Here

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

          if (res != null) {
            // 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("\nRequest Headers:\n");
                sb.append(rh);
                sd = sb.toString();
              }
              sampleDataField.setText(sd);
            }

            StringBuffer statsBuff = new StringBuffer(200);
            statsBuff.append("Thread Name: ").append(res.getThreadName()).append(NL);
            String startTime = dateFormat.format(new Date(res.getStartTime()));
            statsBuff.append("Sample Start: ").append(startTime).append(NL);
            statsBuff.append("Load time: ").append(res.getTime()).append(NL);
            statsBuff.append("Size in bytes: ").append(res.getBytes()).append(NL);
            statsBuff.append("Sample Count: ").append(res.getSampleCount()).append(NL);
            statsBuff.append("Error Count: ").append(res.getErrorCount()).append(NL);
            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("Response code: ").append(responseCode).append(NL);
            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("Response message: ").append(responseMsgStr).append(NL);

            statsBuff.append(NL).append("Response headers:").append(NL);
            statsBuff.append(res.getResponseHeaders()).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(response);
              }
            } 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);
          }

          if (res != null) {
            StringBuffer statsBuff = new StringBuffer(100);
            statsBuff.append("Assertion error: ").append(res.isError()).append(NL);
            statsBuff.append("Assertion failure: ").append(res.isFailure()).append(NL);
            statsBuff.append("Assertion failure message : ").append(res.getFailureMessage()).append(NL);
            statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
            statsBuff = null;
          }
        }
      }
    } catch (BadLocationException 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

    @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);
                statsBuff.append(JMeterUtils.getResString("view_results_thread_name")).append(sampleResult.getThreadName()).append(NL); //$NON-NLS-1$
                String startTime = dateFormat.format(new Date(sampleResult.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(sampleResult.getTime()).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.getBytes()).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.getBodySize()).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$
                statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
                statsBuff.setLength(0); // reset for reuse

                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; // default - do nothing
                }

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

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

                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(sampleResult.getResponseHeaders()).append(NL);
                statsBuff.append(NL);
                statsBuff.append(typeResult + " "+ JMeterUtils.getResString("view_results_fields")).append(NL); //$NON-NLS-1$ $NON-NLS-2$
                statsBuff.append("ContentType: ").append(sampleResult.getContentType()).append(NL); //$NON-NLS-1$
                statsBuff.append("DataEncoding: ").append(sampleResult.getDataEncodingNoDefault()).append(NL); //$NON-NLS-1$
                statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
                statsBuff = null; // Done
               
                // Tabbed results: fill table
                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_latency"), sampleResult.getLatency())); //$NON-NLS-1$
                resultModel.addRow(new RowResult(JMeterUtils.getParsedLabel("view_results_size_in_bytes"), sampleResult.getBytes())); //$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.getBodySize())); //$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)); //$NON-NLS-1$
               
                // 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
                resFieldsModel.addRow(new RowResult("Type Result ", typeResult)); //$NON-NLS-1$
                //not sure needs I18N?
                resFieldsModel.addRow(new RowResult("ContentType", sampleResult.getContentType())); //$NON-NLS-1$
                resFieldsModel.addRow(new RowResult("DataEncoding", sampleResult.getDataEncodingNoDefault())); //$NON-NLS-1$
               
                // 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);
                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); //$NON-NLS-1$
                statsDoc.insertString(statsDoc.getLength(), statsBuff.toString(), null);
            }
        } catch (BadLocationException exc) {
            stats.setText(exc.getLocalizedMessage());
        }
    }
View Full Code Here

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

        // 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);

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

  /**
   * Creates the entity display.
   */
  private void displayEntities() {
    // for speed, detach document from text pane before updating
    StyledDocument doc = (StyledDocument) textPane.getDocument();
    Document blank = new DefaultStyledDocument();
    textPane.setDocument(blank);

    // make sure entityCheckboxPanel is showing
    if (legendScrollPane.getViewport().getView() != entityCheckboxPanel) {
      legendScrollPane.setViewportView(entityCheckboxPanel);
    }

    // add text from CAS
    try {
      doc.remove(0, doc.getLength());
      doc.insertString(0, mCAS.getDocumentText(), new SimpleAttributeSet());
    } catch (BadLocationException e) {
      throw new RuntimeException(e);
    }

    // Iterate over EntityAnnotations using JCAS, because the EntityResolver interface
    // uses JCAS as a convenience to the user.
    JCas jcas;
    try {
      // NOTE: for a large type system, this can take a few seconds, which results in a
      // noticeable delay when the user first switches to Entity mode.
      jcas = mCAS.getJCas();
    } catch (CASException e) {
      throw new RuntimeException(e);
    }
    FSIterator iter = jcas.getAnnotationIndex().iterator();
    while (iter.isValid()) {
      Annotation annot = (Annotation) iter.get();
      iter.moveToNext();

      // find out what entity this annotation represents
      EntityResolver.Entity entity = mEntityResolver.getEntity(annot);

      //if not an entity, skip it
      if (entity == null)
        continue;
     
      // have we seen this entity before?
      JCheckBox checkbox = (JCheckBox) mEntityToCheckboxMap.get(entity);
      if (checkbox == null) {
        // assign next available color
        Color c = COLORS[mEntityToCheckboxMap.size() % COLORS.length];
        // add checkbox
        checkbox = new JCheckBox(entity.getCanonicalForm(), true);
        checkbox.setToolTipText(entity.getCanonicalForm());
        checkbox.addActionListener(this);
        checkbox.setBackground(c);
        entityCheckboxPanel.add(checkbox);
        // add to (Entity, Checkbox) map
        mEntityToCheckboxMap.put(entity, checkbox);
      }

      // if checkbox is checked, assign color to text
      if (checkbox.isSelected()) {
        int begin = annot.getBegin();
        int end = annot.getEnd();
        // be careful of 0-length annotation. If we try to set background color when there
        // is no selection, it will set the input text style, which is not what we want.
        if (begin != end) {
          MutableAttributeSet attrs = new SimpleAttributeSet();
          StyleConstants.setBackground(attrs, checkbox.getBackground());
          doc.setCharacterAttributes(begin, end - begin, attrs, false);
        }
      }
    }

    // add/remove checkboxes from display as determined by the
View Full Code Here

      // match
      int pos = 0;
      while (matcher.find(pos)) {
        MutableAttributeSet attrs = new SimpleAttributeSet();
        StyleConstants.setBold(attrs, true);
        StyledDocument doc = (StyledDocument) textPane.getDocument();
        doc.setCharacterAttributes(matcher.start(), matcher.end() - matcher.start(), attrs, false);

        if (pos == matcher.end()) // infinite loop check
          break;
        else
          pos = matcher.end();
      }
    }
    // Spans
    int docLength = mCAS.getDocumentText().length();
    int len = mBoldfaceSpans.length;
    len -= len % 2; // to avoid ArrayIndexOutOfBoundsException if some numbskull passes in an
    // odd-length array
    int i = 0;
    while (i < len) {
      int begin = mBoldfaceSpans[i];
      int end = mBoldfaceSpans[i + 1];
      if (begin >= 0 && begin <= docLength && end >= 0 && end <= docLength) {
        MutableAttributeSet attrs = new SimpleAttributeSet();
        StyleConstants.setBold(attrs, true);
        StyledDocument doc = (StyledDocument) textPane.getDocument();
        doc.setCharacterAttributes(begin, end - begin, attrs, false);
      }
      i += 2;
    }
  }
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.