public void substarterEnd(String prefix, String userName, String input) { System.out.println("ending give"); if (substarter.end(winNum)) { g_start.setEnabled(true); g_end.setEnabled(false); String winner = substarter.returnWinner(winNum); input = "Congrats to the new sub winner: " + winner + "!"; prefix = "<b><font color=blue>[" + userName + "]:</font></b> "; registeredUserList.setText(winner + "\n"); } else { g_start.setEnabled(true); g_end.setEnabled(false); prefix = "<b><font color=blue>[" + userName + "]:</font></b> "; input = "No one entered giveaway, ending giveaway."; } sock.outputToChannel(input, channelName); try { toChatScreen(prefix + input, false); } catch (IOException | BadLocationException ex) { Logger.getLogger(IRCBOT.class.getName()).log(Level.SEVERE, null, ex); } }
/** sets this user to be an admin */ public void setAdmin() { admin = true; popup.add("kick user").addActionListener(myAction); if (chanAdmin) { butCreate.setEnabled(true); } }
/** * used to manage the connection icons to signify connection and secure status * * @param b true if connected */ public void setConnected(boolean b) { if (b) { conIcon.setIcon(conYes); conIcon.setToolTipText("Connected"); secIcon.setIcon(secYes); secIcon.setToolTipText("Secure Connection"); butChannel.setEnabled(true); } else { conIcon.setIcon(conNo); conIcon.setToolTipText("Not Connected"); secIcon.setIcon(secNo); secIcon.setToolTipText("Connection not Secured"); butChannel.setEnabled(false); butCreate.setEnabled(false); butInvite.setEnabled(false); } }
protected void addMyControls() { // add browser-style control buttons JButton home = new JButton(new ImageIcon("data/Home24.gif")); JButton back = new JButton(new ImageIcon("data/Back24.gif")); JButton fwd = new JButton(new ImageIcon("data/Forward24.gif")); home.setToolTipText("Home"); home.addActionListener(this); home.setActionCommand(homeCmd); back.setToolTipText("Back"); back.addActionListener(this); back.setActionCommand(backCmd); back.setEnabled(false); // initially disabled fwd.setToolTipText("Forward"); fwd.addActionListener(this); fwd.setActionCommand(forwardCmd); fwd.setEnabled(false); // initially disabled add(home); add(back); add(fwd); add(new JToolBar.Separator()); // set built-in index variables homeIndex = getComponentIndex(home); backIndex = getComponentIndex(back); forwardIndex = getComponentIndex(fwd); JComboBox comboBox = new JComboBox(); comboBox.setEditable(true); comboBox.addActionListener(this); comboBox.setActionCommand(comboCmd); comboBox.setMaximumRowCount(3); // don't let it get too long comboBox.insertItemAt(mainBrowserURL, 0); // don't start it out empty add(comboBox); comboBoxIndex = getComponentIndex(comboBox); }
public void substarterBegin(String prefix, String userName, String input) { if (substarter.start(winNum)) { System.out.println("Starting give"); g_start.setEnabled(false); g_end.setEnabled(true); registeredUserList.setText(""); prefix = "<b><font color=blue>[" + userName + "]:</font></b> "; input = "Substarter giveaway is starting, make sure to register at http://substarter.com/my-account to participate. Type !substarter for a chance to win a free sub!"; sock.outputToChannel(input, channelName); } else { input = "<font color='red'>[WARNING]: Giveaway already started, perhaps in another chat window.</font>"; } try { toChatScreen(prefix + input, false); } catch (IOException | BadLocationException ex) { Logger.getLogger(IRCBOT.class.getName()).log(Level.SEVERE, null, ex); } }
public IRCBOT(boolean uList, String channel, int chatNum) { // chatter = new ChatDisplay("<html><body bgcolor='black'><table border=0pt width=100%>"); winNum = chatNum; URL iconURL = getClass().getResource("P_300x300.png"); ImageIcon icon = new ImageIcon(iconURL); setIconImage(icon.getImage()); Action doNothing = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) {} }; channelName = channel; standardWindow = uList; chatInput = new JTextArea(4, 55); chatInput.setWrapStyleWord(true); chatInput.setLineWrap(true); chatInput.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "doNothing"); chatScreen = new JTextPane(); chatScreen.setContentType("text/html"); chatScreen.setEditorKit(kit); chatScreen.setDocument(doc); userList = new JTextPane(); registeredUserList = new JTextPane(); sendButton = new JButton("SEND"); g_start = new JButton("START"); g_end = new JButton("END"); g_reroll = new JButton("secret"); JLabel l_giveaway = new JLabel("Giveaway", JLabel.CENTER); JLabel l_chat = new JLabel("Chat", JLabel.CENTER); JLabel l_uList = new JLabel("User List", JLabel.CENTER); sendButton.addActionListener(this); g_start.addActionListener(this); g_end.addActionListener(this); g_reroll.addActionListener(this); g_start.setEnabled(false); // disabled for basic irc client g_end.setEnabled(false); g_reroll.setEnabled(false); // String start = "<html><body>"; Dimension min = new Dimension(100, 1); Dimension pref = new Dimension(150, 1); Dimension max = new Dimension(600, 600); // chatScreen.setMinimumSize(min); // userList.setMinimumSize(min); // chatInput.addKeyListener(KeyBoardListener); JPanel mainPanel = new JPanel(new BorderLayout(5, 5)); JPanel left = new JPanel(new BorderLayout(5, 5)); JPanel mid = new JPanel(new BorderLayout(5, 5)); JPanel right = new JPanel(new BorderLayout(5, 5)); JPanel giveaway_buttons = new JPanel(new BorderLayout(5, 5)); JPanel sendBar = new JPanel(); scrollChat = new JScrollPane(chatScreen); JScrollPane scrollChatInput = new JScrollPane(chatInput); userListScroll = new JScrollPane(userList); JScrollPane regUserListScroll = new JScrollPane(registeredUserList); userListScroll.setMinimumSize(min); // userListScroll.setPreferredSize(pref); // userListScroll.setMaximumSize(new Dimension(800,600)); // userListScroll.setPreferredSize(new Dimension(100,100)); // scrollChat.setPreferredSize(pref); scrollChat.setMinimumSize(min); // scrollChat.setMaximumSize(new Dimension(500,500)); regUserListScroll.setPreferredSize(pref); mid.add(l_chat, BorderLayout.NORTH); mid.add(scrollChat, BorderLayout.CENTER); right.add(l_uList, BorderLayout.NORTH); right.add(userListScroll, BorderLayout.CENTER); giveaway_buttons.add(g_start, BorderLayout.WEST); giveaway_buttons.add(g_end, BorderLayout.CENTER); giveaway_buttons.add(g_reroll, BorderLayout.PAGE_END); left.add(giveaway_buttons, BorderLayout.PAGE_END); JSplitPane chat_userList = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, mid, right); chat_userList.setOneTouchExpandable(true); chat_userList.setDividerLocation(500); chat_userList.setResizeWeight(0.5); chat_userList.setContinuousLayout(true); // chat_userList.setPreferredSize(new Dimension(100,100)); chat_userList.setMinimumSize(min); // chat_userList.setMaximumSize(max); userListScroll.setHorizontalScrollBarPolicy(HORIZONTAL_SCROLLBAR_NEVER); // scroll.add(chatScreen); sendBar.add(scrollChatInput); sendBar.add(sendButton); if (standardWindow) { mainPanel.add(chat_userList, BorderLayout.CENTER); mainPanel.add(sendBar, BorderLayout.PAGE_END); JMenuBar menuBar = new JMenuBar(); JMenu fileMenu = new JMenu("File"); settings = new JMenuItem("Settings"); settings.addActionListener(this); fileMenu.add(settings); menuBar.add(fileMenu); left.add(l_giveaway, BorderLayout.NORTH); left.add(regUserListScroll, BorderLayout.CENTER); // left.setBorder(new EmptyBorder(0,5,0,0)); // chat_userList.setBorder(new EtchedBorder(0,0,0,5)); mainPanel.add(left, BorderLayout.WEST); mainPanel.add(menuBar, BorderLayout.PAGE_START); // mainPanel.setBorder(new EmptyBorder(0,10,10,10)); } else { mainPanel.add(scrollChat, BorderLayout.CENTER); } registeredUserList.setEditable(false); userList.setEditable(false); chatScreen.setEditable(false); registeredUserList.setFont(new Font("Courier New", Font.PLAIN, 12)); chatScreen.setFont(new Font("Courier New", Font.PLAIN, 12)); chatInput.setFont(new Font("Courier New", Font.PLAIN, 12)); getContentPane().add(mainPanel); setSize(800, 500); setVisible(true); setResizable(true); setLocationRelativeTo(null); setTitle("IRC Chatter"); setMinimumSize(new Dimension(500, 200)); addWindowListener( new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { // System.out.println("\n\n\n\n\n\\n\nCLOSEDWINDOW\n\n\n\n\n\n\n\n"); if (sock.isSafe() == true) sock.outputText("PART " + channelName + "\r\n"); // System.out.println("\n\n\n\n\n\\n\nCLOSEDWINDOW\n\n\n\n\n\n\n\n"); } }); chatInput.addKeyListener(this); chatInput.requestFocus(); }
/** Initializes the graphical components */ public void init() { username = getParameter("username"); if (username == null) { username = JOptionPane.showInputDialog( this, "Please enter a username", "Login", JOptionPane.QUESTION_MESSAGE); } try { PORT = Integer.valueOf(getParameter("port")).intValue(); } catch (NumberFormatException e) { PORT = 42412; } URL url = getDocumentBase(); site = url.getHost(); locationURL = "http://" + site + ":" + url.getPort() + "/" + url.getPath(); setSize(615, 362); c = getContentPane(); c.setBackground(new Color(224, 224, 224)); if (site == null || locationURL == null) { c.add(new JLabel("ERROR: did not recieve needed data from page")); } myAction = new MyAction(); myKeyListener = new MyKeyListener(); myMouseListener = new MyMouseListener(); myHyperlinkListener = new MyHyperlinkListener(); c.setLayout(null); cboChannels = new JComboBox(); cboChannels.setBounds(5, 5, 150, 24); butChannel = new JButton("Join"); butChannel.setToolTipText("Join channel"); butChannel.addActionListener(myAction); butChannel.setBounds(160, 5, 60, 24); butCreate = new JButton("Create"); butCreate.setToolTipText("Create new channel"); butCreate.addActionListener(myAction); butCreate.setBounds(230, 5, 100, 24); butCreate.setEnabled(false); butInvite = new JButton("Invite"); butInvite.setToolTipText("Invite Friend"); butInvite.addActionListener(myAction); butInvite.setBounds(340, 5, 80, 24); mainChat = new ChatPane(this); textScroller = new JScrollPane( mainChat, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); textScroller.setBounds(5, 34, 500, 270); userList = new JList(); userList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); userList.setCellRenderer(new MyCellRenderer()); userList.setBackground(new Color(249, 249, 250)); JScrollPane userScroller = new JScrollPane(userList); userScroller.setBounds(510, 34, 100, 297); messageText = new JTextField(); messageText.setBounds(5, 309, 500, 22); messageText.setColumns(10); messageText.setBackground(new Color(249, 249, 250)); JMenuItem item; popup = new JPopupMenu("test"); popup.add("whisper").addActionListener(myAction); popup.add("private message").addActionListener(myAction); popup.add("ignore").addActionListener(myAction); popup.add("clear ignore list").addActionListener(myAction); conNo = new ImageIcon(getURL("images/connect_no.gif")); conYes = new ImageIcon(getURL("images/connect_established.gif")); secNo = new ImageIcon(getURL("images/decrypted.gif")); secYes = new ImageIcon(getURL("images/encrypted.gif")); conIcon = new JLabel(conNo); conIcon.setBorder(new EtchedBorder()); secIcon = new JLabel(secNo); secIcon.setBorder(new EtchedBorder()); conIcon.setBounds(563, 334, 22, 22); secIcon.setBounds(588, 334, 22, 22); bottomText = new JLabel( "<html><body><font color=#445577><b>" + "LlamaChat " + VERSION + "</b></font> © " + "<a href=\"" + linkURL + "\">Joseph Monti</a> 2002-2003" + "</body></html>"); bottomText.setBounds(5, 336, 500, 20); c.add(cboChannels); c.add(butChannel); c.add(butCreate); c.add(butInvite); c.add(textScroller); c.add(userScroller); c.add(messageText); c.add(conIcon); c.add(secIcon); c.add(bottomText); userList.addMouseListener(myMouseListener); messageText.addKeyListener(myKeyListener); bottomText.addMouseListener(myMouseListener); users = new ArrayList(); ignores = new ArrayList(5); afks = new ArrayList(5); admins = new ArrayList(5); history = new CommandHistory(10); admin = false; channels = new Hashtable(); privates = new PrivateMsg(this); showUserStatus = false; myColors[0] = new Color(200, 0, 0); myColors[1] = new Color(0, 150, 0); myColors[2] = new Color(0, 0, 200); rect = new Rectangle(0, 0, 1, 1); String opening = "<font color=#333333>" + "==================================<br>" + "Welcome to LlamaChat " + VERSION + "<br>" + "If you need assistance, type \\help<br>" + "Enjoy your stay!<br>" + "Maestria Aplicada en Redes<br>" + "==================================<br></font>"; HTMLDocument doc = (HTMLDocument) mainChat.getDocument(); HTMLEditorKit kit = (HTMLEditorKit) mainChat.getEditorKit(); try { kit.insertHTML(doc, doc.getLength(), opening, 0, 0, HTML.Tag.FONT); } catch (Throwable t) { t.printStackTrace(System.out); } // validate the name if (!username.matches("[\\w_-]+?")) { error( "username contains invalid characters, changing to " + "'invalid' for now. " + "Type \\rename to chose a new name"); username = "******"; } if (username.length() > 10) { username = username.substring(0, 10); error("username too long, changed to " + username); } connect(); }