當前位置: 首頁>>代碼示例>>Java>>正文


Java DefaultStyledDocument.getText方法代碼示例

本文整理匯總了Java中javax.swing.text.DefaultStyledDocument.getText方法的典型用法代碼示例。如果您正苦於以下問題:Java DefaultStyledDocument.getText方法的具體用法?Java DefaultStyledDocument.getText怎麽用?Java DefaultStyledDocument.getText使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.text.DefaultStyledDocument的用法示例。


在下文中一共展示了DefaultStyledDocument.getText方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: extractText

import javax.swing.text.DefaultStyledDocument; //導入方法依賴的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

示例2: getFormatedDocument

import javax.swing.text.DefaultStyledDocument; //導入方法依賴的package包/類
public StyledDocument getFormatedDocument(String content){
	StyleContext context = new StyleContext();
	DefaultStyledDocument document = new DefaultStyledDocument(context);
	try{
		String tagedText= translateLine(content, false);
		int pointer=0;
		int tagIndex=0;
		while(tagedText.indexOf(BalloonTemplateHandler.START_TAG,pointer)!=-1){
			tagIndex=tagedText.indexOf(BalloonTemplateHandler.START_TAG,pointer);
			// Is there any character before the strat tag which is not parsed yet?
			if (tagIndex!=pointer){
				document.insertString(document.getLength(), tagedText.substring(pointer, tagIndex), NewCSVColumnDialog.getDefaultStyle());
				pointer = tagIndex;
			}
			pointer+=BalloonTemplateHandler.START_TAG.length();
			tagIndex=tagedText.indexOf(BalloonTemplateHandler.END_TAG,pointer);
			document.insertString(document.getLength(), tagedText.substring(pointer, tagIndex), NewCSVColumnDialog.getLabelStyle());
			pointer=tagIndex+BalloonTemplateHandler.END_TAG.length();
		}
		if (pointer!=tagedText.length()-1){
			document.insertString(document.getLength(), tagedText.substring(pointer,tagedText.length()), NewCSVColumnDialog.getDefaultStyle());
		}
		// check for [EOL]
		pointer=0;
		tagIndex=0;
		tagedText= document.getText(0, document.getLength());
		String lineSeparator=System.getProperty("line.separator");
		while(tagedText.indexOf(lineSeparator,pointer)!=-1){
			tagIndex=tagedText.indexOf(lineSeparator,pointer);
			document.remove(tagIndex,lineSeparator.length());
			document.insertString(tagIndex,NewCSVColumnDialog.EOL,
					NewCSVColumnDialog.getEOLStyle());
			pointer=tagIndex+NewCSVColumnDialog.EOL.length();
			tagedText= document.getText(0, document.getLength());
		}		
	}catch(Exception e){}
	return document;
}
 
開發者ID:3dcitydb,項目名稱:plugin-spreadsheet-generator,代碼行數:39,代碼來源:Translator.java

示例3: parseElement

import javax.swing.text.DefaultStyledDocument; //導入方法依賴的package包/類
private static void parseElement( DefaultStyledDocument document,
		Element parent, RTFDocumentHandler handler, boolean lostLast )
{
	for ( int i = 0; i < parent.getElementCount( ); i++ )
	{
		if (lostLast && i==parent.getElementCount( )-1 && parent.getElementCount( ) != 1)
		{
			break;
		}
		Element element = parent.getElement( i );
		AttributeSet attributeset = element.getAttributes( );
		handler.startElement( element.getName( ), attributeset );
		if ( element.getName( ).equalsIgnoreCase( "content" ) )
		{
			try
			{
				int start = element.getStartOffset( );
				int end = element.getEndOffset( );
				String s = document.getText( start, end - start );
				handler.content( s );
			}
			catch ( BadLocationException e )
			{
			}
		}
		parseElement( document, element, handler, false );
		handler.endElement( element.getName( ) );
	}
}
 
開發者ID:eclipse,項目名稱:birt,代碼行數:30,代碼來源:RTFParser.java

示例4: action

import javax.swing.text.DefaultStyledDocument; //導入方法依賴的package包/類
public void action()
{
	JEditorPane ed = getEditor();
	if(ed != null)
	{
		try
		{
			Caret ca = ed.getCaret();
			int beg = Math.min(ca.getMark(), ca.getDot());
			int end = Math.max(ca.getMark(), ca.getDot());
			if(beg == end)
			{
				// select word
				beg = getWordStart(ed, beg);
				end = getWordEnd(ed, end);
				if(beg < 0)
				{
					return;
				}
				else if(end < 0)
				{
					return;
				}
				else if(beg == end)
				{
					return;
				}
			}
			
			DefaultStyledDocument d = getStyledDocument(ed);
			String s = d.getText(beg, end - beg);
			Locale loc = CEditorKit.getLocale(ed);
			s = s.toLowerCase(loc);
			d.replace(beg, end - beg, s, null);
		}
		catch(Exception e)
		{
			Log.ex(e);
			UI.beep();
		}
	}
}
 
開發者ID:andy-goryachev,項目名稱:PasswordSafe,代碼行數:43,代碼來源:CEditorToLowerCaseAction.java

示例5: action

import javax.swing.text.DefaultStyledDocument; //導入方法依賴的package包/類
public void action()
{
	JEditorPane ed = getEditor();
	if(ed != null)
	{
		try
		{
			Caret ca = ed.getCaret();
			int beg = Math.min(ca.getMark(), ca.getDot());
			int end = Math.max(ca.getMark(), ca.getDot());
			if(beg == end)
			{
				// select word
				beg = getWordStart(ed, beg);
				end = getWordEnd(ed, end);
				if(beg < 0)
				{
					return;
				}
				else if(end < 0)
				{
					return;
				}
				else if(beg == end)
				{
					return;
				}
			}
			
			DefaultStyledDocument d = getStyledDocument(ed);
			String s = d.getText(beg, end - beg);
			Locale loc = CEditorKit.getLocale(ed);
			s = s.toUpperCase(loc);
			d.replace(beg, end - beg, s, null);
		}
		catch(Exception e)
		{
			Log.ex(e);
			UI.beep();
		}
	}
}
 
開發者ID:andy-goryachev,項目名稱:PasswordSafe,代碼行數:43,代碼來源:CEditorToUpperCaseAction.java

示例6: rtf2text

import javax.swing.text.DefaultStyledDocument; //導入方法依賴的package包/類
public String rtf2text(InputStream is) throws Exception {
    DefaultStyledDocument styledDoc = new DefaultStyledDocument();
    new RTFEditorKit().read(is, styledDoc, 0);
    return styledDoc.getText(0, styledDoc.getLength());
}
 
開發者ID:mariosotil,項目名稱:text-extractor,代碼行數:6,代碼來源:TextExtractor.java

示例7: getText

import javax.swing.text.DefaultStyledDocument; //導入方法依賴的package包/類
/**
 * Extract text from the Rich text file document 
 * @throws Exception 
 * 
 * @see edu.ur.ir.index.FileTextExtractor#getText(java.io.File)
 */
public String getText(File f) throws Exception {
	String text = null;
	// don't even try if the file is too large
	if( isFileTooLarge(f) || f.length() <= 0l)
	{
		return text;
	}
	DefaultStyledDocument styledDoc = new DefaultStyledDocument();
	RTFEditorKit editorKit = new RTFEditorKit();
	FileInputStream inputStream = null;
	
	try
	{
	    inputStream = new FileInputStream(f);
	    editorKit.read(inputStream, styledDoc, 0);
	    String myText = styledDoc.getText(0, styledDoc.getLength());
	    if( myText != null && !myText.trim().equals(""))
	    {
	    	text = myText;
	    }
	}
	catch(OutOfMemoryError oome)
	{
		text = null;
		log.error("could not extract text", oome);
		throw(oome);
	}
	catch(Exception e)
	{
		text = null;
		log.error("could not get text for rich text document " + f.getAbsolutePath(), e);
		throw(e);
	}
	
	finally
	{
		closeInputStream(inputStream);
		editorKit = null;
	}
	
	return text;
}
 
開發者ID:nate-rcl,項目名稱:irplus,代碼行數:49,代碼來源:DefaultRtfTextExtractor.java


注:本文中的javax.swing.text.DefaultStyledDocument.getText方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。