Search in sources :

Example 6 with ContactItem

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

the class NotificationPlugin method processPacket.

public void processPacket(Stanza stanza) {
    final Presence presence = (Presence) stanza;
    String jid = presence.getFrom();
    if (jid == null) {
        return;
    }
    // Make sure the user is in the contact list.
    ContactItem contactItem = SparkManager.getWorkspace().getContactList().getContactItemByJID(jid);
    if (contactItem == null) {
        return;
    }
    jid = XmppStringUtils.parseBareJid(jid);
    boolean isOnline = onlineUsers.contains(jid);
    if (presence.isAvailable()) {
        if (preferences.isOnlineNotificationsOn()) {
            if (!isOnline) {
                notifyUserOnline(jid, presence);
            }
        }
        onlineUsers.add(jid);
    } else {
        if (preferences.isOfflineNotificationsOn() && isOnline) {
            notifyUserOffline(jid, presence);
        }
        onlineUsers.remove(jid);
    }
}
Also used : ContactItem(org.jivesoftware.spark.ui.ContactItem) Presence(org.jivesoftware.smack.packet.Presence)

Example 7 with ContactItem

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

the class PrivacyAddDialogUI method showRoster.

/**
 * Displays a pick list of available users within their roster.
 *
 * @param parent
 *            the parent container.
 * @return all items chosen in the pick list.
 */
public Collection<PrivacyItem> showRoster(Component parent, boolean showGroups) {
    _showGroups = showGroups;
    // Populate Invite Panel with Available users.
    createList();
    // Sort Users
    final JOptionPane pane;
    TitlePanel titlePanel;
    // Create the title panel for this dialog
    titlePanel = new TitlePanel(Res.getString("privacy.title.add.picker"), Res.getString("privacy.pick.one.or.more"), SparkRes.getImageIcon(SparkRes.BLANK_IMAGE), true);
    // Construct main panel w/ layout.
    final JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(titlePanel, BorderLayout.NORTH);
    // The user should only be able to close this dialog.
    Object[] options = { Res.getString("ok"), Res.getString("cancel") };
    pane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
    mainPanel.add(pane, BorderLayout.CENTER);
    final JOptionPane p = new JOptionPane();
    final JDialog dlg = p.createDialog(parent, Res.getString("privacy.title.add.picker"));
    dlg.setModal(true);
    dlg.pack();
    dlg.setSize(350, 450);
    dlg.setResizable(true);
    dlg.setContentPane(mainPanel);
    dlg.setLocationRelativeTo(parent);
    PropertyChangeListener changeListener = e -> {
        String value = (String) pane.getValue();
        if (Res.getString("cancel").equals(value)) {
            rosterList.clearSelection();
            pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
            dlg.dispose();
        } else if (Res.getString("ok").equals(value)) {
            pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
            dlg.dispose();
        }
    };
    pane.addPropertyChangeListener(changeListener);
    dlg.setVisible(true);
    dlg.toFront();
    dlg.requestFocus();
    List<PrivacyItem> selectedContacts = new ArrayList<>();
    Object[] values = rosterList.getSelectedValues();
    final int no = values != null ? values.length : 0;
    for (int i = 0; i < no; i++) {
        try {
            ContactItem item = (ContactItem) values[i];
            PrivacyItem.Type type = _showGroups ? PrivacyItem.Type.group : PrivacyItem.Type.jid;
            PrivacyItem pitem = new PrivacyItem(type, item.getJID(), false, 999);
            pitem.setFilterIQ(_blockIQ.isSelected());
            pitem.setFilterMessage(_blockMsg.isSelected());
            pitem.setFilterPresenceIn(_blockPIn.isSelected());
            pitem.setFilterPresenceOut(_blockPOout.isSelected());
            selectedContacts.add(pitem);
        } catch (NullPointerException e) {
            Log.error(e);
        }
    }
    return selectedContacts;
}
Also used : Insets(java.awt.Insets) JDialog(javax.swing.JDialog) Res(org.jivesoftware.resource.Res) Log(org.jivesoftware.spark.util.log.Log) ContactItem(org.jivesoftware.spark.ui.ContactItem) ArrayList(java.util.ArrayList) PresenceManager(org.jivesoftware.spark.PresenceManager) RosterGroup(org.jivesoftware.smack.roster.RosterGroup) BorderLayout(java.awt.BorderLayout) PrivacyItem(org.jivesoftware.smackx.privacy.packet.PrivacyItem) Presence(org.jivesoftware.smack.packet.Presence) SparkRes(org.jivesoftware.resource.SparkRes) Collection(java.util.Collection) JList(javax.swing.JList) BorderFactory(javax.swing.BorderFactory) GridBagConstraints(java.awt.GridBagConstraints) JOptionPane(javax.swing.JOptionPane) Component(java.awt.Component) TitlePanel(org.jivesoftware.spark.component.TitlePanel) JScrollPane(javax.swing.JScrollPane) List(java.util.List) DefaultListModel(javax.swing.DefaultListModel) PropertyChangeListener(java.beans.PropertyChangeListener) Roster(org.jivesoftware.smack.roster.Roster) SparkManager(org.jivesoftware.spark.SparkManager) JCheckBox(javax.swing.JCheckBox) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) GridBagLayout(java.awt.GridBagLayout) Comparator(java.util.Comparator) Collections(java.util.Collections) JPanel(javax.swing.JPanel) JPanel(javax.swing.JPanel) PropertyChangeListener(java.beans.PropertyChangeListener) ContactItem(org.jivesoftware.spark.ui.ContactItem) ArrayList(java.util.ArrayList) JOptionPane(javax.swing.JOptionPane) TitlePanel(org.jivesoftware.spark.component.TitlePanel) BorderLayout(java.awt.BorderLayout) PrivacyItem(org.jivesoftware.smackx.privacy.packet.PrivacyItem) JDialog(javax.swing.JDialog)

Example 8 with ContactItem

use of org.jivesoftware.spark.ui.ContactItem 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)

Example 9 with ContactItem

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

the class ConversationHistoryPlugin method showHistoryPopup.

/**
 * Displays the Previous Conversation Window.
 */
private void showHistoryPopup() {
    // Get Transcript Directory
    if (!transcriptDir.exists()) {
        return;
    }
    jidMap.clear();
    model.clear();
    final ContactList contactList = SparkManager.getWorkspace().getContactList();
    int limit = historyList.size() > 10 ? 10 : historyList.size();
    for (final String user : historyList.subList(0, limit)) {
        ContactItem contactItem = contactList.getContactItemByJID(user);
        Icon icon;
        if (contactItem != null) {
            icon = contactItem.getIcon();
            if (icon == null) {
                icon = SparkRes.getImageIcon(SparkRes.CLEAR_BALL_ICON);
            }
            JLabel label = new JLabel();
            label.setText(contactItem.getDisplayName());
            label.setIcon(icon);
            model.addElement(label);
            jidMap.put(label, user);
        }
    }
    window.setSize(200, 200);
    GraphicUtils.centerWindowOnComponent(window, SparkManager.getMainWindow());
    if (model.size() > 0) {
        contacts.setSelectedIndex(0);
    }
    window.setVisible(true);
}
Also used : ContactItem(org.jivesoftware.spark.ui.ContactItem) ContactList(org.jivesoftware.spark.ui.ContactList)

Example 10 with ContactItem

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

the class FrequentContactsPlugin method initialize.

public void initialize() {
    transcriptDir = new File(SparkManager.getUserDirectory(), "transcripts");
    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.frequent.contacts"));
    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();
        }
    });
    // Add KeyMappings
    SparkManager.getMainWindow().getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_T, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "favoritePeople");
    SparkManager.getMainWindow().getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_T, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "favoritePeople");
    SparkManager.getMainWindow().getRootPane().getActionMap().put("favoritePeople", new AbstractAction("favoritePeople") {

        private static final long serialVersionUID = 6836584242669218932L;

        public void actionPerformed(ActionEvent e) {
            // Show History Popup
            showPopup();
        }
    });
}
Also used : JPanel(javax.swing.JPanel) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) ContactItem(org.jivesoftware.spark.ui.ContactItem) KeyAdapter(java.awt.event.KeyAdapter) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) FocusEvent(java.awt.event.FocusEvent) KeyEvent(java.awt.event.KeyEvent) File(java.io.File) FocusListener(java.awt.event.FocusListener) AbstractAction(javax.swing.AbstractAction) JList(javax.swing.JList)

Aggregations

ContactItem (org.jivesoftware.spark.ui.ContactItem)34 ContactList (org.jivesoftware.spark.ui.ContactList)16 MouseEvent (java.awt.event.MouseEvent)10 Presence (org.jivesoftware.smack.packet.Presence)8 MouseAdapter (java.awt.event.MouseAdapter)7 ArrayList (java.util.ArrayList)7 ChatRoom (org.jivesoftware.spark.ui.ChatRoom)7 File (java.io.File)6 SmackException (org.jivesoftware.smack.SmackException)6 SwingWorker (org.jivesoftware.spark.util.SwingWorker)6 GridBagConstraints (java.awt.GridBagConstraints)5 Insets (java.awt.Insets)5 MalformedURLException (java.net.MalformedURLException)5 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)5 ContactGroup (org.jivesoftware.spark.ui.ContactGroup)5 Color (java.awt.Color)4 Cursor (java.awt.Cursor)4 ActionEvent (java.awt.event.ActionEvent)4 Action (javax.swing.Action)4 IOException (java.io.IOException)3