當前位置: 首頁>>代碼示例>>Java>>正文


Java Utilities.getParagraphElement方法代碼示例

本文整理匯總了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();
    }
}
 
開發者ID:apache,項目名稱:groovy,代碼行數:24,代碼來源:TextEditor.java

示例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();
	}
}
 
開發者ID:ltrr-arizona-edu,項目名稱:tellervo,代碼行數:25,代碼來源:LineHighlighter.java

示例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);
	}

}
 
開發者ID:Thecarisma,項目名稱:powertext,代碼行數:36,代碼來源:RTextAreaEditorKit.java

示例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;
}
 
開發者ID:bwollman,項目名稱:41_follow,代碼行數:37,代碼來源:SearchableTextPane.java


注:本文中的javax.swing.text.Utilities.getParagraphElement方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。