Search in sources :

Example 76 with Document

use of javax.swing.text.Document in project LauncherV3 by TechnicPack.

the class LimitLinesDocumentListener method removeLines.

private void removeLines(DocumentEvent e) {
    // The root Element of the Document will tell us the total number
    // of line in the Document.
    Document document = e.getDocument();
    Element root = document.getDefaultRootElement();
    while (root.getElementCount() > maximumLines) {
        if (isRemoveFromStart) {
            removeFromStart(document, root);
        } else {
            removeFromEnd(document, root);
        }
    }
}
Also used : Element(javax.swing.text.Element) Document(javax.swing.text.Document)

Example 77 with Document

use of javax.swing.text.Document in project openj9 by eclipse.

the class Rtf method convert.

public static String convert(String rtf) throws Exception {
    DefaultStyledDocument styledDoc = new DefaultStyledDocument();
    RTFEditorKit rtfKit = new RTFEditorKit();
    StringReader reader = null;
    reader = new StringReader(rtf);
    rtfKit.read(reader, styledDoc, 0);
    Document doc = styledDoc.getDefaultRootElement().getDocument();
    String txt = doc.getText(0, doc.getLength());
    return txt;
}
Also used : StringReader(java.io.StringReader) RTFEditorKit(javax.swing.text.rtf.RTFEditorKit) DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) Document(javax.swing.text.Document) DefaultStyledDocument(javax.swing.text.DefaultStyledDocument)

Example 78 with Document

use of javax.swing.text.Document in project freeplane by freeplane.

the class ScaledHTML method createHTMLView.

/**
 * Create an html renderer for the given component and
 * string of html.
 */
public static View createHTMLView(JComponent c, String html) {
    ScaledEditorKit kit = ScaledEditorKit.create();
    Document doc = kit.createDefaultDocument(c.getFont(), c.getForeground());
    Object base = c.getClientProperty(documentBaseKey);
    if (base instanceof URL) {
        ((HTMLDocument) doc).setBase((URL) base);
    }
    Reader r = new StringReader(html);
    try {
        kit.read(r, doc, 0);
    } catch (Throwable e) {
    }
    ViewFactory f = kit.getViewFactory();
    View hview = f.create(doc.getDefaultRootElement());
    View v = new Renderer(c, f, hview);
    return v;
}
Also used : HTMLDocument(javax.swing.text.html.HTMLDocument) ViewFactory(javax.swing.text.ViewFactory) StringReader(java.io.StringReader) Reader(java.io.Reader) StringReader(java.io.StringReader) HTMLDocument(javax.swing.text.html.HTMLDocument) Document(javax.swing.text.Document) View(javax.swing.text.View) URL(java.net.URL)

Example 79 with Document

use of javax.swing.text.Document in project freeplane by freeplane.

the class XHTMLWriter method html2xhtml.

/**
 * Read HTML from the Reader, and send XHTML to the writer. Common mistakes
 * in the HTML code will also be corrected. The result is pretty-printed.
 *
 * @param reader
 *            HTML source
 * @param writer
 *            XHTML target
 */
public static void html2xhtml(final Reader reader, final Writer writer) throws IOException, BadLocationException {
    final HTMLEditorKit kit = new HTMLEditorKit();
    final Document doc = kit.createDefaultDocument();
    kit.read(reader, doc, doc.getLength());
    final XHTMLWriter xhw = new XHTMLWriter(writer, (HTMLDocument) doc);
    xhw.write();
}
Also used : HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) HTMLDocument(javax.swing.text.html.HTMLDocument) Document(javax.swing.text.Document)

Example 80 with Document

use of javax.swing.text.Document in project openj9 by eclipse.

the class RtfChild method convert.

public static String convert(String rtf) throws Exception {
    DefaultStyledDocument styledDoc = new DefaultStyledDocument();
    RTFEditorKit rtfKit = new RTFEditorKit();
    StringReader reader = null;
    reader = new StringReader(rtf);
    rtfKit.read(reader, styledDoc, 0);
    Document doc = styledDoc.getDefaultRootElement().getDocument();
    String txt = doc.getText(0, doc.getLength());
    return txt;
}
Also used : StringReader(java.io.StringReader) RTFEditorKit(javax.swing.text.rtf.RTFEditorKit) DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) Document(javax.swing.text.Document) DefaultStyledDocument(javax.swing.text.DefaultStyledDocument)

Aggregations

Document (javax.swing.text.Document)170 BadLocationException (javax.swing.text.BadLocationException)85 DocumentEvent (javax.swing.event.DocumentEvent)15 DefaultStyledDocument (javax.swing.text.DefaultStyledDocument)15 HTMLDocument (javax.swing.text.html.HTMLDocument)15 Element (javax.swing.text.Element)14 AbstractDocument (javax.swing.text.AbstractDocument)11 StringReader (java.io.StringReader)10 PlainDocument (javax.swing.text.PlainDocument)10 DocumentAdapter (com.intellij.ui.DocumentAdapter)8 Matcher (java.util.regex.Matcher)8 JTextComponent (javax.swing.text.JTextComponent)8 ActionEvent (java.awt.event.ActionEvent)7 DocumentListener (javax.swing.event.DocumentListener)7 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)7 IOException (java.io.IOException)6 PatternSyntaxException (java.util.regex.PatternSyntaxException)6 Highlighter (javax.swing.text.Highlighter)5 FieldDefinition (com.revolsys.record.schema.FieldDefinition)4 Point (java.awt.Point)4