Search in sources :

Example 6 with SimpleAttributeSet

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);
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet)

Example 7 with SimpleAttributeSet

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);
    }
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) User(lib.pircbot.User) Message(irc.message.Message) Subscriber(irc.Subscriber)

Example 8 with SimpleAttributeSet

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;
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet)

Example 9 with SimpleAttributeSet

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;
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) java.util(java.util) CombinedChatPane(gui.CombinedChatPane) URL(java.net.URL) SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) Settings(util.settings.Settings) StyleConstants(javax.swing.text.StyleConstants) User(lib.pircbot.User) java.awt(java.awt) Matcher(java.util.regex.Matcher) java.io(java.io) Charset(java.nio.charset.Charset) GUIMain(gui.forms.GUIMain) ConsoleCommand(util.comm.ConsoleCommand) Command(util.comm.Command) URI(java.net.URI) Pattern(java.util.regex.Pattern) ChatPane(gui.ChatPane) HTML(javax.swing.text.html.HTML)

Example 10 with SimpleAttributeSet

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();
        }
    }
}
Also used : SimpleAttributeSet(javax.swing.text.SimpleAttributeSet) ChangedCharSetException(javax.swing.text.ChangedCharSetException)

Aggregations

SimpleAttributeSet (javax.swing.text.SimpleAttributeSet)28 StyledDocument (javax.swing.text.StyledDocument)5 AttributeSet (javax.swing.text.AttributeSet)3 BadLocationException (javax.swing.text.BadLocationException)3 HTML (javax.swing.text.html.HTML)3 User (lib.pircbot.User)3 URL (java.net.URL)2 Matcher (java.util.regex.Matcher)2 Pattern (java.util.regex.Pattern)2 Document (javax.swing.text.Document)2 HTMLDocument (javax.swing.text.html.HTMLDocument)2 ColorSet (com.android.tools.sherpa.drawing.ColorSet)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 Project (com.intellij.openapi.project.Project)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 HyperlinkAdapter (com.intellij.ui.HyperlinkAdapter)1 Icons (face.Icons)1 ChatPane (gui.ChatPane)1 CombinedChatPane (gui.CombinedChatPane)1 GUIMain (gui.forms.GUIMain)1