Refine search
class Page extends HTMLEditorKit.ParserCallback { public void handleStartTag(HTML.Tag t, MutableAttributeSet a, int pos) { if (t == HTML.Tag.A) { String link = null; Enumeration<?> attributeNames = a.getAttributeNames(); if (attributeNames.nextElement().equals(HTML.Attribute.HREF)) link = a.getAttribute(HTML.Attribute.HREF).toString(); //save link some where } } }
public MutableAttributeSet banMessage(User user, String message) { MutableAttributeSet style = new SimpleAttributeSet(standard()); style.addAttribute(Attribute.IS_BAN_MESSAGE, user); style.addAttribute(Attribute.TIMESTAMP, System.currentTimeMillis()); style.addAttribute(Attribute.BAN_MESSAGE, message); return style; }
/** * The default align is <code>center</code>. * * {@inheritDoc} * @see javax.swing.text.html.HTML.Tag#TABLE */ public void tableRows( int[] justification, boolean grid ) { // similar to super.tableRows( justification, grid ) but without class. this.tableRows = true; setCellJustif( justification ); if ( this.tableAttributes == null ) { this.tableAttributes = new SinkEventAttributeSet( 0 ); } MutableAttributeSet att = new SinkEventAttributeSet(); if ( !tableAttributes.isDefined( Attribute.BORDER.toString() ) ) { att.addAttribute( Attribute.BORDER, ( grid ? "1" : "0" ) ); } att.addAttributes( tableAttributes ); tableAttributes.removeAttributes( tableAttributes ); writeStartTag( TABLE, att ); }
private void addBy(MutableAttributeSet attributes, String byName) { java.util.List<String> old = (java.util.List)attributes.getAttribute(Attribute.ACTION_BY); java.util.List<String> changed; if (old != null) { changed = new ArrayList<>(old); } else { changed = new ArrayList<>(); } // If already present, append to end changed.remove(byName); changed.add(byName); attributes.addAttribute(Attribute.ACTION_BY, changed); }
@Override protected void writeAttributes(AttributeSet attr) throws IOException { convAttr.removeAttributes(convAttr); convertToHTML(attr, convAttr); Enumeration names = convAttr.getAttributeNames(); while (names.hasMoreElements()) { Object name = names.nextElement(); if (name instanceof HTML.Tag || name instanceof StyleConstants || name == HTML.Attribute.ENDTAG) continue; write(" " + name + "=\"" + convAttr.getAttribute(name) + "\""); } } }
public class BackgroundColorAction extends StyledEditorKit.StyledTextAction { private Color color; public BackgroundColorAction(Color color) { super(StyleConstants.Background.toString()); this.color = color; } @Override public void actionPerformed(ActionEvent ae) { JEditorPane editor = getEditor(ae); if (editor == null) { return; } //Add span Tag String htmlStyle = "background-color:" + Util.getHTMLColor(color); SimpleAttributeSet attr = new SimpleAttributeSet(); attr.addAttribute(HTML.Attribute.STYLE, htmlStyle); MutableAttributeSet outerAttr = new SimpleAttributeSet(); outerAttr.addAttribute(HTML.Tag.SPAN, attr); //Next line is just an instruction to editor to change color StyleConstants.setBackground(outerAttr, this.color); setCharacterAttributes(editor, outerAttr, false); } }
public void actionPerformed(ActionEvent e) { if(!(this.isEnabled())) { return; } JEditorPane editor = getEditor(e); if(editor != null) { String stylename = (String)(parent.getSelectedItem()); if(stylename == null) { return; } else if(stylename.equals(Translatrix.getTranslationString("NoCSSStyle"))) { return; } boolean replace = false; MutableAttributeSet attr = null; SimpleAttributeSet cls = new SimpleAttributeSet(); cls.addAttribute(HTML.Attribute.CLASS, stylename); attr = new SimpleAttributeSet(); attr.addAttribute(HTML.Tag.FONT, cls); MutableAttributeSet inattr = ((HTMLEditorKit)(editor.getEditorKitForContentType("text/html"))).getInputAttributes(); inattr.addAttributes(attr); setCharacterAttributes(editor, attr, replace); } } }
public void actionPerformed(ActionEvent ae) { JTextPane parentTextPane = parentEkit.getTextPane(); String selText = parentTextPane.getSelectedText(); int textLength = -1; if (selText != null) { textLength = selText.length(); } if (selText == null || textLength < 1) { return; } JEditorPane editor = getEditor(ae); if (editor != null) { StyledEditorKit kit = getStyledEditorKit(editor); MutableAttributeSet attr = kit.getInputAttributes(); boolean newValue = (attr.getAttribute(htmlTag) == Boolean.TRUE) ? false : true; SimpleAttributeSet sas = new SimpleAttributeSet(); sas.addAttribute(htmlTag, Boolean.valueOf(newValue)); //StyleConstants.setUnderline(sas, newValue); setCharacterAttributes(editor, sas, false); } } }
clientProperties = new SimpleAttributeSet(); clientProperties.removeAttribute(key); clientProperties.addAttribute(key, value); if (clientProperties.getAttributeCount() == 0 && clientProperties.getResolveParent() == null) { clientProperties = null;
/** * Inserts a link into the current document. * * @param link - the link to insert( ex. http://www.javasoft.com ) * @throws BadLocationException if the location is not available for insertion. */ public void insertLink( Document doc, String link ) throws BadLocationException { // Create a new style, based on the style used for generic text, for the link. final MutableAttributeSet linkStyle = new SimpleAttributeSet( getMessageStyle().copyAttributes() ); StyleConstants.setForeground( linkStyle, (Color) UIManager.get( "Link.foreground" ) ); StyleConstants.setUnderline( linkStyle, true ); linkStyle.addAttribute( "link", link ); doc.insertString( doc.getLength(), link, linkStyle ); }
public MutableAttributeSet applyMessageStyle( char directive, MutableAttributeSet messageStyle ) { final MutableAttributeSet style = new SimpleAttributeSet( messageStyle.copyAttributes() ); switch ( directive ) { case '*': StyleConstants.setBold( style, true ); break; case '_': StyleConstants.setItalic( style, true ); break; case '~': StyleConstants.setStrikeThrough( style, true ); break; case '`': StyleConstants.setFontFamily( style, "Monospaced" ); break; case 'K': // Keyword StyleConstants.setForeground( style, ((Color) messageStyle.getAttribute( Foreground )).brighter().brighter().brighter() ); break; default: Log.warning( "Cannot apply message style for unrecognized directive: " + directive ); } return style; }
continue; } else { SimpleAttributeSet hrefAttributeSet = new SimpleAttributeSet(); hrefAttributeSet.addAttribute( HTML.Attribute.HREF, attr.getAttribute( HTML.Attribute.HREF ) ); muxList.add( hrefAttributeSet ); final MutableAttributeSet retval = new SimpleAttributeSet(); for ( int i = muxList.size() - 1; i >= 0; i-- ) { final AttributeSet o = muxList.get( i ); retval.addAttributes( o );
/** * @see javax.swing.text.html.HTMLEditorKit.ParserCallback#handleStartTag(javax.swing.text.html.HTML.Tag, * javax.swing.text.MutableAttributeSet, int) */ @Override public void handleStartTag(Tag tag, MutableAttributeSet attrSet, int pos) { if (tag == HTML.Tag.A) { String name = (String) attrSet.getAttribute(HTML.Attribute.HREF); addComponents(name); } } }
private Vector tagValues = new Vector(10); private Vector tagsToRemove = new Vector(10); private MutableAttributeSet convAttr = new SimpleAttributeSet(); private MutableAttributeSet oConvAttr = new SimpleAttributeSet(); to.removeAttributes(to); if (from != null) to.addAttribute(key, from.getAttribute(key)); to.addAttribute(HTML.Attribute.STYLE, value); protected void writeAttributes(AttributeSet attr) throws IOException convAttr.removeAttributes(convAttr); convertToHTML(attr, convAttr); Enumeration names = convAttr.getAttributeNames();
/** {@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 ); }
final SimpleAttributeSet set = new SimpleAttributeSet(); StyleConstants.setForeground(set, Color.RED); int p0 = textPane2.getSelectionStart(); textPane2.getCaret().setDot(textPane2.getText().length()); MutableAttributeSet inputAttributes = textPane2.getInputAttributes(); inputAttributes.addAttributes(set);
getContentPane().add(contentPanel); set = new SimpleAttributeSet(); StyleConstants.setFontFamily(set, "Courier New"); StyleConstants.setForeground(set, Color.GREEN); k.getInputAttributes().removeAttributes(set);
/** * Sets the background color. * * @param a the attribute set * @param fg the color */ public static void setTwoToneColor(MutableAttributeSet a, Color fg) { a.addAttribute(TwoToneColor, fg); }
private SinkEventAttributeSet getGraphicsAttributes( String logo ) { MutableAttributeSet atts = null; try { atts = DoxiaUtils.getImageAttributes( logo ); } catch ( IOException e ) { getLog().debug( e ); } if ( atts == null ) { return new SinkEventAttributeSet( new String[]{ SinkEventAttributes.HEIGHT, COVER_HEADER_HEIGHT } ); } // FOP dpi: 72 // Max width : 3.125 inch, table cell size, see #coverPage() final int maxWidth = 225; // 3.125 * 72 if ( Integer.parseInt( atts.getAttribute( SinkEventAttributes.WIDTH ).toString() ) > maxWidth ) { atts.addAttribute( "content-width", "3.125in" ); } return new SinkEventAttributeSet( atts ); } }
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);