本文整理汇总了Java中javax.swing.text.SimpleAttributeSet.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java SimpleAttributeSet.getAttribute方法的具体用法?Java SimpleAttributeSet.getAttribute怎么用?Java SimpleAttributeSet.getAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.SimpleAttributeSet
的用法示例。
在下文中一共展示了SimpleAttributeSet.getAttribute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hyperlinkUpdate
import javax.swing.text.SimpleAttributeSet; //导入方法依赖的package包/类
@Override
public void hyperlinkUpdate(final HyperlinkEvent e) {
if (!HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
return;
}
BugTrackingAccessor accessor = Lookup.getDefault().lookup(BugTrackingAccessor.class);
if (accessor != null){
AttributeSet ats = e.getSourceElement().getAttributes();
Object attribute = ats.getAttribute(HTML.getTag("a"));
if (attribute instanceof SimpleAttributeSet) {
SimpleAttributeSet attributeSet = (SimpleAttributeSet) attribute;
Object bugId = attributeSet.getAttribute(HTML.getAttributeKey("id"));
if (bugId != null){
try{
Integer.parseInt(bugId.toString());
LOG.log(Level.FINE, "Open issue {0}", bugId);
accessor.openIssue(bugId.toString());
return;
}catch(NumberFormatException nfe){
LOG.log(Level.INFO, "Invalid id attribute", nfe);
}
}
}
} else {
LOG.log(Level.INFO, "Bugzilla Accessor not found");
}
RP.post(new Runnable(){
@Override
public void run() {
HtmlBrowser.URLDisplayer.getDefault().showURL(e.getURL());
}
});
}
示例2: appendLineForBatch
import javax.swing.text.SimpleAttributeSet; //导入方法依赖的package包/类
/**
* Stores the given {@link String} line for the next batch update. If the number of elements
* awaiting batch update are >= maxRows, will discard the oldest element. Call
* {@link #executeBatch(int)} or {@link #executeBatchAppend()} to execute the batch update.
* <p>
* <strong>Attention:</strong> Every {@link String} is considered as one line so a line
* separator will be added into the document after it.
* </p>
* <p>
* This method is thread safe.
* </p>
*
* @param str
* the {@link String} to add to the document.
* @param a
* the style formatting settings
*/
public void appendLineForBatch(String str, SimpleAttributeSet a) {
if (str == null || str.isEmpty()) {
throw new IllegalArgumentException("str must not be null or empty!");
}
if (!str.endsWith(System.lineSeparator())) {
str += System.lineSeparator();
}
char[] txt = str.toCharArray();
a = a != null ? (SimpleAttributeSet) a.copyAttributes() : new SimpleAttributeSet();
// set font family if not set
if (a.getAttribute(StyleConstants.FontFamily) == null) {
StyleConstants.setFontFamily(a, DEFAULT_FONT_FAMILY);
}
synchronized (LOCK) {
// make sure batch size does not exceed maxRows *3 (*3 because we add the str and 2 line
// separator tags)
if (maxRows > 0) {
while (listToInsert.size() >= maxRows * 3) {
// remove element itself and both line separator elements)
// we start at the beginning because we discard oldest first
listToInsert.removeFirst();
listToInsert.removeFirst();
listToInsert.removeFirst();
lineLength.removeFirst();
}
}
// close previous paragraph tag, start new one, add text
// yes the order is correct; no you cannot change to start/text/end
// if you do, linebreaks get messed up
listToInsert.add(new ElementSpec(new SimpleAttributeSet(), ElementSpec.EndTagType));
listToInsert.add(new ElementSpec(new SimpleAttributeSet(), ElementSpec.StartTagType));
listToInsert.add(new ElementSpec(a, ElementSpec.ContentType, txt, 0, txt.length));
// store length of each row we add
lineLength.add(txt.length);
}
}
示例3: handleEmptyTag
import javax.swing.text.SimpleAttributeSet; //导入方法依赖的package包/类
/**
* Handle Empty Tag.
*/
protected void handleEmptyTag(TagElement tag) throws ChangedCharSetException {
Element elem = tag.getElement();
if (elem == dtd.meta && !ignoreCharSet) {
SimpleAttributeSet atts = getAttributes();
if (atts != null) {
String content = (String)atts.getAttribute(HTML.Attribute.CONTENT);
if (content != null) {
if ("content-type".equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
if (!content.equalsIgnoreCase("text/html") &&
!content.equalsIgnoreCase("text/plain")) {
throw new ChangedCharSetException(content, false);
}
} else if ("charset" .equalsIgnoreCase((String)atts.getAttribute(HTML.Attribute.HTTPEQUIV))) {
throw new ChangedCharSetException(content, true);
}
}
}
}
if (inbody != 0 || elem == dtd.meta || elem == dtd.base || elem == dtd.isindex || elem == dtd.style || elem == dtd.link) {
if (debugFlag) {
if (tag.fictional()) {
debug("Empty Tag: " + tag.getHTMLTag() + " pos: " + getCurrentPos());
} else {
debug("Empty Tag: " + tag.getHTMLTag() + " attributes: "
+ getAttributes() + " pos: " + getCurrentPos());
}
}
if (tag.fictional()) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
attrs.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,
Boolean.TRUE);
callback.handleSimpleTag(tag.getHTMLTag(), attrs,
getBlockStartPosition());
} else {
callback.handleSimpleTag(tag.getHTMLTag(), getAttributes(),
getBlockStartPosition());
flushAttributes();
}
}
}