use of gui.ChatPane 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();
}
use of gui.ChatPane 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());
}
}
}
}
use of gui.ChatPane in project Botnak by Gocnak.
the class GUIMain method getCurrentPane.
public static ChatPane getCurrentPane() {
ChatPane toReturn;
int index = channelPane.getSelectedIndex();
if (index == 0)
return getSystemLogsPane();
toReturn = Utils.getChatPane(index);
if (toReturn == null) {
toReturn = Utils.getCombinedChatPane(index);
}
return toReturn == null ? getSystemLogsPane() : toReturn;
}
use of gui.ChatPane in project Botnak by Gocnak.
the class GUIMain method exitButtonActionPerformed.
public void exitButtonActionPerformed() {
shutDown = true;
if (viewer != null) {
viewer.close(false);
}
if (bot != null) {
bot.close(false);
}
if (!tabPulses.isEmpty()) {
tabPulses.forEach(TabPulse::interrupt);
tabPulses.clear();
}
if (systemTrayIcon != null)
systemTrayIcon.close();
SoundEngine.getEngine().close();
Settings.save();
heartbeat.interrupt();
ThreadEngine.close();
Set<Map.Entry<String, ChatPane>> entries = chatPanes.entrySet();
for (Map.Entry<String, ChatPane> entry : entries) {
String channel = entry.getKey();
ChatPane pane = entry.getValue();
if (Settings.logChat.getValue()) {
Utils.logChat(pane.getText().split("\\n"), channel, 2);
}
}
System.gc();
dispose();
System.exit(0);
}
use of gui.ChatPane 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);
}
}
}
}
}
Aggregations