当前位置: 首页>>代码示例>>Java>>正文


Java Style.getAttributeNames方法代码示例

本文整理汇总了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;
}
 
开发者ID:ser316asu,项目名称:Neukoelln_SER316,代码行数:42,代码来源:AltHTMLWriter.java

示例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;
}
 
开发者ID:cst316,项目名称:spring16project-Fortran,代码行数:41,代码来源:AltHTMLWriter.java

示例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;
}
 
开发者ID:LowResourceLanguages,项目名称:InuktitutComputing,代码行数:35,代码来源:NRC_HTMLDocument.java

示例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;
}
 
开发者ID:otros-systems,项目名称:otroslogviewer,代码行数:44,代码来源:ExportToHtml.java


注:本文中的javax.swing.text.Style.getAttributeNames方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。