use of javax.swing.text.SimpleAttributeSet in project pcgen by PCGen.
the class ExtendedHTMLEditorKit method removeAttributeByKey.
/**
* Remove attribute by key
* @param sourceAS
* @param removeKey
* @return attribute set
*/
private static SimpleAttributeSet removeAttributeByKey(SimpleAttributeSet sourceAS, String removeKey) {
SimpleAttributeSet temp = new SimpleAttributeSet();
temp.addAttribute(removeKey, "NULL");
return removeAttribute(sourceAS, temp);
}
use of javax.swing.text.SimpleAttributeSet in project Botnak by Gocnak.
the class ChatPane method onMessage.
/**
* This is the main message method when somebody sends a message to the channel.
*
* @param m The message from the chat.
*/
public void onMessage(MessageWrapper m, boolean showChannel) {
if (textPane == null)
return;
Message message = m.getLocal();
String sender = message.getSender().toLowerCase();
String channel = message.getChannel();
String mess = message.getContent();
boolean isMe = (message.getType() == Message.MessageType.ACTION_MESSAGE);
try {
print(m, "\n" + getTime(), GUIMain.norm);
User u = Settings.channelManager.getUser(sender, true);
SimpleAttributeSet user = getUserSet(u);
if (channel.substring(1).equals(sender)) {
insertIcon(m, IconEnum.BROADCASTER, null);
}
if (u.isOp(channel)) {
if (!channel.substring(1).equals(sender) && !u.isStaff() && !u.isAdmin() && !u.isGlobalMod()) {
//not the broadcaster again
insertIcon(m, IconEnum.MOD, null);
}
}
if (u.isGlobalMod()) {
insertIcon(m, IconEnum.GLOBAL_MOD, null);
}
if (u.isStaff()) {
insertIcon(m, IconEnum.STAFF, null);
}
if (u.isAdmin()) {
insertIcon(m, IconEnum.ADMIN, null);
}
boolean isSubscriber = u.isSubscriber(channel);
if (isSubscriber) {
insertIcon(m, IconEnum.SUBSCRIBER, channel);
} else {
if (Utils.isMainChannel(channel)) {
Optional<Subscriber> sub = Settings.subscriberManager.getSubscriber(sender);
if (sub.isPresent() && !sub.get().isActive()) {
insertIcon(m, IconEnum.EX_SUBSCRIBER, channel);
}
}
}
if (u.isTurbo()) {
insertIcon(m, IconEnum.TURBO, null);
}
if (u.isPrime())
insertIcon(m, IconEnum.PRIME, null);
//Cheering
int cheerTotal = u.getCheer(channel);
if (cheerTotal > 0) {
insertIcon(m, Donor.getCheerStatus(cheerTotal), null);
}
// Third party donor
if (Settings.showDonorIcons.getValue()) {
if (u.isDonor()) {
insertIcon(m, u.getDonationStatus(), null);
}
}
//name stuff
print(m, " ", GUIMain.norm);
SimpleAttributeSet userColor = new SimpleAttributeSet(user);
FaceManager.handleNameFaces(sender, user);
if (showChannel) {
print(m, determineName(u), user);
print(m, " (" + channel.substring(1) + ")" + (isMe ? " " : ": "), GUIMain.norm);
} else {
print(m, determineName(u), user);
print(m, (!isMe ? ": " : " "), userColor);
}
//keyword?
SimpleAttributeSet set;
if (Utils.mentionsKeyword(mess)) {
set = Utils.getSetForKeyword(mess);
} else {
set = (isMe ? userColor : GUIMain.norm);
}
//URL, Faces, rest of message
printMessage(m, mess, set, u);
if (BotnakTrayIcon.shouldDisplayMentions() && !Utils.isTabSelected(index)) {
if (mess.toLowerCase().contains(Settings.accountManager.getUserAccount().getName().toLowerCase())) {
GUIMain.getSystemTrayIcon().displayMention(m.getLocal());
}
}
if (Utils.isMainChannel(channel))
//check status of the sub, has it been a month?
Settings.subscriberManager.updateSubscriber(u, channel, isSubscriber);
if (shouldPulse())
GUIMain.instance.pulseTab(this);
} catch (Exception e) {
GUIMain.log(e);
}
}
use of javax.swing.text.SimpleAttributeSet in project Botnak by Gocnak.
the class Utils method URLStyle.
/**
* Returns the SimpleAttributeSet for a specified URL.
*
* @param URL The link to make into a URL.
* @return The SimpleAttributeSet of the URL.
*/
public static SimpleAttributeSet URLStyle(String URL) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
StyleConstants.setForeground(attrs, new Color(43, 162, 235));
StyleConstants.setFontFamily(attrs, Settings.font.getValue().getFamily());
StyleConstants.setFontSize(attrs, Settings.font.getValue().getSize());
StyleConstants.setUnderline(attrs, true);
attrs.addAttribute(HTML.Attribute.HREF, URL);
return attrs;
}
use of javax.swing.text.SimpleAttributeSet in project Botnak by Gocnak.
the class Utils method getSetForKeyword.
/**
* Gets the SimpleAttributeSet with the correct color for the message.
* Cycles through all of the keywords, so the first keyword it matches is the color.
*
* @param message The message to dissect.
* @return The set with the correct color.
*/
public static SimpleAttributeSet getSetForKeyword(String message) {
SimpleAttributeSet setToRet = new SimpleAttributeSet(GUIMain.norm);
Set<String> keys = GUIMain.keywordMap.keySet();
//case doesnt matter
keys.stream().filter(s -> message.toLowerCase().contains(s.toLowerCase())).forEach(s -> StyleConstants.setForeground(setToRet, GUIMain.keywordMap.get(s)));
return setToRet;
}
use of javax.swing.text.SimpleAttributeSet in project jdk8u_jdk by JetBrains.
the class DocumentParser method handleEmptyTag.
/**
* 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();
}
}
}
Aggregations