Search in sources :

Example 1 with ContactList

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

the class BroadcastDialog method hideOfflineUsers.

private void hideOfflineUsers() {
    int i;
    if (OfflineUsers.isSelected()) {
        final ContactList contactList = SparkManager.getWorkspace().getContactList();
        i = 0;
        for (CheckNode node : nodes) {
            if (contactList.getContactItemByDisplayName(node.toString()).getPresence().getType() == Presence.Type.unavailable) {
                if (node.getParent() != null) {
                    TreeNode parent = node.getParent();
                    TreeNode[] path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(parent);
                    ((DefaultTreeModel) checkTree.getTree().getModel()).removeNodeFromParent(node);
                    checkTree.getTree().setSelectionPath(new TreePath(path));
                    NodesGroups.add(new ArrayList<>());
                    NodesGroups.get(i).add(parent);
                    NodesGroups.get(i).add(node);
                    i++;
                }
            }
        }
        for (int x = 0; x < groupNodes.size(); x++) {
            if (groupNodes.get(x).toString().equals(Res.getString("group.offline"))) {
                OfflineGroup = x;
                TreeNode parent = groupNodes.get(x).getParent();
                TreeNode[] path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(parent);
                ((DefaultTreeModel) checkTree.getTree().getModel()).removeNodeFromParent(groupNodes.get(x));
                checkTree.getTree().setSelectionPath(new TreePath(path));
            }
        }
    } else {
        i = 0;
        DefaultMutableTreeNode child = groupNodes.get(OfflineGroup);
        ((DefaultTreeModel) checkTree.getTree().getModel()).insertNodeInto(child, rosterNode, rosterNode.getChildCount());
        TreeNode[] path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(rosterNode);
        checkTree.getTree().expandPath(new TreePath(path));
        checkTree.expandTree();
        for (CheckNode node : nodes) {
            if (node.getParent() == null) {
                child = (CheckNode) NodesGroups.get(i).get(1);
                ((DefaultTreeModel) checkTree.getTree().getModel()).insertNodeInto(child, ((CheckNode) NodesGroups.get(i).get(0)), ((CheckNode) NodesGroups.get(i).get(0)).getChildCount());
                path = ((DefaultTreeModel) checkTree.getTree().getModel()).getPathToRoot(node);
                checkTree.getTree().expandPath(new TreePath(path));
                checkTree.expandTree();
                i++;
            }
        }
    }
}
Also used : TreePath(javax.swing.tree.TreePath) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) ContactList(org.jivesoftware.spark.ui.ContactList) CheckNode(org.jivesoftware.spark.component.CheckNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 2 with ContactList

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

the class ReceiveFileTransfer method acceptFileTransfer.

public void acceptFileTransfer(final FileTransferRequest request) {
    String fileName = request.getFileName();
    long fileSize = request.getFileSize();
    String requestor = request.getRequestor();
    String bareJID = XmppStringUtils.parseBareJid(requestor);
    // SPARK-1869
    FileTransferNegotiator.getInstanceFor(SparkManager.getConnection());
    FileTransferNegotiator.IBB_ONLY = SettingsManager.getLocalPreferences().isFileTransferIbbOnly();
    ByteFormat format = new ByteFormat();
    String text = format.format(fileSize);
    fileLabel.setText(fileName + " (" + text + ")");
    ContactList contactList = SparkManager.getWorkspace().getContactList();
    ContactItem contactItem = contactList.getContactItemByJID(bareJID);
    titleLabel.setText(Res.getString("message.user.is.sending.you.a.file", contactItem.getDisplayName()));
    File tempFile = new File(Spark.getSparkUserHome(), "/tmp");
    try {
        tempFile.mkdirs();
        File file = new File(tempFile, fileName);
        file.delete();
        BufferedWriter out = new BufferedWriter(new FileWriter(file));
        out.write("a");
        out.close();
        imageLabel.setIcon(GraphicUtils.getIcon(file));
        // Delete temp file when program exits.
        file.delete();
    } catch (IOException e) {
        imageLabel.setIcon(SparkRes.getImageIcon(SparkRes.DOCUMENT_INFO_32x32));
        Log.error(e);
    }
    acceptButton.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            try {
                Downloads.checkDownloadDirectory();
                acceptRequest(request);
            } catch (Exception ex) {
                // this means there is a problem with the download directory
                try {
                    request.reject();
                } catch (SmackException.NotConnectedException e1) {
                    Log.warning("Unable to reject the request.", ex);
                }
                setBackground(new Color(239, 245, 250));
                acceptButton.setVisible(false);
                declineButton.setVisible(false);
                if (Downloads.getDownloadDirectory() == null) {
                    fileLabel.setText("");
                } else {
                    ResourceUtils.resLabel(fileLabel, null, Res.getString("label.transfer.download.directory") + " " + Downloads.getDownloadDirectory().getAbsolutePath());
                }
                // option to set a new path for the file-download
                pathButton.setVisible(true);
                pathButton.addMouseListener(new MouseAdapter() {

                    public void mousePressed(MouseEvent e) {
                        Preference p = SparkManager.getPreferenceManager().getPreference(new FileTransferPreference().getNamespace());
                        // retrieve the filetransfer preferences and show the preference menu
                        // to the user
                        SparkManager.getPreferenceManager().showPreferences(p);
                    }
                });
                titleLabel.setText(ex.getMessage());
                titleLabel.setForeground(new Color(65, 139, 179));
                invalidate();
                validate();
                repaint();
            }
        }
    });
    declineButton.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            rejectRequest(request);
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) ContactItem(org.jivesoftware.spark.ui.ContactItem) FileWriter(java.io.FileWriter) SmackException(org.jivesoftware.smack.SmackException) Color(java.awt.Color) MouseAdapter(java.awt.event.MouseAdapter) ContactList(org.jivesoftware.spark.ui.ContactList) IOException(java.io.IOException) FileTransferPreference(org.jivesoftware.spark.filetransfer.preferences.FileTransferPreference) SmackException(org.jivesoftware.smack.SmackException) URISyntaxException(java.net.URISyntaxException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) BufferedWriter(java.io.BufferedWriter) ByteFormat(org.jivesoftware.spark.util.ByteFormat) FileTransferPreference(org.jivesoftware.spark.filetransfer.preferences.FileTransferPreference) Preference(org.jivesoftware.spark.preference.Preference) File(java.io.File)

Example 3 with ContactList

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

the class OutgoingCall method handleOutgoingCall.

/**
 * Handles a new outgoing call.
 *
 * @param session  the JingleSession for the outgoing call.
 * @param chatRoom the room the session is associated with.
 * @param jid      the users jid.
 */
public void handleOutgoingCall(final JingleSession session, ChatRoom chatRoom, final String jid) throws SmackException {
    this.chatRoom = chatRoom;
    JingleStateManager.getInstance().addJingleSession(chatRoom, JingleStateManager.JingleRoomState.ringing);
    chatRoom.addClosingListener(this);
    session.addListener(this);
    cancelButton.setVisible(true);
    this.session = session;
    // Start the call
    this.session.startOutgoing();
    fileLabel.setText(jid);
    ContactList contactList = SparkManager.getWorkspace().getContactList();
    ContactItem contactItem = contactList.getContactItemByJID(jid);
    titleLabel.setText(JingleResources.getString("label.outgoing.voicechat", contactItem.getNickname()));
    cancelButton.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent e) {
            cancel();
        }

        public void mouseEntered(MouseEvent e) {
            cancelButton.setCursor(new Cursor(Cursor.HAND_CURSOR));
        }

        public void mouseExited(MouseEvent e) {
            cancelButton.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
        }
    });
    makeClickable(imageLabel);
    makeClickable(titleLabel);
    // Notify state change
    SparkManager.getChatManager().notifySparkTabHandlers(chatRoom);
    updateOutgoingCallPanel();
}
Also used : MouseEvent(java.awt.event.MouseEvent) ContactItem(org.jivesoftware.spark.ui.ContactItem) MouseAdapter(java.awt.event.MouseAdapter) ContactList(org.jivesoftware.spark.ui.ContactList) Cursor(java.awt.Cursor)

Example 4 with ContactList

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

the class ScratchPadPlugin method initialize.

public void initialize() {
    TimerTask startTask = new TimerTask() {

        @Override
        public void run() {
            EventQueue.invokeLater(() -> {
                panel_events = new JPanel();
                mainPanel = new JPanel();
            });
        }
    };
    TaskEngine.getInstance().schedule(startTask, 500);
    ContactList contactList = SparkManager.getWorkspace().getContactList();
    contactList.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("control F6"), "viewNotes");
    contactList.getActionMap().put("viewNotes", new AbstractAction("viewNotes") {

        private static final long serialVersionUID = -3258500919859584696L;

        public void actionPerformed(ActionEvent evt) {
            // Retrieve notes and dispaly in editor.
            retrieveNotes();
        }
    });
    contactList.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke("control F5"), "viewTasks");
    contactList.getActionMap().put("viewTasks", new AbstractAction("viewTasks") {

        private static final long serialVersionUID = 8589614513097901484L;

        public void actionPerformed(ActionEvent evt) {
            // Retrieve notes and dispaly in editor.
            showTaskList();
        }
    });
    // TODO REMOVE
    @SuppressWarnings("unused") int index = -1;
    JPanel commandPanel = SparkManager.getWorkspace().getCommandPanel();
    for (int i = 0; i < commandPanel.getComponentCount(); i++) {
        if (commandPanel.getComponent(i) instanceof JLabel) {
            break;
        }
    }
    JMenuItem taskMenu = new JMenuItem(Res.getString("button.view.tasklist"), SparkRes.getImageIcon(SparkRes.DESKTOP_IMAGE));
    JMenuItem notesMenu = new JMenuItem(Res.getString("button.view.notes"), SparkRes.getImageIcon(SparkRes.DOCUMENT_16x16));
    taskMenu.addActionListener(e -> showTaskList());
    notesMenu.addActionListener(e -> retrieveNotes());
    // Add To toolbar
    final JMenu actionsMenu = SparkManager.getMainWindow().getMenuByName(Res.getString("menuitem.actions"));
    actionsMenu.addSeparator();
    // See if we should disable the "View task list" option under "Actions"
    if (!Default.getBoolean("DISABLE_VIEW_TASK_LIST") && Enterprise.containsFeature(Enterprise.VIEW_TASKS_FEATURE))
        actionsMenu.add(taskMenu);
    // See if we should disable the "View notes" option under "Actions"
    if (!Default.getBoolean("DISABLE_VIEW_NOTES") && Enterprise.containsFeature(Enterprise.VIEW_NOTES_FEATURE))
        actionsMenu.add(notesMenu);
    // Start notifications.
    new TaskNotification();
}
Also used : TimerTask(java.util.TimerTask) ContactList(org.jivesoftware.spark.ui.ContactList)

Example 5 with ContactList

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

Aggregations

ContactList (org.jivesoftware.spark.ui.ContactList)20 ContactItem (org.jivesoftware.spark.ui.ContactItem)16 MouseEvent (java.awt.event.MouseEvent)10 MouseAdapter (java.awt.event.MouseAdapter)6 File (java.io.File)5 StanzaTypeFilter (org.jivesoftware.smack.filter.StanzaTypeFilter)5 Color (java.awt.Color)4 Cursor (java.awt.Cursor)4 GridBagConstraints (java.awt.GridBagConstraints)4 Insets (java.awt.Insets)4 ActionEvent (java.awt.event.ActionEvent)4 MalformedURLException (java.net.MalformedURLException)4 AbstractAction (javax.swing.AbstractAction)4 Action (javax.swing.Action)4 JPopupMenu (javax.swing.JPopupMenu)4 Presence (org.jivesoftware.smack.packet.Presence)4 ContextMenuListener (org.jivesoftware.spark.plugin.ContextMenuListener)4 ContactGroup (org.jivesoftware.spark.ui.ContactGroup)4 IOException (java.io.IOException)3 URL (java.net.URL)3