Search in sources :

Example 21 with ContactItem

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

the class BuzzPlugin method shakeWindow.

private void shakeWindow(Message message) {
    String bareJID = XmppStringUtils.parseBareJid(message.getFrom());
    ContactItem contact = SparkManager.getWorkspace().getContactList().getContactItemByJID(bareJID);
    String nickname = XmppStringUtils.parseLocalpart(bareJID);
    if (contact != null) {
        nickname = contact.getDisplayName();
    }
    ChatRoom room;
    try {
        room = SparkManager.getChatManager().getChatContainer().getChatRoom(bareJID);
    } catch (ChatRoomNotFoundException e) {
        // Create the room if it does not exist.
        room = SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname);
    }
    ChatFrame chatFrame = SparkManager.getChatManager().getChatContainer().getChatFrame();
    if (chatFrame != null) {
        if (SettingsManager.getLocalPreferences().isBuzzEnabled()) {
            chatFrame.buzz();
            SparkManager.getChatManager().getChatContainer().activateChatRoom(room);
        }
    }
    // Insert offline message
    room.getTranscriptWindow().insertNotificationMessage(Res.getString("message.buzz.message", nickname), ChatManager.NOTIFICATION_COLOR);
    room.scrollToBottom();
}
Also used : ChatFrame(org.jivesoftware.spark.ui.ChatFrame) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) ContactItem(org.jivesoftware.spark.ui.ContactItem)

Example 22 with ContactItem

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

the class NotificationPlugin method registerListener.

private void registerListener() {
    preferences = SettingsManager.getLocalPreferences();
    // Iterate through all online users and add them to the list.
    ContactList contactList = SparkManager.getWorkspace().getContactList();
    for (ContactGroup contactGroup : contactList.getContactGroups()) {
        for (ContactItem item : contactGroup.getContactItems()) {
            if (item != null && item.getJID() != null && item.getPresence().isAvailable()) {
                String bareJID = XmppStringUtils.parseBareJid(item.getJID());
                onlineUsers.add(bareJID);
            }
        }
    }
    // Add Presence Listener
    SparkManager.getConnection().addAsyncStanzaListener(this, new StanzaTypeFilter(Presence.class));
}
Also used : StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) ContactItem(org.jivesoftware.spark.ui.ContactItem) Presence(org.jivesoftware.smack.packet.Presence) ContactList(org.jivesoftware.spark.ui.ContactList) ContactGroup(org.jivesoftware.spark.ui.ContactGroup)

Example 23 with ContactItem

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

the class JabberVersion method initialize.

public void initialize() {
    // Create IQ Filter
    StanzaFilter packetFilter = new StanzaTypeFilter(IQ.class);
    SparkManager.getConnection().addAsyncStanzaListener(stanza -> {
        IQ iq = (IQ) stanza;
        try {
            // Handle Version Request
            if (iq instanceof Version && iq.getType() == IQ.Type.get) {
                // Send Version
                Version version = new Version(JiveInfo.getName(), JiveInfo.getVersion(), JiveInfo.getOS());
                // Send back as a reply
                version.setStanzaId(iq.getStanzaId());
                version.setType(IQ.Type.result);
                version.setTo(iq.getFrom());
                version.setFrom(iq.getTo());
                SparkManager.getConnection().sendStanza(version);
            } else // Send time
            if (iq instanceof Time && iq.getType() == IQ.Type.get) {
                Time time = new Time();
                time.setStanzaId(iq.getStanzaId());
                time.setFrom(iq.getTo());
                time.setTo(iq.getFrom());
                time.setTime(new Date());
                time.setType(IQ.Type.result);
                // Send Time
                SparkManager.getConnection().sendStanza(time);
            }
        } catch (SmackException.NotConnectedException e) {
            Log.warning("Unable to answer request: " + stanza, e);
        }
    }, packetFilter);
    final ContactList contactList = SparkManager.getWorkspace().getContactList();
    contactList.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("control F11"), "viewClient");
    contactList.addContextMenuListener(new ContextMenuListener() {

        public void poppingUp(final Object component, JPopupMenu popup) {
            if (!(component instanceof ContactItem)) {
                return;
            }
            ContactItem contactItem = (ContactItem) component;
            if (contactItem.getPresence() == null) {
                return;
            }
            Action versionRequest = new AbstractAction() {

                private static final long serialVersionUID = -5619737417315441711L;

                public void actionPerformed(ActionEvent e) {
                    viewClient();
                }
            };
            versionRequest.putValue(Action.NAME, Res.getString("menuitem.view.client.version"));
            popup.add(versionRequest);
        }

        public void poppingDown(JPopupMenu popup) {
        }

        public boolean handleDefaultAction(MouseEvent e) {
            return false;
        }
    });
    contactList.getActionMap().put("viewClient", new AbstractAction("viewClient") {

        private static final long serialVersionUID = 8282301357403753561L;

        public void actionPerformed(ActionEvent evt) {
            viewClient();
        }
    });
}
Also used : Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) StanzaFilter(org.jivesoftware.smack.filter.StanzaFilter) MouseEvent(java.awt.event.MouseEvent) ActionEvent(java.awt.event.ActionEvent) SmackException(org.jivesoftware.smack.SmackException) ContactItem(org.jivesoftware.spark.ui.ContactItem) IQ(org.jivesoftware.smack.packet.IQ) ContextMenuListener(org.jivesoftware.spark.plugin.ContextMenuListener) Time(org.jivesoftware.smackx.time.packet.Time) ContactList(org.jivesoftware.spark.ui.ContactList) Date(java.util.Date) JPopupMenu(javax.swing.JPopupMenu) StanzaTypeFilter(org.jivesoftware.smack.filter.StanzaTypeFilter) Version(org.jivesoftware.smackx.iqversion.packet.Version) AbstractAction(javax.swing.AbstractAction)

Example 24 with ContactItem

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

the class JabberVersion method viewClient.

private void viewClient() {
    final ContactList contactList = SparkManager.getWorkspace().getContactList();
    Collection<ContactItem> selectedUsers = contactList.getSelectedUsers();
    if (selectedUsers.size() == 1) {
        ContactItem item = (ContactItem) selectedUsers.toArray()[0];
        Presence presence = item.getPresence();
        final String jid = presence.getFrom();
        SwingWorker worker = new SwingWorker() {

            public Object construct() {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException e1) {
                // Nothing to do
                }
                return jid;
            }

            public void finished() {
                VersionViewer.viewVersion(jid);
            }
        };
        worker.start();
    }
}
Also used : ContactItem(org.jivesoftware.spark.ui.ContactItem) Presence(org.jivesoftware.smack.packet.Presence) SwingWorker(org.jivesoftware.spark.util.SwingWorker) ContactList(org.jivesoftware.spark.ui.ContactList)

Example 25 with ContactItem

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

the class FrequentContactsPlugin method showPopup.

/**
 * Displays your favorite contacts.
 */
private void showPopup() {
    // Get Transcript Directory
    if (!transcriptDir.exists()) {
        return;
    }
    jidMap.clear();
    model.clear();
    final ContactList contactList = SparkManager.getWorkspace().getContactList();
    for (final String user : getFavoriteContacts()) {
        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) JLabel(javax.swing.JLabel) ContactList(org.jivesoftware.spark.ui.ContactList) Icon(javax.swing.Icon)

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