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


Java Utilities.getPreviousWord方法代碼示例

本文整理匯總了Java中javax.swing.text.Utilities.getPreviousWord方法的典型用法代碼示例。如果您正苦於以下問題:Java Utilities.getPreviousWord方法的具體用法?Java Utilities.getPreviousWord怎麽用?Java Utilities.getPreviousWord使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.text.Utilities的用法示例。


在下文中一共展示了Utilities.getPreviousWord方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: actionPerformed

import javax.swing.text.Utilities; //導入方法依賴的package包/類
@Override
public void actionPerformed(ActionEvent e) {
    JTextComponent jtc = getTextComponent(e);
    if (jtc != null) {
        try {
            int offs = jtc.getCaretPosition();
            jtc.setSelectionEnd(offs);
            offs = Utilities.getPreviousWord(jtc, offs);
            jtc.setSelectionStart(offs);
            String selectedText = jtc.getSelectedText();
            if (selectedText != null) {
                KillRing.getInstance().add(selectedText);
            }
            jtc.cut();
        } catch (BadLocationException ble) {
            jtc.getToolkit().beep();
        }
    }
}
 
開發者ID:JabRef,項目名稱:jabref,代碼行數:20,代碼來源:EmacsKeyBindings.java

示例2: 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())) {
        int     offs   = target.getCaretPosition();
        boolean failed = false;

        try {
            offs = Utilities.getPreviousWord(target, offs);
        } catch (BadLocationException bl) {

            if (offs != 0) {
                offs = 0;
            } else {
                failed = true;
            }
        }

        if (!failed) {
            target.moveCaretPosition(offs);

            // and then delete it
            target.replaceSelection("");
            beep = false;
        }
    }

    if (beep) {
        provideErrorFeedback(target);
    }
}
 
開發者ID:khuxtable,項目名稱:seaglass,代碼行數:36,代碼來源:MacEditorKit.java

示例3: actionPerformed

import javax.swing.text.Utilities; //導入方法依賴的package包/類
public void actionPerformed(ActionEvent e) {
	JTextComponent jtc = getTextComponent(e);
	if (jtc != null) {
		try {
			int offs = jtc.getCaretPosition();
			jtc.setSelectionEnd(offs);
			offs = Utilities.getPreviousWord(jtc, offs);
			jtc.setSelectionStart(offs);
			KillRing.getInstance().add(jtc.getSelectedText());
			jtc.cut();
		} catch (BadLocationException ble) {
			jtc.getToolkit().beep();
		}
	}
}
 
開發者ID:jpverkamp,項目名稱:wombat-ide,代碼行數:16,代碼來源:EmacsKeyBindings.java

示例4: getPreviousWordStart

import javax.swing.text.Utilities; //導入方法依賴的package包/類
/**
 * Returns the starting offset to delete.  Exists so subclasses can
 * override.
 */
protected int getPreviousWordStart(RTextArea textArea, int end)
		throws BadLocationException {
	return Utilities.getPreviousWord(textArea, end);
}
 
開發者ID:Thecarisma,項目名稱:powertext,代碼行數:9,代碼來源:RTextAreaEditorKit.java

示例5: getPreviousWord

import javax.swing.text.Utilities; //導入方法依賴的package包/類
protected int getPreviousWord(RTextArea textArea, int offs)
		throws BadLocationException {
	return Utilities.getPreviousWord(textArea, offs);
}
 
開發者ID:Thecarisma,項目名稱:powertext,代碼行數:5,代碼來源:RTextAreaEditorKit.java

示例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);
  }
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:57,代碼來源:NavigationFilterDemo.java

示例7: 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);
  }
}
 
開發者ID:nmldiegues,項目名稱:jvm-stm,代碼行數:57,代碼來源:NavigationFilterDemo.java


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