pane.addCaretListener(new CaretListener() { public void caretUpdate(CaretEvent event) { final JTextPane textPane = (JTextPane) event.getSource(); EventQueue.invokeLater(new Runnable() { public void run() { MutableAttributeSet inputAttr = textPane.getInputAttributes(); inputAttr.removeAttribute(StyleConstants.Foreground); } }); } });
private void blockURLTyping(MutableAttributeSet inputAttr, int dot, int mark) { StyledDocument doc = getStyledDocument(); int begin = (dot < mark) ? dot - 1 : mark - 1; if(begin >= 0) { Element dotEl = doc.getCharacterElement(begin); Element markEl = doc.getCharacterElement((dot < mark) ? mark : dot); AttributeSet dotAttr = dotEl.getAttributes(); AttributeSet markAttr = markEl.getAttributes(); if(dotAttr.isDefined(HTML.Attribute.HREF)) // Ensure atleast one of them isn't null { if(dotAttr.getAttribute(HTML.Attribute.HREF) == markAttr.getAttribute(HTML.Attribute.HREF)) { inputAttr.addAttribute(HTML.Attribute.HREF, dotAttr.getAttribute(HTML.Attribute.HREF)); inputAttr.addAttribute(StyleConstants.Foreground, Color.BLUE); inputAttr.addAttribute(StyleConstants.Underline, true); return; } } } if(inputAttr.isDefined(HTML.Attribute.HREF)) // In all other cases => remove { inputAttr.removeAttribute(HTML.Attribute.HREF); inputAttr.removeAttribute(StyleConstants.Foreground); inputAttr.removeAttribute(StyleConstants.Underline); } }
/** {@inheritDoc} */ public void verbatim( SinkEventAttributes attributes ) { MutableAttributeSet atts = SinkUtils.filterAttributes( attributes, SinkUtils.SINK_VERBATIM_ATTRIBUTES ); if ( atts == null ) { atts = new SinkEventAttributeSet(); } boolean boxed = false; if ( atts.isDefined( SinkEventAttributes.DECORATION ) ) { boxed = "boxed".equals( atts.getAttribute( SinkEventAttributes.DECORATION ).toString() ); } if ( boxed ) { atts.addAttribute( Attribute.CLASS, "source" ); } atts.removeAttribute( SinkEventAttributes.DECORATION ); String width = (String) atts.getAttribute( Attribute.WIDTH.toString() ); atts.removeAttribute( Attribute.WIDTH.toString() ); writeStartTag( Tag.DIV, atts ); writeEOL( true ); if ( width != null ) { atts.addAttribute( Attribute.WIDTH.toString(), width ); } atts.removeAttribute( Attribute.ALIGN.toString() ); atts.removeAttribute( Attribute.CLASS.toString() ); writeStartTag( VERBATIM_TAG, atts ); }
atts.removeAttribute( SinkEventAttributes.DECORATION ); atts.removeAttribute( Attribute.ALIGN.toString() ); writeStartTag( PRE, atts );
/** * Writes a start tag, prepending EOL. * * @param tag The tag. * @param id An id to add. * @param name The name (value) of the id. * @param attributeId An id identifying the attribute set. */ protected void writeStartTag( Tag tag, String id, String name, String attributeId ) { MutableAttributeSet att = config.getAttributeSet( attributeId ); // make sure we don't add it twice if ( att.isDefined( id ) ) { att.removeAttribute( id ); } att.addAttribute( id, name ); writeEOL(); writeStartTag( tag, att ); }
clientProperties.removeAttribute(key);
element.removeAttribute(a.getKey());
value = attr.getAttribute(aName); if (value != null && !value.toString().equalsIgnoreCase(tag.toString())) { attr.removeAttribute(aName);