⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 addbuddydialog.java

📁 JBother是纯Java开发的Jabber(即时消息开源软件)客户端。支持群组聊天
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            if (buddyGroup.equals(resources.getString("none"))) {                buddyGroup = null;            }            addBuddy(buddyGroup, buddyAliasBox.getText(), buddyIDBox.getText());        }    }    /**     *  Handles all button events     *     *@author     Adam Olsen     *@created    September 26, 2005     *@version    1.0     */    class ActionHandler implements ActionListener {        /**         *  Description of the Method         *         *@param  e  Description of the Parameter         */        public void actionPerformed(ActionEvent e) {            if (e.getSource() != cancelButton) {                okButtonHandler();            } else {                cancelButtonHandler();            }        }    }    /**     *  Creates an input box with a corresponding label     *     *@param  container  the container to add the input box to     *@param  grid       the GridBagLayout to use     *@param  label      the label to use     *@param  box        the input box to use     */    private void createInputBox(Container container, GridBagLayout grid,            String label, Container box) {        JLabel labelBox = new JLabel(label + "    ");        c.gridy = row++;        c.gridx = 0;        c.anchor = GridBagConstraints.EAST;        grid.setConstraints(labelBox, c);        container.add(labelBox);        c.gridx = 1;        c.anchor = GridBagConstraints.WEST;        grid.setConstraints(box, c);        container.add(box);    }    /**     *  Gets the different available RosterGroups     *     *@return    an array of strings representing the RosterGroups     */    private String[] getRosterGroups() {        Roster roster = ConnectorThread.getInstance().getRoster();        String rosterGroups[] = new String[roster.getGroupCount() + 2];        int i = 0;        if ((!currentGroup.equals(""))) {            rosterGroups[i] = currentGroup;            i++;        }        rosterGroups[i++] = resources.getString("none");        rosterGroups[i++] = resources.getString("newGroup");        Iterator iterator = roster.getGroups();        while (iterator.hasNext()) {            RosterGroup rosterGroup = (RosterGroup) iterator.next();            if ((currentGroup.equals(""))                     || (!rosterGroup.getName().equals(currentGroup))) {                rosterGroups[i] = rosterGroup.getName();                i++;            }        }        return rosterGroups;    }    /**     *  Runs the add buddy thread and adds or modifies a buddy in the Roster     *     *@param  groupName   the group to put the buddy in     *@param  buddyAlias  the alias of the buddy     *@param  buddyId     the buddy's JID     */    private void addBuddy(String groupName, String buddyAlias, String buddyId) {        Roster buddyGroups = ConnectorThread.getInstance()                .getRoster();        WaitDialog wait = new WaitDialog(this, null, resources.getString("pleaseWait"));        wait.setVisible(true);        setVisible(false);        Thread thread = new Thread(new AddBuddyThread(wait, groupName,                buddyAlias, buddyId, this));        thread.start();    }    /**     *  Actually adds the buddy to the Roster     *     *@author     Adam Olsen     *@created    September 26, 2005     *@version    1.0     */    class AddBuddyThread implements Runnable {        private String errorMessage;        private String groupName;        private String buddyAlias;        private String buddyId;        private AddBuddyDialog dialog;        private WaitDialog wait;        /**         *  Default constructor         *         *@param  wait        the wait dialog         *@param  groupName   the group to use         *@param  buddyAlias  the buddy's alias         *@param  buddyId     the buddy's JID         *@param  dialog      the AddBuddyDialog that called this thread         */        public AddBuddyThread(WaitDialog wait, String groupName,                String buddyAlias, String buddyId, AddBuddyDialog dialog) {            this.wait = wait;            this.groupName = groupName;            this.buddyAlias = buddyAlias;            this.buddyId = buddyId.trim();            this.dialog = dialog;        }        /**         *  Called by the enclosing Thread - will attempt to add the buddy to         *  the Roster, and will display an error if it wasn't successfull         */        public void run() {            final Roster roster = BuddyList.getInstance().getConnection().getRoster();            final BuddyStatus buddy = BuddyList.getInstance().getBuddyStatus(                    buddyId);            if (modify) {                SwingUtilities.invokeLater(                    new Runnable() {                        public void run() {                            BuddyList.getInstance().getBuddyListTree().removeBuddy(                                    buddy, buddy.getGroup(), true);                        }                    });            }            try {                if (modify) {                    com.valhalla.Logger.debug("modifying roster item");                    RosterEntry entry = buddy.getRosterEntry();                    entry.setName(buddyAlias);                    int c = 0;                    Iterator groups = entry.getGroups();                    while (groups.hasNext()) {                        RosterGroup g = (RosterGroup) groups.next();                        if(!g.contains(entry)) continue;                        g.removeEntry(entry);                        c++;                    }                    buddy.setTempGroup(groupName);                    SwingUtilities.invokeLater(new Runnable()                    {                        public void run()                        {                            dialog.setVisible(false);                            buddy.setRemoved(false);                            NMOptionDialog.createMessageDialog(null, resources.getString("addBuddyDialogTitle"), resources.getString("buddyAdded"));                            BuddyList.getInstance().getBuddyListTree().addBuddy(                                    buddy);                        }                    });                    if (groupName != null && !groupName.equals("")) {                        RosterGroup newGroup = null;                        newGroup = roster.getGroup(groupName);                        if (newGroup == null) {                            com.valhalla.Logger.debug("had to create new group" + groupName);                            newGroup = roster.createGroup(groupName);                        } else {                            com.valhalla.Logger.debug("found group " + newGroup.getName());                        }                        if (c != 0) {                            com.valhalla.Logger.debug("Moving buddy to " + newGroup.getName());                            newGroup.addEntry(entry);                        } else {                            roster.createEntry(buddyId, buddyAlias,                                    new String[]{groupName});                        }                    }                }                /*                 *  if it's a new entry                 */else {                    if (groupName == null) {                        roster.createEntry(buddyId, buddyAlias, null);                    } else {                        roster.createEntry(buddyId, buddyAlias,                                new String[]{groupName});                        buddy.setTempGroup(groupName);                    }                    SwingUtilities.invokeLater(new Runnable()                    {                        public void run()                        {                            dialog.setVisible(false);                            buddy.setRemoved(false);                            NMOptionDialog.createMessageDialog(null, resources.getString("addBuddyDialogTitle"), resources.getString("buddyAdded"));                            BuddyList.getInstance().getBuddyListTree().addBuddy(                                    buddy);                        }                    });                }            } catch (XMPPException e) {                if (e.getXMPPError() == null) {                    errorMessage = e.getMessage();                } else {                    errorMessage = resources.getString("xmppError"                             + e.getXMPPError().getCode());                }            }            SwingUtilities.invokeLater(                new Runnable() {                    public void run() {                        wait.dispose();                        if (errorMessage != null) {                            Standard.warningMessage(dialog, resources.getString("addBuddyDialogTitle"),                                    errorMessage);                            dialog.setVisible(true);                        } else {                            DialogTracker.removeDialog(dialog);                        }                    }                });        }    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -