javax.swing.text.AttributeSet.getAttributeNames()方法的使用及代码示例

x33g5p2x  于10个月前 转载在 其他  
字(11.6k)|赞(0)|评价(0)|浏览(26)

本文整理了Java中javax.swing.text.AttributeSet.getAttributeNames()方法的一些代码示例,展示了AttributeSet.getAttributeNames()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AttributeSet.getAttributeNames()方法的具体详情如下:
包路径:javax.swing.text.AttributeSet
类名称:AttributeSet
方法名:getAttributeNames

AttributeSet.getAttributeNames介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

private static boolean hasTargetStyle(AttributeSet attributes) {
  final List<?> attributeNames = Collections.list(attributes.getAttributeNames());

  for(Object name: attributeNames){
    if(name.equals(MY_STYLE_NAME)){
      return true;
    }
  }

  return false;
}

代码示例来源:origin: Chatanga/Girinoscope

@Nullable
  private static Object getAttribute(AttributeSet attributes, String name) {
    for (Enumeration<?> enumeration = attributes.getAttributeNames(); enumeration.hasMoreElements();) {
      Object nameKey = enumeration.nextElement();
      if (name.equals(nameKey.toString())) {
        return attributes.getAttribute(nameKey);
      }
    }
    return null;
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-gsf

private static AttributeSet adjustAttributes(AttributeSet as) {
  Collection<Object> attrs = new LinkedList<Object>();
  
  for (Enumeration<?> e = as.getAttributeNames(); e.hasMoreElements(); ) {
    Object key = e.nextElement();
    Object value = as.getAttribute(key);
    
    if (value != Boolean.FALSE) {
      attrs.add(key);
      attrs.add(value);
    }
  }
  
  return AttributesUtilities.createImmutable(attrs.toArray());
}

代码示例来源:origin: pentaho/pentaho-reporting

private HTML.Tag findTag( final AttributeSet attr ) {
 final Enumeration names = attr.getAttributeNames();
 while ( names.hasMoreElements() ) {
  final Object name = names.nextElement();
  final Object o = attr.getAttribute( name );
  if ( o instanceof HTML.Tag ) {
   if ( HTML.Tag.CONTENT == o ) {
    continue;
   }
   if ( HTML.Tag.COMMENT == o ) {
    continue;
   }
   return (HTML.Tag) o;
  }
 }
 return null;
}

代码示例来源:origin: edu.ucar/netcdf

private void extractHREF(AttributeSet attributes) {
 Enumeration e = attributes.getAttributeNames();
 while (e.hasMoreElements()) {
  Object name = e.nextElement();
  String value = (String) attributes.getAttribute(name);
  //System.out.println(" name= <"+name+ ">"+" value= <"+value+ ">");
  try {
   if (name == HTML.Attribute.HREF) {
    URL u = baseURL.toURI().resolve(value).toURL();
    String urlName = u.toString();
    if (urlList != null)
     urlList.add(u.toString());
    if (debug) System.out.println(" extracted URL= <" + urlName + ">");
   }
  } catch (MalformedURLException ex) {
   System.err.println(ex);
   System.err.println(baseURL);
   System.err.println(value);
   ex.printStackTrace();
  } catch (URISyntaxException ex) {
   System.err.println(ex);
   System.err.println(baseURL);
   System.err.println(value);
   ex.printStackTrace();
  }
 } // while
} // extractHREF

代码示例来源:origin: Unidata/thredds

private void extractHREF(AttributeSet attributes) {
 Enumeration e = attributes.getAttributeNames();
 while (e.hasMoreElements()) {
  Object name = e.nextElement();
  String value = (String) attributes.getAttribute(name);
  //System.out.println(" name= <"+name+ ">"+" value= <"+value+ ">");
  try {
   if (name == HTML.Attribute.HREF) {
    URL u = baseURL.toURI().resolve(value).toURL();
    String urlName = u.toString();
    if (urlList != null)
     urlList.add(u.toString());
    if (debug) System.out.println(" extracted URL= <" + urlName + ">");
   }
  } catch (MalformedURLException ex) {
   System.err.println(ex);
   System.err.println(baseURL);
   System.err.println(value);
   ex.printStackTrace();
  } catch (URISyntaxException ex) {
   System.err.println(ex);
   System.err.println(baseURL);
   System.err.println(value);
   ex.printStackTrace();
  }
 } // while
} // extractHREF

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-mobility-svgcore

protected static String describeElement(DocumentElement el) {
  StringBuilder sb = new StringBuilder();
  AttributeSet attrs = el.getAttributes();
  for (Enumeration names = attrs.getAttributeNames(); names.hasMoreElements();) {
    String attrName = (String) names.nextElement();
    sb.append("&nbsp;"); //NOI18N
    sb.append(attrName);
    sb.append("=\""); //NOI18N
    Object o = attrs.getAttribute(attrName);
    if ( o != null) {
      String value = o.toString();
      if (value.length() > MAX_TOOLTIP_ATTR_SIZE) {
        sb.append(value.substring(0, MAX_TOOLTIP_ATTR_SIZE));
        sb.append("..."); //NOI18N
      } else {
        sb.append(value);
      }
    }
    sb.append('"');
    sb.append("&nbsp;<br>"); //NOI18N
  }
  return sb.toString();
}

代码示例来源:origin: edu.ucar/cdm

private void extractHREF(AttributeSet attributes) {
 Enumeration e = attributes.getAttributeNames();
 while (e.hasMoreElements()) {
  Object name = e.nextElement();
  String value = (String) attributes.getAttribute(name);
  //System.out.println(" name= <"+name+ ">"+" value= <"+value+ ">");
  try {
   if (name == HTML.Attribute.HREF) {
    URL u = baseURL.toURI().resolve(value).toURL();
    String urlName = u.toString();
    if (urlList != null)
     urlList.add(u.toString());
    if (debug) System.out.println(" extracted URL= <" + urlName + ">");
   }
  } catch (MalformedURLException ex) {
   System.err.println(ex);
   System.err.println(baseURL);
   System.err.println(value);
   ex.printStackTrace();
  } catch (URISyntaxException ex) {
   System.err.println(ex);
   System.err.println(baseURL);
   System.err.println(value);
   ex.printStackTrace();
  }
 } // while
} // extractHREF

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-lexer-editorbridge

Enumeration<?> keys = attribs.getAttributeNames();
while (keys.hasMoreElements()) {
  Object key = keys.nextElement();

代码示例来源:origin: org.netbeans.api/org-netbeans-modules-mobility-svgcore

public String getAttribsText() {
  StringBuffer attribsText = new StringBuffer();
  Enumeration attrNames = getDocumentElement().getAttributes().getAttributeNames();
  if(attrNames.hasMoreElements()) {
    while(attrNames.hasMoreElements()) {
      String aname = (String)attrNames.nextElement();
      String value = (String)getDocumentElement().getAttributes().getAttribute(aname);
      attribsText.append(aname);
      attribsText.append("=\"");  //NOI18N
      attribsText.append(value);
      attribsText.append("\""); //NOI18N
      if(attrNames.hasMoreElements()) attribsText.append(", ");  //NOI18N
    }
  }
  return attribsText.toString();
}

代码示例来源:origin: org.eclipse.scout.rt/org.eclipse.scout.commons

private static void visitAttributeRec(Element elem, AttributeSet atts, IDocumentVisitor v) {
 for (Enumeration<?> en = atts.getAttributeNames(); en.hasMoreElements();) {
  Object nm = en.nextElement();
  Object value = atts.getAttribute(nm);
  if (value instanceof AttributeSet) {
   visitAttributeRec(elem, (AttributeSet) value, v);
  }
  else {
   v.visitAttribute(elem, atts, nm, value);
  }
 }
}

代码示例来源:origin: stackoverflow.com

int offset, length; //The value of the first 2 parameters in the setParagraphAttributes() call

Element section = doc.getDefaultRootElement();
int index0 = section.getElementIndex(offset);
int index1 = section.getElementIndex(offset + ((length > 0) ? length - 1 : 0));
for (int i = index0; i <= index1; i++)
{
  Element paragraph = section.getElement(i);
  AttributeSet attributeSet = paragraph.getAttributes();
  Enumeration keys = attributeSet.getAttributeNames();
  while (keys.hasMoreElements())
  {
    Object key = keys.nextElement();
    Object attribute = attributeSet.getAttribute(key);
    //System.out.println("key = " + key); //For other AttributeSet classes this line is useful because it shows the actual parameter, like "Bold"
    System.out.println(attribute.getClass());
    System.out.println(attribute);
  }
}

代码示例来源:origin: stackoverflow.com

protected void writeEmbeddedTags(AttributeSet attr) throws IOException {

  // translate css attributes to html
  attr = convertToHTML(attr, oConvAttr);

  Enumeration names = attr.getAttributeNames();
  while (names.hasMoreElements()) {
    Object name = names.nextElement();
    if (name instanceof HTML.Tag) {
      HTML.Tag tag = (HTML.Tag)name;
      if (tag == HTML.Tag.FORM || tags.contains(tag)) {
        continue;
      }
      write('<');
      write(tag.toString());//Here
      Object o = attr.getAttribute(tag);
      if (o != null && o instanceof AttributeSet) {
        writeAttributes((AttributeSet)o);
      }
      write('>');
      tags.addElement(tag);
      tagValues.addElement(o);
    }
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-kenai-ui

private void registerHTMLButton(HTMLDocument htm, String elementID, ActionListener action) {
  Element e = htm.getElement(elementID);
  if (e != null) {
    AttributeSet attr = e.getAttributes();
    Enumeration enu = attr.getAttributeNames();
    while (enu.hasMoreElements()) {
      Object name = enu.nextElement();
      Object value = attr.getAttribute(name);
      if ("model".equals(name.toString())) { //NOI18N
        final DefaultButtonModel model = (DefaultButtonModel) value;
        model.setActionCommand(elementID);
        model.addActionListener(action);
      }
    }
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-kenai-ui

private void registerHTMLButton(HTMLDocument htm, String elementID, ActionListener action) {
  Element e = htm.getElement(elementID);
  if (e != null) {
    AttributeSet attr = e.getAttributes();
    Enumeration enu = attr.getAttributeNames();
    while (enu.hasMoreElements()) {
      Object name = enu.nextElement();
      Object value = attr.getAttribute(name);
      if ("model".equals(name.toString())) { //NOI18N
        final DefaultButtonModel model = (DefaultButtonModel) value;
        model.setActionCommand(elementID);
        model.addActionListener(action);
      }
    }
  }
}

代码示例来源:origin: chatty/chatty

result.append("<b>").append(attrs.toString()).append("</b>");
result.append("<br />");
Enumeration en = attrs.getAttributeNames();
while (en.hasMoreElements()) {
  Object key = en.nextElement();

代码示例来源:origin: freeplane/freeplane

/**
 * Create an older style of HTML attributes. This will convert character
 * level attributes that have a StyleConstants mapping over to an HTML
 * tag/attribute. Other CSS attributes will be placed in an HTML style
 * attribute.
 */
private static void convertToHTML(final AttributeSet from, final MutableAttributeSet to) {
  if (from == null) {
    return;
  }
  final Enumeration<?> keys = from.getAttributeNames();
  String value = "";
  while (keys.hasMoreElements()) {
    final Object key = keys.nextElement();
    if (key instanceof CSS.Attribute) {
      if (value.length() > 0) {
        value = value + "; ";
      }
      value = value + key + ": " + from.getAttribute(key);
    }
    else {
      to.addAttribute(key, from.getAttribute(key));
    }
  }
  if (value.length() > 0) {
    to.addAttribute(HTML.Attribute.STYLE, value);
  }
}

代码示例来源:origin: org.opengis.cite.teamengine/teamengine-core

public javax.swing.text.View create(javax.swing.text.Element elem) {
    AttributeSet as = elem.getAttributes();
    HTML.Tag tag = (HTML.Tag) (as
        .getAttribute(StyleConstants.NameAttribute));
    if (tag == HTML.Tag.INPUT) {
      String type = "";
      String name = "";
      Enumeration e = as.getAttributeNames();
      while (e.hasMoreElements()) {
        Object key = e.nextElement();
        if (key == HTML.Attribute.TYPE) {
          type = as.getAttribute(key).toString();
        }
        if (key == HTML.Attribute.NAME) {
          name = as.getAttribute(key).toString();
        }
      }
      if (type.equalsIgnoreCase("submit")) {
        return new CustomFormView(elem);
      }
      if (type.equalsIgnoreCase("file")) {
        fileFields.add(name);
      }
    }
    return super.create(elem);
  }
}

代码示例来源:origin: girtel/Net2Plan

@Override
protected void writeEmbeddedTags(AttributeSet attr) throws IOException
{
  /* translate css attributes to html */
  attr = convertToHTML(attr, oConvAttr);
  Enumeration names = attr.getAttributeNames();
  while (names.hasMoreElements())
  {
    Object name = names.nextElement();
    if (name instanceof HTML.Tag)
    {
      HTML.Tag tag = (HTML.Tag) name;
      if (tag == HTML.Tag.FORM || tags.contains(tag)) continue;
      write('<');
      write(tag.toString());
      Object o = attr.getAttribute(tag);
      if (o != null && o instanceof AttributeSet) writeAttributes((AttributeSet) o);
      write('>');
      tags.add(tag);
      tagValues.add(o);
    }
  }
}

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-ui

/**
 * Searches the specified element for CLASS attribute setting
 */
private String findStyle(Element element) {
 AttributeSet as = element.getAttributes();
 if (as == null) {
  return null;
 }
 Object val = as.getAttribute(HTML.Attribute.CLASS);
 if (val != null && (val instanceof String)) {
  return (String) val;
 }
 for (Enumeration e = as.getAttributeNames(); e.hasMoreElements();) {
  Object key = e.nextElement();
  if (key instanceof HTML.Tag && as.getAttribute(key) instanceof AttributeSet) {
   AttributeSet eas = (AttributeSet) (as.getAttribute(key));
   if (eas != null) {
    val = eas.getAttribute(HTML.Attribute.CLASS);
    if (val != null) {
     return (String) val;
    }
   }
  }
 }
 return null;
}

相关文章