Search in sources :

Example 41 with SwingWorker

use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.

the class PhonePlugin method initialize.

public void initialize() {
    ProviderManager.addExtensionProvider("phone-event", "http://jivesoftware.com/xmlns/phone", new PhoneEventPacketExtensionProvider());
    ProviderManager.addIQProvider("phone-action", "http://jivesoftware.com/xmlns/phone", new PhoneActionIQProvider());
    final XMPPConnection con = SparkManager.getConnection();
    SwingWorker worker = new SwingWorker() {

        public Object construct() {
            try {
                phoneClient = new PhoneClient(con);
                // Add BaseListener
                phoneClient.addEventListener(new PhoneListener());
            } catch (Exception e) {
            // Ignore because the user does not have support.
            // Log.debug(e);
            }
            return phoneClient;
        }

        public void finished() {
            if (phoneClient != null) {
                setupPhoneSystem();
            }
        }
    };
    worker.start();
}
Also used : PhoneEventPacketExtensionProvider(org.jivesoftware.phone.client.event.PhoneEventPacketExtensionProvider) SwingWorker(org.jivesoftware.spark.util.SwingWorker) XMPPConnection(org.jivesoftware.smack.XMPPConnection) PhoneActionIQProvider(org.jivesoftware.phone.client.action.PhoneActionIQProvider)

Example 42 with SwingWorker

use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.

the class PhoneManager method chatRoomOpened.

public void chatRoomOpened(final ChatRoom room) {
    if (!phones.isEmpty() && room instanceof ChatRoomImpl) {
        final ChatRoomImpl chatRoomImpl = (ChatRoomImpl) room;
        final ChatRoomButton dialButton = new ChatRoomButton(SparkRes.getImageIcon(SparkRes.DIAL_PHONE_IMAGE_24x24));
        dialButton.setToolTipText(Res.getString("tooltip.place.voice.call"));
        final List<Action> actions = new ArrayList<>();
        SwingWorker actionWorker = new SwingWorker() {

            public Object construct() {
                for (Phone phone : phones) {
                    final Collection<Action> phoneActions = phone.getPhoneActions(chatRoomImpl.getParticipantJID());
                    if (phoneActions != null) {
                        for (Action action : phoneActions) {
                            actions.add(action);
                        }
                    }
                }
                return actions;
            }

            public void finished() {
                if (!actions.isEmpty()) {
                    room.addChatRoomButton(dialButton, true);
                }
            }
        };
        actionWorker.start();
        dialButton.addMouseListener(new MouseAdapter() {

            public void mousePressed(final MouseEvent e) {
                SwingWorker worker = new SwingWorker() {

                    public Object construct() {
                        try {
                            Thread.sleep(50);
                        } catch (InterruptedException e1) {
                            e1.printStackTrace();
                        }
                        return true;
                    }

                    public void finished() {
                        // Handle actions.
                        if (actions.size() > 0) {
                            // Display PopupMenu
                            final JPopupMenu menu = new JPopupMenu();
                            for (Action action : actions) {
                                menu.add(action);
                            }
                            menu.show(dialButton, e.getX(), e.getY());
                        }
                    }
                };
                worker.start();
            }
        });
    }
}
Also used : Action(javax.swing.Action) MouseEvent(java.awt.event.MouseEvent) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) MouseAdapter(java.awt.event.MouseAdapter) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl) JPopupMenu(javax.swing.JPopupMenu) SwingWorker(org.jivesoftware.spark.util.SwingWorker) ChatRoomButton(org.jivesoftware.spark.ui.ChatRoomButton)

Example 43 with SwingWorker

use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.

the class PhoneManager method poppingUp.

public void poppingUp(Object object, final JPopupMenu popup) {
    if (!phones.isEmpty()) {
        if (object instanceof ContactItem) {
            final ContactItem contactItem = (ContactItem) object;
            final List<Action> actions = new ArrayList<>();
            SwingWorker worker = new SwingWorker() {

                public Object construct() {
                    for (Phone phone : phones) {
                        final Collection<Action> itemActions = phone.getPhoneActions(contactItem.getJID());
                        for (Action action : itemActions) {
                            actions.add(action);
                        }
                    }
                    return null;
                }

                public void finished() {
                    if (actions.size() > 0) {
                        final JMenu dialMenu = new JMenu(Res.getString("title.dial.phone"));
                        dialMenu.setIcon(SparkRes.getImageIcon(SparkRes.DIAL_PHONE_IMAGE_16x16));
                        for (Action action : actions) {
                            dialMenu.add(action);
                        }
                        int count = popup.getComponentCount();
                        if (count > 2) {
                            popup.insert(dialMenu, 2);
                        }
                        popup.invalidate();
                        popup.validate();
                        popup.repaint();
                    }
                }
            };
            worker.start();
        }
    }
}
Also used : Action(javax.swing.Action) ContactItem(org.jivesoftware.spark.ui.ContactItem) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) SwingWorker(org.jivesoftware.spark.util.SwingWorker) JMenu(javax.swing.JMenu)

Example 44 with SwingWorker

use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.

the class SipCodecsPreference method load.

@Override
public void load() {
    SwingWorker thread = new SwingWorker() {

        LocalPreferences localPreferences;

        public Object construct() {
            localPreferences = SettingsManager.getLocalPreferences();
            return localPreferences;
        }

        public void finished() {
            String sel = localPreferences.getSelectedCodecs();
            String avail = localPreferences.getAvailableCodecs();
            panel.setAvailable(avail);
            panel.setSelected(sel);
        }
    };
    thread.start();
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences)

Example 45 with SwingWorker

use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.

the class SipPreference method load.

public void load() {
    SwingWorker worker = new SwingWorker() {

        public Object construct() {
            loadFromFile();
            return preferences;
        }

        public void finished() {
            panel.setUserName(preferences.getUserName() != null ? preferences.getUserName() : "");
            panel.setAuthUserName(preferences.getAuthUserName() != null ? preferences.getAuthUserName() : "");
            panel.setServer(preferences.getServer() != null ? preferences.getServer() : "");
            panel.setPassword(preferences.getPassword() != null ? preferences.getPassword() : "");
            panel.setRegister(preferences.isRegisterAtStart());
            panel.setStunServer(preferences.getStunServer());
            panel.setStunPort(preferences.getStunPort());
            panel.setUseStun(preferences.isUseStun());
        }
    };
    worker.start();
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker)

Aggregations

SwingWorker (org.jivesoftware.spark.util.SwingWorker)65 SmackException (org.jivesoftware.smack.SmackException)22 XMPPException (org.jivesoftware.smack.XMPPException)15 Presence (org.jivesoftware.smack.packet.Presence)11 MouseAdapter (java.awt.event.MouseAdapter)8 MouseEvent (java.awt.event.MouseEvent)8 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)8 ActionEvent (java.awt.event.ActionEvent)7 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)7 GridBagConstraints (java.awt.GridBagConstraints)6 Insets (java.awt.Insets)6 Collection (java.util.Collection)6 JLabel (javax.swing.JLabel)6 JPanel (javax.swing.JPanel)5 ContactItem (org.jivesoftware.spark.ui.ContactItem)5 Action (javax.swing.Action)4 Cursor (java.awt.Cursor)3 ActionListener (java.awt.event.ActionListener)3 File (java.io.File)3