本文整理汇总了Java中javax.swing.text.Highlighter.Highlight.getEndOffset方法的典型用法代码示例。如果您正苦于以下问题:Java Highlight.getEndOffset方法的具体用法?Java Highlight.getEndOffset怎么用?Java Highlight.getEndOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.Highlighter.Highlight
的用法示例。
在下文中一共展示了Highlight.getEndOffset方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
}
示例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;
}
示例5: 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();
}
}
示例6: 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;
}
示例7: 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;
}
示例8: 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();
}
}
示例9: withinHighlightArea
import javax.swing.text.Highlighter.Highlight; //导入方法依赖的package包/类
private boolean withinHighlightArea(int dot, Highlight h) {
return dot >= h.getStartOffset() && dot < h.getEndOffset();
}
示例10: 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();
}
}
示例11: 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];
int hlStartOffset = highlight.getStartOffset();
int hlEndOffset = highlight.getEndOffset();
if( (i <= hlStartOffset && hlStartOffset <= j) ||
(i <= hlEndOffset && hlEndOffset <= j) ) {
if( highlight.getPainter() == painter ) {
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 ) {
SpellChecker.getMessageHandler().handleException( e );
}
}