當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。