当前位置: 首页>>代码示例>>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;未经允许,请勿转载。