271 (newValue instanceof Document)) { 272 // New document will have changed selection to 0,0. 273 updateInputAttributes(0, 0, (JTextComponent)source); 274 } 275 } 276 277 public void caretUpdate(CaretEvent e) { 278 updateInputAttributes(e.getDot(), e.getMark(), 279 (JTextComponent)e.getSource()); 280 } 281 } 282 283 /** 284 * Copies the key/values in <code>element</code>s AttributeSet into 285 * <code>set</code>. This does not copy component, icon, or element 286 * names attributes. Subclasses may wish to refine what is and what 287 * isn't copied here. But be sure to first remove all the attributes that 288 * are in <code>set</code>.<p> 289 * This is called anytime the caret moves over a different location. 290 * 291 */ 292 protected void createInputAttributes(Element element, 293 MutableAttributeSet set) { 294 if (element.getAttributes().getAttributeCount() > 0 295 || element.getEndOffset() - element.getStartOffset() > 1 296 || element.getEndOffset() < element.getDocument().getLength()) { 297 set.removeAttributes(set); 298 set.addAttributes(element.getAttributes()); 299 set.removeAttribute(StyleConstants.ComponentAttribute); 300 set.removeAttribute(StyleConstants.IconAttribute); 301 set.removeAttribute(AbstractDocument.ElementNameAttribute); 302 set.removeAttribute(StyleConstants.ComposedTextAttribute); 303 } 304 } 305 306 // ---- default ViewFactory implementation --------------------- 307 308 static class StyledViewFactory implements ViewFactory { 309 310 public View create(Element elem) { | 271 (newValue instanceof Document)) { 272 // New document will have changed selection to 0,0. 273 updateInputAttributes(0, 0, (JTextComponent)source); 274 } 275 } 276 277 public void caretUpdate(CaretEvent e) { 278 updateInputAttributes(e.getDot(), e.getMark(), 279 (JTextComponent)e.getSource()); 280 } 281 } 282 283 /** 284 * Copies the key/values in <code>element</code>s AttributeSet into 285 * <code>set</code>. This does not copy component, icon, or element 286 * names attributes. Subclasses may wish to refine what is and what 287 * isn't copied here. But be sure to first remove all the attributes that 288 * are in <code>set</code>.<p> 289 * This is called anytime the caret moves over a different location. 290 * 291 * @param element the element 292 * @param set the attributes 293 */ 294 protected void createInputAttributes(Element element, 295 MutableAttributeSet set) { 296 if (element.getAttributes().getAttributeCount() > 0 297 || element.getEndOffset() - element.getStartOffset() > 1 298 || element.getEndOffset() < element.getDocument().getLength()) { 299 set.removeAttributes(set); 300 set.addAttributes(element.getAttributes()); 301 set.removeAttribute(StyleConstants.ComponentAttribute); 302 set.removeAttribute(StyleConstants.IconAttribute); 303 set.removeAttribute(AbstractDocument.ElementNameAttribute); 304 set.removeAttribute(StyleConstants.ComposedTextAttribute); 305 } 306 } 307 308 // ---- default ViewFactory implementation --------------------- 309 310 static class StyledViewFactory implements ViewFactory { 311 312 public View create(Element elem) { |