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


public class StyledDocument3 extends DefaultStyledDocument implements Testlet
{
  public void test(TestHarness harness)
  {
    h2 = harness;
    StyledDocument doc = new StyledDocument3();
    SimpleAttributeSet atts = new SimpleAttributeSet();
    try
      {
        atts.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
        doc.insertString(0, "bbbbb", atts);
        doc.insertString(5, "aaaaa", null);
        doc.insertString(5, "N", atts);
        atts.addAttribute(StyleConstants.Bold, Boolean.TRUE);
        doc.insertString(6, "M", atts);
      }
    catch (Exception ex)
      {
        // ex.printStackTrace();
        harness.debug(ex);
View Full Code Here

public class StyledDocument5 extends DefaultStyledDocument implements Testlet
{
  public void test(TestHarness harness)
  {
    h2 = harness;
    StyledDocument doc = new StyledDocument5();
    try
      {
        doc.insertString(0, "aaaaaaaaa\nbbbbbbbbb", null);
        doc.insertString(10, "N", null);       
        doc.insertString(5, "\nhellooooo", null);
      }
    catch (Exception ex)
      {
        //ex.printStackTrace();
        harness.debug(ex);
View Full Code Here

public class StyledDocument6 extends DefaultStyledDocument implements Testlet
{
  public void test(TestHarness harness)
  {
    h2 = harness;
    StyledDocument doc = new StyledDocument6();
    SimpleAttributeSet atts = new SimpleAttributeSet();
    try
      {
        doc.insertString(0, "aaa", null);
        atts.addAttribute(StyleConstants.Underline, Boolean.TRUE);
        doc.insertString(3, "bbb", atts);
        atts.removeAttributes(atts);
        atts.addAttribute(StyleConstants.StrikeThrough, Boolean.TRUE);
        doc.insertString(6, "ccc", atts);
        atts.removeAttributes(atts);
        atts.addAttribute(StyleConstants.Underline, Boolean.TRUE);
        doc.insertString(5, "\nB", atts);
      }
    catch (Exception ex)
      {
        // ex.printStackTrace();
        harness.debug(ex);
View Full Code Here

public class StyledDocument4 extends DefaultStyledDocument implements Testlet
{
  public void test(TestHarness harness)
  {
    h2 = harness;
    StyledDocument doc = new StyledDocument4();
    try
      {
        doc.insertString(0, "aaaaaaaaa\nbbbbbbbbb", null);
        doc.insertString(5, "\nN", null);
      }
    catch (Exception ex)
      {
        // ex.printStackTrace();
        harness.debug(ex);
View Full Code Here

      text = text.replaceAll("&lt;", "<");
      text = text.replaceAll("&gt;", ">");

     
      JEditorPane jEditorPane = new JEditorPane("text/html", text);
      StyledDocument doc = (StyledDocument) jEditorPane.getDocument();
     
      // pane.getStyledDocument();
      // pane.setStyledDocument(doc);
     
      pane.setContentType("text/html");
View Full Code Here

            return;
        }

        final int start = getSelectionStart();
        final int end = getSelectionEnd();
        final StyledDocument doc = getStyledDocument();

        AttributeSet attrs;

        try {
            if (start != end) {
                attrs = doc.getCharacterElement(start).getAttributes();

                doc.remove(start, end - start);

                if (StyleConstants.getIcon(attrs) != null) {
                    final MutableAttributeSet newAttrs =
                        new SimpleAttributeSet(attrs);
                    newAttrs.removeAttribute(StyleConstants.IconAttribute);
                    newAttrs.removeAttribute(AbstractDocument
                                             .ElementNameAttribute);
                    attrs = newAttrs;
                }
                if (StyleConstants.getComponent(attrs) != null) {
                    final MutableAttributeSet newAttrs =
                        new SimpleAttributeSet(attrs);
                    newAttrs.removeAttribute(StyleConstants.ComponentAttribute);
                    newAttrs.removeAttribute(AbstractDocument
                                             .ElementNameAttribute);
                    attrs = newAttrs;
                }

            } else {
                attrs = getInputAttributes();
            }

            if (content != null) {
                doc.insertString(start, content, attrs);
            }
        } catch (BadLocationException e) {
        }
    }
View Full Code Here

        if (!(getDocument() instanceof DefaultStyledDocument)) {
            // XXX: it's not clear what to do in this case
            throw new UnsupportedOperationException("Not implemented");
        }

        StyledDocument styledDocument = (StyledDocument)getDocument();
        Enumeration styles = ((DefaultStyledDocument)getDocument()).getStyleNames();
        while (styles.hasMoreElements()) {
            String styleName = (String)styles.nextElement();
            if (StyleSheet.DEFAULT_STYLE.equals(styleName)) {
                continue;
            }
            indent();
            write("p." + styleName + " {");
            writeLineSeparator();
            incrIndent();
            writeAttributes(styledDocument.getStyle(styleName));
            decrIndent();
            indent();
            write("}");
            writeLineSeparator();
        }
View Full Code Here

            super.setDocument(doc);

            if (doc != null) {
                doc.addDocumentListener(docListener);
                if (doc instanceof StyledDocument) {
                    StyledDocument sd = (StyledDocument) doc;
                    Style style = sd.getStyle(StyleContext.DEFAULT_STYLE);
                    StyleConstants.setFontFamily(style, "SansSerif");
                   
                    attrNormal = style;
                   
                    attrAddedLocally = sd.addStyle(STYLE_ADDED_LOCALLY, attrNormal);
                    StyleConstants.setForeground(attrAddedLocally, Color.BLUE);
                    StyleConstants.setBold(attrAddedLocally, true);
                   
                    attrAddedByOther = sd.addStyle(STYLE_ADDED_BY_OTHER, attrNormal);
                    StyleConstants.setForeground(attrAddedByOther, Color.RED);
                    StyleConstants.setBold(attrAddedByOther, true);
                   
                    attrRemovedByOther = sd.addStyle(STYLE_REMOVED_BY_OTHER, attrNormal);
                    StyleConstants.setForeground(attrRemovedByOther, Color.RED);
                    StyleConstants.setStrikeThrough(attrRemovedByOther, true);
                    StyleConstants.setBold(attrRemovedByOther, true);
                   
                    attrRemovedLocally = sd.addStyle(STYLE_REMOVED_LOCALLY, attrNormal);
                    StyleConstants.setForeground(attrRemovedLocally, Color.BLUE);
                    StyleConstants.setStrikeThrough(attrRemovedLocally, true);
                    StyleConstants.setBold(attrRemovedLocally, true);
                }
            }
View Full Code Here

            }
        }
       
        private String getStyleNameAt(int pos) {
            try {
                StyledDocument doc = (StyledDocument) getDocument();
                Element elem = doc.getCharacterElement(pos);
                AttributeSet attrs = elem.getAttributes();
                Object result = attrs.getAttribute(StyleConstants.NameAttribute);
                return (String) result;
            } catch (Exception e) {
                return null;
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.