本文整理匯總了Java中javax.swing.text.Utilities.getNextWord方法的典型用法代碼示例。如果您正苦於以下問題:Java Utilities.getNextWord方法的具體用法?Java Utilities.getNextWord怎麽用?Java Utilities.getNextWord使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.text.Utilities
的用法示例。
在下文中一共展示了Utilities.getNextWord方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: actionPerformed
import javax.swing.text.Utilities; //導入方法依賴的package包/類
/**
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
*/
public void actionPerformed(ActionEvent e) {
JTextComponent target = getTextComponent(e);
boolean beep = true;
if ((target != null) && (target.isEditable())) {
try {
// select the next word
int offs = target.getCaretPosition();
int endOffs;
String s = target.getDocument().getText(offs, 1);
if (Character.isWhitespace(s.charAt(0))) {
endOffs = Utilities.getNextWord(target, offs);
endOffs = Utilities.getWordEnd(target, endOffs);
} else {
endOffs = Utilities.getWordEnd(target, offs);
}
target.moveCaretPosition(endOffs);
// and then delete it
target.replaceSelection("");
beep = false;
} catch (BadLocationException exc) {
// nothing to do, because we set beep to true already
}
}
if (beep) {
provideErrorFeedback(target);
}
}
示例2: getWordEnd
import javax.swing.text.Utilities; //導入方法依賴的package包/類
private static int getWordEnd(JTextComponent jtc, int start)
throws BadLocationException {
try {
return Utilities.getNextWord(jtc, start);
} catch (BadLocationException ble) {
int end = jtc.getText().length();
if (start < end) {
return end;
} else {
throw ble;
}
}
}
示例3: getWordEnd
import javax.swing.text.Utilities; //導入方法依賴的package包/類
private static int getWordEnd(JTextComponent jtc, int start)
throws BadLocationException {
try {
return Utilities.getNextWord(jtc, start);
} catch (BadLocationException ble) {
int end = jtc.getText().length();
if (start < end) {
return end;
} else {
throw ble;
}
}
}
示例4: getNextWord
import javax.swing.text.Utilities; //導入方法依賴的package包/類
protected int getNextWord(RTextArea textArea, int offs)
throws BadLocationException {
return Utilities.getNextWord(textArea, offs);
}
示例5: getNextVisualPositionFrom
import javax.swing.text.Utilities; //導入方法依賴的package包/類
public int getNextVisualPositionFrom(JTextComponent text,
int pos,
Position.Bias bias,
int direction,
Position.Bias[] biasRet)
throws BadLocationException
{
Point pt;
int newpos = pos;
switch (direction)
{
case SwingConstants.NORTH:
// Find out where the caret want to be positioned ideally.
pt = text.getCaret().getMagicCaretPosition();
// Calculate its position above.
newpos = Utilities.getPositionAbove(text, pos, (pt != null) ? pt.x : 0);
// If we have a valid position, then calculate the next word start
// from there.
if (newpos != -1)
return Utilities.getWordStart(text, newpos);
else
return pos;
case SwingConstants.SOUTH:
// Find out where the caret want to be positioned ideally.
pt = text.getCaret().getMagicCaretPosition();
// Calculate its position below.
newpos = Utilities.getPositionBelow(text, pos, (pt != null) ? pt.x : 0);
// If we have a valid position, then calculate the next word start
// from there.
if (newpos != -1)
return Utilities.getWordStart(text, newpos);
else
return pos;
case SwingConstants.WEST:
// Calculate the next word start.
newpos = Utilities.getWordStart(text, newpos);
// If that means that the caret will not move, return
// the start of the previous word.
if (newpos != pos)
return newpos;
else
return Utilities.getPreviousWord(text, newpos);
case SwingConstants.EAST:
return Utilities.getNextWord(text, newpos);
default:
// Do whatever the super implementation did.
return super.getNextVisualPositionFrom(text, pos, bias,
direction, biasRet);
}
}
示例6: getNextVisualPositionFrom
import javax.swing.text.Utilities; //導入方法依賴的package包/類
public int getNextVisualPositionFrom(JTextComponent text,
int pos,
Position.Bias bias,
int direction,
Position.Bias[] biasRet)
throws BadLocationException
{
Point pt;
int newpos = pos;
switch (direction)
{
case SwingConstants.NORTH:
// Find out where the caret want to be positioned ideally.
pt = text.getCaret().getMagicCaretPosition();
// Calculate its position above.
newpos = Utilities.getPositionAbove(text, pos, (pt != null) ? pt.x : 0);
// If we have a valid position, then calculate the next word start
// from there.
if (newpos != -1)
return Utilities.getWordStart(text, newpos);
else
return pos;
case SwingConstants.SOUTH:
// Find out where the caret want to be positioned ideally.
pt = text.getCaret().getMagicCaretPosition();
// Calculate its position below.
newpos = Utilities.getPositionBelow(text, pos, (pt != null) ? pt.x : 0);
// If we have a valid position, then calculate the next word start
// from there.
if (newpos != -1)
return Utilities.getWordStart(text, newpos);
else
return pos;
case SwingConstants.WEST:
// Calculate the next word start.
newpos = Utilities.getWordStart(text, newpos);
// If that means that the caret will not move, return
// the start of the previous word.
if (newpos != pos)
return newpos;
else
return Utilities.getPreviousWord(text, newpos);
case SwingConstants.EAST:
return Utilities.getNextWord(text, newpos);
default:
// Do whatever the super implementation did.
return super.getNextVisualPositionFrom(text, pos, bias,
direction, biasRet);
}
}