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


Java Utilities.isSelectionShowing方法代码示例

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


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

示例1: mouseReleased

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
public @Override void mouseReleased(MouseEvent evt) {
    lastMouseEvent = evt;
    setToolTipVisible(false);

    // Check that if a selection becomes visible by dragging a mouse
    // the tooltip evaluation should be posted.
    EditorUI ui = extEditorUI;
    if (ui != null) {
        JTextComponent component = ui.getComponent();
        if (enabled && component != null && Utilities.isSelectionShowing(component)) {
            enterTimer.restart();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:15,代码来源:ToolTipSupport.java

示例2: actionPerformed

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        Caret caret = target.getCaret();
        if (Utilities.isSelectionShowing(caret)) {
            EditorFindSupport findSupport = EditorFindSupport.getInstance();
            HashMap<String, Object> props = new HashMap<>(findSupport.createDefaultFindProperties());
            String searchWord = target.getSelectedText();
            int n = searchWord.indexOf('\n');
            if (n >= 0) {
                searchWord = searchWord.substring(0, n);
            }
            props.put(EditorFindSupport.FIND_WHAT, searchWord);
            props.put(EditorFindSupport.ADD_MULTICARET, Boolean.TRUE);
            EditorUI eui = org.netbeans.editor.Utilities.getEditorUI(target);
            if (eui.getComponent().getClientProperty("AsTextField") == null) { //NOI18N
                findSupport.setFocusedTextComponent(eui.getComponent());
            }
            findSupport.putFindProperties(props);
            findSupport.find(null, false);
            props.put(EditorFindSupport.ADD_MULTICARET, Boolean.FALSE);
            findSupport.putFindProperties(props);
        } else {
            try {
                int[] identifierBlock = Utilities.getIdentifierBlock((BaseDocument) target.getDocument(), caret.getDot());
                if (identifierBlock != null) {
                    caret.setDot(identifierBlock[0]);
                    caret.moveDot(identifierBlock[1]);
                }
            } catch (BadLocationException e) {
                LOGGER.log(Level.WARNING, null, e);
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:37,代码来源:AddCaretSelectNextAction.java

示例3: actionPerformed

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        EditorFindSupport findSupport = EditorFindSupport.getInstance();
        Caret caret = target.getCaret();
        int dotPos = caret.getDot();
        HashMap<String, Object> props = new HashMap<>(findSupport.createDefaultFindProperties());
        String searchWord = null;
        boolean revert = false;
        Boolean originalValue = null;
        Map<String, Object> revertMap = (Map<String, Object>) props.get(EditorFindSupport.REVERT_MAP);
        Boolean revertValue = revertMap != null ? (Boolean) revertMap.get(EditorFindSupport.FIND_WHOLE_WORDS) : null;
        if (Utilities.isSelectionShowing(caret)) {
            // valid selection
            searchWord = target.getSelectedText();
            originalValue = (Boolean) props.put(EditorFindSupport.FIND_WHOLE_WORDS, Boolean.FALSE);
            if (Boolean.FALSE.equals(revertValue)) {
                revertMap.remove(EditorFindSupport.FIND_WHOLE_WORDS);
            } else {
                revert = !Boolean.FALSE.equals(originalValue);
            }
        } else {
            // no selection, get current word
            try {
                searchWord = Utilities.getIdentifier((BaseDocument) target.getDocument(), dotPos);
                originalValue = (Boolean) props.put(EditorFindSupport.FIND_WHOLE_WORDS, Boolean.TRUE);
                if (Boolean.TRUE.equals(revertValue)) {
                    revertMap.remove(EditorFindSupport.FIND_WHOLE_WORDS);
                } else {
                    revert = !Boolean.TRUE.equals(originalValue);
                }
            } catch (BadLocationException e) {
                LOGGER.log(Level.WARNING, null, e);
            }
        }
        if (searchWord != null) {
            int n = searchWord.indexOf('\n');
            if (n >= 0) {
                searchWord = searchWord.substring(0, n);
            }
            props.put(EditorFindSupport.FIND_WHAT, searchWord);
            if (revert) {
                revertMap = new HashMap<>();
                revertMap.put(EditorFindSupport.FIND_WHOLE_WORDS, originalValue != null ? originalValue : Boolean.FALSE);
                props.put(EditorFindSupport.REVERT_MAP, revertMap);
            }
            props.put(EditorFindSupport.FIND_BLOCK_SEARCH, Boolean.FALSE);
            props.put(EditorFindSupport.FIND_BLOCK_SEARCH_START, null);
            props.put(EditorFindSupport.FIND_BLOCK_SEARCH_END, null);
            EditorUI eui = org.netbeans.editor.Utilities.getEditorUI(target);
            if (eui.getComponent().getClientProperty("AsTextField") == null) {
                //NOI18N
                findSupport.setFocusedTextComponent(eui.getComponent());
            }
            findSupport.putFindProperties(props);
            if (findSupport.find(null, false)) {
                findSupport.addToHistory(new EditorFindSupport.SPW((String) props.get(EditorFindSupport.FIND_WHAT), (Boolean) props.get(EditorFindSupport.FIND_WHOLE_WORDS), (Boolean) props.get(EditorFindSupport.FIND_MATCH_CASE), (Boolean) props.get(EditorFindSupport.FIND_REG_EXP)));
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:63,代码来源:FindSelectionAction.java

示例4: actionPerformed

import org.netbeans.editor.Utilities; //导入方法依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        Caret caret = target.getCaret();
        if (!Utilities.isSelectionShowing(caret)) {
            try {
                int[] identifierBlock = Utilities.getIdentifierBlock((BaseDocument) target.getDocument(), caret.getDot());
                if (identifierBlock != null) {
                    caret.setDot(identifierBlock[0]);
                    caret.moveDot(identifierBlock[1]);
                }
            } catch (BadLocationException e) {
                LOGGER.log(Level.WARNING, null, e);
            }
        }

        EditorFindSupport findSupport = EditorFindSupport.getInstance();
        HashMap<String, Object> props = new HashMap<>(findSupport.createDefaultFindProperties());
        String searchWord = target.getSelectedText();
        if (searchWord != null) {
            int n = searchWord.indexOf('\n');
            if (n >= 0) {
                searchWord = searchWord.substring(0, n);
            }
            props.put(EditorFindSupport.FIND_WHAT, searchWord);
            Document doc = target.getDocument();
            EditorUI eui = org.netbeans.editor.Utilities.getEditorUI(target);
            if (eui.getComponent().getClientProperty("AsTextField") == null) { //NOI18N
                findSupport.setFocusedTextComponent(eui.getComponent());
            }
            findSupport.putFindProperties(props);
            findSupport.find(null, false);

            if (caret instanceof EditorCaret) {
                EditorCaret editorCaret = (EditorCaret) caret;
                try {
                    int[] blocks = findSupport.getBlocks(new int[]{-1, -1}, doc, 0, doc.getLength());
                    if (blocks[0] >= 0 && blocks.length % 2 == 0) {
                        List<Position> newCarets = new ArrayList<>();

                        for (int i = 0; i < blocks.length; i += 2) {
                            int start = blocks[i];
                            int end = blocks[i + 1];
                            if (start == -1 || end == -1) {
                                break;
                            }
                            Position startPos = doc.createPosition(start);
                            Position endPos = doc.createPosition(end);
                            newCarets.add(endPos);
                            newCarets.add(startPos);
                        }

                        editorCaret.replaceCarets(newCarets, null); // TODO handle biases
                    }
                } catch (BadLocationException ex) {
                    Exceptions.printStackTrace(ex);
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:63,代码来源:AddCaretSelectAllAction.java


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