本文整理汇总了Java中javax.swing.text.rtf.RTFEditorKit类的典型用法代码示例。如果您正苦于以下问题:Java RTFEditorKit类的具体用法?Java RTFEditorKit怎么用?Java RTFEditorKit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RTFEditorKit类属于javax.swing.text.rtf包,在下文中一共展示了RTFEditorKit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RTF2TXT
import javax.swing.text.rtf.RTFEditorKit; //导入依赖的package包/类
public static final String RTF2TXT(String Str)
throws IOException, BadLocationException
{
if (Str != null && Str.startsWith("{\\rtf1") == true)
{
// There is a "questionable" bug in the RTF-to-Text routine in the Java library. With tables, text in
// adjacent cells are concatenated without any
// spacing. So, for example, a table with a cell containing "abc" followed by another call containing "123",
// after conversion, you'll get "abc123".
// With this hack, we capture the RTF cell delimiter "\cell$" and replace it with ". \cell$". This will
// separate text in cells from other text and will
// allow text processing to give better results.
Str = RTF_CELL_PATTERN.matcher(Str).replaceAll(". $0");
RTFEditorKit RTF = new RTFEditorKit();
Document doc = RTF.createDefaultDocument();
RTF.read(new StringReader(Str), doc, 0);
Str = doc.getText(0, doc.getLength());
}
return Str;
}
示例2: main
import javax.swing.text.rtf.RTFEditorKit; //导入依赖的package包/类
public static void main(String[] args) throws Exception{
rtfEditorKit = new RTFEditorKit();
robot = new Robot();
SwingUtilities.invokeAndWait(() -> {
frame = new JFrame();
frame.setUndecorated(true);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.setSize(600, 200);
jTextPane = new JTextPane();
frame.getContentPane().add(jTextPane);
frame.setVisible(true);
});
test(StyleConstants.ALIGN_LEFT);
test(StyleConstants.ALIGN_CENTER);
test(StyleConstants.ALIGN_RIGHT);
test(StyleConstants.ALIGN_JUSTIFIED);
SwingUtilities.invokeAndWait(()->frame.dispose());
System.out.println("ok");
}
示例3: extractText
import javax.swing.text.rtf.RTFEditorKit; //导入依赖的package包/类
/**
* {@inheritDoc}
*/
public String extractText(InputStream stream, String type, String encoding) throws IOException {
try {
RTFEditorKit rek = new RTFEditorKit();
DefaultStyledDocument doc = new DefaultStyledDocument();
rek.read(stream, doc, 0);
String text = doc.getText(0, doc.getLength());
return text;
} catch (Throwable e) {
logger.warn("Failed to extract RTF text content", e);
throw new IOException(e.getMessage(), e);
} finally {
stream.close();
}
}
示例4: installWidgetsFromRTF
import javax.swing.text.rtf.RTFEditorKit; //导入依赖的package包/类
/**
* @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);
}
}
示例5: actionPerformed
import javax.swing.text.rtf.RTFEditorKit; //导入依赖的package包/类
@Override
public void actionPerformed(ActionEvent event) {
try {
boolean b = sysCaller.isPastingAllowed();
System.out.println("Pasting allowed: " + b);
if (!b) {
JOptionPane.showMessageDialog(null, sysCaller.getLastError());
return;
}
RTFEditorKit myEditorKit = (RTFEditorKit) myEditorPane.getEditorKit();
Action edKitPasteAct = getActionByName(RTFEditorKit.pasteAction);
edKitPasteAct.actionPerformed(event);
} catch (Exception e) {
e.printStackTrace();
JOptionPane.showMessageDialog(RTFEditor.this, "Exception while copying selected text: " + e.getMessage());
}
}
示例6: testTextRtfEditorKits
import javax.swing.text.rtf.RTFEditorKit; //导入依赖的package包/类
public void testTextRtfEditorKits() {
JEditorPane pane = new JEditorPane();
setContentTypeInAwt(pane, "text/rtf");
// Test JDK kit
EditorKit kitFromJdk = pane.getEditorKit();
assertNotNull("Can't find JDK kit for text/rtf", kitFromJdk);
assertTrue("Wrong JDK kit for application/rtf", kitFromJdk instanceof RTFEditorKit);
}
示例7: testApplicationRtfEditorKits
import javax.swing.text.rtf.RTFEditorKit; //导入依赖的package包/类
public void testApplicationRtfEditorKits() {
JEditorPane pane = new JEditorPane();
setContentTypeInAwt(pane, "application/rtf");
// Test JDK kit
EditorKit kitFromJdk = pane.getEditorKit();
assertNotNull("Can't find JDK kit for application/rtf", kitFromJdk);
assertTrue("Wrong JDK kit for application/rtf", kitFromJdk instanceof RTFEditorKit);
}
示例8: RTFFileExport
import javax.swing.text.rtf.RTFEditorKit; //导入依赖的package包/类
/**
* Constructor for RTFFileExport.
*/
public RTFFileExport(File f, Document doc) {
RTFEditorKit kit = new RTFEditorKit();
try {
kit.write(new FileOutputStream(f), (DefaultStyledDocument)doc, 0, doc.getLength());
}
catch (Exception ex) {
ex.printStackTrace();
}
}
示例9: RTFDocsSwingDisplayer
import javax.swing.text.rtf.RTFEditorKit; //导入依赖的package包/类
public RTFDocsSwingDisplayer(String heading, String filename, String jarName)
{
super(heading);
setSize(650, 550);
// Initialize String which will go into the JTextPane
String display_me = readFile(filename, jarName);
// Buttons
b1 = new JButton("Back");
b1.setActionCommand("back");
b1.addActionListener(this);
// Initializing JTextPane()
JTextPane textPane = new JTextPane();
RTFEditorKit rtfkit = new RTFEditorKit();
// HTMLEditorKit htmlkit = new HTMLEditorKit();
textPane.setEditorKit(rtfkit); // set Kit which will read RTF Doc
// textPane.setEditorKit(htmlkit);
textPane.setEditable(false); // make uneditable
textPane.setText(display_me); // set the Text
textPane.setCaretPosition(0); // set Cret position to 0
// Panels and addition to container
p1 = new JPanel();
Container contentPane = getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
p1.setLayout(new BoxLayout(this.p1, BoxLayout.Y_AXIS));
p1.add(new JScrollPane(textPane));
p1.add(b1);
contentPane.add(p1);
setVisible(true);
}
示例10: HyperCardTextField
import javax.swing.text.rtf.RTFEditorKit; //导入依赖的package包/类
public HyperCardTextField(ToolEditablePart toolEditablePart) {
this.toolEditablePart = toolEditablePart;
// Create the editor component
textPane = new HyperCardTextPane(new DefaultStyledDocument());
textPane.setEditorKit(new RTFEditorKit());
this.setViewportView(textPane);
getViewport().addChangeListener(e -> {
textPane.invalidateViewport(getViewport());
});
}
示例11: convertDocumentToRtf
import javax.swing.text.rtf.RTFEditorKit; //导入依赖的package包/类
private byte[] convertDocumentToRtf(StyledDocument doc) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
new RTFEditorKit().write(baos, doc, 0, doc.getLength());
baos.close();
return baos.toByteArray();
} catch (IOException | BadLocationException e) {
throw new RuntimeException("An error occurred while saving field contents.", e);
}
}
示例12: parse
import javax.swing.text.rtf.RTFEditorKit; //导入依赖的package包/类
public static void parse( String rtfString, RTFDocumentHandler handler )
throws IOException, BadLocationException
{
RTFEditorKit rtfeditorkit = new RTFEditorKit( );
DefaultStyledDocument document = new DefaultStyledDocument( );
ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream( rtfString.getBytes( ) );
rtfeditorkit.read( bytearrayinputstream, document, 0 );
Element element = document.getDefaultRootElement( );
parseElement( document, element, handler, true );
}
示例13: toHtml
import javax.swing.text.rtf.RTFEditorKit; //导入依赖的package包/类
public String toHtml(String s2) {
RTFEditorKit rtfeditorkit = new RTFEditorKit();
DefaultStyledDocument defaultstyleddocument = new DefaultStyledDocument();
readString(s2, defaultstyleddocument, rtfeditorkit);
scanDocument(defaultstyleddocument);
// Parse all rtf elements
for (RtfElementParser r : parserItems) {
r.parseDocElements(entries.entrySet().iterator());
}
// Parse all textnodes
for (Map.Entry<TextNode, Element> entry : entries.entrySet()) {
TextNode txtNode = entry.getKey();
// Replace \n an element node
while (txtNode.getWholeText().contains("\n")){
int pos = txtNode.getWholeText().indexOf("\n");
String txt = txtNode.getWholeText();
txtNode.before(new TextNode(txt.substring(0, pos), ""));
txtNode.before(new org.jsoup.nodes.Element(Tag.valueOf("br"), ""));
txtNode.text(txt.substring(pos + 1));
}
}
return removeEmptyNodes(body).toString();
}
示例14: readString
import javax.swing.text.rtf.RTFEditorKit; //导入依赖的package包/类
private void readString(String s, Document document,
RTFEditorKit rtfeditorkit) {
try {
ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream(
s.getBytes());
rtfeditorkit.read(bytearrayinputstream, document, 0);
} catch (Exception exception) {
return;
// exception.printStackTrace();
}
}
示例15: parseContent
import javax.swing.text.rtf.RTFEditorKit; //导入依赖的package包/类
@Override
protected void parseContent(StreamLimiter streamLimiter, LanguageEnum lang)
throws IOException {
RTFEditorKit rtf = new RTFEditorKit();
Document doc = rtf.createDefaultDocument();
try {
ParserResultItem result = getNewParserResultItem();
rtf.read(streamLimiter.getNewInputStream(), doc, 0);
result.addField(ParserFieldEnum.content,
doc.getText(0, doc.getLength()).trim());
} catch (BadLocationException e) {
throw new IOException(e);
}
}