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


Java JTextComponent.addKeyListener方法代码示例

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


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

示例1: RenameImplementation

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
RenameImplementation (
    DatabaseItem        databaseItem,
    JTextComponent      editor,
    ASTNode             node
) throws BadLocationException {
    this.editor = editor;
    document = (NbEditorDocument) editor.getDocument ();
    elements = getUssages (databaseItem, node);
    MarkOccurrencesSupport.removeHighlights (editor);
    if (!elements.isEmpty ()) {
        SwingUtilities.invokeLater (new Runnable () {
            public void run () {
                highlights = new ArrayList<Highlight> ();
                Highlighting highlighting = Highlighting.getHighlighting (document);
                Iterator<Element> it = elements.iterator ();
                while (it.hasNext ()) {
                    Element element = it.next ();
                    ASTItem item = element.getItem ();
                    highlights.add (highlighting.highlight (item.getOffset (), item.getEndOffset (), getHighlightAS ()));
                }
            }
        });
    }
    document.addDocumentListener (this);
    editor.addKeyListener (this);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:27,代码来源:InstantRenameAction.java

示例2: register

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void register() {
    JTextComponent comp = getComponent(); 
    if (comp == null) {
        return;
    }
    comp.addKeyListener (this);
    comp.addCaretListener(this);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:HintsUI.java

示例3: PopupManager

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/** Creates a new instance of PopupManager */
public PopupManager(JTextComponent textComponent) {
    this.textComponent = textComponent;
    keyListener = new PopupKeyListener();
    textComponent.addKeyListener(keyListener);
    componentListener = new TextComponentListener();
    textComponent.addComponentListener(componentListener);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:PopupManager.java

示例4: setEditorComponent

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
public void setEditorComponent(JTextComponent comp) {
    JTextComponent thisComp = getEditorComponent();
    boolean change = thisComp != comp;
    if (thisComp != null && change) {
        thisComp.removeKeyListener(getChKeyListener());
    }
    super.setEditorComponent(comp);
    if (comp != null && change) {
        comp.addKeyListener(getChKeyListener());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:13,代码来源:CompletionLayoutPopup.java

示例5: AbbrevDetection

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private AbbrevDetection(JTextComponent component) {
    this.component = component;
    component.addCaretListener(this);
    doc = component.getDocument();
    if (doc != null) {
        listenOnDoc();
    }

    String mimeType = DocumentUtilities.getMimeType(component);
    if (mimeType != null) {
        mimePath = MimePath.parse(mimeType);
        prefs = MimeLookup.getLookup(mimePath).lookup(Preferences.class);
        prefs.addPreferenceChangeListener(WeakListeners.create(PreferenceChangeListener.class, this, prefs));
    }
    
    // Load the settings
    preferenceChange(null);
    
    component.addKeyListener(this);
    component.addPropertyChangeListener(this);
    
    surroundsWithTimer = new Timer(0, new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // #124515, give up when the document is locked otherwise we are likely
            // to cause a deadlock.
            if (!DocumentUtilities.isReadLocked(doc)) {
                showSurroundWithHint();
            }
        }
    });
    surroundsWithTimer.setRepeats(false);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:33,代码来源:AbbrevDetection.java

示例6: 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

示例7: 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

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