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

📄 chatpanel.java

📁 JBother是纯Java开发的Jabber(即时消息开源软件)客户端。支持群组聊天
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
            if (!BuddyList.getInstance().checkConnection()) {                BuddyList.getInstance().connectionError();                return;            }            if ((areaTextComplete.startsWith("/all ") == true || areaTextComplete.startsWith("/ame ") == true)) {                if (areaTextComplete.startsWith("/ame ") == true) {                    areaTextComplete = areaTextComplete.replaceAll("^/ame ",                            "/me ");                } else {                    areaTextComplete = areaTextComplete.replaceAll("^/all ", "");                }                if (allText == null) {                    Hashtable buddyStatuses = BuddyList.getInstance()                            .getBuddyStatuses();                    if (buddyStatuses != null) {                        Iterator iterator = buddyStatuses.keySet().iterator();                        while (iterator.hasNext()) {                            String user2 = (String) iterator.next();                            BuddyStatus buddy2 = (BuddyStatus) buddyStatuses.get(user2);                            if (buddy2.equals(buddy) == false                                     && buddy2.getConversation() != null                                     && buddy2.getConversation() instanceof ChatPanel) {                                ((ChatPanel) buddy2.getConversation())                                        .sendHandler(areaTextComplete);                            }                        }                    }                }            }            areaText = areaTextComplete;            if ((buddy.isEncrypting())                     &&            // ( BuddyList.getInstance().isEncrypting() ) &&                    ((buddy.getPubKey() == null) || (buddy.getPubKey() == null))) {                KeySelectDialog dialog = new KeySelectDialog("pub");                dialog.showDialog();                if (dialog.getID() != null) {                    buddy.setPubKey(dialog.getID());                } else {                    buddy.isEncrypting(false);                    encryptButton.setIcon(Standard.getIcon("images/buttons/ssl_no.png"));                }            }            if (!sendBuddyMessage(areaText)) {                return;            }            isTyping = false;            typingTimer.stop();            SwingUtilities.invokeLater(                new Runnable() {                    public void run() {                        String text = areaText;                        if (text.startsWith("/me ")) {                            text = text.replaceAll("^/me ", "");                            conversationArea.append(getDate(null), ConversationArea.RECEIVER);                            conversationArea.append( " *" + BuddyList.getInstance().getMyName() + " ", ConversationArea.RECEIVER, true);                            conversationArea.append(text + "\n", ConversationArea.BLACK);                        } else {                            conversationArea.append(getDate(null), ConversationArea.RECEIVER);                            conversationArea.append(" " + BuddyList.getInstance().getMyName()+ ": ", ConversationArea.RECEIVER, true);                            conversationArea.append(text + "\n", ConversationArea.BLACK);                        }                        textEntryArea.setText("");                    }                });        }    }    /**     *  Sends the message to the resource in the JComboBox     *     *@param  text  the message to send     *@return       Description of the Return Value     */    public boolean sendBuddyMessage(String text) {        String to = buddy.getUser();        int sel = resourceBox.getSelectedIndex();        SecureExtension secureExtension = new SecureExtension();        SecureExtension signedExtension = new SecureExtension("signed");        // if they've selected a resource, send to it        if (sel != 0 && sel != 1 && sel != -1) {            to += "/" + (String) resourceBox.getSelectedItem();        }        ArrayList send = new ArrayList();        if (sel != 1 || resourceBox.getItemCount() <= 2) {            send.add(to);        }        // if they've selected to send to all resources, send to all        else {            Set keys = buddy.keySet();            Iterator i = keys.iterator();            while (i.hasNext()) {                String key = (String) i.next();                if (!key.equals("N/A")) {                    send.add(buddy.getUser() + "/" + key);                }            }        }        String gnupgSecurityVariant = Settings.getInstance().getProperty(                "gnupgSecurityVariant");        String gnupgSecretKey = Settings.getInstance().getProperty(                "gnupgSecretKeyID");        String gnupgPublicKey = buddy.getPubKey();        if (JBotherLoader.isGPGEnabled() &&        // BuddyList.getInstance().isEncrypting()                buddy.isEncrypting() && (gnupgSecretKey != null)                 && (gnupgPublicKey != null)) {            GnuPG gnupg = new GnuPG();            String encryptedData = null;            String signedData = null;            if (gnupgSecurityVariant == null) {                gnupgSecurityVariant = "0";                Settings.getInstance().setProperty("gnupgSecurityVariant", "0");            }            if ((gnupgSecurityVariant.equals("0"))                     || (gnupgSecurityVariant.equals("1"))) {                encryptedData = gnupg.encryptExtension(text, gnupgSecretKey,                        gnupgPublicKey);                if (encryptedData != null) {                    secureExtension.setData(encryptedData);                }            }            if ((gnupgSecurityVariant.equals("0"))                     || (gnupgSecurityVariant.equals("2"))) {                signedData = gnupg.signExtension(text, gnupgSecretKey);                if (signedData != null) {                    signedExtension.setData(signedData);                }            }            if ((encryptedData == null) && (signedData == null)) {                buddy.isEncrypting(false);                encryptButton.setIcon(Standard.getIcon("images/buttons/ssl_no.png"));                Standard.warningMessage(null,                        resources.getString("gnupgError"), resources.getString("gnupgErrorEncrypting")                         + ".\n\n"                         + resources.getString("reason")                         + ":\n\n"                         + gnupg.getResult()                         + gnupg.getErrorString()                         + "\n"                         + resources.getString("gnupgTryOrSendUnencrypted")                         + ".");                return false;            }        }        for (int i = 0; i < send.size(); i++) {            Chat chat = null;            if (buddy instanceof MUCBuddyStatus) {                MultiUserChat muc = ((MUCBuddyStatus) buddy).getMUC();                chat = muc.createPrivateChat(buddy.getUser());            } else {                chat = (Chat) chats.get((String) send.get(i));            }            if (chat == null) {                chat = BuddyList.getInstance().getConnection().createChat(                        (String) send.get(i));                chats.put((String) send.get(i), chat);            }            Message message = chat.createMessage();            if (secureExtension.getData() != null) {                message.setBody("[This message is encrypted]");                message.addExtension(secureExtension);            } else {                message.setBody(text);            }            if (signedExtension.getData() != null) {                message.addExtension(signedExtension);            }            if (buddy.isAskForDelivered()) {                BuddyList.getInstance().putEventMessage(message.getPacketID(), message.getTo(), getDate(null), 1);            }            if (buddy.isAskForDisplayed()) {                BuddyList.getInstance().putEventMessage(message.getPacketID(), message.getTo(), getDate(null), 2);            }            if (buddy.isAskForOffline()) {                BuddyList.getInstance().putEventMessage(message.getPacketID(), message.getTo(), getDate(null), 3);            }            MessageEventManager.addNotificationsRequests(message, buddy.isAskForOffline(), buddy.isAskForDelivered(), buddy.isAskForDisplayed(), true);            MessageSendingEvent event = new MessageSendingEvent(this);            event.setMessage(message);            com.valhalla.pluginmanager.PluginChain.fireEvent(event);            try {                if (BuddyList.getInstance().checkConnection()) {                    chat.sendMessage(message);                } else {                    BuddyList.getInstance().connectionError();                }            } catch (XMPPException e) {                com.valhalla.Logger.debug("Could not send message: "                         + e.getMessage());            }        }        return true;    }    public void closeHandler() {        removeScroll();        super.closeHandler();    }    /**     *  Creates the containing frame     */    public void createFrame() {        frame = new JFrame();        frame.setContentPane(this);        frame.pack();        frame.setIconImage(Standard.getImage("frameicon.png"));        frame.addWindowListener(            new WindowAdapter() {                public void windowClosing(WindowEvent e) {                    if (Settings.getInstance().getProperty("preserveMessages") == null) {                        closeHandler();                    } else {                        startTimer();                        frame.setVisible(false);                    }                }            });//        frame.addFocusListener(new FocusListener() {//        JFrame f = frame;        //      if (frame !=null)//        {//        final BuddyStatus buddy2 = buddy;        frame.addWindowFocusListener(            new WindowFocusListener() {                public void windowGainedFocus(WindowEvent e) {//                SwingUtilities.invokeLater(new Runnable() {//                    public void run() {                    buddy2.sendNotDisplayedID();//                    }//                });                }                public void windowLostFocus(WindowEvent e) {                }            });//        }//        else//        {        String title = buddy.getUser();        if (buddy.getName() != null) {            if ((buddy.getName().toLowerCase()).matches(buddy.getUser())) {                title = buddy.getName();            } else {                title = buddy.getName() + " (" + buddy.getUser() + ")";            }//            title = buddy.getName()//            + " (" + title + ")";        }        frame.setTitle(title);        frame.pack();        String stringWidth = Settings.getInstance().getProperty(                "conversationWindowWidth");        String stringHeight = Settings.getInstance().getProperty(                "conversationWindowHeight");        if (stringWidth == null) {            stringWidth = "400";        }        if (stringHeight == null) {            stringHeight = "340";        }        frame.setSize(new Dimension(Integer.parseInt(stringWidth), Integer.parseInt(stringHeight)));        // add a resize window listener        frame.addComponentListener(            new ComponentAdapter() {                public void componentResized(ComponentEvent e) {                    Dimension dim = frame.getSize();                    Settings.getInstance().setProperty("conversationWindowWidth",                            new Integer((int) dim.getWidth()).toString());                    Settings.getInstance().setProperty("conversationWindowHeight",                            new Integer((int) dim.getHeight()).toString());                }            });        Standard.cascadePlacement(frame);        setUpDivider();        validate();    }    /**     *  This renders the resource combo box - and displays icons for the online     *  status of each resource     *     *@author     Adam Olsen     *@created    September 9, 2005     *@version    1.0     */    class PresenceComboBoxRenderer extends JLabel implements ListCellRenderer {        /**         *  Gets the listCellRendererComponent attribute of the         *  PresenceComboBoxRenderer object         *         *@param  list          Description of the Parameter         *@param  value         Description of the Parameter         *@param  index         Description of the Parameter         *@param  isSelected    Description of the Parameter         *@param  cellHasFocus  Description of the Parameter         *@return               The listCellRendererComponent value         */        public Component getListCellRendererComponent(JList list, Object value,                int index, boolean isSelected, boolean cellHasFocus) {            Presence.Mode mode = null;            if (value == null) {                value = "";            }            if (buddy.size() != 0) {                mode = buddy.getPresence(buddy.getHighestResource());            }            if (value.toString().equals(resources.getString("allResources"))) {                mode = Presence.Mode.AVAILABLE;            }            if (!value.toString()                    .equals(resources.getString("defaultResource"))                     && !value.toString().equals(                    resources.getString("allResources"))) {                mode = buddy.getPresence(value.toString());            }            ImageIcon icon = StatusIconCache.getStatusIcon(mode);            if (icon != null) {                setIcon(icon);            }            setText(value.toString());            return this;        }    }}

⌨️ 快捷键说明

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