List of usage examples for javax.swing.text MutableAttributeSet removeAttributes
public void removeAttributes(AttributeSet attributes);
From source file:com.hexidec.ekit.component.ExtendedHTMLDocument.java
@Override public void setParagraphAttributes(int offset, int length, AttributeSet s, boolean replace) { for (HTMLDocumentBehavior b : behaviors) { s = b.beforeSetParagraphAttributes(this, offset, length, s, replace); }/* www.ja v a 2 s.c om*/ try { writeLock(); // Make sure we send out a change for the length of the paragraph. int end = Math.min(offset + length, getLength()); Element e = getParagraphElement(offset); offset = e.getStartOffset(); e = getParagraphElement(end); length = Math.max(0, e.getEndOffset() - offset); DefaultDocumentEvent changes = new DefaultDocumentEvent(offset, length, DocumentEvent.EventType.CHANGE); AttributeSet sCopy = s.copyAttributes(); int lastEnd = Integer.MAX_VALUE; for (int pos = offset; pos <= end; pos = lastEnd) { Element paragraph = getParagraphElement(pos); if (lastEnd == paragraph.getEndOffset()) { lastEnd++; } else { lastEnd = paragraph.getEndOffset(); } MutableAttributeSet attr = (MutableAttributeSet) paragraph.getAttributes(); changes.addEdit(new AttributeUndoableEdit(paragraph, sCopy, replace)); if (replace) { attr.removeAttributes(attr); } DocumentUtil.copyAllAttributesRemovingMarked(attr, s); } 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 .ja va 2 s . co m 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)); }