javax.swing.text.rtf

Class RTFEditorKit

Implemented Interfaces:
Cloneable, Serializable

public class RTFEditorKit
extends StyledEditorKit

This is the default implementation of RTF editing functionality. The RTF support was not written by the Swing team. In the future we hope to improve the support provided.
See Also:
Serialized Form

Nested Class Summary

Nested classes/interfaces inherited from class javax.swing.text.StyledEditorKit

StyledEditorKit.AlignmentAction, StyledEditorKit.BoldAction, StyledEditorKit.FontFamilyAction, StyledEditorKit.FontSizeAction, StyledEditorKit.ForegroundAction, StyledEditorKit.ItalicAction, StyledEditorKit.StyledTextAction, StyledEditorKit.UnderlineAction

Nested classes/interfaces inherited from class javax.swing.text.DefaultEditorKit

DefaultEditorKit.BeepAction, DefaultEditorKit.CopyAction, DefaultEditorKit.CutAction, DefaultEditorKit.DefaultKeyTypedAction, DefaultEditorKit.InsertBreakAction, DefaultEditorKit.InsertContentAction, DefaultEditorKit.InsertTabAction, DefaultEditorKit.PasteAction

Field Summary

Fields inherited from class javax.swing.text.DefaultEditorKit

EndOfLineStringProperty, backwardAction, beepAction, beginAction, beginLineAction, beginParagraphAction, beginWordAction, copyAction, cutAction, defaultKeyTypedAction, deleteNextCharAction, deletePrevCharAction, downAction, endAction, endLineAction, endParagraphAction, endWordAction, forwardAction, insertBreakAction, insertContentAction, insertTabAction, nextWordAction, pageDownAction, pageUpAction, pasteAction, previousWordAction, readOnlyAction, selectAllAction, selectLineAction, selectParagraphAction, selectWordAction, selectionBackwardAction, selectionBeginAction, selectionBeginLineAction, selectionBeginParagraphAction, selectionBeginWordAction, selectionDownAction, selectionEndAction, selectionEndLineAction, selectionEndParagraphAction, selectionEndWordAction, selectionForwardAction, selectionNextWordAction, selectionPreviousWordAction, selectionUpAction, upAction, writableAction

Constructor Summary

RTFEditorKit()
Constructs an RTFEditorKit.

Method Summary

String
getContentType()
Get the MIME type of the data that this kit represents support for.
void
read(InputStream in, Document doc, int pos)
Insert content from the given stream which is expected to be in a format appropriate for this kind of content handler.
void
read(Reader in, Document doc, int pos)
Insert content from the given stream, which will be treated as plain text.
void
write(OutputStream out, Document doc, int pos, int len)
Write content from a document to the given stream in a format appropriate for this kind of content handler.
void
write(Writer out, Document doc, int pos, int len)
Write content from a document to the given stream as plain text.

Methods inherited from class javax.swing.text.StyledEditorKit

clone, createDefaultDocument, createInputAttributes, deinstall, getActions, getCharacterAttributeRun, getInputAttributes, getViewFactory, install

Methods inherited from class javax.swing.text.DefaultEditorKit

createCaret, createDefaultDocument, getActions, getContentType, getViewFactory, read, read, write, write

Methods inherited from class javax.swing.text.EditorKit

clone, createCaret, createDefaultDocument, deinstall, getActions, getContentType, getViewFactory, install, read, read, write, write

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

RTFEditorKit

public RTFEditorKit()
Constructs an RTFEditorKit.
Usages and Demos :

View More Examples of RTFEditorKit()
   1:     {
   2:         final RTFEditorKit rtf_edit = new RTFEditorKit();
   3:         final StyleContext rtf_context = new StyleContext();
   4:         final DefaultStyledDocument rtf_doc = new DefaultStyledDocument( rtf_context );
   5:         try 

View Full Code Here
   1:     try {
   2:       new RTFEditorKit().read(is, styledDoc, 0);
   3:       bodyText = styledDoc.getText(0, styledDoc.getLength());
   4:     }
   5:     catch (IOException e) {

View Full Code Here
   1: 
   2:         RTFEditorKit rtfEditor = new RTFEditorKit();
   3:         Document doc = rtfEditor.createDefaultDocument();
   4:         rtfEditor.read(new StringReader(input), doc, 0);

View Full Code Here
   1:             if (theRtfEditorKit==null)
   2:                 theRtfEditorKit = new RTFEditorKit();
   3:     }
   4: 

View Full Code Here
   1:       case RTF :
   2:         ek= new RTFEditorKit();
   3:         break;
   4:     }
   5:     Document dk= ek.createDefaultDocument();

View Full Code Here

Method Details

getContentType

public String getContentType()
Get the MIME type of the data that this kit represents support for. This kit supports the type text/rtf.
Overrides:
getContentType in interface DefaultEditorKit
Returns:
the type

read

public void read(InputStream in,
                 Document doc,
                 int pos)
            throws IOException,
                   BadLocationException
Insert content from the given stream which is expected to be in a format appropriate for this kind of content handler.
Overrides:
read in interface DefaultEditorKit
Parameters:
in - The stream to read from
doc - The destination for the insertion.
pos - The location in the document to place the content.
Throws:
IOException - on any I/O error
BadLocationException - if pos represents an invalid location within the document.
Usages and Demos :

View More Examples of read(InputStream in,Document doc,int pos)
   1: import javax.swing.text.DefaultStyledDocument;
   2: import javax.swing.text.rtf.RTFEditorKit;
   3: import java.io.*;
   4:         ...
   5:         DefaultStyledDocument document = new DefaultStyledDocument();
   6:         RTFEditorKit rtf = new RTFEditorKit();
   7:         ...
   8:         rtf.read(reader, document, 0);
   9:         contents = document.getText(0, document.getLength());

View Full Code Here

read

public void read(Reader in,
                 Document doc,
                 int pos)
            throws IOException,
                   BadLocationException
Insert content from the given stream, which will be treated as plain text.
Overrides:
read in interface DefaultEditorKit
Parameters:
in - The stream to read from
doc - The destination for the insertion.
pos - The location in the document to place the content.
Throws:
IOException - on any I/O error
BadLocationException - if pos represents an invalid location within the document.
Usages and Demos :

View More Examples of read(Reader in,Document doc,int pos)
   1: import javax.swing.text.DefaultStyledDocument;
   2: import javax.swing.text.rtf.RTFEditorKit;
   3: import java.io.*;
   4:         ...
   5:         DefaultStyledDocument document = new DefaultStyledDocument();
   6:         RTFEditorKit rtf = new RTFEditorKit();
   7:         ...
   8:         rtf.read(reader, document, 0);
   9:         contents = document.getText(0, document.getLength());

View Full Code Here

write

public void write(OutputStream out,
                  Document doc,
                  int pos,
                  int len)
            throws IOException,
                   BadLocationException
Write content from a document to the given stream in a format appropriate for this kind of content handler.
Overrides:
write in interface DefaultEditorKit
Parameters:
out - The stream to write to
doc - The source for the write.
pos - The location in the document to fetch the content.
len - The amount to write out.
Throws:
IOException - on any I/O error
BadLocationException - if pos represents an invalid location within the document.
Usages and Demos :

View More Examples of write(OutputStream out,Document doc,int pos,int len)
   1: import javax.swing.text.html.StyleSheet;
   2: import javax.swing.text.rtf.RTFEditorKit;
   3: import javax.swing.undo.CannotUndoException;
   4:         ...
   5:             FileWriter fw = new FileWriter(whatFile);
   6:             htmlKit.write(fw, doc, 0, doc.getLength());
   7:             fw.flush();
   8:         ...
   9:             FileOutputStream fos = new FileOutputStream(whatFile);
  10:             RTFEditorKit rtfKit = new RTFEditorKit();
  11:         ...
  12:             rtfKit.write(fos, doc, 0, doc.getLength());

View Full Code Here
   1: import javax.swing.text.html.StyleSheet;
   2: import javax.swing.text.rtf.RTFEditorKit;
   3: import javax.swing.undo.CannotUndoException;
   4:         ...
   5:                 fw = new FileWriter(whatFile);
   6:                 htmlKit.write(fw, doc, 0, doc.getLength());
   7:                 System.out.println(whatFile.getAbsolutePath() +"  "+ whatFile.getName());
   8:         ...
   9:                 {
  10:                     htmlKit.write(fw, doc, 0, doc.getLength());
  11:                 }
  12:         ...
  13:             FileOutputStream fos = new FileOutputStream(whatFile);
  14:             RTFEditorKit rtfKit = new RTFEditorKit();

View Full Code Here

write

public void write(Writer out,
                  Document doc,
                  int pos,
                  int len)
            throws IOException,
                   BadLocationException
Write content from a document to the given stream as plain text.
Overrides:
write in interface DefaultEditorKit
Parameters:
out - The stream to write to
doc - The source for the write.
pos - The location in the document to fetch the content.
len - The amount to write out.
Throws:
IOException - on any I/O error
BadLocationException - if pos represents an invalid location within the document.
Usages and Demos :

View More Examples of write(Writer out,Document doc,int pos,int len)
   1: import javax.swing.text.html.StyleSheet;
   2: import javax.swing.text.rtf.RTFEditorKit;
   3: import javax.swing.undo.CannotUndoException;
   4:         ...
   5:             FileWriter fw = new FileWriter(whatFile);
   6:             htmlKit.write(fw, doc, 0, doc.getLength());
   7:             fw.flush();
   8:         ...
   9:             FileOutputStream fos = new FileOutputStream(whatFile);
  10:             RTFEditorKit rtfKit = new RTFEditorKit();
  11:         ...
  12:             rtfKit.write(fos, doc, 0, doc.getLength());

View Full Code Here
   1: import javax.swing.text.html.StyleSheet;
   2: import javax.swing.text.rtf.RTFEditorKit;
   3: import javax.swing.undo.CannotUndoException;
   4:         ...
   5:                 fw = new FileWriter(whatFile);
   6:                 htmlKit.write(fw, doc, 0, doc.getLength());
   7:                 System.out.println(whatFile.getAbsolutePath() +"  "+ whatFile.getName());
   8:         ...
   9:                 {
  10:                     htmlKit.write(fw, doc, 0, doc.getLength());
  11:                 }
  12:         ...
  13:             FileOutputStream fos = new FileOutputStream(whatFile);
  14:             RTFEditorKit rtfKit = new RTFEditorKit();

View Full Code Here