本文整理汇总了Java中javax.swing.text.html.HTMLDocument.getLength方法的典型用法代码示例。如果您正苦于以下问题:Java HTMLDocument.getLength方法的具体用法?Java HTMLDocument.getLength怎么用?Java HTMLDocument.getLength使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.html.HTMLDocument
的用法示例。
在下文中一共展示了HTMLDocument.getLength方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPlaintextFromEditor
import javax.swing.text.html.HTMLDocument; //导入方法依赖的package包/类
/**
* Returns plain text from the editor.
*
* @param editor
* the editor from which to take the text.
* @param onlySelected
* if {@code true} will only return the selected text
* @return the text of the editor converted to plain text
* @throws BadLocationException
* @throws IOException
*/
public static String getPlaintextFromEditor(final JEditorPane editor, final boolean onlySelected) throws IOException,
BadLocationException {
if (editor == null) {
throw new IllegalArgumentException("editor must not be null!");
}
HTMLDocument document = (HTMLDocument) editor.getDocument();
StringWriter writer = new StringWriter();
int start = 0;
int length = document.getLength();
if (onlySelected) {
start = editor.getSelectionStart();
length = editor.getSelectionEnd() - start;
}
editor.getEditorKit().write(writer, document, start, length);
String text = writer.toString();
text = AnnotationDrawUtils.removeStyleFromComment(text);
// switch <br> and <br/> to actual newline (current system)
text = text.replaceAll("<br.*?>", System.lineSeparator());
// kill all other html tags
text = text.replaceAll("\\<.*?>", "");
text = StringEscapeUtils.unescapeHtml(text);
return text;
}
示例2: AltHTMLWriter
import javax.swing.text.html.HTMLDocument; //导入方法依赖的package包/类
public AltHTMLWriter(Writer w, HTMLDocument doc, String enc, boolean nument) {
this(w, doc, 0, doc.getLength(), enc, nument);
}
示例3: AltHTMLWriter
import javax.swing.text.html.HTMLDocument; //导入方法依赖的package包/类
public AltHTMLWriter(Writer w, HTMLDocument doc, String enc) {
this(w, doc, 0, doc.getLength(), enc, false);
}
示例4: AltHTMLWriter
import javax.swing.text.html.HTMLDocument; //导入方法依赖的package包/类
/**
* Creates a new HTMLWriter.
*
* @param w a Writer
* @param doc an HTMLDocument
*
*/
public AltHTMLWriter(Writer w, HTMLDocument doc) {
this(w, doc, 0, doc.getLength(), null, false);
}