當前位置: 首頁>>代碼示例>>Java>>正文


Java MutableAttributeSet.addAttribute方法代碼示例

本文整理匯總了Java中javax.swing.text.MutableAttributeSet.addAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java MutableAttributeSet.addAttribute方法的具體用法?Java MutableAttributeSet.addAttribute怎麽用?Java MutableAttributeSet.addAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.swing.text.MutableAttributeSet的用法示例。


在下文中一共展示了MutableAttributeSet.addAttribute方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: convertToHTML40

import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
/**
 * Copies the given AttributeSet to a new set, converting
 * any CSS attributes found to arguments of an HTML style
 * attribute.
 */
private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {
    Enumeration keys = from.getAttributeNames();
    String value = "";
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (key instanceof CSS.Attribute) {
            value = value + " " + key + "=" + from.getAttribute(key) + ";";
        }
        else {
            to.addAttribute(key, from.getAttribute(key));
        }
    }
    if (value.length() > 0) {
        to.addAttribute(HTML.Attribute.STYLE, value);
    }
}
 
開發者ID:ser316asu,項目名稱:SER316-Aachen,代碼行數:22,代碼來源:AltHTMLWriter.java

示例2: add

import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
public static AttrSet add(Context context, Object... keyValuePairs) throws Exception {
    @SuppressWarnings("unchecked")
    List<Item> list = (List<Item>) context.getInstance(List.class);
    MutableAttributeSet expected = new SimpleAttributeSet();
    for (int i = keyValuePairs.length; i > 0;) {
        Object value = keyValuePairs[--i];
        Object key = keyValuePairs[--i];
        expected.addAttribute(key, value);
    }
    AttrSet attrSet = AttrSet.get(keyValuePairs);
    Item item = new Item(expected, attrSet);
    list.add(item);
    StringBuilder sb = context.logOpBuilder();
    if (sb != null) {
        sb.append("Add[").append(list.size() - 1).append("]: ").append(expected);
        context.logOp(sb);
    }
    return attrSet;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:20,代碼來源:AttrSetTesting.java

示例3: createFontAttribute

import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
/**
 * Create/update an HTML &lt;font&gt; tag attribute. The value of the
 * attribute should be a MutableAttributeSet so that the attributes can be
 * updated as they are discovered.
 */
private static void createFontAttribute(CSS.Attribute a, AttributeSet from, MutableAttributeSet to) {
	MutableAttributeSet fontAttr = (MutableAttributeSet) to.getAttribute(HTML.Tag.FONT);
	if (fontAttr == null) {
		fontAttr = new SimpleAttributeSet();
		to.addAttribute(HTML.Tag.FONT, fontAttr);
	}
	// edit the parameters to the font tag
	String htmlValue = from.getAttribute(a).toString();
	if (a == CSS.Attribute.FONT_FAMILY) {
		fontAttr.addAttribute(HTML.Attribute.FACE, htmlValue);
	} else if (a == CSS.Attribute.FONT_SIZE) {
		fontAttr.addAttribute(HTML.Attribute.SIZE, htmlValue);
	} else if (a == CSS.Attribute.COLOR) {
		fontAttr.addAttribute(HTML.Attribute.COLOR, htmlValue);
	}
}
 
開發者ID:cst316,項目名稱:spring16project-Fortran,代碼行數:22,代碼來源:AltHTMLWriter.java

示例4: addSpecialElement

import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
/**
 * Adds content that is specified in the attribute set.
 *
 * @param t the HTML.Tag
 * @param a the attribute set specifying the special content
 */
protected void addSpecialElement(HTML.Tag t, MutableAttributeSet a)
{
  if (t != HTML.Tag.FRAME && ! inParagraph())
    {
      blockOpen(HTML.Tag.IMPLIED, new SimpleAttributeSet());
    }

  a.addAttribute(StyleConstants.NameAttribute, t);

  // The two spaces are required because some special elements like HR
  // must be broken. At least two characters are needed to break into the
  // two parts.
  DefaultStyledDocument.ElementSpec spec =
    new DefaultStyledDocument.ElementSpec(a.copyAttributes(),
      DefaultStyledDocument.ElementSpec.ContentType,
      new char[] {' '}, 0, 1 );
  parseBuffer.add(spec);
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:25,代碼來源:HTMLDocument.java

示例5: createFontAttribute

import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
/**
 * Create/update an HTML &lt;font&gt; tag attribute.  The
 * value of the attribute should be a MutableAttributeSet so
 * that the attributes can be updated as they are discovered.
 */
private static void createFontAttribute(CSS.Attribute a, AttributeSet from, MutableAttributeSet to) {
    MutableAttributeSet fontAttr = (MutableAttributeSet) to.getAttribute(HTML.Tag.FONT);
    if (fontAttr == null) {
        fontAttr = new SimpleAttributeSet();
        to.addAttribute(HTML.Tag.FONT, fontAttr);
    }
    // edit the parameters to the font tag
    String htmlValue = from.getAttribute(a).toString();
    if (a == CSS.Attribute.FONT_FAMILY) {
        fontAttr.addAttribute(HTML.Attribute.FACE, htmlValue);
    }
    else if (a == CSS.Attribute.FONT_SIZE) {
        fontAttr.addAttribute(HTML.Attribute.SIZE, htmlValue);
    }
    else if (a == CSS.Attribute.COLOR) {
        fontAttr.addAttribute(HTML.Attribute.COLOR, htmlValue);
    }
}
 
開發者ID:cst316,項目名稱:spring16project-Modula-2,代碼行數:24,代碼來源:AltHTMLWriter.java

示例6: set

import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
public boolean set(MutableAttributeSet target)
{
    if (swingValue == null)
        target.removeAttribute(swingName);
    else
        target.addAttribute(swingName, swingValue);

    return true;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:10,代碼來源:RTFAttributes.java

示例7: set

import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
public boolean set(MutableAttributeSet target, int parameter)
{
    /* See above note in the case that parameter==1 */
    Boolean value = ( parameter != 0 ? True : False );

    target.addAttribute(swingName, value);

    return true; /* true indicates we were successful */
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:10,代碼來源:RTFAttributes.java

示例8: setDefault

import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
public boolean setDefault(MutableAttributeSet target)
{
    if (swingDefault != rtfDefault ||
        ( target.getAttribute(swingName) != null ) )
      target.addAttribute(swingName, Boolean.valueOf(rtfDefault));
    return true;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:8,代碼來源:RTFAttributes.java

示例9: set

import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
public boolean set(MutableAttributeSet target)
{
    /* TODO: There's some ambiguity about whether this should
       *set* or *toggle* the attribute. */
    target.addAttribute(swingName, True);

    return true;  /* true indicates we were successful */
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:9,代碼來源:RTFAttributes.java

示例10: addCSSAttribute

import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
/**
 * Adds a CSS attribute to the given set.
 *
 * @param attr - the attribute set
 * @param key - the attribute to add
 * @param value - the value of the key
 */
public void addCSSAttribute(MutableAttributeSet attr, CSS.Attribute key,
                            String value)
{
  Object val = CSS.getValue(key, value);
  CSS.addInternal(attr, key, value);
  attr.addAttribute(key, val);
}
 
開發者ID:vilie,項目名稱:javify,代碼行數:15,代碼來源:StyleSheet.java

示例11: convertToHTML32

import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
/**
 * Create an older style of HTML attributes.  This will
 * convert character level attributes that have a StyleConstants
 * mapping over to an HTML tag/attribute.  Other CSS attributes
 * will be placed in an HTML style attribute.
 */
private static void convertToHTML32(AttributeSet from, MutableAttributeSet to) {
    if (from == null) {
        return;
    }
    Enumeration keys = from.getAttributeNames();
    String value = "";
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (key instanceof CSS.Attribute) {
            if ((key == CSS.Attribute.FONT_FAMILY)
                || (key == CSS.Attribute.FONT_SIZE)
                || (key == CSS.Attribute.COLOR)) {

                createFontAttribute((CSS.Attribute) key, from, to);
            }
            else if (key == CSS.Attribute.FONT_WEIGHT) {
                // add a bold tag is weight is bold
                //CSS.FontWeight weightValue = (CSS.FontWeight) from.getAttribute(CSS.Attribute.FONT_WEIGHT);
                String weightValue = from.getAttribute(CSS.Attribute.FONT_WEIGHT).toString();
               // if (weightValue != null) {
                    int fweight;
                    try {
                        fweight = new Integer(weightValue).intValue(); 
                    }
                    catch (Exception ex) {
                        fweight = -1; 
                    }
                    if ((weightValue.toLowerCase().equals("bold")) || (fweight > 400))
                        to.addAttribute(HTML.Tag.B, SimpleAttributeSet.EMPTY);
               //}
            }
            else if (key == CSS.Attribute.FONT_STYLE) {
                String s = from.getAttribute(key).toString();
                if (s.indexOf("italic") >= 0) {
                    to.addAttribute(HTML.Tag.I, SimpleAttributeSet.EMPTY);
                }
            }
            else if (key == CSS.Attribute.TEXT_DECORATION) {
                String decor = from.getAttribute(key).toString();
                if (decor.indexOf("underline") >= 0) {
                    to.addAttribute(HTML.Tag.U, SimpleAttributeSet.EMPTY);
                }
                if (decor.indexOf("line-through") >= 0) {
                    to.addAttribute(HTML.Tag.STRIKE, SimpleAttributeSet.EMPTY);
                }
            }
            else if (key == CSS.Attribute.VERTICAL_ALIGN) {
                String vAlign = from.getAttribute(key).toString();
                if (vAlign.indexOf("sup") >= 0) {
                    to.addAttribute(HTML.Tag.SUP, SimpleAttributeSet.EMPTY);
                }
                if (vAlign.indexOf("sub") >= 0) {
                    to.addAttribute(HTML.Tag.SUB, SimpleAttributeSet.EMPTY);
                }
            }
            else if (key == CSS.Attribute.TEXT_ALIGN) {
                to.addAttribute(HTML.Attribute.ALIGN, from.getAttribute(key).toString());
            }
            else {
                // default is to store in a HTML style attribute
                if (value.length() > 0) {
                    value = value + "; ";
                }
                value = value + key + ": " + from.getAttribute(key);
            }
        }
        else {
            to.addAttribute(key, from.getAttribute(key));
        }
    }
    if (value.length() > 0) {
        to.addAttribute(HTML.Attribute.STYLE, value);
    }
}
 
開發者ID:ser316asu,項目名稱:Neukoelln_SER316,代碼行數:81,代碼來源:AltHTMLWriter.java

示例12: convertToHTML32

import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
/**
 * Create an older style of HTML attributes.  This will
 * convert character level attributes that have a StyleConstants
 * mapping over to an HTML tag/attribute.  Other CSS attributes
 * will be placed in an HTML style attribute.
 */
private static void convertToHTML32(AttributeSet from, MutableAttributeSet to) {
    if (from == null) {
        return;
    }
    Enumeration keys = from.getAttributeNames();
    String value = "";
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (key instanceof CSS.Attribute) {
            if ((key == CSS.Attribute.FONT_FAMILY)
                || (key == CSS.Attribute.FONT_SIZE)
                || (key == CSS.Attribute.COLOR)) {

                createFontAttribute((CSS.Attribute) key, from, to);
            }
            else if (key == CSS.Attribute.FONT_WEIGHT) {
                // add a bold tag is weight is bold
                //CSS.FontWeight weightValue = (CSS.FontWeight) from.getAttribute(CSS.Attribute.FONT_WEIGHT);
                String weightValue = from.getAttribute(CSS.Attribute.FONT_WEIGHT).toString();
                if (weightValue != null) {
                    int fweight;
                    try {
                        fweight = Integer.parseInt(weightValue);
                    }
                    catch (Exception ex) {
                        fweight = -1;
                    }
                    if ((weightValue.toLowerCase().equals("bold")) || (fweight > 400))
                        to.addAttribute(HTML.Tag.B, SimpleAttributeSet.EMPTY);
                }
            }
            else if (key == CSS.Attribute.FONT_STYLE) {
                String s = from.getAttribute(key).toString();
                if (s.indexOf("italic") >= 0) {
                    to.addAttribute(HTML.Tag.I, SimpleAttributeSet.EMPTY);
                }
            }
            else if (key == CSS.Attribute.TEXT_DECORATION) {
                String decor = from.getAttribute(key).toString();
                if (decor.indexOf("underline") >= 0) {
                    to.addAttribute(HTML.Tag.U, SimpleAttributeSet.EMPTY);
                }
                if (decor.indexOf("line-through") >= 0) {
                    to.addAttribute(HTML.Tag.STRIKE, SimpleAttributeSet.EMPTY);
                }
            }
            else if (key == CSS.Attribute.VERTICAL_ALIGN) {
                String vAlign = from.getAttribute(key).toString();
                if (vAlign.indexOf("sup") >= 0) {
                    to.addAttribute(HTML.Tag.SUP, SimpleAttributeSet.EMPTY);
                }
                if (vAlign.indexOf("sub") >= 0) {
                    to.addAttribute(HTML.Tag.SUB, SimpleAttributeSet.EMPTY);
                }
            }
            else if (key == CSS.Attribute.TEXT_ALIGN) {
                to.addAttribute(HTML.Attribute.ALIGN, from.getAttribute(key).toString());
            }
            else {
                // default is to store in a HTML style attribute
                if (value.length() > 0) {
                    value = value + "; ";
                }
                value = value + key + ": " + from.getAttribute(key);
            }
        }
        else {
            to.addAttribute(key, from.getAttribute(key));
        }
    }
    if (value.length() > 0) {
        to.addAttribute(HTML.Attribute.STYLE, value);
    }
}
 
開發者ID:ser316asu,項目名稱:SER316-Dresden,代碼行數:81,代碼來源:AltHTMLWriter.java

示例13: convertToHTML32

import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
/**
 * Create an older style of HTML attributes.  This will
 * convert character level attributes that have a StyleConstants
 * mapping over to an HTML tag/attribute.  Other CSS attributes
 * will be placed in an HTML style attribute.
 */
private static void convertToHTML32(AttributeSet from, MutableAttributeSet to) {
    if (from == null) {
        return;
    }
    Enumeration keys = from.getAttributeNames();
    String value = "";
    while (keys.hasMoreElements()) {
        Object key = keys.nextElement();
        if (key instanceof CSS.Attribute) {
            if ((key == CSS.Attribute.FONT_FAMILY)
                || (key == CSS.Attribute.FONT_SIZE)
                || (key == CSS.Attribute.COLOR)) {

                createFontAttribute((CSS.Attribute) key, from, to);
            }
            else if (key == CSS.Attribute.FONT_WEIGHT) {
                // add a bold tag is weight is bold
                //CSS.FontWeight weightValue = (CSS.FontWeight) from.getAttribute(CSS.Attribute.FONT_WEIGHT);
                String weightValue = from.getAttribute(CSS.Attribute.FONT_WEIGHT).toString();
                if (weightValue != null) {
                    int fweight;
                    try {
                        fweight = new Integer(weightValue).intValue();
                    }
                    catch (Exception ex) {
                        fweight = -1;
                    }
                    if ((weightValue.toLowerCase().equals("bold")) || (fweight > 400))
                        to.addAttribute(HTML.Tag.B, SimpleAttributeSet.EMPTY);
                }
            }
            else if (key == CSS.Attribute.FONT_STYLE) {
                String s = from.getAttribute(key).toString();
                if (s.indexOf("italic") >= 0) {
                    to.addAttribute(HTML.Tag.I, SimpleAttributeSet.EMPTY);
                }
            }
            else if (key == CSS.Attribute.TEXT_DECORATION) {
                String decor = from.getAttribute(key).toString();
                if (decor.indexOf("underline") >= 0) {
                    to.addAttribute(HTML.Tag.U, SimpleAttributeSet.EMPTY);
                }
                if (decor.indexOf("line-through") >= 0) {
                    to.addAttribute(HTML.Tag.STRIKE, SimpleAttributeSet.EMPTY);
                }
            }
            else if (key == CSS.Attribute.VERTICAL_ALIGN) {
                String vAlign = from.getAttribute(key).toString();
                if (vAlign.indexOf("sup") >= 0) {
                    to.addAttribute(HTML.Tag.SUP, SimpleAttributeSet.EMPTY);
                }
                if (vAlign.indexOf("sub") >= 0) {
                    to.addAttribute(HTML.Tag.SUB, SimpleAttributeSet.EMPTY);
                }
            }
            else if (key == CSS.Attribute.TEXT_ALIGN) {
                to.addAttribute(HTML.Attribute.ALIGN, from.getAttribute(key).toString());
            }
            else {
                // default is to store in a HTML style attribute
                if (value.length() > 0) {
                    value = value + "; ";
                }
                value = value + key + ": " + from.getAttribute(key);
            }
        }
        else {
            to.addAttribute(key, from.getAttribute(key));
        }
    }
    if (value.length() > 0) {
        to.addAttribute(HTML.Attribute.STYLE, value);
    }
}
 
開發者ID:ser316asu,項目名稱:SER316-Munich,代碼行數:81,代碼來源:AltHTMLWriter.java

示例14: convertToHTML32

import javax.swing.text.MutableAttributeSet; //導入方法依賴的package包/類
/**
 * Create an older style of HTML attributes. This will convert character
 * level attributes that have a StyleConstants mapping over to an HTML
 * tag/attribute. Other CSS attributes will be placed in an HTML style
 * attribute.
 */
private static void convertToHTML32(AttributeSet from, MutableAttributeSet to) {
	if (from == null) {
		return;
	}
	Enumeration keys = from.getAttributeNames();
	String value = "";
	while (keys.hasMoreElements()) {
		Object key = keys.nextElement();
		if (key instanceof CSS.Attribute) {
			if ((key == CSS.Attribute.FONT_FAMILY) || (key == CSS.Attribute.FONT_SIZE)
					|| (key == CSS.Attribute.COLOR)) {

				createFontAttribute((CSS.Attribute) key, from, to);
			} else if (key == CSS.Attribute.FONT_WEIGHT) {
				// add a bold tag is weight is bold
				// CSS.FontWeight weightValue = (CSS.FontWeight)
				// from.getAttribute(CSS.Attribute.FONT_WEIGHT);
				String weightValue = from.getAttribute(CSS.Attribute.FONT_WEIGHT).toString();
				if (weightValue != null) {
					int fweight;
					try {
						fweight = new Integer(weightValue).intValue();
					} catch (Exception ex) {
						fweight = -1;
					}
					if ((weightValue.toLowerCase().equals("bold")) || (fweight > 400)) {
						to.addAttribute(HTML.Tag.B, SimpleAttributeSet.EMPTY);
					}
				}
			} else if (key == CSS.Attribute.FONT_STYLE) {
				String s = from.getAttribute(key).toString();
				if (s.indexOf("italic") >= 0) {
					to.addAttribute(HTML.Tag.I, SimpleAttributeSet.EMPTY);
				}
			} else if (key == CSS.Attribute.TEXT_DECORATION) {
				String decor = from.getAttribute(key).toString();
				if (decor.indexOf("underline") >= 0) {
					to.addAttribute(HTML.Tag.U, SimpleAttributeSet.EMPTY);
				}
				if (decor.indexOf("line-through") >= 0) {
					to.addAttribute(HTML.Tag.STRIKE, SimpleAttributeSet.EMPTY);
				}
			} else if (key == CSS.Attribute.VERTICAL_ALIGN) {
				String vAlign = from.getAttribute(key).toString();
				if (vAlign.indexOf("sup") >= 0) {
					to.addAttribute(HTML.Tag.SUP, SimpleAttributeSet.EMPTY);
				}
				if (vAlign.indexOf("sub") >= 0) {
					to.addAttribute(HTML.Tag.SUB, SimpleAttributeSet.EMPTY);
				}
			} else if (key == CSS.Attribute.TEXT_ALIGN) {
				to.addAttribute(HTML.Attribute.ALIGN, from.getAttribute(key).toString());
			} else {
				// default is to store in a HTML style attribute
				if (value.length() > 0) {
					value = value + "; ";
				}
				value = value + key + ": " + from.getAttribute(key);
			}
		} else {
			to.addAttribute(key, from.getAttribute(key));
		}
	}
	if (value.length() > 0) {
		to.addAttribute(HTML.Attribute.STYLE, value);
	}
}
 
開發者ID:cst316,項目名稱:spring16project-Fortran,代碼行數:74,代碼來源:AltHTMLWriter.java


注:本文中的javax.swing.text.MutableAttributeSet.addAttribute方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。