javax.swing.text.Document#addDocumentListener ( )源码实例Demo

下面列出了javax.swing.text.Document#addDocumentListener ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: openjdk-8   文件: LWTextAreaPeer.java
@Override
public void replaceRange(final String text, final int start,
                         final int end) {
    synchronized (getDelegateLock()) {
        // JTextArea.replaceRange() posts two different events.
        // Since we make no differences between text events,
        // the document listener has to be disabled while
        // JTextArea.replaceRange() is called.
        final Document document = getTextComponent().getDocument();
        document.removeDocumentListener(this);
        getDelegate().getView().replaceRange(text, start, end);
        revalidate();
        postEvent(new TextEvent(getTarget(), TextEvent.TEXT_VALUE_CHANGED));
        document.addDocumentListener(this);
    }
    repaintPeer();
}
 
源代码2 项目: dragonwell8_jdk   文件: ElementTreePanel.java
/**
 * Invoked when a property changes. We are only interested in when the
 * Document changes to reset the DocumentListener.
 */
public void propertyChange(PropertyChangeEvent e) {
    if (e.getSource() == getEditor() && e.getPropertyName().equals(
            "document")) {
        Document oldDoc = (Document) e.getOldValue();
        Document newDoc = (Document) e.getNewValue();

        // Reset the DocumentListener
        oldDoc.removeDocumentListener(this);
        newDoc.addDocumentListener(this);

        // Recreate the TreeModel.
        treeModel = new ElementTreeModel(newDoc);
        tree.setModel(treeModel);
    }
}
 
源代码3 项目: openjdk-jdk8u   文件: LWTextComponentPeer.java
@Override
public final void setText(final String text) {
    synchronized (getDelegateLock()) {
        // JTextArea.setText() posts two different events (remove & insert).
        // Since we make no differences between text events,
        // the document listener has to be disabled while
        // JTextArea.setText() is called.
        final Document document = getTextComponent().getDocument();
        document.removeDocumentListener(this);
        getTextComponent().setText(text);
        revalidate();
        if (firstChangeSkipped) {
            postEvent(new TextEvent(getTarget(),
                                    TextEvent.TEXT_VALUE_CHANGED));
        }
        document.addDocumentListener(this);
    }
    repaintPeer();
}
 
源代码4 项目: hottub   文件: ElementTreePanel.java
/**
 * Invoked when a property changes. We are only interested in when the
 * Document changes to reset the DocumentListener.
 */
public void propertyChange(PropertyChangeEvent e) {
    if (e.getSource() == getEditor() && e.getPropertyName().equals(
            "document")) {
        Document oldDoc = (Document) e.getOldValue();
        Document newDoc = (Document) e.getNewValue();

        // Reset the DocumentListener
        oldDoc.removeDocumentListener(this);
        newDoc.addDocumentListener(this);

        // Recreate the TreeModel.
        treeModel = new ElementTreeModel(newDoc);
        tree.setModel(treeModel);
    }
}
 
源代码5 项目: openjdk-jdk9   文件: ElementTreePanel.java
/**
 * Invoked when a property changes. We are only interested in when the
 * Document changes to reset the DocumentListener.
 */
public void propertyChange(PropertyChangeEvent e) {
    if (e.getSource() == getEditor() && e.getPropertyName().equals(
            "document")) {
        Document oldDoc = (Document) e.getOldValue();
        Document newDoc = (Document) e.getNewValue();

        // Reset the DocumentListener
        oldDoc.removeDocumentListener(this);
        newDoc.addDocumentListener(this);

        // Recreate the TreeModel.
        treeModel = new ElementTreeModel(newDoc);
        tree.setModel(treeModel);
    }
}
 
源代码6 项目: TencentKona-8   文件: LWTextComponentPeer.java
@Override
public final void setText(final String text) {
    synchronized (getDelegateLock()) {
        // JTextArea.setText() posts two different events (remove & insert).
        // Since we make no differences between text events,
        // the document listener has to be disabled while
        // JTextArea.setText() is called.
        final Document document = getTextComponent().getDocument();
        document.removeDocumentListener(this);
        getTextComponent().setText(text);
        revalidate();
        if (firstChangeSkipped) {
            postEvent(new TextEvent(getTarget(),
                                    TextEvent.TEXT_VALUE_CHANGED));
        }
        document.addDocumentListener(this);
    }
    repaintPeer();
}
 
源代码7 项目: netbeans   文件: WeakPositions.java
/**
 * Gets a <code>Position</code> in the document at the given offset. The 
 * position is automatically updated when the document's contents is modified.
 * The <code>Position</code> does not reference the document in anyway that
 * would prevent the document from being garbage collected.
 * 
 * @param doc The document to get a position in.
 * @param offset The initial offset of the position.
 * 
 * @return A <code>Position</code> inside the document.
 * @throws BadLocationException If the offset is not valid for the document.
 */
public static Position get(Document doc, int offset) throws BadLocationException {
    // Check that the offset is valid. This should excercise any rule imposed by
    // the document on its positions.
    doc.createPosition(offset);
    
    synchronized (OGLS) {
        OffsetGapList<WeakP> ogl = OGLS.get(doc);

        if (ogl == null) {
            ogl = new OffsetGapList<WeakPositions.WeakP>();
            OGLS.put(doc, ogl);
            doc.addDocumentListener(WeakListeners.document(documentsTracker, doc));
        }
        
        int index = ogl.findElementIndex(offset);
        WeakP pos = index >= 0 ? ogl.get(index) : null;

        if (pos == null) {
            pos = new WeakP(offset);
            ogl.add(pos);
        }
        
        return pos;
    }
}
 
源代码8 项目: jdk8u-dev-jdk   文件: LWTextAreaPeer.java
@Override
public void replaceRange(final String text, final int start,
                         final int end) {
    synchronized (getDelegateLock()) {
        // JTextArea.replaceRange() posts two different events.
        // Since we make no differences between text events,
        // the document listener has to be disabled while
        // JTextArea.replaceRange() is called.
        final Document document = getTextComponent().getDocument();
        document.removeDocumentListener(this);
        getDelegate().getView().replaceRange(text, start, end);
        revalidate();
        postEvent(new TextEvent(getTarget(), TextEvent.TEXT_VALUE_CHANGED));
        document.addDocumentListener(this);
    }
    repaintPeer();
}
 
源代码9 项目: jdk8u60   文件: LWTextComponentPeer.java
@Override
public final void setText(final String text) {
    synchronized (getDelegateLock()) {
        // JTextArea.setText() posts two different events (remove & insert).
        // Since we make no differences between text events,
        // the document listener has to be disabled while
        // JTextArea.setText() is called.
        final Document document = getTextComponent().getDocument();
        document.removeDocumentListener(this);
        getTextComponent().setText(text);
        revalidate();
        if (firstChangeSkipped) {
            postEvent(new TextEvent(getTarget(),
                                    TextEvent.TEXT_VALUE_CHANGED));
        }
        document.addDocumentListener(this);
    }
    repaintPeer();
}
 
源代码10 项目: openjdk-jdk8u-backup   文件: LWTextComponentPeer.java
@Override
public final void setText(final String text) {
    synchronized (getDelegateLock()) {
        // JTextArea.setText() posts two different events (remove & insert).
        // Since we make no differences between text events,
        // the document listener has to be disabled while
        // JTextArea.setText() is called.
        final Document document = getTextComponent().getDocument();
        document.removeDocumentListener(this);
        getTextComponent().setText(text);
        revalidate();
        if (firstChangeSkipped) {
            postEvent(new TextEvent(getTarget(),
                                    TextEvent.TEXT_VALUE_CHANGED));
        }
        document.addDocumentListener(this);
    }
    repaintPeer();
}
 
源代码11 项目: jdk8u_jdk   文件: ElementTreePanel.java
/**
 * 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);
    }
}
 
源代码12 项目: pumpernickel   文件: FixedWidthTextArea.java
@Override
public void setDocument(Document d) {
	Document oldDocument = getDocument();
	if (oldDocument != null)
		oldDocument.removeDocumentListener(docListener);
	super.setDocument(d);
	d.addDocumentListener(docListener);
	cachedSize = null;
}
 
源代码13 项目: openjdk-8   文件: ElementTreePanel.java
/**
 * 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);
    }
}
 
源代码14 项目: blog   文件: JLabelTextComponent.java
public final void setDocument(Document document) {
	if (this.document != null) {
		this.document.removeDocumentListener(documentListenerAdapter);
	}
	this.document = document;
	if (document != null) {
		document.addDocumentListener(documentListenerAdapter);
	}
}
 
源代码15 项目: jdk8u-jdk   文件: ElementTreePanel.java
/**
 * 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);
    }
}
 
源代码16 项目: openjdk-jdk8u-backup   文件: ElementTreePanel.java
/**
 * 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);
    }
}
 
源代码17 项目: netbeans   文件: FileSearchAction.java
FileDescriptorConvertor(@NonNull final Document doc) {
    doc.addDocumentListener(this);
}
 
源代码18 项目: beast-mcmc   文件: WholeNumberField.java
protected Document createDefaultModel() {
    Document doc = new WholeNumberFieldDocument();
    doc.addDocumentListener(this);
    return doc;
}
 
源代码19 项目: beast-mcmc   文件: RealNumberField.java
protected Document createDefaultModel() {
    Document doc = new RealNumberField.RealNumberFieldDocument();
    doc.addDocumentListener(this);
    return doc;
}
 
源代码20 项目: netbeans   文件: DocumentUtilities.java
/**
 * Add document listener to document with given priority
 * or default to using regular {@link Document#addDocumentListener(DocumentListener)}
 * if the given document is not listener priority aware.
 * 
 * @param doc document to which the listener should be added.
 * @param listener document listener to add.
 * @param priority priority with which the listener should be added.
 *  If the document does not support document listeners ordering
 *  then the listener is added in a regular way by using
 *  {@link javax.swing.text.Document#addDocumentListener(
 *  javax.swing.event.DocumentListener)} method.
 */
public static void addDocumentListener(Document doc, DocumentListener listener,
DocumentListenerPriority priority) {
    if (!addPriorityDocumentListener(doc, listener, priority))
        doc.addDocumentListener(listener);
}