Package javax.swing.text

Examples of javax.swing.text.StyledDocument


  public final void format(MWPane pane, PageAnalysis pageAnalysis) {
    if (pane == null) {
      return;
    }
    // TODO: Detach document from Pane to speed up formatting
    StyledDocument doc = pane.getStyledDocument();
    //StyledDocument tmpDoc = new DefaultStyledDocument();
    //pane.setDocument(tmpDoc);

    // Format document
    format(doc, pageAnalysis);
View Full Code Here


  /**
   * @return A styled document that can be used to format a MWPane.
   */
  public static StyledDocument createDocument() {
    initializeStyles();
    StyledDocument document = new DefaultStyledDocument(styleContext);
    return document;
  }
View Full Code Here

  public void actionPerformed(ActionEvent e) {
    MWPane textPane = getMWPane(e);
    if (textPane == null) {
      return;
    }
    StyledDocument doc = textPane.getStyledDocument();
    if (doc == null) {
      return;
    }
    int length = doc.getLength();
    int lastEnd = Integer.MAX_VALUE;
    for (int pos = 0; pos < length; pos = lastEnd) {
      try {
        Element run = doc.getCharacterElement(pos);
        lastEnd = run.getEndOffset();
        if (pos == lastEnd) {
          // offset + length beyond length of document, bail.
          break;
        }
        MutableAttributeSet attr = (MutableAttributeSet) run.getAttributes();
        if ((attr != null) &&
            (attr.getAttribute(MWPaneFormatter.ATTRIBUTE_TYPE) != null) &&
            (attr.getAttribute(MWPaneFormatter.ATTRIBUTE_INFO) != null)) {
          Object attrInfo = attr.getAttribute(MWPaneFormatter.ATTRIBUTE_INFO);
          if (attrInfo instanceof CheckErrorResult) {
            int startOffset = MWPaneFormatter.getUUIDStartOffset(textPane, run);
            int endOffset = MWPaneFormatter.getUUIDEndOffet(textPane, run);
            if (originalText.equals(textPane.getText(startOffset, endOffset - startOffset))) {
              boolean possible = false;
              CheckErrorResult info = (CheckErrorResult) attrInfo;
              List<Actionnable> actionnables = info.getPossibleActions();
              if (actionnables != null) {
                for (Actionnable actionnable : actionnables) {
                  possible |= actionnable.isPossibleReplacement(newText);
                }
              }
              if (possible) {
                doc.remove(startOffset, endOffset - startOffset);
                doc.insertString(startOffset, newText, attr);
                lastEnd = startOffset + newText.length();
              }
            }
          }
        }
View Full Code Here

   */
  private void initialize() {
    boolean oldState = isInInternalModification;
    isInInternalModification = true;
    this.setComponentOrientation(wikipedia.getSettings().getComponentOrientation());
    StyledDocument doc = MWPaneFormatter.createDocument();
    setStyledDocument(doc);
    doc.addDocumentListener(new DocumentListener() {

      /* (non-Javadoc)
       * @see javax.swing.event.DocumentListener#changedUpdate(javax.swing.event.DocumentEvent)
       */
      public void changedUpdate(@SuppressWarnings("unused") DocumentEvent e) {
View Full Code Here

  /**
   * Select first occurrence of text.
   */
  public void selectFirstOccurrence() {
    StyledDocument doc = textPane.getStyledDocument();
    int length = doc.getLength();
    int lastEnd = Integer.MAX_VALUE;
    for (int pos = 0; pos < length; pos = lastEnd) {
      Element run = doc.getCharacterElement(pos);
      lastEnd = run.getEndOffset();
      if (pos == lastEnd) {
        // offset + length beyond length of document, bail.
        break;
      }
      MutableAttributeSet attr = (MutableAttributeSet) run.getAttributes();
      if ((attr != null) &&
          (attr.getAttribute(MWPaneFormatter.ATTRIBUTE_TYPE) != null) &&
          (attr.getAttribute(MWPaneFormatter.ATTRIBUTE_OCCURRENCE) != Boolean.FALSE)) {
        select(run);
        return;
      }
    }
    for (int pos = 0; pos < length; pos = lastEnd) {
      Element run = doc.getCharacterElement(pos);
      lastEnd = run.getEndOffset();
      if (pos == lastEnd) {
        // offset + length beyond length of document, bail.
        break;
      }
View Full Code Here

  /**
   * Select previous occurrence of text.
   */
  public void selectPreviousOccurrence() {
    StyledDocument doc = textPane.getStyledDocument();
    int lastStart = Integer.MIN_VALUE;
    for (int pos = textPane.getSelectionStart(); pos > 0; pos = lastStart) {
      Element run = doc.getCharacterElement(pos - 1);
      lastStart = run.getStartOffset();
      MutableAttributeSet attr = (MutableAttributeSet) run.getAttributes();
      if ((attr != null) &&
          (attr.getAttribute(MWPaneFormatter.ATTRIBUTE_TYPE) != null) &&
          (attr.getAttribute(MWPaneFormatter.ATTRIBUTE_OCCURRENCE) != Boolean.FALSE)) {
View Full Code Here

  /**
   * Select next occurrence of text.
   */
  public void selectNextOccurrence() {
    StyledDocument doc = textPane.getStyledDocument();
    int length = doc.getLength();
    int lastEnd = Integer.MAX_VALUE;
    for (int pos = textPane.getSelectionEnd() + 1; pos < length; pos = lastEnd) {
      Element run = doc.getCharacterElement(pos);
      lastEnd = run.getEndOffset();
      if (pos == lastEnd) {
        // offset + length beyond length of document, bail.
        break;
      }
View Full Code Here

  /**
   * Select last occurrence of text.
   */
  public void selectLastOccurrence() {
    StyledDocument doc = textPane.getStyledDocument();
    int lastStart = Integer.MIN_VALUE;
    for (int pos = doc.getLength(); pos > 0; pos = lastStart) {
      Element run = doc.getCharacterElement(pos - 1);
      lastStart = run.getStartOffset();
      MutableAttributeSet attr = (MutableAttributeSet) run.getAttributes();
      if ((attr != null) &&
          (attr.getAttribute(MWPaneFormatter.ATTRIBUTE_TYPE) != null) &&
          (attr.getAttribute(MWPaneFormatter.ATTRIBUTE_OCCURRENCE) != Boolean.FALSE)) {
View Full Code Here

        }
    }
   
    private void updateTextActions(JTextComponent text) {
        if (text.getDocument() instanceof StyledDocument) {
            StyledDocument document = (StyledDocument) text.getDocument();
            boolean editable = text.isEditable();
           
            Caret caret = text.getCaret();
            int dot = caret.getDot();
            dot = dot > 0 ? dot - 1 : dot;
            Element elem = document.getCharacterElement(dot);
            AttributeSet set = elem.getAttributes();
           
            setBoldEnabled(editable);
            setBoldSelected(StyleConstants.isBold(set));
            setItalicEnabled(editable);
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);
          }

          // 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("Latency: ").append(res.getLatency()).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(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("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) {
      log.error("Error setting statistics text", exc);
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.