Search in sources :

Example 1 with CombinedChatPane

use of gui.CombinedChatPane in project Botnak by Gocnak.

the class GUIStreams method addStreamButtonActionPerformed.

public void addStreamButtonActionPerformed() {
    String text = Utils.checkText(newChannel.getText());
    if (!text.isEmpty()) {
        if (text.contains(",")) {
            String[] channels = text.split(",");
            ArrayList<ChatPane> panes = new ArrayList<>();
            for (String channel : channels) {
                channel = channel.trim().toLowerCase();
                if (channel.equals(""))
                    continue;
                //create the ChatPane but do not add to the tabbed pane
                if (GUIMain.chatPanes.containsKey(channel)) {
                    //if the pane exists just use it, no need to create multiple
                    panes.add(GUIMain.getChatPane(channel));
                //note: since they're adding the combined tab and the tab
                //already exists, they know full well that it does, so
                //we're not removing/setting visible to false for the tab
                } else {
                    ChatPane cp = ChatPane.createPane(channel);
                    //the tab will not be added to the tabbed pane and therefore invisible
                    cp.setTabVisible(false);
                    if (GUIMain.viewer != null)
                        GUIMain.viewer.doConnect(channel);
                    if (GUIMain.bot != null)
                        GUIMain.bot.doConnect(channel);
                    GUIMain.channelSet.add(channel);
                    GUIMain.chatPanes.put(cp.getChannel(), cp);
                    panes.add(cp);
                }
            }
            CombinedChatPane ccp = CombinedChatPane.createCombinedChatPane(panes.toArray(new ChatPane[panes.size()]));
            GUIMain.channelPane.insertTab(ccp.getTabTitle(), null, ccp.getScrollPane(), null, GUIMain.channelPane.getTabCount() - 1);
            GUIMain.combinedChatPanes.add(ccp);
        } else {
            String channel = text.toLowerCase();
            if (!channel.isEmpty() && !channel.contains(" ") && !GUIMain.chatPanes.containsKey(channel)) {
                ChatPane cp = ChatPane.createPane(channel);
                if (GUIMain.viewer != null)
                    GUIMain.viewer.doConnect(channel);
                if (GUIMain.bot != null)
                    GUIMain.bot.doConnect(channel);
                GUIMain.chatPanes.put(cp.getChannel(), cp);
                GUIMain.channelSet.add(channel);
                GUIMain.channelPane.insertTab(cp.getChannel(), null, cp.getScrollPane(), null, cp.getIndex());
            }
        }
    }
    GUIMain.channelPane.updateIndexes();
    newChannel.setText("");
    parseFollowed();
}
Also used : CombinedChatPane(gui.CombinedChatPane) ChatPane(gui.ChatPane) CombinedChatPane(gui.CombinedChatPane) ArrayList(java.util.ArrayList)

Example 2 with CombinedChatPane

use of gui.CombinedChatPane in project Botnak by Gocnak.

the class ListenerName method mouseReleased.

@Override
public void mouseReleased(MouseEvent e) {
    JTextPane textPane = (JTextPane) e.getSource();
    Point pt = new Point(e.getX(), e.getY());
    int pos = textPane.viewToModel(pt);
    try {
        Rectangle rect = textPane.modelToView(pos);
        int lowerCorner = rect.y + rect.height;
        if (e.getX() < rect.x && e.getY() < lowerCorner && pos > 0) {
            pos--;
        }
    } catch (BadLocationException ex) {
        GUIMain.log(ex);
    }
    if (pos >= 0) {
        Document doc = textPane.getDocument();
        if (doc instanceof DefaultStyledDocument) {
            ChatPane cp = Utils.getChatPane(GUIMain.channelPane.getSelectedIndex());
            CombinedChatPane ccp = Utils.getCombinedChatPane(GUIMain.channelPane.getSelectedIndex());
            String channel = (cp != null ? cp.getChannel() : (ccp != null ? ccp.getActiveChannel() : ""));
            DefaultStyledDocument hdoc = (DefaultStyledDocument) doc;
            Element el = hdoc.getCharacterElement(pos);
            AttributeSet a = el.getAttributes();
            String name = (String) a.getAttribute(HTML.Attribute.NAME);
            if (name != null) {
                createUserPopup(channel, name, textPane, e.getX(), e.getY());
            }
        }
    }
}
Also used : CombinedChatPane(gui.CombinedChatPane) ChatPane(gui.ChatPane) CombinedChatPane(gui.CombinedChatPane)

Example 3 with CombinedChatPane

use of gui.CombinedChatPane in project Botnak by Gocnak.

the class GUIMain method chatButtonActionPerformed.

public void chatButtonActionPerformed() {
    userResponsesIndex = 0;
    String channel = channelPane.getTitleAt(channelPane.getSelectedIndex());
    if (Settings.accountManager.getViewer() == null)
        return;
    if (!Settings.accountManager.getViewer().isConnected()) {
        logCurrent("Failed to send message, currently trying to reconnect!");
        return;
    }
    String userInput = Utils.checkText(userChat.getText().replaceAll("\n", ""));
    if (channel != null && !channel.equalsIgnoreCase("system logs")) {
        CombinedChatPane ccp = Utils.getCombinedChatPane(channelPane.getSelectedIndex());
        boolean comboExists = ccp != null;
        if (comboExists) {
            String[] channels;
            if (!ccp.getActiveChannel().equalsIgnoreCase("All")) {
                channels = new String[] { ccp.getActiveChannel() };
            } else {
                channels = ccp.getChannels();
            }
            if (!"".equals(userInput)) {
                for (String c : channels) {
                    Settings.accountManager.getViewer().sendMessage("#" + c, userInput);
                }
                if (!userResponses.contains(userInput))
                    userResponses.add(userInput);
            }
            userChat.setText("");
        } else {
            if (!"".equals(userInput)) {
                Settings.accountManager.getViewer().sendMessage("#" + channel, userInput);
                if (!userResponses.contains(userInput))
                    userResponses.add(userInput);
            }
            userChat.setText("");
        }
    }
}
Also used : CombinedChatPane(gui.CombinedChatPane)

Example 4 with CombinedChatPane

use of gui.CombinedChatPane in project Botnak by Gocnak.

the class MessageQueue method addMessage.

public static void addMessage(Message mess) {
    if (mess != null && mess.getType() != null) {
        pool.execute(() -> {
            MessageWrapper wrap = new MessageWrapper(mess);
            try {
                //try catch for security, if one message fails, we still want to receive messages
                switch(mess.getType()) {
                    case LOG_MESSAGE:
                        if (mess.getChannel() != null) {
                            GUIMain.getChatPane(mess.getChannel()).log(wrap, true);
                        } else if (mess.getExtra() != null) {
                            ((ChatPane) mess.getExtra()).log(wrap, true);
                        } else {
                            GUIMain.getSystemLogsPane().log(wrap, true);
                        }
                        break;
                    case NORMAL_MESSAGE:
                    case ACTION_MESSAGE:
                        if (!GUIMain.combinedChatPanes.isEmpty()) {
                            for (CombinedChatPane cc : GUIMain.combinedChatPanes) {
                                for (String chan : cc.getChannels()) {
                                    if (mess.getChannel().substring(1).equalsIgnoreCase(chan)) {
                                        cc.onMessage(wrap, true);
                                        break;
                                    }
                                }
                            }
                        }
                        GUIMain.getChatPane(mess.getChannel()).onMessage(wrap, false);
                        break;
                    case SUB_NOTIFY:
                        GUIMain.getChatPane(mess.getChannel()).onSub(wrap);
                        break;
                    case BAN_NOTIFY:
                    case HOSTED_NOTIFY:
                    case HOSTING_NOTIFY:
                    case JTV_NOTIFY:
                        GUIMain.getChatPane(mess.getChannel()).log(wrap, false);
                        break;
                    case DONATION_NOTIFY:
                        GUIMain.getChatPane(mess.getChannel()).onDonation(wrap);
                        if (Settings.loadedDonationSounds) {
                            SoundEngine.getEngine().playSpecialSound(false);
                        }
                        break;
                    case CLEAR_TEXT:
                        wrap.addPrint(((ChatPane) mess.getExtra())::cleanupChat);
                        break;
                    case WHISPER_MESSAGE:
                        GUIMain.getCurrentPane().onWhisper(wrap);
                        break;
                    case CHEER_MESSAGE:
                        GUIMain.getChatPane(mess.getChannel()).onCheer(wrap);
                        //TODO: Update this to use a separate folder, if need be
                        int cheerAmount = (int) wrap.getLocal().getExtra();
                        if (Settings.loadedDonationSounds && Utils.isMainChannel(mess.getChannel()) && cheerAmount >= 200) {
                            SoundEngine.getEngine().playSpecialSound(false);
                        }
                        break;
                    default:
                        break;
                }
                addToQueue(wrap);
            } catch (Exception e) {
                GUIMain.log(e);
            }
        });
    }
}
Also used : CombinedChatPane(gui.CombinedChatPane)

Example 5 with CombinedChatPane

use of gui.CombinedChatPane in project Botnak by Gocnak.

the class PaneMenuListener method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    JMenuItem source = (JMenuItem) e.getSource();
    if (source != null && source.getText() != null) {
        ChatPane pane = Utils.getChatPane(GUIMain.channelPane.getSelectedIndex());
        String text = source.getText();
        if (text.startsWith("Pop-out")) {
            if (pane != null) {
                pane.createPopOut();
            }
        } else if (text.startsWith("Toggle Tab")) {
            if (pane != null) {
                pane.setShouldPulse(text.contains("ON"));
            } else {
                CombinedChatPane ccp = Utils.getCombinedChatPane(GUIMain.channelPane.getSelectedIndex());
                if (ccp != null) {
                    ccp.setShouldPulse(text.contains("ON"));
                }
            }
        } else if (text.startsWith("View viewer")) {
            if (pane != null) {
                GUIViewerList newVL = new GUIViewerList(pane.getChannel());
                newVL.setVisible(true);
                GUIMain.viewerLists.put(pane.getChannel(), newVL);
            }
        } else if (text.startsWith("Remove ")) {
            if (pane != null) {
                if (GUIMain.viewer != null) {
                    GUIMain.viewer.doLeave(pane.getChannel());
                }
                if (GUIMain.bot != null) {
                    GUIMain.bot.doLeave(pane.getChannel());
                }
                GUIMain.channelSet.remove(pane.getChannel());
                GUIMain.chatPanes.remove(pane.getChannel());
                pane.deletePane();
                GUIMain.channelPane.updateIndexes();
            }
        } else if (text.startsWith("Disband")) {
            CombinedChatPane ccp = Utils.getCombinedChatPane(GUIMain.channelPane.getSelectedIndex());
            if (ccp != null) {
                ccp.disbandTab();
            }
        } else if (text.startsWith("Go to")) {
            //ex: Go to gocnak's channel
            //    0123456     ^ substring
            String name = text.substring(6, text.indexOf("'"));
            Utils.openWebPage("http://twitch.tv/" + name);
        } else if (text.startsWith("Clear ")) {
            if (pane == null)
                pane = Utils.getCombinedChatPane(GUIMain.channelPane.getSelectedIndex());
            if (pane != null) {
                //The combined could return null, still have to check
                if (pane instanceof CombinedChatPane)
                    pane = ((CombinedChatPane) pane).getActiveChatPane();
                pane.resetCleanupCounter();
                final ChatPane pane1 = pane;
                EventQueue.invokeLater(() -> {
                    //this should be fine, no need for message queue since clearing would be situational anyways
                    if (Settings.logChat.getValue()) {
                        String[] toPrint = pane1.getText().split("\\n");
                        Utils.logChat(toPrint, pane1.getChannel(), 1);
                    }
                    pane1.getTextPane().setText(null);
                });
            }
        }
        if (source instanceof JCheckBoxMenuItem) {
            String channel = source.getText();
            if (channel != null) {
                CombinedChatPane ccp = Utils.getCombinedChatPane(GUIMain.channelPane.getSelectedIndex());
                if (ccp == null || ccp.getActiveChannel().equalsIgnoreCase(channel)) {
                    return;
                }
                ccp.setActiveChannel(channel);
                if (channel.equalsIgnoreCase("All")) {
                    ccp.setDefaultScrollPane();
                } else {
                    //and pulse the + tab as well
                    ccp.setActiveScrollPane(channel);
                }
            }
        }
    }
}
Also used : CombinedChatPane(gui.CombinedChatPane) ChatPane(gui.ChatPane) CombinedChatPane(gui.CombinedChatPane) GUIViewerList(gui.forms.GUIViewerList)

Aggregations

CombinedChatPane (gui.CombinedChatPane)5 ChatPane (gui.ChatPane)3 GUIViewerList (gui.forms.GUIViewerList)1 ArrayList (java.util.ArrayList)1