本文整理匯總了Java中javax.swing.text.Utilities.getParagraphElement方法的典型用法代碼示例。如果您正苦於以下問題:Java Utilities.getParagraphElement方法的具體用法?Java Utilities.getParagraphElement怎麽用?Java Utilities.getParagraphElement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.text.Utilities
的用法示例。
在下文中一共展示了Utilities.getParagraphElement方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: actionPerformed
import javax.swing.text.Utilities; //導入方法依賴的package包/類
public void actionPerformed(ActionEvent ae) {
try {
if (multiLineTab && TextEditor.this.getSelectedText() != null) {
int end = Utilities.getRowEnd(TextEditor.this, getSelectionEnd());
TextEditor.this.setSelectionEnd(end);
Element el = Utilities.getParagraphElement(TextEditor.this, getSelectionStart());
int start = el.getStartOffset();
TextEditor.this.setSelectionStart(start);
// remove text and reselect the text
String text = tabsAsSpaces ?
TAB_BACK_PATTERN.matcher(getSelectedText()).replaceAll("") :
getSelectedText().replaceAll("^\t", "");
TextEditor.this.replaceSelection(text);
TextEditor.this.select(start, start + text.length());
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例2: caretUpdate
import javax.swing.text.Utilities; //導入方法依賴的package包/類
public void caretUpdate(CaretEvent evt)
{
JTextComponent comp = (JTextComponent)evt.getSource();
if (comp != null && highlight != null)
{
comp.getHighlighter().removeHighlight(highlight);
highlight = null;
}
int pos = comp.getCaretPosition();
Element elem = Utilities.getParagraphElement(comp, pos);
int start = elem.getStartOffset();
int end = elem.getEndOffset();
try
{
highlight = comp.getHighlighter().addHighlight(start, end,
painter);
}
catch (BadLocationException ex)
{
ex.printStackTrace();
}
}
示例3: actionPerformedImpl
import javax.swing.text.Utilities; //導入方法依賴的package包/類
@Override
public void actionPerformedImpl(ActionEvent e, RTextArea textArea) {
int offs = textArea.getCaretPosition();
int oldOffs = offs;
Element curPara = Utilities.getParagraphElement(textArea, offs);
try {
offs = getNextWord(textArea, offs);
if(offs >= curPara.getEndOffset() &&
oldOffs != curPara.getEndOffset() - 1) {
// we should first move to the end of current paragraph
// http://bugs.sun.com/view_bug.do?bug_id=4278839
offs = curPara.getEndOffset() - 1;
}
} catch (BadLocationException ble) {
int end = textArea.getDocument().getLength();
if (offs != end) {
if(oldOffs != curPara.getEndOffset() - 1) {
offs = curPara.getEndOffset() - 1;
}
else {
offs = end;
}
}
}
if (select) {
textArea.moveCaretPosition(offs);
}
else {
textArea.setCaretPosition(offs);
}
}
示例4: convertWords2Lines
import javax.swing.text.Utilities; //導入方法依賴的package包/類
/**
* Converts word results from search into line results
*
* @param words
* @return
*/
private List<LineResult> convertWords2Lines(List<WordResult> words) throws BadLocationException
{
ArrayList<LineResult> lines = new ArrayList<LineResult>();
LineResult tempLine = null;
int lastLine = -1;
for (WordResult word : words)
{
int line = getLineOfOffset(word.start);
if (line != lastLine)
{
if (tempLine != null)
{
lines.add(tempLine);
}
Element elem = Utilities.getParagraphElement(this, word.start);
int lineStart = elem.getStartOffset();
int lineEnd = elem.getEndOffset();
tempLine = new LineResult(line, lineStart, lineEnd);
}
updateWordResult(word, tempLine);
lastLine = line;
// allow other things to happen in case the search takes a while
Thread.yield();
}
if (tempLine != null)
{
lines.add(tempLine);
}
return lines;
}