本文整理汇总了Java中javax.swing.text.AttributeSet.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java AttributeSet.getAttribute方法的具体用法?Java AttributeSet.getAttribute怎么用?Java AttributeSet.getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.AttributeSet
的用法示例。
在下文中一共展示了AttributeSet.getAttribute方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeEmbeddedTags
import javax.swing.text.AttributeSet; //导入方法依赖的package包/类
/**
* Searches for embedded tags in the AttributeSet
* and writes them out. It also stores these tags in a vector
* so that when appropriate the corresponding end tags can be
* written out.
*
* @exception IOException on any I/O error
*/
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.addElement(tag);
tagValues.addElement(o);
}
}
}
示例2: showInThreads
import javax.swing.text.AttributeSet; //导入方法依赖的package包/类
public void showInThreads(Instance instance) {
if (!showThreads) {
showThreads = true;
instanceToSelect = instance;
refreshSummary();
return;
}
String referenceId = String.valueOf(instance.getInstanceId());
dataArea.scrollToReference(referenceId);
Document d = dataArea.getDocument();
HTMLDocument doc = (HTMLDocument) d;
HTMLDocument.Iterator iter = doc.getIterator(HTML.Tag.A);
for (; iter.isValid(); iter.next()) {
AttributeSet a = iter.getAttributes();
String nm = (String) a.getAttribute(HTML.Attribute.NAME);
if ((nm != null) && nm.equals(referenceId)) {
dataArea.select(iter.getStartOffset(),iter.getEndOffset());
dataArea.requestFocusInWindow();
}
}
}
示例3: convertToHTML40
import javax.swing.text.AttributeSet; //导入方法依赖的package包/类
/**
* Copies the given AttributeSet to a new set, converting
* any CSS attributes found to arguments of an HTML style
* attribute.
*/
private static void convertToHTML40(AttributeSet from, MutableAttributeSet to) {
Enumeration keys = from.getAttributeNames();
String value = "";
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
if (key instanceof CSS.Attribute) {
value = value + " " + key + "=" + from.getAttribute(key) + ";";
}
else {
to.addAttribute(key, from.getAttribute(key));
}
}
if (value.length() > 0) {
to.addAttribute(HTML.Attribute.STYLE, value);
}
}
示例4: checkMaps
import javax.swing.text.AttributeSet; //导入方法依赖的package包/类
private boolean checkMaps(Map<String, AttributeSet> savedMap, Map<String, AttributeSet> currentMap) {
boolean isChanged = false;
for (String name : savedMap.keySet()) {
if (currentMap.containsKey(name)) {
AttributeSet currentAS = currentMap.get(name);
AttributeSet savedAS = savedMap.get(name);
Color currentForeground = (Color) currentAS.getAttribute(StyleConstants.Foreground);
Color savedForeground = (Color) savedAS.getAttribute(StyleConstants.Foreground);
Color currentBackground = (Color) currentAS.getAttribute(StyleConstants.Background);
Color savedBackground = (Color) savedAS.getAttribute(StyleConstants.Background);
Color currentWave = (Color) currentAS.getAttribute(EditorStyleConstants.WaveUnderlineColor);
Color savedWave = (Color) savedAS.getAttribute(EditorStyleConstants.WaveUnderlineColor);
isChanged |= (currentForeground == null ? savedForeground != null : !currentForeground.equals(savedForeground))
|| (currentBackground == null ? savedBackground != null : !currentBackground.equals(savedBackground))
|| (currentWave == null ? savedWave != null : !currentWave.equals(savedWave));
if(isChanged) { // no need to iterate further
return true;
}
}
}
return isChanged;
}
示例5: Highlighting
import javax.swing.text.AttributeSet; //导入方法依赖的package包/类
/** Creates a new instance of Highlighting */
public Highlighting(Document doc) {
AttributeSet firstLineFontColor = MimeLookup.getLookup(MimePath.get("text/x-java")).lookup(FontColorSettings.class).getTokenFontColors("javadoc-first-sentence"); //NOI18N
AttributeSet commentFontColor = MimeLookup.getLookup(MimePath.get("text/x-java")).lookup(FontColorSettings.class).getTokenFontColors("comment"); //NOI18N
if(firstLineFontColor != null && commentFontColor != null) {
Collection<Object> attrs = new LinkedList<Object>();
for (Enumeration<?> e = firstLineFontColor.getAttributeNames(); e.hasMoreElements(); ) {
Object key = e.nextElement();
Object value = firstLineFontColor.getAttribute(key);
if (!commentFontColor.containsAttribute(key, value)) {
attrs.add(key);
attrs.add(value);
}
}
fontColor = AttributesUtilities.createImmutable(attrs.toArray());
} else {
fontColor = AttributesUtilities.createImmutable();
LOG.warning("FontColorSettings for javadoc-first-sentence or comment are not available."); //NOI18N
}
this.document = doc;
hierarchy = TokenHierarchy.get(document);
if (hierarchy != null) {
hierarchy.addTokenHierarchyListener(WeakListeners.create(TokenHierarchyListener.class, this, hierarchy));
}
}
示例6: createRegionContainment
import javax.swing.text.AttributeSet; //导入方法依赖的package包/类
/**
* Creates and returns an instance of RegionContainment that can be
* used to test if a particular point lies inside a region.
*/
protected RegionContainment createRegionContainment(AttributeSet attributes) {
Object shape = attributes.getAttribute(HTML.Attribute.SHAPE);
if (shape == null) {
shape = "rect";
}
if (shape instanceof String) {
String shapeString = ((String) shape).toLowerCase();
RegionContainment rc = null;
try {
if (shapeString.equals("rect")) {
rc = new RectangleRegionContainment(attributes);
}
else if (shapeString.equals("circle")) {
rc = new CircleRegionContainment(attributes);
}
else if (shapeString.equals("poly")) {
rc = new PolygonRegionContainment(attributes);
}
else if (shapeString.equals("default")) {
rc = DefaultRegionContainment.sharedInstance();
}
}
catch (RuntimeException re) {
// Something wrong with attributes.
rc = null;
}
return rc;
}
return null;
}
示例7: matchNameAttribute
import javax.swing.text.AttributeSet; //导入方法依赖的package包/类
/**
* Returns true if the StyleConstants.NameAttribute is
* equal to the tag that is passed in as a parameter.
*/
protected boolean matchNameAttribute(AttributeSet attr, HTML.Tag tag) {
Object o = attr.getAttribute(StyleConstants.NameAttribute);
if (o instanceof HTML.Tag) {
HTML.Tag name = (HTML.Tag) o;
if (name == tag) {
return true;
}
}
return false;
}
示例8: if
import javax.swing.text.AttributeSet; //导入方法依赖的package包/类
/**
* Creates and returns an instance of RegionContainment that can be
* used to test if a particular point lies inside a region.
*/
protected RegionContainment createRegionContainment
(AttributeSet attributes) {
Object shape = attributes.getAttribute(HTML.Attribute.SHAPE);
if (shape == null) {
shape = "rect";
}
if (shape instanceof String) {
String shapeString = ((String)shape).toLowerCase();
RegionContainment rc = null;
try {
if (shapeString.equals("rect")) {
rc = new RectangleRegionContainment(attributes);
}
else if (shapeString.equals("circle")) {
rc = new CircleRegionContainment(attributes);
}
else if (shapeString.equals("poly")) {
rc = new PolygonRegionContainment(attributes);
}
else if (shapeString.equals("default")) {
rc = DefaultRegionContainment.sharedInstance();
}
} catch (RuntimeException re) {
// Something wrong with attributes.
rc = null;
}
return rc;
}
return null;
}
示例9: containsAttributes
import javax.swing.text.AttributeSet; //导入方法依赖的package包/类
@Override
public boolean containsAttributes(AttributeSet attributes) {
for(Enumeration<?> keys = attributes.getAttributeNames(); keys.hasMoreElements(); ) {
Object key = keys.nextElement();
Object value = attributes.getAttribute(key);
if (!containsAttribute(key, value)) {
return false;
}
}
return true;
}
示例10: getName
import javax.swing.text.AttributeSet; //导入方法依赖的package包/类
/** Get element name if defined */
public String getName() {
AttributeSet as = attrs;
if (as != null && as.isDefined(ElementNameAttribute)) {
return (String)as.getAttribute(ElementNameAttribute);
} else {
return null;
}
}
示例11: isBlockTag
import javax.swing.text.AttributeSet; //导入方法依赖的package包/类
/**
* Determines if the HTML.Tag associated with the
* element is a block tag.
*
* @param attr an AttributeSet
* @return true if tag is block tag, false otherwise.
*/
protected boolean isBlockTag(AttributeSet attr) {
Object o = attr.getAttribute(StyleConstants.NameAttribute);
if (o instanceof HTML.Tag) {
HTML.Tag name = (HTML.Tag) o;
return name.isBlock();
}
return false;
}
示例12: refreshUI
import javax.swing.text.AttributeSet; //导入方法依赖的package包/类
private void refreshUI () {
int index = lCategories.getSelectedIndex ();
if (index < 0) {
// no category selected
cbForeground.setEnabled (false);
cbBackground.setEnabled (false);
cbEffectColor.setEnabled (false);
return;
}
cbForeground.setEnabled (true);
cbBackground.setEnabled (true);
cbEffectColor.setEnabled (true);
listen = false;
// set defaults
AttributeSet defAs = getDefaultColoring();
if (defAs != null) {
Color inheritedForeground = (Color) defAs.getAttribute(StyleConstants.Foreground);
if (inheritedForeground == null) {
inheritedForeground = Color.black;
}
ColorComboBoxSupport.setInheritedColor((ColorComboBox)cbForeground, inheritedForeground);
Color inheritedBackground = (Color) defAs.getAttribute(StyleConstants.Background);
if (inheritedBackground == null) {
inheritedBackground = Color.white;
}
ColorComboBoxSupport.setInheritedColor((ColorComboBox)cbBackground, inheritedBackground);
}
// set values
List<AttributeSet> annotations = getAnnotations (currentScheme);
AttributeSet c = annotations.get (index);
ColorComboBoxSupport.setSelectedColor( (ColorComboBox)cbForeground, (Color) c.getAttribute (StyleConstants.Foreground));
ColorComboBoxSupport.setSelectedColor( (ColorComboBox)cbBackground, (Color) c.getAttribute (StyleConstants.Background));
if (c.getAttribute(EditorStyleConstants.WaveUnderlineColor) != null) {
cbEffects.setSelectedIndex(1);
cbEffectColor.setEnabled(true);
((ColorComboBox)cbEffectColor).setSelectedColor((Color) c.getAttribute (EditorStyleConstants.WaveUnderlineColor));
} else {
cbEffects.setSelectedIndex(0);
cbEffectColor.setEnabled(false);
cbEffectColor.setSelectedIndex(-1);
}
listen = true;
}
示例13: convertToHTML32
import javax.swing.text.AttributeSet; //导入方法依赖的package包/类
/**
* 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 convertToHTML32(AttributeSet from, MutableAttributeSet to) {
if (from == null) {
return;
}
Enumeration keys = from.getAttributeNames();
String value = "";
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
if (key instanceof CSS.Attribute) {
if ((key == CSS.Attribute.FONT_FAMILY)
|| (key == CSS.Attribute.FONT_SIZE)
|| (key == CSS.Attribute.COLOR)) {
createFontAttribute((CSS.Attribute) key, from, to);
}
else if (key == CSS.Attribute.FONT_WEIGHT) {
// add a bold tag is weight is bold
//CSS.FontWeight weightValue = (CSS.FontWeight) from.getAttribute(CSS.Attribute.FONT_WEIGHT);
String weightValue = from.getAttribute(CSS.Attribute.FONT_WEIGHT).toString();
if (weightValue != null) {
int fweight;
try {
fweight = new Integer(weightValue).intValue();
}
catch (Exception ex) {
fweight = -1;
}
if ((weightValue.toLowerCase().equals("bold")) || (fweight > 400))
to.addAttribute(HTML.Tag.B, SimpleAttributeSet.EMPTY);
}
}
else if (key == CSS.Attribute.FONT_STYLE) {
String s = from.getAttribute(key).toString();
if (s.indexOf("italic") >= 0) {
to.addAttribute(HTML.Tag.I, SimpleAttributeSet.EMPTY);
}
}
else if (key == CSS.Attribute.TEXT_DECORATION) {
String decor = from.getAttribute(key).toString();
if (decor.indexOf("underline") >= 0) {
to.addAttribute(HTML.Tag.U, SimpleAttributeSet.EMPTY);
}
if (decor.indexOf("line-through") >= 0) {
to.addAttribute(HTML.Tag.STRIKE, SimpleAttributeSet.EMPTY);
}
}
else if (key == CSS.Attribute.VERTICAL_ALIGN) {
String vAlign = from.getAttribute(key).toString();
if (vAlign.indexOf("sup") >= 0) {
to.addAttribute(HTML.Tag.SUP, SimpleAttributeSet.EMPTY);
}
if (vAlign.indexOf("sub") >= 0) {
to.addAttribute(HTML.Tag.SUB, SimpleAttributeSet.EMPTY);
}
}
else if (key == CSS.Attribute.TEXT_ALIGN) {
to.addAttribute(HTML.Attribute.ALIGN, from.getAttribute(key).toString());
}
else {
// default is to store in a HTML style 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);
}
}
示例14: emptyTag
import javax.swing.text.AttributeSet; //导入方法依赖的package包/类
/**
* Writes out all empty elements (all tags that have no
* corresponding end tag).
*
* @param elem an Element
* @exception IOException on any I/O error
* @exception BadLocationException if pos represents an invalid
* location within the document.
*/
protected void emptyTag(Element elem) throws BadLocationException, IOException {
if (!inContent && !inPre) {
indent();
}
AttributeSet attr = elem.getAttributes();
closeOutUnwantedEmbeddedTags(attr);
writeEmbeddedTags(attr);
if (matchNameAttribute(attr, HTML.Tag.CONTENT)) {
inContent = true;
text(elem);
}
else if (matchNameAttribute(attr, HTML.Tag.COMMENT)) {
comment(elem);
}
else {
boolean isBlock = isBlockTag(elem.getAttributes());
if (inContent && isBlock) {
writeLineSeparator();
indent();
}
Object nameTag = (attr != null) ? attr.getAttribute(StyleConstants.NameAttribute) : null;
Object endTag = (attr != null) ? attr.getAttribute(HTML.Attribute.ENDTAG) : null;
boolean outputEndTag = false;
// If an instance of an UNKNOWN Tag, or an instance of a
// tag that is only visible during editing
//
if (nameTag != null && endTag != null && (endTag instanceof String) && ((String) endTag).equals("true")) {
outputEndTag = true;
}
if (completeDoc && matchNameAttribute(attr, HTML.Tag.HEAD)) {
if (outputEndTag) {
// Write out any styles.
writeStyles(((HTMLDocument) getDocument()).getStyleSheet());
}
wroteHead = true;
}
write('<');
if (outputEndTag) {
write('/');
}
write(elem.getName());
writeAttributes(attr);
write('>');
if (matchNameAttribute(attr, HTML.Tag.TITLE) && !outputEndTag) {
Document doc = elem.getDocument();
String title = (String) doc.getProperty(Document.TitleProperty);
write(title);
}
else if (!inContent || isBlock) {
writeLineSeparator();
if (isBlock && inContent) {
indent();
}
}
}
}