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

📄 chatroompanel.java

📁 网站即时通讯系统
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        }    }    protected void inviteUser(final String jid, final String reason) {        Thread thread = new Thread(new Runnable() {            public void run() {                chat.invite(jid, reason);            }        });        thread.start();    }    private void destroyHandler() {        final int r = JOptionPane.showConfirmDialog(BuddyList.getInstance()                .getTabFrame(), resources.getString("sureDestroyRoom"),                resources.getString("destroyRoom"), JOptionPane.YES_NO_OPTION);        if (r == JOptionPane.YES_OPTION) {            final String reason = (String) JOptionPane.showInputDialog(                    BuddyList.getInstance().getTabFrame(), resources                            .getString("enterReasonForDestroy"), resources                            .getString("destroyRoom"),                    JOptionPane.QUESTION_MESSAGE, null, null,                    "Room has been moved");            if (reason == null)                return;            final String result = (String) JOptionPane.showInputDialog(                    BuddyList.getInstance().getTabFrame(), resources                            .getString("enterAlternate"), resources                            .getString("destroyRoom"),                    JOptionPane.QUESTION_MESSAGE, null, null, "");            if (result == null)                return;            new Thread(new DestroyThread(reason, result)).start();        }    }    class DestroyThread implements Runnable {        String reason, result;        public DestroyThread(String reason, String result) {            this.reason = reason;            this.result = result;        }        public void run() {            String error = null;            try {                chat.destroy(reason, result);            } catch (XMPPException ex) {                error = ex.getMessage();            }            final String e = error;            SwingUtilities.invokeLater(new Runnable() {                public void run() {                    if (e != null) {                        serverErrorMessage(e);                    } else {                        serverErrorMessage("Room has been destroyed");                    }                }            });        }    }    /**     * Collects a Data Form to be filled out     *     * @param type     *            the type of form. Either "configure" or "registerFor"     */    public void configurationHandler(String type) {        Thread thread = new Thread(new ConfigThread(type));        thread.start();    }    /**     * Collects the data form and displays it.     *     * @author Adam Olsen     */    private class ConfigThread implements Runnable {        private String type = "configure";        /**         * @param type         *            the type of form to collect.         */        public ConfigThread(String type) {            this.type = type;        }        /**         * Called by the enclosing thread         */        public void run() {            try {                Form temp;                // get the form                if (type.equals("configure")) {                    temp = chat.getConfigurationForm();                } else {                    temp = chat.getRegistrationForm();                }                if (temp == null) {                    serverErrorMessage(resources                            .getString("couldNotCollectForm"));                    return;                }                final Form form = temp;                final JBDataForm f = new JBDataForm(BuddyList.getInstance().getTabFrame(), form);                f.addActionListener(new ActionListener() {                    public void actionPerformed(ActionEvent e) {                        // if the cancel button is pressed, close the form                        if (e.getActionCommand().equals("cancel")) {                            SwingUtilities.invokeLater(new Runnable() {                                public void run() {                                    f.dispose();                                }                            });                        }                        // else submit the form                        else if (e.getActionCommand().equals("ok")) {                            SwingUtilities.invokeLater(new Runnable() {                                public void run() {                                    if (submitConfigurationForm(f, type)) {                                        f.setVisible(false);                                    }                                }                            });                        }                    }                });                // show the form                SwingUtilities.invokeLater(new Runnable() {                    public void run() {                        f.setVisible(true);                    }                });            }            // if there was an error collecting the form            catch (XMPPException ex) {                String message = ex.getMessage();                if (ex.getXMPPError() != null) {                    message = resources.getString("xmppError"                            + ex.getXMPPError().getCode());                }                serverErrorMessage(resources.getString(type + "Room") + ": "                        + message);            }        }    }    /**     * Submits the form     *     * @param form     *            the form to submit     * @param type     *            the type of form, either "configure" or "registerFor"     * @return false if the required fields have not been filled out     */    private boolean submitConfigurationForm(JBDataForm form, final String type) {        final Form answer = form.getAnswerForm();        if (answer == null)            return false;        Thread thread = new Thread(new Runnable() {            public void run() {                try {                    if (type.equals("configure")) {                        chat.sendConfigurationForm(answer);                    } else {                        chat.sendRegistrationForm(answer);                    }                } catch (XMPPException ex) {                }                SwingUtilities.invokeLater(new Runnable() {                    public void run() {                        if (type.equals("configure")) {                            serverNoticeMessage(resources                                    .getString("configureSubmitted"));                        } else {                            serverNoticeMessage(resources                                    .getString("registerSubmitted"));                        }                    }                });            }        });        thread.start();        return true;    }    /**     * Opens the log window for this chat room     */    public void openLogWindow() {        new LogViewerDialog(this, getRoomName());    }    /**     * Adds a buddy to the nickname list     *     * @param buddy     *            the buddy to add     */    public void addBuddy(String buddy) {        nickList.addBuddy(buddy);    }    /**     * Removes a buddy from the nick list     *     * @param buddy     *            the buddy to remove     */    public void removeBuddy(String buddy) {        nickList.removeBuddy(buddy);    }    /**     * Opens the log file     */    public void startLog() {        // for loggingg        if (Settings.getInstance().getBoolean("keepLogs")) {            String logFileName = LogViewerDialog.getDateName() + ".log.html";            String logFileDir = JBother.profileDir                    + File.separatorChar                    + "logs"                    + File.separatorChar                    + getRoomName().replaceAll("@", "_at_").replaceAll("\\/",                            "-");            File logDir = new File(logFileDir);            if (!logDir.isDirectory() && !logDir.mkdirs())                Standard.warningMessage(this, resources.getString("log"),                        resources.getString("couldNotCreateLogDir"));            String logEnc =                Settings.getInstance().getProperty("keepLogsEncoding");            conversationArea.setLogFile(new File(logDir, logFileName), logEnc);        }    }    /**     * Gets the BuddyStatus represending a user in the room     *     * @param user     *            the BuddyStatus to get     * @return the requested BuddyStatus     */    public MUCBuddyStatus getBuddyStatus(String user) {        if (!buddyStatuses.containsKey(user)) {            MUCBuddyStatus buddy = new MUCBuddyStatus(user);            buddy.setMUC(chat);            buddy.setName(user.substring(user.indexOf("/") + 1, user.length()));            buddyStatuses.put(user, buddy);        }        return (MUCBuddyStatus) buddyStatuses.get(user);    }    /**     * Returns the tab name for the TabFramePanel     *     * @return the panel name     */    public String getPanelName() {        return getShortRoomName();    }    /**     * Returns the tooltip for the tab in the TabFrame     *     * @return the tooltip for this tab in the tab frame     */    public String getTooltip() {        return getRoomName();    }    /**     * Returns the window title     *     * @return the window title for the TabFrame when this tab is selected     */    public String getWindowTitle() {        return resources.getString("groupChat") + ": " + getRoomName();    }    /**     * Gets the short room name - for example, if you are talking in     * jdev@conference.jabber.org, it would return "jdev"     *     * @return short room name     */    public String getShortRoomName() {        return chatroom.replaceAll("\\@.*", "");    }    /**     * Gets the entire room name, server included     *     * @return gets the room address     */    public String getRoomName() {        return chatroom;    }    /**     * Returns the nickname of a user in a group chat.     *     * @param id     *            The full id of someone in a room, ie:     *            jdev@conference.jabber.org/synic     * @return the nickname of the person in the room     */    public String getNickname(String id) {        int index = id.indexOf("/");        if (index == -1)            return id;        return id.substring(index + 1);    }    public MultiUserChat getChat() {        return chat;    }    public GroupParticipantListener getParticipantListener() {        return participantListener;    }    /**     * Starts the groupchat. Sets up a thread to connect, and start that thread     */    public void startChat() {        if (!BuddyList.getInstance().checkConnection())            return;        serverNoticeMessage("Connecting to " + getRoomName() + "...");        BuddyList.getInstance().addTabPanel(this);        JoinChatThread t = new JoinChatThread();        t.start();        startLog();    }    private void leaveChat() {        if (chat == null)            return;        com.valhalla.Logger.debug("Leaving " + chat.getRoom());        Presence p = new Presence(Presence.Type.UNAVAILABLE);        p.setTo(chat.getRoom());        if (BuddyList.getInstance().checkConnection())            BuddyList.getInstance().getConnection().sendPacket(p);        chat.removeMessageListener(messageListener);        chat.removeParticipantListener(participantListener);        chat.removeSubjectUpdatedListener(subjectListener);        chat.removeParticipantStatusListener(statusListener);        chat.removeUserStatusListener(userStatusListener);        chat = null;    }    /**     * Asks for a new topic, then sets the new topic     */    private void topicHandler(final String subject) {        Thread thread = new Thread(new Runnable() {            public void run() {                try {                    chat.changeSubject(subject);                } catch (final XMPPException e) {                    SwingUtilities.invokeLater(new Runnable() {                        public void run() {                            String message = e.getMessage();                            serverErrorMessage(resources                                    .getString("errorSettingSubject")                                    + ": " + message);                        }                    });                }                SwingUtilities.invokeLater(new Runnable() {                    public void run() {                        subjectField.setEnabled(true);                    }                });            }        });        thread.start();    }    private class RunTaskThread implements Runnable {        private String err, method;        private Object param;        public RunTaskThread(String err, String method, Object param) {            this.err = err;            this.method = method;            this.param = param;        }        public void run() {            java.lang.reflect.Method m;            try {                m = chat.getClass().getMethod(this.method,                        new Class[] { param.getClass() });            } catch (Exception e) {                e.printStackTrace();                return;            }            try {                m.invoke(chat, new Object[] { param });            } catch (final java.lang.reflect.InvocationTargetException ex) {                final XMPPException xmpp = (XMPPException) ex.getCause();                if (xmpp == null)                    return;                SwingUtilities.invokeLater(new Runnable() {                    public void run() {                        serverErrorMessage(err                                + ": "                                + resources.getString("xmppError"                                        + xmpp.getXMPPError().getCode()));                    }                });            } catch (Exception e) {                e.printStackTrace();            }        }    }

⌨️ 快捷键说明

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