Example usage for javax.swing.text MutableAttributeSet addAttributes

List of usage examples for javax.swing.text MutableAttributeSet addAttributes

Introduction

In this page you can find the example usage for javax.swing.text MutableAttributeSet addAttributes.

Prototype

public void addAttributes(AttributeSet attributes);

Source Link

Document

Creates a new attribute set similar to this one except that it contains the given attributes and values.

Usage

From source file:com.hexidec.ekit.component.ExtendedHTMLDocument.java

public void replaceAttributes(Element e, AttributeSet a, Tag tag) {
    if ((e != null) && (a != null)) {
        try {/*from   ww w. j a va2s .c  o  m*/
            writeLock();
            int start = e.getStartOffset();
            DefaultDocumentEvent changes = new DefaultDocumentEvent(start, e.getEndOffset() - start,
                    DocumentEvent.EventType.CHANGE);
            AttributeSet sCopy = a.copyAttributes();
            changes.addEdit(new AttributeUndoableEdit(e, sCopy, false));
            MutableAttributeSet attr = (MutableAttributeSet) e.getAttributes();
            Enumeration aNames = attr.getAttributeNames();
            Object value;
            Object aName;
            while (aNames.hasMoreElements()) {
                aName = aNames.nextElement();
                value = attr.getAttribute(aName);
                if (value != null && !value.toString().equalsIgnoreCase(tag.toString())) {
                    attr.removeAttribute(aName);
                }
            }
            attr.addAttributes(a);
            changes.end();
            fireChangedUpdate(changes);
            fireUndoableEditUpdate(new UndoableEditEvent(this, changes));
        } finally {
            writeUnlock();
        }
    }
}

From source file:org.docx4all.swing.text.WordMLEditorKit.java

protected void createInputAttributes(WordMLDocument.TextElement element, MutableAttributeSet set,
        JEditorPane editor) {//  w w  w  .j  a v  a 2  s.com

    set.removeAttributes(set);
    if (element != null && element.getEndOffset() < element.getDocument().getLength()) {
        set.addAttributes(element.getAttributes());
        // set.removeAttribute(StyleConstants.ComponentAttribute);
        // set.removeAttribute(StyleConstants.IconAttribute);
        // set.removeAttribute(AbstractDocument.ElementNameAttribute);
        // set.removeAttribute(StyleConstants.ComposedTextAttribute);
    }
    fireInputAttributeChanged(new InputAttributeEvent(editor));
}