Search in sources :

Example 1 with IrcException

use of org.jibble.pircbot.IrcException in project ChatGameFontificator by GlitchCog.

the class ControlPanelIrc method build.

@Override
protected void build() {
    userInput = new LabeledInput("Username", 11);
    authInput = new LabeledInput("OAuth Token", true, 25);
    authHelpButton = new JButton("Get OAuth Token");
    chanInput = new LabeledInput("Channel", 11);
    hostInput = new LabeledInput("Host", 7);
    portInput = new LabeledInput("Port", 3);
    anonymous = new JCheckBox("Read Only (Credentials not required)");
    anonymous.setToolTipText("Connect without credentials, but also without access to custom Twitch badges");
    anonymous.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            userInput.setEnabled(!anonymous.isSelected());
            authInput.setEnabled(!anonymous.isSelected());
            config.setAnonymous(anonymous.isSelected());
        }
    });
    FocusListener fl = new FocusListener() {

        @Override
        public void focusGained(FocusEvent e) {
        }

        @Override
        public void focusLost(FocusEvent e) {
            // the configuration
            try {
                fillConfigFromInput();
            } catch (Exception ex) {
                logger.trace(ex.toString(), ex);
            }
        }
    };
    userInput.addFocusListener(fl);
    authInput.addFocusListener(fl);
    chanInput.addFocusListener(fl);
    hostInput.addFocusListener(fl);
    portInput.addFocusListener(fl);
    authHelpButton.addActionListener(new ActionListener() {

        final String url = "http://www.twitchapps.com/tmi/";

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                Desktop.getDesktop().browse(URI.create(url));
            } catch (java.io.IOException ex) {
                ChatWindow.popup.handleProblem("Unable to open website at URL: " + url);
            }
        }
    });
    connectButton = new JButton(BUTTON_TEXT_CONNECT);
    connectButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JButton source = (JButton) e.getSource();
            // Reset it just in case
            source.setText(bot.isConnected() ? BUTTON_TEXT_DISCONNECT : BUTTON_TEXT_CONNECT);
            if (bot.isConnected()) {
                bot.setDisconnectExpected(true);
                bot.disconnect();
            } else {
                try {
                    LoadConfigReport report = validateInputForConnect();
                    if (report.isErrorFree()) {
                        // Connect to the IRC channel
                        connect();
                        emojiControl.loadAndRunEmojiWork();
                    } else {
                        ChatWindow.popup.handleProblem(report);
                    }
                } catch (NumberFormatException ex) {
                    ChatWindow.popup.handleProblem("Invalid login port value", ex);
                } catch (NickAlreadyInUseException ex) {
                    ChatWindow.popup.handleProblem("Nickname already in use", ex);
                } catch (IOException ex) {
                    ChatWindow.popup.handleProblem("Error connecting to the IRC server. Verify the Internet connection and then the host and port values.", ex);
                } catch (IrcException ex) {
                    ChatWindow.popup.handleProblem("The host IRC server rejected the connection", ex);
                } catch (Exception ex) {
                    ChatWindow.popup.handleProblem("Unanticipated error connecting", ex);
                }
            }
        }
    });
    clearChatButton = new JButton("Clear Chat");
    clearChatButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            chat.clearChat();
            chat.repaint();
        }
    });
    autoReconnectBox = new JCheckBox("Automatically attempt to reconnect if connection is lost");
    autoReconnectBox.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            config.setAutoReconnect(autoReconnectBox.isSelected());
        }
    });
    JPanel everything = new JPanel(new GridBagLayout());
    everything.setBorder(new TitledBorder(baseBorder, "IRC Connection Properties / Clear Chat", TitledBorder.CENTER, TitledBorder.TOP));
    JPanel topRow = new JPanel(new GridBagLayout());
    JPanel midRow = new JPanel(new GridBagLayout());
    JPanel botRow = new JPanel(new GridBagLayout());
    gbc.weightx = 0.0;
    gbc.fill = GridBagConstraints.NONE;
    topRow.add(anonymous, gbc);
    gbc.gridx++;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;
    topRow.add(userInput, gbc);
    gbc.gridx++;
    topRow.add(chanInput, gbc);
    gbc.gridx++;
    gbc.gridx = 0;
    midRow.add(authInput, gbc);
    gbc.gridx++;
    gbc.weightx = 0.0;
    gbc.fill = GridBagConstraints.NONE;
    midRow.add(authHelpButton, gbc);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.weightx = 1.0;
    gbc.gridx = 0;
    botRow.add(hostInput, gbc);
    gbc.gridx++;
    botRow.add(portInput, gbc);
    gbc.gridx++;
    gbc.anchor = GridBagConstraints.NORTHEAST;
    botRow.add(connectButton, gbc);
    gbc.gridx++;
    botRow.add(clearChatButton, gbc);
    gbc.gridx++;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridx = 0;
    everything.add(topRow, gbc);
    gbc.gridy++;
    everything.add(midRow, gbc);
    gbc.gridy++;
    everything.add(botRow, gbc);
    gbc.gridy++;
    everything.add(autoReconnectBox, gbc);
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weightx = 1.0;
    gbc.weighty = 0.0;
    gbc.anchor = GridBagConstraints.NORTH;
    add(everything, gbc);
    gbc.gridy++;
    gbc.weightx = 1.0;
    gbc.weighty = 1.0;
    gbc.anchor = GridBagConstraints.SOUTH;
    gbc.fill = GridBagConstraints.BOTH;
    add(logBox, gbc);
}
Also used : JPanel(javax.swing.JPanel) LabeledInput(com.glitchcog.fontificator.gui.component.LabeledInput) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) NickAlreadyInUseException(org.jibble.pircbot.NickAlreadyInUseException) JButton(javax.swing.JButton) IOException(java.io.IOException) TitledBorder(javax.swing.border.TitledBorder) FocusEvent(java.awt.event.FocusEvent) LoadConfigReport(com.glitchcog.fontificator.config.loadreport.LoadConfigReport) IOException(java.io.IOException) NickAlreadyInUseException(org.jibble.pircbot.NickAlreadyInUseException) IrcException(org.jibble.pircbot.IrcException) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) FocusListener(java.awt.event.FocusListener) IrcException(org.jibble.pircbot.IrcException)

Aggregations

LoadConfigReport (com.glitchcog.fontificator.config.loadreport.LoadConfigReport)1 LabeledInput (com.glitchcog.fontificator.gui.component.LabeledInput)1 GridBagLayout (java.awt.GridBagLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 FocusEvent (java.awt.event.FocusEvent)1 FocusListener (java.awt.event.FocusListener)1 IOException (java.io.IOException)1 JButton (javax.swing.JButton)1 JCheckBox (javax.swing.JCheckBox)1 JPanel (javax.swing.JPanel)1 TitledBorder (javax.swing.border.TitledBorder)1 IrcException (org.jibble.pircbot.IrcException)1 NickAlreadyInUseException (org.jibble.pircbot.NickAlreadyInUseException)1