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


Java JTextComponent.addCaretListener方法代码示例

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


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

示例1: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public @Override void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        int selectionStartOffset = target.getSelectionStart();
        int selectionEndOffset = target.getSelectionEnd();
        if (selectionEndOffset > selectionStartOffset || selectNext) {
            SelectionHandler handler = (SelectionHandler)target.getClientProperty(SelectionHandler.class);
            if (handler == null) {
                handler = new SelectionHandler(target);
                target.addCaretListener(handler);
                // No need to remove the listener above as the handler
                // is stored is the client-property of the component itself
                target.putClientProperty(SelectionHandler.class, handler);
            }
            
            if (selectNext) { // select next element
                handler.selectNext();
            } else { // select previous
                handler.selectPrevious();
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:SelectCodeElementAction.java

示例2: setEditor

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
protected void setEditor (JTextComponent editor) {
    if (currentEditor != null) {
        currentEditor.removeCaretListener (caretListener);
    }
    currentEditor = editor;
    if (editor != null) {
        if (listensOnSettings.compareAndSet(false,true)) {
            BreadcrumbsController.addBreadCrumbsEnabledListener(new AListener ());
        }
        if (caretListener == null) {
            caretListener = new ACaretListener ();
        }
        editor.addCaretListener (caretListener);
        Document document = editor.getDocument ();
        if (currentDocument == document) return;
        currentDocument = document;
        final Source source = Source.create (currentDocument);
        schedule (source, new CursorMovedSchedulerEvent (this, editor.getCaret ().getDot (), editor.getCaret ().getMark ()) {});
    } else {
        currentDocument = null;
        schedule(null, null);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:24,代码来源:BreadCrumbsScheduler.java

示例3: actionPerformed

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void actionPerformed(ActionEvent evt, JTextComponent target) {
    if (target != null) {
        int selectionStartOffset = target.getSelectionStart();
        int selectionEndOffset = target.getSelectionEnd();
        if (selectionEndOffset > selectionStartOffset || selectNext) {
            SelectionHandler handler = (SelectionHandler)target.getClientProperty(SelectionHandler.class);
            if (handler == null) {
                handler = new SelectionHandler(target, getShortDescription());
                target.addCaretListener(handler);
                // No need to remove the listener above as the handler
                // is stored is the client-property of the component itself
                target.putClientProperty(SelectionHandler.class, handler);
            }

            if (selectNext) { // select next element
                handler.selectNext();
            } else { // select previous
                handler.selectPrevious();
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:23,代码来源:SelectCodeElementAction.java

示例4: setEditor

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
protected void setEditor (JTextComponent editor) {
    if (currentEditor != null)
        currentEditor.removeCaretListener (caretListener);
    currentEditor = editor;
    if (editor != null) {
        if (caretListener == null)
            caretListener = new ACaretListener ();
        editor.addCaretListener (caretListener);
        Document document = editor.getDocument ();
        if (currentDocument == document) return;
        currentDocument = document;
        final Source source = Source.create (currentDocument);
        schedule (source, new CursorMovedSchedulerEvent (this, editor.getCaret ().getDot (), editor.getCaret ().getMark ()) {});
    }
    else {
        currentDocument = null;
        schedule(null, null);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:CursorSensitiveScheduler.java

示例5: updateActiveEditor

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void updateActiveEditor() {
    if (!SwingUtilities.isEventDispatchThread()) {
        SwingUtilities.invokeLater(this);
        return;
    }
    JTextComponent c = findActivePane();
    if (c == null) {
        editorReleased();
        return;
    }
    if (activeEditor != null && activeEditor.get() == c) {
        return;
    }
    editorReleased();
    activeEditor = new WeakReference<>(c);
    wCaretL = WeakListeners.create(CaretListener.class, this, c);
    c.addCaretListener(this);
    selectCurrentNode();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:20,代码来源:NavigatorContent.java

示例6: TextLineNumber

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 *	Create a line number component for a text component.
 *
 *  @param component  the related text component
 *  @param minimumDisplayDigits  the number of digits used to calculate
 *                               the minimum width of the component
 */
public TextLineNumber(JTextComponent component, int minimumDisplayDigits)
{
	this.component = component;

	setBackground(Color.white);
	setForeground(Color.GRAY);
	setCurrentLineForeground( new Color(58,142,186) );
	setBorderGap( 4 );
	setFont(new Font("Arial", Font.PLAIN, 10));
	setDigitAlignment( RIGHT );
	setMinimumDisplayDigits( minimumDisplayDigits );

	component.getDocument().addDocumentListener(this);
	component.addCaretListener( this );
	component.addPropertyChangeListener("font", this);
}
 
开发者ID:BlidiWajdi,项目名称:Mujeed-Arabic-Prolog,代码行数:24,代码来源:TextLineNumber.java

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

示例8: ComponentPeer

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/** Creates a new instance of ComponentPeer */
    private ComponentPeer(JTextComponent pane) {
        this.pane = pane;
//        reschedule();
        pane.addPropertyChangeListener(this);
        pane.addCaretListener(this);
        pane.addAncestorListener(this);
        document = pane.getDocument();
        weakDocL = WeakListeners.document(this, document);
        document.addDocumentListener(weakDocL);

        ancestorAdded(null);
    }
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:14,代码来源:ComponentPeer.java

示例9: editorRegistryChanged

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
private void editorRegistryChanged() {
    final JTextComponent editor = EditorRegistry.lastFocusedComponent();
    final JTextComponent lastEditor = lastEditorRef == null ? null : lastEditorRef.get();
    if (lastEditor != editor && (editor == null || editor.getClientProperty("AsTextField") == null)) {
        if (lastEditor != null) {
            lastEditor.removeCaretListener(this);
            lastEditor.removePropertyChangeListener(this);
            k24.set(false);
        }
        lastEditorRef = new WeakReference<JTextComponent>(editor);
        if (editor != null) {
            editor.addCaretListener(this);
            editor.addPropertyChangeListener(this);
        }
        final JTextComponent focused = EditorRegistry.focusedComponent();
        if (focused != null) {
            final Document doc = editor.getDocument();
            final String mimeType = DocumentUtilities.getMimeType (doc);
            if (doc != null && mimeType != null) {
                final Source source = Source.create (doc);
                if (source != null) {
                    ((EventSupport)SourceEnvironment.forSource(source)).resetState(true, false, -1, -1, true);
                }
            }
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:28,代码来源:EventSupport.java

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

示例11: subscribeActual

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
@Override
protected void subscribeActual(Observer<? super CaretEvent> observer) {
    JTextComponent w = widget;

    CaretEventConsumer aec = new CaretEventConsumer(observer, w);
    observer.onSubscribe(aec);

    w.addCaretListener(aec);
    if (aec.get() == null) {
        aec.onDispose(w);
    }
}
 
开发者ID:akarnokd,项目名称:RxJava2Swing,代码行数:13,代码来源:CaretEventObservable.java

示例12: setEditor

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/**
 * Resets the JTextComponent to <code>editor</code>. This will update
 * the tree accordingly.
 */
public void setEditor(JTextComponent editor) {
    if (this.editor == editor) {
        return;
    }

    if (this.editor != null) {
        Document oldDoc = this.editor.getDocument();

        oldDoc.removeDocumentListener(this);
        this.editor.removePropertyChangeListener(this);
        this.editor.removeCaretListener(this);
    }
    this.editor = editor;
    if (editor == null) {
        treeModel = null;
        tree.setModel(null);
    } else {
        Document newDoc = editor.getDocument();

        newDoc.addDocumentListener(this);
        editor.addPropertyChangeListener(this);
        editor.addCaretListener(this);
        treeModel = new ElementTreeModel(newDoc);
        tree.setModel(treeModel);
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:31,代码来源:ElementTreePanel.java

示例13: addNotificationListeners

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public void addNotificationListeners(Component c) {
    if (c instanceof JTextComponent) {
        JTextComponent tc = (JTextComponent) c;
        AXTextChangeNotifier listener = new AXTextChangeNotifier();
        tc.getDocument().addDocumentListener(listener);
        tc.addCaretListener(listener);
    }
    if (c instanceof JProgressBar) {
        JProgressBar pb = (JProgressBar) c;
        pb.addChangeListener(new AXProgressChangeNotifier());
    } else if (c instanceof JSlider) {
        JSlider slider = (JSlider) c;
        slider.addChangeListener(new AXProgressChangeNotifier());
    }
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:16,代码来源:CAccessible.java

示例14: CaretMarkProvider

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
/** Creates a new instance of AnnotationMarkProvider */
public CaretMarkProvider(JTextComponent component) {
    this.component = component;
    component.addCaretListener(this);
    marks = createMarks();
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:7,代码来源:CaretMarkProvider.java

示例15: BreadcrumbProvider

import javax.swing.text.JTextComponent; //导入方法依赖的package包/类
public BreadcrumbProvider(JTextComponent pane) {
    this.pane = pane;
    pane.addCaretListener(this);
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:5,代码来源:BreadcrumbProvider.java


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