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