本文整理汇总了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();
}
}
示例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;
}
示例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( ) );
}
}
示例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();
}
}
}
示例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();
}
}
}
示例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());
}
示例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;
}