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


Java JTextComponent.select方法代码示例

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


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

示例1: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        try {
            Caret caret = target.getCaret();
            boolean emptySelection = false;
            boolean disableNoSelectionCopy =
                    Boolean.getBoolean("org.netbeans.editor.disable.no.selection.copy");
            int caretPosition = caret.getDot();
            if(!disableNoSelectionCopy &&
                    (!(caret instanceof EditorCaret)) || !(((EditorCaret)caret).getCarets().size() > 1)) {
                emptySelection = !Utilities.isSelectionShowing(target);
                // If there is no selection then pre-select a current line including newline
                if (emptySelection && !disableNoSelectionCopy) {
                    Element elem = ((AbstractDocument) target.getDocument()).getParagraphElement(
                            caretPosition);
                    if (!Utilities.isRowWhite((BaseDocument) target.getDocument(), elem.getStartOffset())) {
                        target.select(elem.getStartOffset(), elem.getEndOffset());
                    }
                }
            }
            target.copy();
            if (emptySelection && !disableNoSelectionCopy) {
                target.setCaretPosition(caretPosition);
            }
        } catch (BadLocationException ble) {
            LOG.log(Level.FINE, null, ble);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:31,代码来源:BaseKit.java

示例2: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        Caret caret = target.getCaret();
        BaseDocument doc = (BaseDocument)target.getDocument();
        int dotPos = caret.getDot();
        int selectStartPos = -1;
        try {
            if (dotPos > 0) {
                if (doc.getChars(dotPos - 1, 1)[0] == ',') { // right after the comma
                    selectStartPos = dotPos;
                }
            }
            if (dotPos < doc.getLength()) {
                char dotChar = doc.getChars(dotPos, 1)[0];
                if (dotChar == ',') {
                    selectStartPos = dotPos + 1;
                } else if (dotChar == ')') {
                    caret.setDot(dotPos + 1);
                }
            }
            if (selectStartPos >= 0) {
                int selectEndPos = doc.find(
                                       new FinderFactory.CharArrayFwdFinder( new char[] { ',', ')' }),
                                       selectStartPos, -1
                                   );
                if (selectEndPos >= 0) {
                    target.select(selectStartPos, selectEndPos);
                }
            }
        } catch (BadLocationException e) {
            target.getToolkit().beep();
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:35,代码来源:ActionFactory.java

示例3: incSearch

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public boolean incSearch(Map<String, Object> props, int caretPos) {
    props = getValidFindProperties(props);
    
    Boolean b = (Boolean)props.get(FIND_INC_SEARCH);
    if (b != null && b.booleanValue()) { // inc search enabled
        JTextComponent comp = getFocusedTextComponent();
        
        if (comp != null) {
            b = (Boolean)props.get(FIND_BACKWARD_SEARCH);
            boolean back = (b != null && b.booleanValue());
            b = (Boolean)props.get(FIND_BLOCK_SEARCH);
            boolean blockSearch = (b != null && b.booleanValue());
            Position blockStartPos = (Position) props.get(FIND_BLOCK_SEARCH_START);
            int blockSearchStartOffset = (blockStartPos != null) ? blockStartPos.getOffset() : -1;
            
            Position endPos = (Position) props.get(FIND_BLOCK_SEARCH_END);
            int blockSearchEndOffset = (endPos != null) ? endPos.getOffset() : -1;
            int pos;
            int len = 0;
            try {
                int start = (blockSearch && blockSearchStartOffset > -1) ? blockSearchStartOffset : 0;
                int end = (blockSearch && blockSearchEndOffset > 0) ? blockSearchEndOffset : -1;
                if (start > 0 && end == -1) {
                    return false;
                }
                int findRet[] = findInBlock(comp, caretPos, 
                    start, 
                    end, 
                    props, false);
                        
                if (findRet == null) {
                    incSearchReset();
                    return false;
                }
                pos = findRet[0];
                len = findRet.length > 1 ? findRet[1] - pos : 0;
            } catch (BadLocationException e) {
                LOG.log(Level.WARNING, e.getMessage(), e);
                return false;
            }
            
            if (pos >= 0) {
                // Find the layer
                BlockHighlighting layer = findLayer(comp, Factory.INC_SEARCH_LAYER);

                if (len > 0) {
                    if (comp.getSelectionEnd() > comp.getSelectionStart()){
                        comp.select(caretPos, caretPos);
                    }
                    
                    if (layer != null) {
                        layer.highlightBlock(
                            pos,
                            pos + len,
                            blockSearch ? FontColorNames.INC_SEARCH_COLORING : FontColorNames.SELECTION_COLORING,
                            false,
                            false
                        );
                    }
                    Preferences prefs = MimeLookup.getLookup(MimePath.EMPTY).lookup(Preferences.class);
                    if (prefs.get(SimpleValueNames.EDITOR_SEARCH_TYPE, "default").equals("closing")) { // NOI18N
                        ensureVisible(comp, pos, pos);
                    } else {
                        selectText(comp, pos, pos + len, back);
                    }
                    return true;
                }
            }
           
        }
    } else { // inc search not enabled
        incSearchReset();
    }
    return false;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:76,代码来源:EditorFindSupport.java

示例4: InstantRenamePerformer

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/** Creates a new instance of InstantRenamePerformer */
   private InstantRenamePerformer(JTextComponent target, Set<OffsetRange> highlights, int caretOffset) throws BadLocationException {
this.target = target;
doc = target.getDocument();

MutablePositionRegion mainRegion = null;
List<MutablePositionRegion> regions = new ArrayList<MutablePositionRegion>();

for (OffsetRange h : highlights) {
    Position start = NbDocument.createPosition(doc, h.getStart(), Bias.Backward);
    Position end = NbDocument.createPosition(doc, h.getEnd(), Bias.Forward);
    MutablePositionRegion current = new MutablePositionRegion(start, end);
    
    if (isIn(current, caretOffset)) {
           mainRegion = current;
    } else {
           regions.add(current);
    }
}

if (mainRegion == null) {
       Logger.getLogger(InstantRenamePerformer.class.getName()).warning("No highlight contains the caret (" + caretOffset + "; highlights=" + highlights + ")"); //NOI18N
       // Attempt to use another region - pick the one closest to the caret
       if (regions.size() > 0) {
           mainRegion = regions.get(0);
           int mainDistance = Integer.MAX_VALUE;
           for (MutablePositionRegion r : regions) {
               int distance = caretOffset < r.getStartOffset() ? (r.getStartOffset()-caretOffset) : (caretOffset-r.getEndOffset());
               if (distance < mainDistance) {
                   mainRegion = r;
                   mainDistance = distance;
               }
           }
       } else {
           return;
       }
}

regions.add(0, mainRegion);

region = new SyncDocumentRegion(doc, regions);

       if (doc instanceof BaseDocument) {
           ((BaseDocument) doc).addPostModificationDocumentListener(this);
       }
       
target.addKeyListener(this);

       target.putClientProperty("NetBeansEditor.navigateBoundaries", mainRegion); // NOI18N
target.putClientProperty(InstantRenamePerformer.class, this);

requestRepaint();
       
       target.select(mainRegion.getStartOffset(), mainRegion.getEndOffset());
   }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:56,代码来源:InstantRenamePerformer.java

示例5: InstantRefactoringPerformer

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public InstantRefactoringPerformer(final JTextComponent target, int caretOffset, InstantRefactoringUI ui) {
    releaseAll();
    this.target = target;
    this.ui = ui;
    doc = target.getDocument();

    MutablePositionRegion mainRegion = null;
    List<MutablePositionRegion> regions = new ArrayList<>(ui.getRegions().size());

    for (MutablePositionRegion current : ui.getRegions()) {
        // TODO: type parameter name is represented as ident -> ignore surrounding <> in rename
        if (isIn(current, caretOffset)) {
            mainRegion = current;
        } else {
            regions.add(current);
        }
    }

    if (mainRegion == null) {
        throw new IllegalArgumentException("No highlight contains the caret.");
    }

    regions.add(0, mainRegion);

    region = new SyncDocumentRegion(doc, regions);

    if (doc instanceof BaseDocument) {
        BaseDocument bdoc = ((BaseDocument) doc);
        bdoc.addPostModificationDocumentListener(this);
        
        UndoableWrapper wrapper = MimeLookup.getLookup("text/x-java").lookup(UndoableWrapper.class);
        if(wrapper != null) {
            wrapper.setActive(true, this);
        }

        UndoableEdit undo = new CancelInstantRenameUndoableEdit(this);
        for (UndoableEditListener l : bdoc.getUndoableEditListeners()) {
            l.undoableEditHappened(new UndoableEditEvent(doc, undo));
        }
    }

    target.addKeyListener(this);

    target.putClientProperty(InstantRefactoringPerformer.class, this);
    target.putClientProperty("NetBeansEditor.navigateBoundaries", mainRegion); // NOI18N
	
    requestRepaint();
    
    target.select(mainRegion.getStartOffset(), mainRegion.getEndOffset());
    
    span = region.getFirstRegionLength();
    compl = new CompletionLayout(this);
    compl.setEditorComponent(target);
    final KeyStroke OKKS = ui.getKeyStroke();
    target.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(OKKS, OKActionKey);
    Action OKAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            if(registry.contains(InstantRefactoringPerformer.this)) {
                doFullRefactoring();
                target.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).remove(OKKS);
                target.getActionMap().remove(OKActionKey);
            } else {
                target.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).remove(OKKS);
                target.getActionMap().remove(OKActionKey);
            }
        }
    };
    target.getActionMap().put(OKActionKey, OKAction);
    final KeyStroke keyStroke = ui.getKeyStroke();
    compl.showCompletion(ui.getOptions(), caretOffset, Bundle.INFO_PressAgain(getKeyStrokeAsText(keyStroke)));
    
    registry.add(this);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:75,代码来源:InstantRefactoringPerformer.java

示例6: InstantRenamePerformer

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/** Creates a new instance of InstantRenamePerformer */
private InstantRenamePerformer(JTextComponent target, Set<Token> highlights, int caretOffset) throws BadLocationException {
    this.target = target;
    doc = target.getDocument();

    MutablePositionRegion mainRegion = null;
    List<MutablePositionRegion> regions = new ArrayList<MutablePositionRegion>();

    for (Token h : highlights) {
        // type parameter name is represented as ident -> ignore surrounding <> in rename
        int delta = h.id() == JavadocTokenId.IDENT && h.text().charAt(0) == '<' && h.text().charAt(h.length() - 1) == '>' ? 1 : 0;
        Position start = NbDocument.createPosition(doc, h.offset(null) + delta, Bias.Backward);
        Position end = NbDocument.createPosition(doc, h.offset(null) + h.length() - delta, Bias.Forward);
        MutablePositionRegion current = new MutablePositionRegion(start, end);
        
        if (isIn(current, caretOffset)) {
            mainRegion = current;
        } else {
            regions.add(current);
        }
    }

    if (mainRegion == null) {
        throw new IllegalArgumentException("No highlight contains the caret.");
    }

    regions.add(0, mainRegion);

    region = new SyncDocumentRegion(doc, regions);

    if (doc instanceof BaseDocument) {
        BaseDocument bdoc = ((BaseDocument) doc);
        bdoc.setPostModificationDocumentListener(this);

        UndoableEdit undo = new CancelInstantRenameUndoableEdit(this);
        for (UndoableEditListener l : bdoc.getUndoableEditListeners()) {
            l.undoableEditHappened(new UndoableEditEvent(doc, undo));
        }
    }

    target.addKeyListener(this);

    target.putClientProperty(InstantRenamePerformer.class, this);
    target.putClientProperty("NetBeansEditor.navigateBoundaries", mainRegion); // NOI18N
	
    requestRepaint();
    
    target.select(mainRegion.getStartOffset(), mainRegion.getEndOffset());
    
    span = region.getFirstRegionLength();
    
    registry.add(this);
    sendUndoableEdit(doc, CloneableEditorSupport.BEGIN_COMMIT_GROUP);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:55,代码来源:InstantRenamePerformer.java


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