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


Java JTextComponent.replaceSelection方法代码示例

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


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

示例1: insertSelectedChoice

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * Inserts the choice selected in the parameter choices window.
 *
 * @return Whether the choice was inserted.  This will be <code>false</code>
 *         if the window is not visible, or no choice is selected.
 */
boolean insertSelectedChoice() {
	if (paramChoicesWindow!=null && paramChoicesWindow.isVisible()) {
		String choice = paramChoicesWindow.getSelectedChoice();
		if (choice!=null) {
			JTextComponent tc = ac.getTextComponent();
			Highlight h = getCurrentParameterHighlight();
			if (h!=null) {
				 // "+1" is a workaround for Java Highlight issues.
				tc.setSelectionStart(h.getStartOffset()+1);
				tc.setSelectionEnd(h.getEndOffset());
				tc.replaceSelection(choice);
				moveToNextParam();
			}
			else {
				UIManager.getLookAndFeel().provideErrorFeedback(tc);
			}
			return true;
		}
	}
	return false;
}
 
开发者ID:Thecarisma,项目名称:powertext,代码行数:28,代码来源:ParameterizedCompletionContext.java

示例2: paste

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * Copies the text contents of the system clipboard to the text component.
 *
 * @param textComponent
 */
public static void paste(JTextComponent textComponent) {
    String contents = ClipboardHandlerFactory.getClipboardHandler()
            .getContents();
    if (contents != null) {
        StringBuffer buffer = new StringBuffer();
        char c;
        for (int i = 0, n = contents.length(); i < n; i++) {
            c = contents.charAt(i);
            // Not to copy a null character
            if (c != 0) {
                buffer.append(c);
            }
        }
        textComponent.replaceSelection(buffer.toString());
    }
    if (!textComponent.hasFocus()) {
        textComponent.requestFocus();
    }
}
 
开发者ID:YcheCourseProject,项目名称:DIA-Umpire-Maven,代码行数:25,代码来源:TextComponentUtil.java

示例3: replaceSelection

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * Hook to insert the given string at the given position into
 * the given document in insert-mode with selection visible
 * Designed to be overridden by subclasses that want
 * to intercept inserted characters.
 *
 * @deprecated Please use Typing Hooks instead, for details see
 *   <a href="@[email protected]/overview-summary.html">Editor Library 2</a>.
 */
protected void replaceSelection(
        JTextComponent target,
        int dotPos,
        Caret caret,
        String str,
        boolean overwrite) throws BadLocationException
{
    target.replaceSelection(str);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:BaseKit.java

示例4: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if ((target != null) && (evt != null)) {
        if (!target.isEditable() || !target.isEnabled()) {
            target.getToolkit().beep();
            return;
        }

        String content = evt.getActionCommand();
        if (content != null) {
            target.replaceSelection(content);
        } else {
            target.getToolkit().beep();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:16,代码来源:BaseKit.java

示例5: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent e) {

	// If the param choices window is visible and something is chosen,
	// replace the parameter with it and move to the next one.
	if (paramChoicesWindow!=null && paramChoicesWindow.isVisible()) {
		if (insertSelectedChoice()) {
			return;
		}
	}

	// Otherwise, just move to the end.
	deactivate();
	JTextComponent tc = ac.getTextComponent();
	int dot = tc.getCaretPosition();
	if (dot!=defaultEndOffs.getOffset()) {
		tc.setCaretPosition(defaultEndOffs.getOffset());
	}
	else {
		// oldEnterAction isn't what we're looking for (wrong key)
		Action a = getDefaultEnterAction(tc);
		if (a!=null) {
			a.actionPerformed(e);
		}
		else {
			tc.replaceSelection("\n");
		}
	}

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

示例6: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed(final ActionEvent evt, final  JTextComponent target) {
    if (target != null) {
        if (!target.isEditable() || !target.isEnabled()) {
            target.getToolkit().beep();
            return;
        }

        EditorUI editorUI = Utilities.getEditorUI(target);
        Caret caret = target.getCaret();
        final BaseDocument doc = Utilities.getDocument(target);

        if(caret instanceof EditorCaret) {
            EditorCaret editorCaret = (EditorCaret) caret;
            if(editorCaret.getCarets().size() > 1) {
                target.getToolkit().beep();
                return;
            }
        }
        
        // Possibly remove selection
        if (Utilities.isSelectionShowing(caret)) {
            target.replaceSelection(null);
        }

        final int caretOffset = caret.getDot();
        final String s = editorUI.getWordMatch().getMatchWord(caretOffset, matchNext);
        final String prevWord = editorUI.getWordMatch().getPreviousWord();
        if (s != null) {
            doc.runAtomicAsUser (new Runnable () {
                public void run () {
                    DocumentUtilities.setTypingModification(doc, true);
                    try {
                        int offset = caretOffset;
                        boolean removePrevWord = (prevWord != null && prevWord.length() > 0);
                        if (removePrevWord) {
                            offset -= prevWord.length();
                        }
                        // Create position due to possible text replication (e.g. for variable renaming)
                        Position pos = doc.createPosition(offset);
                        doc.remove(offset, prevWord.length());
                        doc.insertString(pos.getOffset(), s, null);
                    } catch (BadLocationException e) {
                        target.getToolkit().beep();
                    } finally {
                        DocumentUtilities.setTypingModification(doc, false);
                    }
                }
            });
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:52,代码来源:ActionFactory.java

示例7: delete

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * Deletes the selected text in a text component.
 *
 * @param textComponent
 */
public static void delete(JTextComponent textComponent) {
    textComponent.replaceSelection(EMPTY);
}
 
开发者ID:YcheCourseProject,项目名称:DIA-Umpire-Maven,代码行数:9,代码来源:TextComponentUtil.java


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