当前位置: 首页>>代码示例>>Java>>正文


Java Highlight.getStartOffset方法代码示例

本文整理汇总了Java中javax.swing.text.Highlighter.Highlight.getStartOffset方法的典型用法代码示例。如果您正苦于以下问题:Java Highlight.getStartOffset方法的具体用法?Java Highlight.getStartOffset怎么用?Java Highlight.getStartOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.text.Highlighter.Highlight的用法示例。


在下文中一共展示了Highlight.getStartOffset方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getArgumentText

import javax.swing.text.Highlighter.Highlight; //导入方法依赖的package包/类
/**
 * Returns the text inserted for the parameter containing the specified
 * offset.
 *
 * @param offs The offset into the document.
 * @return The text of the parameter containing the offset, or
 *         <code>null</code> if the offset is not in a parameter.
 */
public String getArgumentText(int offs) {
	List<Highlight> paramHighlights = getParameterHighlights();
	if (paramHighlights==null || paramHighlights.size()==0) {
		return null;
	}
	for (Highlight h : paramHighlights) {
		if (offs>=h.getStartOffset() && offs<=h.getEndOffset()) {
			int start = h.getStartOffset() + 1;
			int len = h.getEndOffset() - start;
			JTextComponent tc = ac.getTextComponent();
			Document doc = tc.getDocument();
			try {
				return doc.getText(start, len);
			} catch (BadLocationException ble) {
				UIManager.getLookAndFeel().provideErrorFeedback(tc);
				ble.printStackTrace();
				return null;
			}
		}
	}
	return null;
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:31,代码来源:ParameterizedCompletionContext.java

示例2: getCurrentParameterHighlight

import javax.swing.text.Highlighter.Highlight; //导入方法依赖的package包/类
/**
 * Returns the highlight of the current parameter.
 *
 * @return The current parameter's highlight, or <code>null</code> if
 *         the caret is not in a parameter's bounds.
 * @see #getCurrentParameterStartOffset()
 */
private Highlight getCurrentParameterHighlight() {

	JTextComponent tc = ac.getTextComponent();
	int dot = tc.getCaretPosition();
	if (dot>0) {
		dot--; // Workaround for Java Highlight issues
	}

	List<Highlight> paramHighlights = getParameterHighlights();
	for (Highlight h : paramHighlights) {
		if (dot>=h.getStartOffset() && dot<h.getEndOffset()) {
			return h;
		}
	}

	return null;

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:26,代码来源:ParameterizedCompletionContext.java

示例3: getCurrentParameterIndex

import javax.swing.text.Highlighter.Highlight; //导入方法依赖的package包/类
private int getCurrentParameterIndex() {

		JTextComponent tc = ac.getTextComponent();
		int dot = tc.getCaretPosition();
		if (dot>0) {
			dot--; // Workaround for Java Highlight issues
		}

		List<Highlight> paramHighlights = getParameterHighlights();
		for (int i=0; i<paramHighlights.size(); i++) {
			Highlight h = paramHighlights.get(i);
			if (dot>=h.getStartOffset() && dot<h.getEndOffset()) {
				return i;
			}
		}

		return -1;

	}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:20,代码来源:ParameterizedCompletionContext.java

示例4: getArgumentText

import javax.swing.text.Highlighter.Highlight; //导入方法依赖的package包/类
/**
 * Returns the text inserted for the parameter containing the specified
 * offset.
 *
 * @param offs
 *            The offset into the document.
 * @return The text of the parameter containing the offset, or
 *         <code>null</code> if the offset is not in a parameter.
 */
public String getArgumentText(int offs) {
	List<Highlight> paramHighlights = getParameterHighlights();
	if (paramHighlights == null || paramHighlights.size() == 0) {
		return null;
	}
	for (Highlight h : paramHighlights) {
		if (offs >= h.getStartOffset() && offs <= h.getEndOffset()) {
			int start = h.getStartOffset() + 1;
			int len = h.getEndOffset() - start;
			JTextComponent tc = ac.getTextComponent();
			Document doc = tc.getDocument();
			try {
				return doc.getText(start, len);
			} catch (BadLocationException ble) {
				UIManager.getLookAndFeel().provideErrorFeedback(tc);
				ble.printStackTrace();
				return null;
			}
		}
	}
	return null;
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:32,代码来源:ParameterizedCompletionContext.java

示例5: getFirstHighlight

import javax.swing.text.Highlighter.Highlight; //导入方法依赖的package包/类
/**
 * Returns the highlight from a list that comes "first" in a list.  Even
 * though most parameter highlights are ordered, sometimes they aren't
 * (e.g. the "cursor" parameter in a template completion is always last,
 * even though it can be anywhere in the template).
 *
 * @param highlights The list of highlights.  Assumed to be non-empty.
 * @return The highlight that comes first in the document.
 * @see #getLastHighlight(List)
 */
private static final int getFirstHighlight(List<Highlight> highlights) {
	int first = -1;
	Highlight firstH = null;
	for (int i=0; i<highlights.size(); i++) {
		Highlight h = highlights.get(i);
		if (firstH==null || h.getStartOffset()<firstH.getStartOffset()) {
			firstH = h;
			first = i;
		}
	}
	return first;
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:23,代码来源:ParameterizedCompletionContext.java

示例6: getLastHighlight

import javax.swing.text.Highlighter.Highlight; //导入方法依赖的package包/类
/**
 * Returns the highlight from a list that comes "last" in that list.  Even
 * though most parameter highlights are ordered, sometimes they aren't
 * (e.g. the "cursor" parameter in a template completion is always last,
 * even though it can be anywhere in the template.
 *
 * @param highlights The list of highlights.  Assumed to be non-empty.
 * @return The highlight that comes last in the document.
 * @see #getFirstHighlight(List)
 */
private static final int getLastHighlight(List<Highlight> highlights) {
	int last = -1;
	Highlight lastH = null;
	for (int i=highlights.size()-1; i>=0; i--) {
		Highlight h = highlights.get(i);
		if (lastH==null || h.getStartOffset()>lastH.getStartOffset()) {
			lastH = h;
			last = i;
		}
	}
	return last;
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:23,代码来源:ParameterizedCompletionContext.java

示例7: moveToNextParam

import javax.swing.text.Highlighter.Highlight; //导入方法依赖的package包/类
/**
 * Moves to and selects the next parameter.
 *
 * @see #moveToPreviousParam()
 */
private void moveToNextParam() {

	JTextComponent tc = ac.getTextComponent();
	int dot = tc.getCaretPosition();
	int tagCount = tags.size();
	if (tagCount==0) {
		tc.setCaretPosition(maxPos.getOffset());
		deactivate();
	}

	Highlight currentNext = null;
	int pos = -1;
	List<Highlight> highlights = getParameterHighlights();
	for (int i=0; i<highlights.size(); i++) {
		Highlight hl = highlights.get(i);
		// Check "< dot", not "<= dot" as OutlineHighlightPainter paints
		// starting at one char AFTER the highlight starts, to work around
		// Java issue.  Thanks to Matthew Adereth!
		if (currentNext==null || currentNext.getStartOffset()</*=*/dot ||
				(hl.getStartOffset()>dot &&
				hl.getStartOffset()<=currentNext.getStartOffset())) {
			currentNext = hl;
			pos = i;
		}
	}

	// No params after caret - go to first one
	if (currentNext.getStartOffset()+1<=dot) {
		int nextIndex = getFirstHighlight(highlights);
		currentNext = highlights.get(nextIndex);
		pos = 0;
	}

	// "+1" is a workaround for Java Highlight issues.
	tc.setSelectionStart(currentNext.getStartOffset()+1);
	tc.setSelectionEnd(currentNext.getEndOffset());
	updateToolTipText(pos);

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:45,代码来源:ParameterizedCompletionContext.java

示例8: possiblyUpdateParamCopies

import javax.swing.text.Highlighter.Highlight; //导入方法依赖的package包/类
private void possiblyUpdateParamCopies(Document doc) {
	
	int index = getCurrentParameterIndex();
	// FunctionCompletions add an extra param at end of inserted text
	if (index>-1 && index<pc.getParamCount()) {

		// Typing in an "end parameter" => stop parameter assistance.
		Parameter param = pc.getParam(index);
		if (param.isEndParam()) {
			deactivate();
			return;
		}

		// Get the current value of the current parameter.
		List<Highlight> paramHighlights = getParameterHighlights();
		Highlight h = paramHighlights.get(index);
		int start = h.getStartOffset() + 1; // param offsets are offset (!) by 1
		int len = h.getEndOffset() - start;
		String replacement = null;
		try {
			replacement = doc.getText(start, len);
		} catch (BadLocationException ble) {
			ble.printStackTrace(); // Never happens
		}

		// Replace any param copies tracking this parameter with the
		// value of this parameter.
		for (ParamCopyInfo pci : paramCopyInfos) {
			if (pci.paramName.equals(param.getName())) {
				pci.h = replaceHighlightedText(doc, pci.h, replacement);
			}
		}

	}

	else { // Probably the "end parameter" for FunctionCompletions.
		deactivate();
	}

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:41,代码来源:ParameterizedCompletionContext.java

示例9: updateToolTipText

import javax.swing.text.Highlighter.Highlight; //导入方法依赖的package包/类
/**
 * Updates the text in the tool tip to have the current parameter
 * displayed in bold.  The "current parameter" is determined from the
 * current caret position.
 *
 * @return The "prefix" of text in the caret's parameter before the caret.
 */
private String updateToolTipText() {

	JTextComponent tc = ac.getTextComponent();
	int dot = tc.getSelectionStart();
	int mark = tc.getSelectionEnd();
	int index = -1;
	String paramPrefix = null;

	List<Highlight> paramHighlights = getParameterHighlights();
	for (int i=0; i<paramHighlights.size(); i++) {
		Highlight h = paramHighlights.get(i);
		// "+1" because of param hack - see OutlineHighlightPainter
		int start = h.getStartOffset()+1;
		if (dot>=start && dot<=h.getEndOffset()) {
			try {
				// All text selected => offer all suggestions, otherwise
				// use prefix before selection
				if (dot!=start || mark!=h.getEndOffset()) {
					paramPrefix = tc.getText(start, dot-start);
				}
			} catch (BadLocationException ble) {
				ble.printStackTrace();
			}
			index = i;
			break;
		}
	}

	updateToolTipText(index);
	return paramPrefix;

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:40,代码来源:ParameterizedCompletionContext.java

示例10: getFirstHighlight

import javax.swing.text.Highlighter.Highlight; //导入方法依赖的package包/类
/**
 * Returns the highlight from a list that comes "first" in a list. Even
 * though most parameter highlights are ordered, sometimes they aren't (e.g.
 * the "cursor" parameter in a template completion is always last, even
 * though it can be anywhere in the template).
 *
 * @param highlights
 *            The list of highlights. Assumed to be non-empty.
 * @return The highlight that comes first in the document.
 * @see #getLastHighlight(List)
 */
private static final int getFirstHighlight(List<Highlight> highlights) {
	int first = -1;
	Highlight firstH = null;
	for (int i = 0; i < highlights.size(); i++) {
		Highlight h = highlights.get(i);
		if (firstH == null || h.getStartOffset() < firstH.getStartOffset()) {
			firstH = h;
			first = i;
		}
	}
	return first;
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:24,代码来源:ParameterizedCompletionContext.java

示例11: getLastHighlight

import javax.swing.text.Highlighter.Highlight; //导入方法依赖的package包/类
/**
 * Returns the highlight from a list that comes "last" in that list. Even
 * though most parameter highlights are ordered, sometimes they aren't (e.g.
 * the "cursor" parameter in a template completion is always last, even
 * though it can be anywhere in the template.
 *
 * @param highlights
 *            The list of highlights. Assumed to be non-empty.
 * @return The highlight that comes last in the document.
 * @see #getFirstHighlight(List)
 */
private static final int getLastHighlight(List<Highlight> highlights) {
	int last = -1;
	Highlight lastH = null;
	for (int i = highlights.size() - 1; i >= 0; i--) {
		Highlight h = highlights.get(i);
		if (lastH == null || h.getStartOffset() > lastH.getStartOffset()) {
			lastH = h;
			last = i;
		}
	}
	return last;
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:24,代码来源:ParameterizedCompletionContext.java

示例12: updateToolTipText

import javax.swing.text.Highlighter.Highlight; //导入方法依赖的package包/类
/**
 * Updates the text in the tool tip to have the current parameter displayed
 * in bold. The "current parameter" is determined from the current caret
 * position.
 *
 * @return The "prefix" of text in the caret's parameter before the caret.
 */
private String updateToolTipText() {

	JTextComponent tc = ac.getTextComponent();
	int dot = tc.getSelectionStart();
	int mark = tc.getSelectionEnd();
	int index = -1;
	String paramPrefix = null;

	List<Highlight> paramHighlights = getParameterHighlights();
	for (int i = 0; i < paramHighlights.size(); i++) {
		Highlight h = paramHighlights.get(i);
		// "+1" because of param hack - see OutlineHighlightPainter
		int start = h.getStartOffset() + 1;
		if (dot >= start && dot <= h.getEndOffset()) {
			try {
				// All text selected => offer all suggestions, otherwise
				// use prefix before selection
				if (dot != start || mark != h.getEndOffset()) {
					paramPrefix = tc.getText(start, dot - start);
				}
			} catch (BadLocationException ble) {
				ble.printStackTrace();
			}
			index = i;
			break;
		}
	}

	updateToolTipText(index);
	return paramPrefix;

}
 
开发者ID:curiosag,项目名称:ftc,代码行数:40,代码来源:ParameterizedCompletionContext.java

示例13: checkElement

import javax.swing.text.Highlighter.Highlight; //导入方法依赖的package包/类
/**
 * Check the spelling of the text of an element.
 * 
 * @param element
 *            the to checking Element
 */
private void checkElement( javax.swing.text.Element element ) {
    try {
        int i = element.getStartOffset();
        int j = element.getEndOffset();
        Highlighter highlighter = jText.getHighlighter();
        Highlight[] highlights = highlighter.getHighlights();
        for( int k = highlights.length; --k >= 0; ) {
            Highlight highlight = highlights[k];
            if( highlight.getStartOffset() >= i && highlight.getEndOffset() <= j ) {
                highlighter.removeHighlight( highlight );
            }
        }

        int l = ((AbstractDocument)jText.getDocument()).getLength();
        j = Math.min( j, l );
        if( i >= j )
            return;

        // prevent a NPE if the dictionary is currently not loaded.
        Dictionary dic = dictionary;
        Locale loc = locale;
        if( dic == null || loc == null ){
            return;
        }
        
        Tokenizer tok = new Tokenizer( jText, dic, loc, i, j, options );
        String word;
        while( (word = tok.nextInvalidWord()) != null ) {
            int wordOffset = tok.getWordOffset();
            highlighter.addHighlight( wordOffset, wordOffset + word.length(), painter );
        }
    } catch( BadLocationException e ) {
        e.printStackTrace();
    }
}
 
开发者ID:dasatti,项目名称:urduhtmlmaster,代码行数:42,代码来源:AutoSpellChecker.java

示例14: moveToPreviousParam

import javax.swing.text.Highlighter.Highlight; //导入方法依赖的package包/类
/**
 * Moves to and selects the previous parameter.
 *
 * @see #moveToNextParam()
 */
private void moveToPreviousParam() {

	JTextComponent tc = ac.getTextComponent();

	int tagCount = tags.size();
	if (tagCount==0) { // Should never happen
		tc.setCaretPosition(maxPos.getOffset());
		deactivate();
	}

	int dot = tc.getCaretPosition();
	int selStart = tc.getSelectionStart()-1; // Workaround for Java Highlight issues.
	Highlight currentPrev = null;
	int pos = 0;
	List<Highlight> highlights = getParameterHighlights();

	for (int i=0; i<highlights.size(); i++) {
		Highlight h = highlights.get(i);
		if (currentPrev==null || currentPrev.getStartOffset()>=dot ||
				(h.getStartOffset()<selStart &&
				(h.getStartOffset()>currentPrev.getStartOffset() ||
						pos==lastSelectedParam))) {
			currentPrev = h;
			pos = i;
		}
	}

	// Loop back from param 0 to last param.
	int firstIndex = getFirstHighlight(highlights);
	//if (pos==0 && lastSelectedParam==0 && highlights.size()>1) {
	if (pos==firstIndex && lastSelectedParam==firstIndex && highlights.size()>1) {
		pos = getLastHighlight(highlights);
		currentPrev = highlights.get(pos);
		 // "+1" is a workaround for Java Highlight issues.
		tc.setSelectionStart(currentPrev.getStartOffset()+1);
		tc.setSelectionEnd(currentPrev.getEndOffset());
		updateToolTipText(pos);
	}
	else if (currentPrev!=null && dot>currentPrev.getStartOffset()) {
		 // "+1" is a workaround for Java Highlight issues.
		tc.setSelectionStart(currentPrev.getStartOffset()+1);
		tc.setSelectionEnd(currentPrev.getEndOffset());
		updateToolTipText(pos);
	}
	else {
		tc.setCaretPosition(maxPos.getOffset());
		deactivate();
	}

}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:56,代码来源:ParameterizedCompletionContext.java

示例15: withinHighlightArea

import javax.swing.text.Highlighter.Highlight; //导入方法依赖的package包/类
private boolean withinHighlightArea(int dot, Highlight h) {
	return dot >= h.getStartOffset() && dot < h.getEndOffset();
}
 
开发者ID:curiosag,项目名称:ftc,代码行数:4,代码来源:ParameterizedCompletionContext.java


注:本文中的javax.swing.text.Highlighter.Highlight.getStartOffset方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。