本文整理了Java中javax.swing.text.StyledDocument.getText()
方法的一些代码示例,展示了StyledDocument.getText()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。StyledDocument.getText()
方法的具体详情如下:
包路径:javax.swing.text.StyledDocument
类名称:StyledDocument
方法名:getText
暂无
代码示例来源:origin: groovy/groovy-core
public void actionPerformed(ActionEvent ae) {
JTextComponent tComp = (JTextComponent) ae.getSource();
if (tComp.getDocument() instanceof StyledDocument) {
doc = (StyledDocument) tComp.getDocument();
try {
doc.getText(0, doc.getLength(), segment);
}
catch (Exception e) {
// should NEVER reach here
e.printStackTrace();
}
int offset = tComp.getCaretPosition();
int index = findTabLocation(offset);
buffer.delete(0, buffer.length());
buffer.append('\n');
if (index > -1) {
for (int i = 0; i < index + 4; i++) {
buffer.append(' ');
}
}
try {
doc.insertString(offset, buffer.toString(),
doc.getDefaultRootElement().getAttributes());
}
catch (BadLocationException ble) {
ble.printStackTrace();
}
}
}
代码示例来源:origin: beryx/text-io
public String getPartialInput() {
try {
return document.getText(startReadLen, document.getLength() - startReadLen);
} catch (BadLocationException e) {
logger.error("Failed to retrieve partial input text", e);
return "";
}
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-javascript2-nodejs
@Override
public void run() {
try {
docContentRef.set(document.getText(0, document.getLength()));
} catch (BadLocationException ex) {
bleRef.set(ex);
}
}
代码示例来源:origin: stackoverflow.com
String html = "<html>...";
JTextPane pane = new JTextPane();
pane.setContentType("text/html");
pane.setText(html);
StyledDocument doc = pane.getStyledDocument();
try {
System.out.println("Text: " + doc.getText(0, doc.getLength()));
} catch (BadLocationException ex) {
Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-jsf
@Override
public void run() {
try {
int position = doc.getText(0, doc.getLength()).indexOf(find);
// if element wasn't found - it isn't likely new project with sample index.html page and
// there is probably not wished to have it changed, so don't do it
if (position >= 0) {
doc.insertString(position, enhanceBy + "\n", null); //NOI18N
}
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
});
代码示例来源:origin: otros-systems/otroslogviewer
private void scrollToSearchResult(ArrayList<String> toHighlight, JTextPane textPane) {
if (toHighlight.size() == 0) {
return;
}
try {
StyledDocument logDetailsDocument = textPane.getStyledDocument();
String text = logDetailsDocument.getText(0, logDetailsDocument.getLength());
String string = toHighlight.get(0);
textPane.setCaretPosition(Math.max(text.indexOf(string), 0));
} catch (BadLocationException e) {
LOGGER.warn("Cant scroll to content, wrong location: " + e.getMessage());
}
}
代码示例来源:origin: stackoverflow.com
StyledDocument document = textPane.getStyledDocument();
Style highlight = document.addStyle("highlight", null);
StyleConstants.setBackground(highlight, Color.YELLOW);
String text = document.getText(0, document.getLength());
while ((index = text.indexOf(myWord, index)) >= 0) {
document.setCharacterAttributes(index, myWord.length(), highlight, false);
index += myWord.length();
}
代码示例来源:origin: org.netbeans.api/org-openide-text
public void run() {
// Part of #33165 - the following code is wrapped by doc.render()
try {
int p = position.getOffset();
if (p >= doc.getLength()) {
retStringArray[0] = "";
} else {
retStringArray[0] = doc.getText(position.getOffset(), getLength());
}
} catch (BadLocationException ex) {
Logger.getLogger(DocumentLine.class.getName()).log(Level.WARNING, null, ex);
retStringArray[0] = null;
}
// End of the code wrapped by doc.render()
}
}
代码示例来源:origin: org.apache.uima/uimaj-ep-cas-editor-ide
private String convert(InputStream rtfDocumentInputStream) throws IOException {
RTFEditorKit aRtfEditorkit = new RTFEditorKit();
StyledDocument styledDoc = new DefaultStyledDocument();
String textDocument;
try {
aRtfEditorkit.read(rtfDocumentInputStream, styledDoc, 0);
textDocument = styledDoc.getText(0, styledDoc.getLength());
} catch (BadLocationException e) {
throw new IOException("Error during parsing");
}
return textDocument;
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-cnd-debugger-common2
/**
* Map document position to contents of whole line at that position.
* SHOULD be combined with addrFromLine to givew:
* Address viewToModel(pos)
*/
private String getLineAt(int pos) {
// By default a "paragraph" is a line
Element pp = styledDoc.getParagraphElement(pos);
int startPos = pp.getStartOffset();
int endPos = pp.getEndOffset();
int length = endPos - startPos;
String line = null;
try {
line = styledDoc.getText(startPos, length);
} catch (Exception x) {
}
return line;
}
代码示例来源:origin: org.netbeans.api/org-openide-text
/** Finds the text contained in this range.
* @return the text
* @exception IOException if any I/O problem occurred during document loading (if that was necessary)
* @exception BadLocationException if the positions are out of the bounds of the document
*/
public String getText() throws BadLocationException, IOException {
StyledDocument doc = begin.getCloneableEditorSupport().openDocument();
int p1 = begin.getOffset();
int p2 = end.getOffset();
return doc.getText(p1, p2 - p1);
}
代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw
@Override
public Figure createTextArea(double x, double y, double w, double h, StyledDocument doc, Map<AttributeKey, Object> attributes) {
SVGTextAreaFigure figure = new SVGTextAreaFigure();
figure.setBounds(new Point2D.Double(x,y),new Point2D.Double(x+w,y+h));
try {
figure.setText(doc.getText(0, doc.getLength()));
} catch (BadLocationException e) {
InternalError ex = new InternalError(e.getMessage());
ex.initCause(e);
throw ex;
}
figure.setAttributes(attributes);
return figure;
}
代码示例来源:origin: org.netbeans.api/org-openide-text
public void run() {
// Part of #33165 - the following code is wrapped by doc.render()
int lineNumber = getLineNumber();
int lineStart = NbDocument.findLineOffset(doc, lineNumber);
// #24434: Check whether the next line exists
// (the current one could be the last one).
int lineEnd;
if ((lineNumber + 1) >= NbDocument.findLineRootElement(doc).getElementCount()) {
lineEnd = doc.getLength();
} else {
lineEnd = NbDocument.findLineOffset(doc, lineNumber + 1);
}
try {
retStringArray[0] = doc.getText(lineStart, lineEnd - lineStart);
} catch (BadLocationException ex) {
Logger.getLogger(DocumentLine.class.getName()).log(Level.WARNING, null, ex);
retStringArray[0] = null;
}
// End of the code wrapped by doc.render()
}
}
代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/openide
/** Finds the text contained in this range.
* @return the text
* @exception IOException if any I/O problem occurred during document loading (if that was necessary)
* @exception BadLocationException if the positions are out of the bounds of the document
*/
public String getText() throws BadLocationException, IOException {
StyledDocument doc = begin.getCloneableEditorSupport().openDocument();
int p1 = begin.getOffset();
int p2 = end.getOffset();
return doc.getText(p1, p2 - p1);
}
代码示例来源:origin: otros-systems/otroslogviewer
public static void highlightSearchResult(
OtrosJTextWithRulerScrollPane<JTextPane> otrosJTextWithRulerScrollPane,
PluginableElementsContainer<MessageColorizer> colorizersContainer,
Theme theme) {
MessageUpdateUtils messageUpdateUtils = new MessageUpdateUtils();
StyledDocument styledDocument = otrosJTextWithRulerScrollPane.getjTextComponent().getStyledDocument();
String text;
try {
text = styledDocument.getText(0, styledDocument.getLength());
} catch (BadLocationException e) {
LOGGER.error("Cant get document text for log details view: ", e);
return;
}
MessageColorizer messageColorizer = colorizersContainer.getElement(SearchResultColorizer.class.getName());
List<MessageFragmentStyle> messageFragmentStyles = new ArrayList<>();
if (messageColorizer != null) {
messageFragmentStyles.addAll(messageUpdateUtils.colorizeMessageWithTimeLimit(text, 0, messageColorizer, 10));
}
markSearchResult(messageFragmentStyles, otrosJTextWithRulerScrollPane, theme);
}
代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide
/** Finds the text contained in this range.
* @return the text
* @exception IOException if any I/O problem occurred during document loading (if that was necessary)
* @exception BadLocationException if the positions are out of the bounds of the document
*/
public String getText() throws BadLocationException, IOException {
StyledDocument doc = begin.getCloneableEditorSupport().openDocument();
int p1 = begin.getOffset();
int p2 = end.getOffset();
return doc.getText(p1, p2 - p1);
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-team-commons
private void registerForIssueLinks(final JTextPane pane, final Link issueLink, final IssueRefProvider issueIdProvider) {
pane.removeMouseMotionListener(motionListener);
try {
String text = "";
try {
text = pane.getStyledDocument().getText(0, pane.getStyledDocument().getLength());
} catch (BadLocationException ex) {
Support.LOG.log(Level.INFO, null, ex);
}
registerLinkIntern(pane, issueIdProvider.getIssueRefSpans(text), issueLink);
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
}
pane.addMouseMotionListener(motionListener);
}
代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-web-beans
static int getRowFirstNonWhite(StyledDocument doc, int offset)
throws BadLocationException {
Element lineElement = doc.getParagraphElement(offset);
int start = lineElement.getStartOffset();
while (start + 1 < lineElement.getEndOffset()) {
try {
if (doc.getText(start, 1).charAt(0) != ' ') {
break;
}
} catch (BadLocationException ex) {
throw (BadLocationException) new BadLocationException(
"calling getText(" + start + ", " + (start + 1)
+ ") on doc of length: " + doc.getLength(), start).initCause(ex);
}
start++;
}
return start;
}
代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw
@Override
public Figure createText(Point2D.Double[] coordinates, double[] rotates, StyledDocument text, Map<AttributeKey, Object> a) {
SVGTextFigure figure = new SVGTextFigure();
figure.setCoordinates(coordinates);
figure.setRotates(rotates);
try {
figure.setText(text.getText(0, text.getLength()));
} catch (BadLocationException e) {
InternalError ex = new InternalError(e.getMessage());
ex.initCause(e);
throw ex;
}
figure.setAttributes(a);
return figure;
}
代码示例来源:origin: net.sf.squirrel-sql.thirdpary-non-maven/openide
doc.render(new Runnable() { public void run() {
// Part of #33165 - the following code is wrapped by doc.render()
int lineNumber = getLineNumber();
int lineStart = NbDocument.findLineOffset(doc, lineNumber);
// #24434: Check whether the next line exists
// (the current one could be the last one).
int lineEnd;
if((lineNumber + 1)
>= NbDocument.findLineRootElement(doc).getElementCount()) {
lineEnd = doc.getLength();
} else {
lineEnd = NbDocument.findLineOffset(doc, lineNumber + 1);
}
try {
retStringArray[0] = doc.getText(lineStart, lineEnd - lineStart);
} catch (BadLocationException ex) {
ErrorManager.getDefault ().notify ( ErrorManager.EXCEPTION, ex);
retStringArray[0] = null;
}
// End of the code wrapped by doc.render()
}});
return retStringArray[0];
内容来源于网络,如有侵权,请联系作者删除!