本文整理匯總了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;
}