Package javax.swing.text

Examples of javax.swing.text.StyledDocument


  }

  private String convert(InputStream rtfDocumentInputStream) throws IOException {
    RTFEditorKit aRtfEditorkit = new RTFEditorKit();

    StyledDocument styledDoc = new DefaultStyledDocument();

    String textDocument;

    try {
      aRtfEditorkit.read(rtfDocumentInputStream, styledDoc, 0);

      textDocument = styledDoc.getText(0, styledDoc.getLength());
    } catch (BadLocationException e) {
      throw new IOException("Error during parsing");
    }

    return textDocument;
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("");
      results.setText("");
            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)
                    {
                      String sd;
                      String rh = res.getRequestHeaders();
                      if (rh==null)
                      {
                        sd=res.getSamplerData().trim();
                      } else {
              sd=res.getSamplerData().trim()
                 +"\n"+rh;
                      }
                        sampleDataField.setText(sd);
                    }

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

          statsDoc.insertString(
            statsDoc.getLength(),
            "\nHTTP response headers:\n" + res.getResponseHeaders() + "\n",
            null);

          // get the text response and image icon
                    // to determine which is NOT null
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("");
      results.setText("");
            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)
                    {
                      String sd;
                      String rh = res.getRequestHeaders();
                      if (rh==null)
                      {
                        sd=res.getSamplerData().trim();
                      } else {
              sd=res.getSamplerData().trim()
                 +"\n"+rh;
                      }
                        sampleDataField.setText(sd);
                    }

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

          statsDoc.insertString(
            statsDoc.getLength(),
            "\nHTTP response headers:\n" + res.getResponseHeaders() + "\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));
        return pane;
View Full Code Here

        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

            return -1;
        }

        String docContent = null;
        try {
            StyledDocument document2 = document.getDocument();
            if (document2 == null) {
                return -1;
            }
            docContent = document2.getText(0, document2.getLength());
        } catch (BadLocationException ble) {
            System.out.println("Bad location exception");
        } catch (NullPointerException npe) {
            return -1;
        }
View Full Code Here

        }

        @Override
        public void run() {
            frame.getSourceCodeTextPane().setEditorKit(src.getEditorKit());
            StyledDocument document = src.getDocument();
            frame.getSourceCodeTextPane().setDocument(document);
            String sourceFile = mySourceLine.getSourceFile();
            if (sourceFile == null || sourceFile.equals("<Unknown>")) {
                sourceFile = mySourceLine.getSimpleClassName();
            }
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.