Package javax.swing.text

Examples of javax.swing.text.DefaultStyledDocument


  public void buildDocument(InputStream is, Document doc) throws DocumentHandlerException {

    String bodyText = null;

    DefaultStyledDocument styledDoc = new DefaultStyledDocument();
    try {
      new RTFEditorKit().read(is, styledDoc, 0);
      bodyText = styledDoc.getText(0, styledDoc.getLength());
    } catch (IOException e) {
      throw new DocumentHandlerException(
          "Cannot extract text from a RTF document", e);
    } catch (BadLocationException e) {
      throw new DocumentHandlerException(
View Full Code Here


  }

  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

         * Get a StyledDocument initialized with this.
         *
         * @return SytledDocument.
         */
        StyledDocument getStyledDocument() {
            DefaultStyledDocument retval = new DefaultStyledDocument(this);
            retval.setLogicalStyle(0, getDefaultStyle());
            return retval;
        }
View Full Code Here

    public void parse(
            InputStream stream, ContentHandler handler, Metadata metadata)
            throws IOException, SAXException, TikaException {
        try {
            DefaultStyledDocument sd = new DefaultStyledDocument();
            new RTFEditorKit().read(stream, sd, 0);

            XHTMLContentHandler xhtml =
                new XHTMLContentHandler(handler, metadata);
            xhtml.startDocument();
            xhtml.element("p", sd.getText(0, sd.getLength()));
            xhtml.endDocument();
        } catch (BadLocationException e) {
            throw new TikaException("Error parsing an RTF document", e);
        }
    }
View Full Code Here

      in = new FileInputStream(args[0]);
    else
      in = System.in;

    RTFParser parser = new RTFParser(in);
    RTFHandler handler = new DocumentRTFHandler(new DefaultStyledDocument(), 0);
    parser.parse(handler);
  }
View Full Code Here

            messageReceivedWhileIconified = true;
        } else {
            setForceFocus();
        }

        DefaultStyledDocument doc = new DefaultStyledDocument();
        int offset = 0;
        try {
            for (ReceivedChatMessage msg : formattedMessages) {
                SimpleAttributeSet attrs = new SimpleAttributeSet();
                ColorConstants.setForeground(attrs, msg.color);

                String nick = msg.nickname;
                String text = msg.ev.getText();
                doc.insertString(offset, nick + ": ", attrs);
                offset += nick.length() + 2;
                doc.insertString(offset, text + "\n", null);
                offset += text.length() + 1;
            }
        } catch (BadLocationException e) {
            e.printStackTrace(); //should never happen
        }
View Full Code Here

   *
   * @param content the content to set
   */
  public void setContent(String content) {
    String newContent = content == null ? "" : content;
    DefaultStyledDocument document = (DefaultStyledDocument) getDocument();

    try {
      document.remove(0, document.getLength());
      if (theme != null) {
        document.insertString(0, newContent, theme.getPlain().getAttributeSet());
      } else {
        document.insertString(0, newContent, new SimpleAttributeSet());
      }
    } catch (BadLocationException ex) {
      LOG.log(Level.SEVERE, null, ex);
    }

View Full Code Here

  protected void applyStyle() {
    if (theme == null || styleList == null) {
      return;
    }

    DefaultStyledDocument document = (DefaultStyledDocument) getDocument();
    // clear all the existing style
    document.setCharacterAttributes(0, document.getLength(), theme.getPlain().getAttributeSet(), true);

    // apply style according to the style list
    for (String key : styleList.keySet()) {
      List<ParseResult> posList = styleList.get(key);

      SimpleAttributeSet attributeSet = theme.getStyle(key).getAttributeSet();
      for (ParseResult pos : posList) {
        document.setCharacterAttributes(pos.getOffset(), pos.getLength(), attributeSet, true);
      }
    }

    repaint();
  }
View Full Code Here

      in = new FileInputStream(args[0]);
    else
      in = System.in;

    RTFParser parser = new RTFParser(in);
    RTFHandler handler = new DocumentRTFHandler(new DefaultStyledDocument(), 0);
    parser.parse(handler);
  }
View Full Code Here

        assertFalse(Color.BLUE.equals(style.getAttribute(StyleConstants.Foreground)));
        textPane.setForeground(Color.BLUE);
        assertEquals(Color.BLUE, style.getAttribute(StyleConstants.Foreground));
        // Document
        style.addAttribute(StyleConstants.Subscript, Boolean.TRUE);
        StyledDocument newDoc = new DefaultStyledDocument();
        Style newStyle = newDoc.getStyle(StyleContext.DEFAULT_STYLE);
        assertNull(newStyle.getAttribute(StyleConstants.FontSize));
        assertNull(newStyle.getAttribute(StyleConstants.FontFamily));
        newStyle.addAttribute(StyleConstants.FontFamily, "family2");
        newStyle.addAttribute(StyleConstants.FontSize, new Integer(10));
        newStyle.addAttribute(StyleConstants.Italic, Boolean.FALSE);
View Full Code Here

TOP

Related Classes of javax.swing.text.DefaultStyledDocument

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.