javax.swing.text.JTextComponent#addPropertyChangeListener ( )源码实例Demo

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

源代码1 项目: netbeans   文件: AnnotationView.java
/** Creates a new instance of AnnotationViewBorder */
public AnnotationView(JTextComponent pane/*, List/ *<MarkProviderCreator>* / creators*/) {
    this.pane = pane;
    // Set the name to be able to check for this component when "errorStripeOnly" property
    // is turned on for the pane in CustomizableSideBar.
    setName("errorStripe");
    
    repaintTask = WORKER.create(repaintTaskRunnable = new RepaintTask());
    this.data = new AnnotationViewDataImpl(this, pane);
    this.scrollBar = UIManager.getInsets("Nb.Editor.ErrorStripe.ScrollBar.Insets"); // NOI18N

    FoldHierarchy fh = FoldHierarchy.get(pane);
    fh.addFoldHierarchyListener(WeakListeners.create(FoldHierarchyListener.class, this, fh));
    pane.addPropertyChangeListener(WeakListeners.propertyChange(this, pane));

    updateForNewDocument();
    
    addMouseListener(this);
    addMouseMotionListener(this);
    
    setOpaque(true);
    
    setToolTipText(NbBundle.getMessage(AnnotationView.class,"TP_ErrorStripe"));
}
 
源代码2 项目: openjdk-8-source   文件: 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);
    }
}
 
源代码3 项目: 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);
    }
}
 
源代码4 项目: 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);
    }
}
 
源代码5 项目: netbeans   文件: HyperlinkOperation.java
/** Creates a new instance of HoveringImpl */
private HyperlinkOperation(JTextComponent component, String mimeType) {
    this.component = component;
    this.operationMimeType  = mimeType;
    this.oldComponentsMouseCursor = null;
    this.hyperlinkUp = false;
    this.listenersSetUp = false;
    
    readSettings();
    
    if (hyperlinkEnabled) {
        component.addPropertyChangeListener("document", this); // NOI18N
    }
}
 
源代码6 项目: netbeans   文件: ComponentPeer.java
/** 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);
    }
 
源代码7 项目: netbeans   文件: MarkOccurrences.java
public MarkOccurrences(JTextComponent component) {
    this.component = component;
    component.addCaretListener(this);
    component.addPropertyChangeListener(this);
    doc = component.getDocument();
    caretPos = component.getCaretPosition();
}
 
源代码8 项目: dragonwell8_jdk   文件: ElementTreePanel.java
@SuppressWarnings("LeakingThisInConstructor")
public ElementTreePanel(JTextComponent editor) {
    this.editor = editor;

    Document document = editor.getDocument();

    // Create the tree.
    treeModel = new ElementTreeModel(document);
    tree = new JTree(treeModel) {

        @Override
        public String convertValueToText(Object value, boolean selected,
                boolean expanded, boolean leaf,
                int row, boolean hasFocus) {
            // Should only happen for the root
            if (!(value instanceof Element)) {
                return value.toString();
            }

            Element e = (Element) value;
            AttributeSet as = e.getAttributes().copyAttributes();
            String asString;

            if (as != null) {
                StringBuilder retBuffer = new StringBuilder("[");
                Enumeration names = as.getAttributeNames();

                while (names.hasMoreElements()) {
                    Object nextName = names.nextElement();

                    if (nextName != StyleConstants.ResolveAttribute) {
                        retBuffer.append(" ");
                        retBuffer.append(nextName);
                        retBuffer.append("=");
                        retBuffer.append(as.getAttribute(nextName));
                    }
                }
                retBuffer.append(" ]");
                asString = retBuffer.toString();
            } else {
                asString = "[ ]";
            }

            if (e.isLeaf()) {
                return e.getName() + " [" + e.getStartOffset() + ", " + e.
                        getEndOffset() + "] Attributes: " + asString;
            }
            return e.getName() + " [" + e.getStartOffset() + ", " + e.
                    getEndOffset() + "] Attributes: " + asString;
        }
    };
    tree.addTreeSelectionListener(this);
    tree.setDragEnabled(true);
    // Don't show the root, it is fake.
    tree.setRootVisible(false);
    // Since the display value of every node after the insertion point
    // changes every time the text changes and we don't generate a change
    // event for all those nodes the display value can become off.
    // This can be seen as '...' instead of the complete string value.
    // This is a temporary workaround, increase the needed size by 15,
    // hoping that will be enough.
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Dimension getPreferredSize() {
            Dimension retValue = super.getPreferredSize();
            if (retValue != null) {
                retValue.width += 15;
            }
            return retValue;
        }
    });
    // become a listener on the document to update the tree.
    document.addDocumentListener(this);

    // become a PropertyChangeListener to know when the Document has
    // changed.
    editor.addPropertyChangeListener(this);

    // Become a CaretListener
    editor.addCaretListener(this);

    // configure the panel and frame containing it.
    setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);

    // Add a label above tree to describe what is being shown
    JLabel label = new JLabel("Elements that make up the current document",
            SwingConstants.CENTER);

    label.setFont(new Font("Dialog", Font.BOLD, 14));
    add(label, BorderLayout.NORTH);

    setPreferredSize(new Dimension(400, 400));
}
 
源代码9 项目: openjdk-jdk9   文件: AquaTextFieldSearch.java
protected static void installSearchFieldListener(final JTextComponent c) {
    c.addPropertyChangeListener(SEARCH_FIELD_PROPERTY_LISTENER);
}
 
源代码10 项目: openjdk-jdk9   文件: ElementTreePanel.java
@SuppressWarnings("LeakingThisInConstructor")
public ElementTreePanel(JTextComponent editor) {
    this.editor = editor;

    Document document = editor.getDocument();

    // Create the tree.
    treeModel = new ElementTreeModel(document);
    tree = new JTree(treeModel) {

        @Override
        public String convertValueToText(Object value, boolean selected,
                boolean expanded, boolean leaf,
                int row, boolean hasFocus) {
            // Should only happen for the root
            if (!(value instanceof Element)) {
                return value.toString();
            }

            Element e = (Element) value;
            AttributeSet as = e.getAttributes().copyAttributes();
            String asString;

            if (as != null) {
                StringBuilder retBuffer = new StringBuilder("[");
                Enumeration names = as.getAttributeNames();

                while (names.hasMoreElements()) {
                    Object nextName = names.nextElement();

                    if (nextName != StyleConstants.ResolveAttribute) {
                        retBuffer.append(" ");
                        retBuffer.append(nextName);
                        retBuffer.append("=");
                        retBuffer.append(as.getAttribute(nextName));
                    }
                }
                retBuffer.append(" ]");
                asString = retBuffer.toString();
            } else {
                asString = "[ ]";
            }

            if (e.isLeaf()) {
                return e.getName() + " [" + e.getStartOffset() + ", " + e.
                        getEndOffset() + "] Attributes: " + asString;
            }
            return e.getName() + " [" + e.getStartOffset() + ", " + e.
                    getEndOffset() + "] Attributes: " + asString;
        }
    };
    tree.addTreeSelectionListener(this);
    tree.setDragEnabled(true);
    // Don't show the root, it is fake.
    tree.setRootVisible(false);
    // Since the display value of every node after the insertion point
    // changes every time the text changes and we don't generate a change
    // event for all those nodes the display value can become off.
    // This can be seen as '...' instead of the complete string value.
    // This is a temporary workaround, increase the needed size by 15,
    // hoping that will be enough.
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Dimension getPreferredSize() {
            Dimension retValue = super.getPreferredSize();
            if (retValue != null) {
                retValue.width += 15;
            }
            return retValue;
        }
    });
    // become a listener on the document to update the tree.
    document.addDocumentListener(this);

    // become a PropertyChangeListener to know when the Document has
    // changed.
    editor.addPropertyChangeListener(this);

    // Become a CaretListener
    editor.addCaretListener(this);

    // configure the panel and frame containing it.
    setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);

    // Add a label above tree to describe what is being shown
    JLabel label = new JLabel("Elements that make up the current document",
            SwingConstants.CENTER);

    label.setFont(new Font("Dialog", Font.BOLD, 14));
    add(label, BorderLayout.NORTH);

    setPreferredSize(new Dimension(400, 400));
}
 
源代码11 项目: TencentKona-8   文件: AquaTextFieldSearch.java
protected static void installSearchFieldListener(final JTextComponent c) {
    c.addPropertyChangeListener(SEARCH_FIELD_PROPERTY_LISTENER);
}
 
源代码12 项目: jdk8u-dev-jdk   文件: AquaTextFieldSearch.java
protected static void installSearchFieldListener(final JTextComponent c) {
    c.addPropertyChangeListener(SEARCH_FIELD_PROPERTY_LISTENER);
}
 
源代码13 项目: jdk8u60   文件: AquaTextFieldSearch.java
protected static void installSearchFieldListener(final JTextComponent c) {
    c.addPropertyChangeListener(SEARCH_FIELD_PROPERTY_LISTENER);
}
 
源代码14 项目: openjdk-jdk8u   文件: ElementTreePanel.java
@SuppressWarnings("LeakingThisInConstructor")
public ElementTreePanel(JTextComponent editor) {
    this.editor = editor;

    Document document = editor.getDocument();

    // Create the tree.
    treeModel = new ElementTreeModel(document);
    tree = new JTree(treeModel) {

        @Override
        public String convertValueToText(Object value, boolean selected,
                boolean expanded, boolean leaf,
                int row, boolean hasFocus) {
            // Should only happen for the root
            if (!(value instanceof Element)) {
                return value.toString();
            }

            Element e = (Element) value;
            AttributeSet as = e.getAttributes().copyAttributes();
            String asString;

            if (as != null) {
                StringBuilder retBuffer = new StringBuilder("[");
                Enumeration names = as.getAttributeNames();

                while (names.hasMoreElements()) {
                    Object nextName = names.nextElement();

                    if (nextName != StyleConstants.ResolveAttribute) {
                        retBuffer.append(" ");
                        retBuffer.append(nextName);
                        retBuffer.append("=");
                        retBuffer.append(as.getAttribute(nextName));
                    }
                }
                retBuffer.append(" ]");
                asString = retBuffer.toString();
            } else {
                asString = "[ ]";
            }

            if (e.isLeaf()) {
                return e.getName() + " [" + e.getStartOffset() + ", " + e.
                        getEndOffset() + "] Attributes: " + asString;
            }
            return e.getName() + " [" + e.getStartOffset() + ", " + e.
                    getEndOffset() + "] Attributes: " + asString;
        }
    };
    tree.addTreeSelectionListener(this);
    tree.setDragEnabled(true);
    // Don't show the root, it is fake.
    tree.setRootVisible(false);
    // Since the display value of every node after the insertion point
    // changes every time the text changes and we don't generate a change
    // event for all those nodes the display value can become off.
    // This can be seen as '...' instead of the complete string value.
    // This is a temporary workaround, increase the needed size by 15,
    // hoping that will be enough.
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Dimension getPreferredSize() {
            Dimension retValue = super.getPreferredSize();
            if (retValue != null) {
                retValue.width += 15;
            }
            return retValue;
        }
    });
    // become a listener on the document to update the tree.
    document.addDocumentListener(this);

    // become a PropertyChangeListener to know when the Document has
    // changed.
    editor.addPropertyChangeListener(this);

    // Become a CaretListener
    editor.addCaretListener(this);

    // configure the panel and frame containing it.
    setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);

    // Add a label above tree to describe what is being shown
    JLabel label = new JLabel("Elements that make up the current document",
            SwingConstants.CENTER);

    label.setFont(new Font("Dialog", Font.BOLD, 14));
    add(label, BorderLayout.NORTH);

    setPreferredSize(new Dimension(400, 400));
}
 
源代码15 项目: jdk8u-jdk   文件: AquaTextFieldSearch.java
protected static void installSearchFieldListener(final JTextComponent c) {
    c.addPropertyChangeListener(SEARCH_FIELD_PROPERTY_LISTENER);
}
 
源代码16 项目: jdk8u-jdk   文件: ElementTreePanel.java
@SuppressWarnings("LeakingThisInConstructor")
public ElementTreePanel(JTextComponent editor) {
    this.editor = editor;

    Document document = editor.getDocument();

    // Create the tree.
    treeModel = new ElementTreeModel(document);
    tree = new JTree(treeModel) {

        @Override
        public String convertValueToText(Object value, boolean selected,
                boolean expanded, boolean leaf,
                int row, boolean hasFocus) {
            // Should only happen for the root
            if (!(value instanceof Element)) {
                return value.toString();
            }

            Element e = (Element) value;
            AttributeSet as = e.getAttributes().copyAttributes();
            String asString;

            if (as != null) {
                StringBuilder retBuffer = new StringBuilder("[");
                Enumeration names = as.getAttributeNames();

                while (names.hasMoreElements()) {
                    Object nextName = names.nextElement();

                    if (nextName != StyleConstants.ResolveAttribute) {
                        retBuffer.append(" ");
                        retBuffer.append(nextName);
                        retBuffer.append("=");
                        retBuffer.append(as.getAttribute(nextName));
                    }
                }
                retBuffer.append(" ]");
                asString = retBuffer.toString();
            } else {
                asString = "[ ]";
            }

            if (e.isLeaf()) {
                return e.getName() + " [" + e.getStartOffset() + ", " + e.
                        getEndOffset() + "] Attributes: " + asString;
            }
            return e.getName() + " [" + e.getStartOffset() + ", " + e.
                    getEndOffset() + "] Attributes: " + asString;
        }
    };
    tree.addTreeSelectionListener(this);
    tree.setDragEnabled(true);
    // Don't show the root, it is fake.
    tree.setRootVisible(false);
    // Since the display value of every node after the insertion point
    // changes every time the text changes and we don't generate a change
    // event for all those nodes the display value can become off.
    // This can be seen as '...' instead of the complete string value.
    // This is a temporary workaround, increase the needed size by 15,
    // hoping that will be enough.
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Dimension getPreferredSize() {
            Dimension retValue = super.getPreferredSize();
            if (retValue != null) {
                retValue.width += 15;
            }
            return retValue;
        }
    });
    // become a listener on the document to update the tree.
    document.addDocumentListener(this);

    // become a PropertyChangeListener to know when the Document has
    // changed.
    editor.addPropertyChangeListener(this);

    // Become a CaretListener
    editor.addCaretListener(this);

    // configure the panel and frame containing it.
    setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);

    // Add a label above tree to describe what is being shown
    JLabel label = new JLabel("Elements that make up the current document",
            SwingConstants.CENTER);

    label.setFont(new Font("Dialog", Font.BOLD, 14));
    add(label, BorderLayout.NORTH);

    setPreferredSize(new Dimension(400, 400));
}
 
源代码17 项目: jdk8u-dev-jdk   文件: ElementTreePanel.java
@SuppressWarnings("LeakingThisInConstructor")
public ElementTreePanel(JTextComponent editor) {
    this.editor = editor;

    Document document = editor.getDocument();

    // Create the tree.
    treeModel = new ElementTreeModel(document);
    tree = new JTree(treeModel) {

        @Override
        public String convertValueToText(Object value, boolean selected,
                boolean expanded, boolean leaf,
                int row, boolean hasFocus) {
            // Should only happen for the root
            if (!(value instanceof Element)) {
                return value.toString();
            }

            Element e = (Element) value;
            AttributeSet as = e.getAttributes().copyAttributes();
            String asString;

            if (as != null) {
                StringBuilder retBuffer = new StringBuilder("[");
                Enumeration names = as.getAttributeNames();

                while (names.hasMoreElements()) {
                    Object nextName = names.nextElement();

                    if (nextName != StyleConstants.ResolveAttribute) {
                        retBuffer.append(" ");
                        retBuffer.append(nextName);
                        retBuffer.append("=");
                        retBuffer.append(as.getAttribute(nextName));
                    }
                }
                retBuffer.append(" ]");
                asString = retBuffer.toString();
            } else {
                asString = "[ ]";
            }

            if (e.isLeaf()) {
                return e.getName() + " [" + e.getStartOffset() + ", " + e.
                        getEndOffset() + "] Attributes: " + asString;
            }
            return e.getName() + " [" + e.getStartOffset() + ", " + e.
                    getEndOffset() + "] Attributes: " + asString;
        }
    };
    tree.addTreeSelectionListener(this);
    tree.setDragEnabled(true);
    // Don't show the root, it is fake.
    tree.setRootVisible(false);
    // Since the display value of every node after the insertion point
    // changes every time the text changes and we don't generate a change
    // event for all those nodes the display value can become off.
    // This can be seen as '...' instead of the complete string value.
    // This is a temporary workaround, increase the needed size by 15,
    // hoping that will be enough.
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Dimension getPreferredSize() {
            Dimension retValue = super.getPreferredSize();
            if (retValue != null) {
                retValue.width += 15;
            }
            return retValue;
        }
    });
    // become a listener on the document to update the tree.
    document.addDocumentListener(this);

    // become a PropertyChangeListener to know when the Document has
    // changed.
    editor.addPropertyChangeListener(this);

    // Become a CaretListener
    editor.addCaretListener(this);

    // configure the panel and frame containing it.
    setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);

    // Add a label above tree to describe what is being shown
    JLabel label = new JLabel("Elements that make up the current document",
            SwingConstants.CENTER);

    label.setFont(new Font("Dialog", Font.BOLD, 14));
    add(label, BorderLayout.NORTH);

    setPreferredSize(new Dimension(400, 400));
}
 
源代码18 项目: pentaho-reporting   文件: FormValidator.java
public void registerTextField( final JTextComponent textField ) {
  textField.getDocument().addDocumentListener( formTextfieldListener );
  textField.addPropertyChangeListener( FormValidator.DOCUMENT_PROPERTY_NAME, formTextfieldListener );
}
 
源代码19 项目: openjdk-jdk8u-backup   文件: AquaTextFieldSearch.java
protected static void installSearchFieldListener(final JTextComponent c) {
    c.addPropertyChangeListener(SEARCH_FIELD_PROPERTY_LISTENER);
}
 
源代码20 项目: openjdk-8-source   文件: ElementTreePanel.java
@SuppressWarnings("LeakingThisInConstructor")
public ElementTreePanel(JTextComponent editor) {
    this.editor = editor;

    Document document = editor.getDocument();

    // Create the tree.
    treeModel = new ElementTreeModel(document);
    tree = new JTree(treeModel) {

        @Override
        public String convertValueToText(Object value, boolean selected,
                boolean expanded, boolean leaf,
                int row, boolean hasFocus) {
            // Should only happen for the root
            if (!(value instanceof Element)) {
                return value.toString();
            }

            Element e = (Element) value;
            AttributeSet as = e.getAttributes().copyAttributes();
            String asString;

            if (as != null) {
                StringBuilder retBuffer = new StringBuilder("[");
                Enumeration names = as.getAttributeNames();

                while (names.hasMoreElements()) {
                    Object nextName = names.nextElement();

                    if (nextName != StyleConstants.ResolveAttribute) {
                        retBuffer.append(" ");
                        retBuffer.append(nextName);
                        retBuffer.append("=");
                        retBuffer.append(as.getAttribute(nextName));
                    }
                }
                retBuffer.append(" ]");
                asString = retBuffer.toString();
            } else {
                asString = "[ ]";
            }

            if (e.isLeaf()) {
                return e.getName() + " [" + e.getStartOffset() + ", " + e.
                        getEndOffset() + "] Attributes: " + asString;
            }
            return e.getName() + " [" + e.getStartOffset() + ", " + e.
                    getEndOffset() + "] Attributes: " + asString;
        }
    };
    tree.addTreeSelectionListener(this);
    tree.setDragEnabled(true);
    // Don't show the root, it is fake.
    tree.setRootVisible(false);
    // Since the display value of every node after the insertion point
    // changes every time the text changes and we don't generate a change
    // event for all those nodes the display value can become off.
    // This can be seen as '...' instead of the complete string value.
    // This is a temporary workaround, increase the needed size by 15,
    // hoping that will be enough.
    tree.setCellRenderer(new DefaultTreeCellRenderer() {

        @Override
        public Dimension getPreferredSize() {
            Dimension retValue = super.getPreferredSize();
            if (retValue != null) {
                retValue.width += 15;
            }
            return retValue;
        }
    });
    // become a listener on the document to update the tree.
    document.addDocumentListener(this);

    // become a PropertyChangeListener to know when the Document has
    // changed.
    editor.addPropertyChangeListener(this);

    // Become a CaretListener
    editor.addCaretListener(this);

    // configure the panel and frame containing it.
    setLayout(new BorderLayout());
    add(new JScrollPane(tree), BorderLayout.CENTER);

    // Add a label above tree to describe what is being shown
    JLabel label = new JLabel("Elements that make up the current document",
            SwingConstants.CENTER);

    label.setFont(new Font("Dialog", Font.BOLD, 14));
    add(label, BorderLayout.NORTH);

    setPreferredSize(new Dimension(400, 400));
}