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