当前位置: 首页>>代码示例>>Java>>正文


Java RTFEditorKit类代码示例

本文整理汇总了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;
  }
 
开发者ID:CapsicoHealth,项目名称:Tilda,代码行数:21,代码来源:TextUtil.java

示例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");
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:RTFWriteParagraphAlignTest.java

示例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();
	}
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:19,代码来源:RTFTextExtractor.java

示例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);
    }

}
 
开发者ID:kasemir,项目名称:org.csstudio.display.builder,代码行数:26,代码来源:WidgetTransfer.java

示例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());
    }
}
 
开发者ID:PM-Master,项目名称:Harmonia-1.5,代码行数:19,代码来源:RTFEditor.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:EditorSanityTest.java

示例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);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:10,代码来源:EditorSanityTest.java

示例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();
    }
}
 
开发者ID:ser316asu,项目名称:SER316-Dresden,代码行数:13,代码来源:RTFFileExport.java

示例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);

}
 
开发者ID:sanskrit-coders,项目名称:indic-transliteration,代码行数:34,代码来源:RTFDocsSwingDisplayer.java

示例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());
    });

}
 
开发者ID:defano,项目名称:hypertalk-java,代码行数:15,代码来源:HyperCardTextField.java

示例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);
    }
}
 
开发者ID:defano,项目名称:hypertalk-java,代码行数:13,代码来源:DocumentSerializer.java

示例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 );
}
 
开发者ID:eclipse,项目名称:birt,代码行数:11,代码来源:RTFParser.java

示例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();
}
 
开发者ID:frickler,项目名称:Html2Rtf,代码行数:28,代码来源:Rtf2Html.java

示例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();
	}
}
 
开发者ID:frickler,项目名称:Html2Rtf,代码行数:12,代码来源:Rtf2Html.java

示例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);
	}
}
 
开发者ID:jaeksoft,项目名称:opensearchserver,代码行数:15,代码来源:RtfParser.java


注:本文中的javax.swing.text.rtf.RTFEditorKit类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。