Search in sources :

Example 1 with MessageFilter

use of org.jivesoftware.spark.ui.MessageFilter in project Spark by igniterealtime.

the class ConversationHistoryPlugin method initialize.

public void initialize() {
    transcriptDir = new File(SparkManager.getUserDirectory(), "transcripts");
    conFile = new File(transcriptDir, "conversations.xml");
    contacts = new JList(model);
    contacts.setCellRenderer(new InternalRenderer());
    window = new Window(SparkManager.getMainWindow());
    final JPanel mainPanel = new JPanel(new BorderLayout());
    final JLabel titleLabel = new JLabel(Res.getString("label.recent.conversation"));
    titleLabel.setFont(new Font("Dialog", Font.BOLD, 11));
    titleLabel.setHorizontalAlignment(JLabel.CENTER);
    mainPanel.add(titleLabel, BorderLayout.NORTH);
    mainPanel.add(contacts, BorderLayout.CENTER);
    mainPanel.setBorder(BorderFactory.createLineBorder(Color.gray));
    window.add(mainPanel);
    // Add Listeners
    contacts.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                contacts.setSelectedIndex(contacts.locationToIndex(e.getPoint()));
                String user = jidMap.get(contacts.getSelectedValue());
                ContactItem contact = SparkManager.getContactList().getContactItemByJID(user);
                SparkManager.getContactList().setSelectedUser(contact.getJID());
                SparkManager.getContactList().showPopup(contacts, e, contact);
            }
            if (e.getClickCount() == 2) {
                final JLabel label = (JLabel) contacts.getSelectedValue();
                String user = jidMap.get(label);
                if (user != null) {
                    final String contactUsername = SparkManager.getUserManager().getUserNicknameFromJID(user);
                    SparkManager.getChatManager().activateChat(user, contactUsername);
                    window.dispose();
                }
            }
        }
    });
    contacts.addKeyListener(new KeyAdapter() {

        public void keyReleased(KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_ENTER) {
                final JLabel label = (JLabel) contacts.getSelectedValue();
                String user = jidMap.get(label);
                if (user != null) {
                    final String contactUsername = SparkManager.getUserManager().getUserNicknameFromJID(user);
                    SparkManager.getChatManager().activateChat(user, contactUsername);
                    window.dispose();
                }
            } else if (e.getKeyChar() == KeyEvent.VK_ESCAPE) {
                window.dispose();
            }
        }
    });
    contacts.addFocusListener(new FocusListener() {

        public void focusGained(FocusEvent e) {
        }

        public void focusLost(FocusEvent e) {
            window.dispose();
        }
    });
    // Load Previous History
    loadPreviousHistory();
    // Add Keymapping to ContactList
    SparkManager.getMainWindow().getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_E, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "historyPeople");
    SparkManager.getMainWindow().getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_E, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "historyPeople");
    SparkManager.getMainWindow().getRootPane().getActionMap().put("historyPeople", new AbstractAction("historyPeople") {

        private static final long serialVersionUID = 2465628887318732082L;

        public void actionPerformed(ActionEvent e) {
            // Show History Popup
            showHistoryPopup();
        }
    });
    // Persist order of conversations.
    SparkManager.getChatManager().addMessageFilter(new MessageFilter() {

        public void filterOutgoing(ChatRoom room, Message message) {
            addUserToHistory(room);
        }

        public void filterIncoming(ChatRoom room, Message message) {
            addUserToHistory(room);
        }
    });
}
Also used : Message(org.jivesoftware.smack.packet.Message) ContactItem(org.jivesoftware.spark.ui.ContactItem) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) MessageFilter(org.jivesoftware.spark.ui.MessageFilter)

Aggregations

Message (org.jivesoftware.smack.packet.Message)1 ChatRoom (org.jivesoftware.spark.ui.ChatRoom)1 ContactItem (org.jivesoftware.spark.ui.ContactItem)1 MessageFilter (org.jivesoftware.spark.ui.MessageFilter)1