Search in sources :

Example 11 with ContactItem

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

the class OnlineAgents method init.

public void init() {
    if (agentRoster != null) {
        return;
    }
    SwingWorker agentWorker = new SwingWorker() {

        Collection<String> agentSet;

        public Object construct() {
            // Initialize Agent Roster
            try {
                agentRoster = FastpathPlugin.getAgentSession().getAgentRoster();
                agentSet = agentRoster.getAgents();
                return agentSet;
            } catch (SmackException.NotConnectedException e) {
                Log.error("Unable to load agent roster.", e);
                return null;
            }
        }

        public void finished() {
            final List<String> agentList = new ArrayList<>(agentSet);
            Collections.sort(agentList);
            for (String agent : agentList) {
                String nickname = SparkManager.getUserManager().getUserNicknameFromJID(agent);
                if (nickname == null) {
                    nickname = agent;
                }
                ContactItem item = new ContactItem(nickname, nickname, agent) {

                    private static final long serialVersionUID = -8888899031363239813L;

                    public String getToolTipText() {
                        Presence agentPresence = agentRoster.getPresence(agent);
                        return buildTooltip(agentPresence);
                    }
                };
                Presence agentPresence = agentRoster.getPresence(agent);
                item.setPresence(agentPresence);
            }
            agentRoster.addListener(new OnlineAgentListener());
        }
    };
    agentWorker.start();
}
Also used : SmackException(org.jivesoftware.smack.SmackException) ContactItem(org.jivesoftware.spark.ui.ContactItem) ArrayList(java.util.ArrayList) SwingWorker(org.jivesoftware.spark.util.SwingWorker) Collection(java.util.Collection) Presence(org.jivesoftware.smack.packet.Presence)

Example 12 with ContactItem

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

the class UserManager method searchContacts.

public void searchContacts(String contact, final JFrame parent) {
    if (parents.get(parent) == null && parent.getGlassPane() != null) {
        parents.put(parent, parent.getGlassPane());
    }
    // Make sure we are using the default glass pane
    final Component glassPane = parents.get(parent);
    parent.setGlassPane(glassPane);
    final Map<String, ContactItem> contactMap = new HashMap<>();
    final List<ContactItem> contacts = new ArrayList<>();
    final ContactList contactList = SparkManager.getWorkspace().getContactList();
    for (ContactGroup contactGroup : contactList.getContactGroups()) {
        contactGroup.clearSelection();
        for (ContactItem contactItem : contactGroup.getContactItems()) {
            if (!contactMap.containsKey(contactItem.getJID())) {
                contacts.add(contactItem);
                contactMap.put(contactItem.getJID(), contactItem);
            }
        }
    }
    // Sort
    Collections.sort(contacts, itemComparator);
    final JContactItemField contactField = new JContactItemField(new ArrayList<>(contacts));
    JPanel layoutPanel = new JPanel();
    layoutPanel.setLayout(new GridBagLayout());
    JLabel enterLabel = new JLabel(Res.getString("label.contact.to.find"));
    enterLabel.setFont(new Font("dialog", Font.BOLD, 10));
    layoutPanel.add(enterLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0));
    layoutPanel.add(contactField, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 50, 0));
    layoutPanel.setBorder(BorderFactory.createBevelBorder(0));
    contactField.addKeyListener(new KeyAdapter() {

        public void keyReleased(KeyEvent keyEvent) {
            if (keyEvent.getKeyChar() == KeyEvent.VK_ENTER) {
                if (ModelUtil.hasLength(contactField.getText())) {
                    ContactItem item = contactMap.get(contactField.getText());
                    if (item == null) {
                        item = contactField.getSelectedContactItem();
                    }
                    if (item != null) {
                        parent.setGlassPane(glassPane);
                        parent.getGlassPane().setVisible(false);
                        contactField.dispose();
                        SparkManager.getChatManager().activateChat(item.getJID(), item.getDisplayName());
                    }
                }
            } else if (keyEvent.getKeyChar() == KeyEvent.VK_ESCAPE) {
                parent.setGlassPane(glassPane);
                parent.getGlassPane().setVisible(false);
                contactField.dispose();
            }
        }
    });
    contactField.getList().addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                contactField.setSelectetIndex(e);
                ContactItem item = contactField.getSelectedContactItem();
                MouseEvent exx = new MouseEvent((Component) e.getSource(), e.getID(), e.getWhen(), e.getModifiers(), e.getX() + 20, e.getY(), e.getClickCount(), false);
                SparkManager.getContactList().setSelectedUser(item.getJID());
                SparkManager.getContactList().showPopup(contactField.getPopup(), exx, item);
            }
            if (e.getClickCount() == 2) {
                if (ModelUtil.hasLength(contactField.getText())) {
                    ContactItem item = contactMap.get(contactField.getText());
                    if (item == null) {
                        item = contactField.getSelectedContactItem();
                    }
                    if (item != null) {
                        parent.setGlassPane(glassPane);
                        parent.getGlassPane().setVisible(false);
                        contactField.dispose();
                        SparkManager.getChatManager().activateChat(item.getJID(), item.getDisplayName());
                    }
                }
            }
        }
    });
    final JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.setLayout(new GridBagLayout());
    mainPanel.add(layoutPanel, new GridBagConstraints(0, 0, 1, 1, 0.5, 0.5, GridBagConstraints.NORTH, GridBagConstraints.NONE, new Insets(SparkManager.getMainWindow().getTopToolBar().getHeight() + SparkManager.getWorkspace().getStatusBar().getHeight() + 47, 1, 5, 1), 200, 0));
    mainPanel.setOpaque(false);
    contactField.setText(contact);
    parent.setGlassPane(mainPanel);
    parent.getGlassPane().setVisible(true);
    contactField.focus();
    mainPanel.addMouseListener(new MouseAdapter() {

        public void mouseClicked(MouseEvent mouseEvent) {
            parent.setGlassPane(glassPane);
            parent.getGlassPane().setVisible(false);
            contactField.dispose();
        }
    });
    parent.addWindowListener(new WindowAdapter() {

        public void windowClosing(WindowEvent windowEvent) {
            parent.setGlassPane(glassPane);
            parent.getGlassPane().setVisible(false);
            contactField.dispose();
            parent.removeWindowListener(this);
        }

        public void windowDeactivated(final WindowEvent windowEvent) {
            TimerTask task = new SwingTimerTask() {

                public void doRun() {
                    if (contactField.canClose()) {
                        windowClosing(windowEvent);
                    }
                }
            };
            TaskEngine.getInstance().schedule(task, 250);
        }
    });
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) HashMap(java.util.HashMap) KeyAdapter(java.awt.event.KeyAdapter) ArrayList(java.util.ArrayList) WindowAdapter(java.awt.event.WindowAdapter) Font(java.awt.Font) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) TimerTask(java.util.TimerTask) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) JContactItemField(org.jivesoftware.spark.component.JContactItemField) Component(java.awt.Component) MouseEvent(java.awt.event.MouseEvent) ContactItem(org.jivesoftware.spark.ui.ContactItem) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) ContactList(org.jivesoftware.spark.ui.ContactList) SwingTimerTask(org.jivesoftware.spark.util.SwingTimerTask) WindowEvent(java.awt.event.WindowEvent) ContactGroup(org.jivesoftware.spark.ui.ContactGroup)

Example 13 with ContactItem

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

the class Workspace method handleOfflineMessage.

/**
 * Creates a new room if necessary and inserts an offline message.
 *
 * @param message The Offline message.
 */
private void handleOfflineMessage(Message message) throws SmackException.NotConnectedException {
    if (!ModelUtil.hasLength(message.getBody())) {
        return;
    }
    String bareJID = XmppStringUtils.parseBareJid(message.getFrom());
    ContactItem contact = contactList.getContactItemByJID(bareJID);
    String nickname = XmppStringUtils.parseLocalpart(bareJID);
    if (contact != null) {
        nickname = contact.getDisplayName();
    }
    // Create the room if it does not exist.
    ChatRoom room = SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname);
    if (!SparkManager.getChatManager().getChatContainer().getChatFrame().isVisible()) {
        SparkManager.getChatManager().getChatContainer().getChatFrame().setVisible(true);
    }
    // Insert offline message
    room.getTranscriptWindow().insertMessage(nickname, message, ChatManager.FROM_COLOR);
    room.addToTranscript(message, true);
    // Send display and notified message back.
    SparkManager.getMessageEventManager().sendDeliveredNotification(message.getFrom(), message.getStanzaId());
    SparkManager.getMessageEventManager().sendDisplayedNotification(message.getFrom(), message.getStanzaId());
}
Also used : ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ContactItem(org.jivesoftware.spark.ui.ContactItem)

Example 14 with ContactItem

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

the class SparkTransferManager method handleTransferRequest.

private void handleTransferRequest(FileTransferRequest request, ContactList contactList) {
    // Check if a listener handled this request
    if (fireTransferListeners(request)) {
        return;
    }
    String requestor = request.getRequestor();
    String bareJID = XmppStringUtils.parseBareJid(requestor);
    String fileName = request.getFileName();
    ContactItem contactItem = contactList.getContactItemByJID(bareJID);
    ChatRoom chatRoom;
    if (contactItem != null) {
        chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, contactItem.getDisplayName(), contactItem.getDisplayName());
    } else {
        chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, bareJID, bareJID);
    }
    TranscriptWindow transcriptWindow = chatRoom.getTranscriptWindow();
    transcriptWindow.insertCustomText(Res.getString("message.file.transfer.chat.window"), true, false, Color.BLACK);
    final ReceiveFileTransfer receivingMessageUI = new ReceiveFileTransfer();
    receivingMessageUI.acceptFileTransfer(request);
    chatRoom.addClosingListener(() -> receivingMessageUI.cancelTransfer());
    transcriptWindow.addComponent(receivingMessageUI);
    chatRoom.increaseUnreadMessageCount();
    chatRoom.scrollToBottom();
    String fileTransMsg = contactItem.getDisplayName() + " " + Res.getString("message.file.transfer.short.message") + " " + fileName;
    SparkManager.getChatManager().getChatContainer().fireNotifyOnMessage(chatRoom, true, fileTransMsg, Res.getString("message.file.transfer.notification"));
}
Also used : ReceiveFileTransfer(org.jivesoftware.sparkimpl.plugin.filetransfer.transfer.ui.ReceiveFileTransfer) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) TranscriptWindow(org.jivesoftware.spark.ui.TranscriptWindow) ContactItem(org.jivesoftware.spark.ui.ContactItem)

Example 15 with ContactItem

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

the class JContactItemField method showPopupMenu.

private void showPopupMenu() {
    model.removeAllElements();
    String typedItem = textField.getText();
    final List<ContactItem> validItems = new ArrayList<>();
    for (ContactItem contactItem : items) {
        String nickname = contactItem.getDisplayName().toLowerCase();
        if (nickname.startsWith(typedItem.toLowerCase())) {
            validItems.add(contactItem);
        } else if (typedItem.length() > 2 && nickname.contains(typedItem.toLowerCase())) {
            validItems.add(contactItem);
        }
    }
    if (validItems.size() > 0) {
        for (final ContactItem label : validItems) {
            model.addElement(label);
        }
    }
    if (validItems.size() != 0) {
        popup.pack();
        if (validItems.size() * 16 <= SparkManager.getContactList().getHeight() - SparkManager.getSearchManager().getSearchServiceUI().getHeight() - 14) {
            popup.setSize(textField.getWidth(), validItems.size() * 16 + 5);
        } else {
            popup.setSize(textField.getWidth(), SparkManager.getContactList().getHeight() - SparkManager.getSearchManager().getSearchServiceUI().getHeight() - 14);
        }
        Point pt = textField.getLocationOnScreen();
        pt.translate(0, textField.getHeight());
        popup.setLocation(pt);
        popup.toFront();
        popup.setVisible(true);
    }
    // set initial selection
    if (validItems.size() > 0) {
        list.setSelectedIndex(0);
    }
}
Also used : ContactItem(org.jivesoftware.spark.ui.ContactItem) ArrayList(java.util.ArrayList) Point(java.awt.Point)

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