本文整理汇总了Java中javax.swing.text.Style.getAttributeNames方法的典型用法代码示例。如果您正苦于以下问题:Java Style.getAttributeNames方法的具体用法?Java Style.getAttributeNames怎么用?Java Style.getAttributeNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.Style
的用法示例。
在下文中一共展示了Style.getAttributeNames方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeStyle
import javax.swing.text.Style; //导入方法依赖的package包/类
/**
* Outputs the named style. <code>outputStyle</code> indicates
* whether or not a style has been output yet. This will return
* true if a style is written.
*/
boolean writeStyle(String name, Style style, boolean outputStyle) throws IOException {
boolean didOutputStyle = false;
Enumeration attributes = style.getAttributeNames();
if (attributes != null) {
while (attributes.hasMoreElements()) {
Object attribute = attributes.nextElement();
if (attribute instanceof CSS.Attribute) {
String value = style.getAttribute(attribute).toString();
if (value != null) {
if (!outputStyle) {
writeStyleStartTag();
outputStyle = true;
}
if (!didOutputStyle) {
didOutputStyle = true;
indent();
write(name);
write(" {");
}
else {
write(";");
}
write(' ');
write(attribute.toString());
write(": ");
write(value);
}
}
}
}
if (didOutputStyle) {
write(" }");
writeLineSeparator();
}
return didOutputStyle;
}
示例2: writeStyle
import javax.swing.text.Style; //导入方法依赖的package包/类
/**
* Outputs the named style. <code>outputStyle</code> indicates whether or
* not a style has been output yet. This will return true if a style is
* written.
*/
boolean writeStyle(String name, Style style, boolean outputStyle) throws IOException {
boolean didOutputStyle = false;
Enumeration attributes = style.getAttributeNames();
if (attributes != null) {
while (attributes.hasMoreElements()) {
Object attribute = attributes.nextElement();
if (attribute instanceof CSS.Attribute) {
String value = style.getAttribute(attribute).toString();
if (value != null) {
if (!outputStyle) {
writeStyleStartTag();
outputStyle = true;
}
if (!didOutputStyle) {
didOutputStyle = true;
indent();
write(name);
write(" {");
} else {
write(";");
}
write(' ');
write(attribute.toString());
write(": ");
write(value);
}
}
}
}
if (didOutputStyle) {
write(" }");
writeLineSeparator();
}
return didOutputStyle;
}
示例3: getAllFontFamiliesInStyleSheets
import javax.swing.text.Style; //导入方法依赖的package包/类
public String[] getAllFontFamiliesInStyleSheets() {
Vector families = new Vector();
StyleSheet styles = getStyleSheet();
Enumeration styleNames = styles.getStyleNames();
while (styleNames.hasMoreElements()) {
String name = (String) styleNames.nextElement();
Style style = styles.getStyle(name);
Enumeration attrNames = style.getAttributeNames();
while (attrNames.hasMoreElements()) {
Object n = attrNames.nextElement();
if (n.toString().equals("resolver")) {
Style nst = (Style) style.getAttribute(n);
Enumeration nAttrNames = nst.getAttributeNames();
while (nAttrNames.hasMoreElements()) {
Object nAttrName = nAttrNames.nextElement();
if (nAttrName.toString().toLowerCase().equals(
"font-family")) {
Object value = nst.getAttribute(nAttrName);
String values[] = value.toString().toLowerCase()
.split(",");
for (int i = 0; i < values.length; i++) {
String val = values[i].trim();
if (!families.contains(val))
families.add(val);
}
}
}
}
}
}
String[] familiesArray = (String[]) families.toArray(new String[] {});
Arrays.sort(familiesArray);
return familiesArray;
}
示例4: styleToCssMap
import javax.swing.text.Style; //导入方法依赖的package包/类
protected Map<String, String> styleToCssMap(MessageFragmentStyle mfs) {
Style style = mfs.getStyle();
HashMap<String, Object> attributes = new HashMap<>();
Enumeration<?> attributeNames = style.getAttributeNames();
while (attributeNames.hasMoreElements()) {
Object nextElement = attributeNames.nextElement();
attributes.put(nextElement.toString(),
style.getAttribute(nextElement));
}
Map<String, String> cssMap = new HashMap<>();
if (attributes.get("family") != null) {
cssMap.put("font-family", String.format("'%s'", StyleConstants.getFontFamily(style)));
}
if (attributes.get("size") != null) {
cssMap.put("font-size", Integer.toString(StyleConstants.getFontSize(style)));
}
if (attributes.get("foreground") != null) {
cssMap.put("color", colorToHex(StyleConstants.getForeground(style)));
}
if (attributes.get("background") != null) {
cssMap.put("background-color", colorToHex(StyleConstants.getBackground(style)));
}
if (attributes.get("bold") != null) {
cssMap.put("font-weight", StyleConstants.isBold(style) ? "bold" : "normal");
}
if (attributes.get("italic") != null) {
cssMap.put("font-style", StyleConstants.isItalic(style) ? "italic" : "normal");
}
if (attributes.get("underline") != null) {
cssMap.put("text-decoration", StyleConstants.isItalic(style) ? "underline" : "none");
}
return cssMap;
}