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