本文整理匯總了Java中javax.swing.text.html.StyleSheet.getStyleNames方法的典型用法代碼示例。如果您正苦於以下問題:Java StyleSheet.getStyleNames方法的具體用法?Java StyleSheet.getStyleNames怎麽用?Java StyleSheet.getStyleNames使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.swing.text.html.StyleSheet
的用法示例。
在下文中一共展示了StyleSheet.getStyleNames方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: writeStyles
import javax.swing.text.html.StyleSheet; //導入方法依賴的package包/類
/**
* Outputs the styles as a single element. Styles are not stored as
* elements, but part of the document. For the time being styles are
* written out as a comment, inside a style tag.
*/
void writeStyles(StyleSheet sheet) throws IOException {
if (sheet != null) {
Enumeration styles = sheet.getStyleNames();
if (styles != null) {
boolean outputStyle = false;
while (styles.hasMoreElements()) {
String name = (String) styles.nextElement();
// Don't write out the default style.
if (!StyleContext.DEFAULT_STYLE.equals(name)
&& writeStyle(name, sheet.getStyle(name), outputStyle)) {
outputStyle = true;
}
}
if (outputStyle) {
writeStyleEndTag();
}
}
}
}
示例2: writeStyles
import javax.swing.text.html.StyleSheet; //導入方法依賴的package包/類
/**
* Outputs the styles as a single element. Styles are not stored as
* elements, but part of the document. For the time being styles are written
* out as a comment, inside a style tag.
*/
void writeStyles(StyleSheet sheet) throws IOException {
if (sheet != null) {
Enumeration styles = sheet.getStyleNames();
if (styles != null) {
boolean outputStyle = false;
while (styles.hasMoreElements()) {
String name = (String) styles.nextElement();
// Don't write out the default style.
if (!StyleContext.DEFAULT_STYLE.equals(name)
&& writeStyle(name, sheet.getStyle(name), outputStyle)) {
outputStyle = true;
}
}
if (outputStyle) {
writeStyleEndTag();
}
}
}
}
示例3: getAllFontFamiliesInStyleSheets
import javax.swing.text.html.StyleSheet; //導入方法依賴的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: trouverProprieteCSS
import javax.swing.text.html.StyleSheet; //導入方法依賴的package包/類
public Object trouverProprieteCSS(Attribute attr, Element element) {
AttributeSet as;
Object attrValue = null;
Object style;
StyleSheet styles;
Style rule;
NRC_HTMLTag tag = null;
if (element == null)
return null;
String elementName = element.getName();
if (elementName.equals("p-implied")) {
Element parent = element.getParentElement();
return trouverProprieteCSS(attr,parent);
}
as = element.getAttributes();
// Vérifier si un attribut STYLE est spécifié avec la propriété 'attr'
if (as.isDefined(HTML.Attribute.STYLE)) {
style = as.getAttribute(HTML.Attribute.STYLE);
StyleSheet ss = new StyleSheet();
AttributeSet ssrule = ss.getDeclaration(style.toString());
if (ssrule.isDefined(attr))
attrValue = ssrule.getAttribute(attr).toString();
}
if (attrValue != null) {
return attrValue;
}
// Si ce n'est pas le cas, vérifier si un style a été défini pour
// cet élément dans une feuille de style (soit par l'élément STYLE
// au début du fichier, soit par une feuille de style externe).
styles = getStyleSheet();
tag = new NRC_HTMLTag(elementName);
rule = styles.getRule(tag, element);
if (rule != null) {
attrValue = rule.getAttribute(attr);
}
if (attrValue != null) {
return attrValue;
}
// Si ce n'est pas le cas, vérifier si un style a été défini pour cet
// élément avec un sélecteur contenant un ':'
Vector attrValuesVector = new Vector();
Pattern p = Pattern.compile("^[^:]+:");
Enumeration rules = styles.getStyleNames();
while (rules.hasMoreElements()) {
String name = (String) rules.nextElement();
Matcher mp = p.matcher(name);
rule = styles.getStyle(name);
if (mp.lookingAt()) {
attrValue = rule.getAttribute(attr);
if (attrValue != null
&& !attrValuesVector.contains(attrValue.toString()))
attrValuesVector.add(attrValue.toString());
}
}
attrValue = null;
if (attrValuesVector.size() != 0) {
StringBuffer sb = new StringBuffer();
for (int i = 0; i < attrValuesVector.size(); i++)
sb.append(attrValuesVector.elementAt(i).toString()).append(" ");
attrValue = sb.toString().trim();
}
return attrValue;
}