Search in sources :

Example 1 with RTFEditorKit

use of javax.swing.text.rtf.RTFEditorKit in project intellij-community by JetBrains.

the class HtmlCopyPastePreProcessor method convertFromRtfStream.

private static String convertFromRtfStream(InputStream stream) {
    final DefaultStyledDocument document = new DefaultStyledDocument();
    try {
        new RTFEditorKit().read(stream, document, 0);
        final StringWriter writer = new StringWriter();
        new HTMLEditorKit().write(writer, document, 0, document.getLength());
        return writer.toString();
    } catch (IOException | BadLocationException e) {
        LOG.error(e);
    }
    return null;
}
Also used : StringWriter(java.io.StringWriter) RTFEditorKit(javax.swing.text.rtf.RTFEditorKit) HTMLEditorKit(javax.swing.text.html.HTMLEditorKit) IOException(java.io.IOException) DefaultStyledDocument(javax.swing.text.DefaultStyledDocument) BadLocationException(javax.swing.text.BadLocationException)

Example 2 with RTFEditorKit

use of javax.swing.text.rtf.RTFEditorKit in project org.csstudio.display.builder by kasemir.

the class WidgetTransfer method installWidgetsFromRTF.

/**
 * @param db The {@link Dragboard} containing the dragged data.
 * @param selection_tracker Used to get the grid steps from its model to be
 *            used in offsetting multiple widgets.
 * @param widgets The container of the created widgets.
 */
private static void installWidgetsFromRTF(final DragEvent event, final SelectedWidgetUITracker selection_tracker, final List<Widget> widgets) {
    final Dragboard db = event.getDragboard();
    final String rtf = db.getRtf();
    final RTFEditorKit rtfParser = new RTFEditorKit();
    final Document document = rtfParser.createDefaultDocument();
    try {
        rtfParser.read(new ByteArrayInputStream(rtf.getBytes()), document, 0);
        installWidgetsFromString(event, document.getText(0, document.getLength()), selection_tracker, widgets);
    } catch (Exception ex) {
        logger.log(Level.WARNING, "Invalid RTF string", ex);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) RTFEditorKit(javax.swing.text.rtf.RTFEditorKit) Document(javax.swing.text.Document) Dragboard(javafx.scene.input.Dragboard)

Example 3 with RTFEditorKit

use of javax.swing.text.rtf.RTFEditorKit 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 4 with RTFEditorKit

use of javax.swing.text.rtf.RTFEditorKit 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)

Example 5 with RTFEditorKit

use of javax.swing.text.rtf.RTFEditorKit 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)

Aggregations

RTFEditorKit (javax.swing.text.rtf.RTFEditorKit)6 DefaultStyledDocument (javax.swing.text.DefaultStyledDocument)5 Document (javax.swing.text.Document)5 StringReader (java.io.StringReader)4 ByteArrayInputStream (java.io.ByteArrayInputStream)1 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 Dragboard (javafx.scene.input.Dragboard)1 BadLocationException (javax.swing.text.BadLocationException)1 HTMLEditorKit (javax.swing.text.html.HTMLEditorKit)1