Search in sources :

Example 46 with SwingWorker

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

the class VCardManager method viewProfile.

/**
 * Displays <code>VCardViewer</code> for a particular JID.
 *
 * @param jid    the jid of the user to display.
 * @param parent the parent component to use for displaying dialog.
 */
public void viewProfile(final String jid, final JComponent parent) {
    final SwingWorker vcardThread = new SwingWorker() {

        VCard vcard = new VCard();

        public Object construct() {
            vcard = getVCard(jid);
            return vcard;
        }

        public void finished() {
            if (vcard == null) {
                // Show vcard not found
                UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                JOptionPane.showMessageDialog(parent, Res.getString("message.unable.to.load.profile", jid), Res.getString("title.profile.not.found"), JOptionPane.ERROR_MESSAGE);
            } else {
                editor.displayProfile(jid, vcard, parent);
            }
        }
    };
    vcardThread.start();
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker) VCard(org.jivesoftware.smackx.vcardtemp.packet.VCard)

Example 47 with SwingWorker

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

the class GatewayPlugin method initialize.

@Override
public void initialize() {
    ProviderManager.addIQProvider(Gateway.ELEMENT_NAME, Gateway.NAMESPACE, new Gateway.Provider());
    LocalPreferences localPref = SettingsManager.getLocalPreferences();
    useTab = localPref.getShowTransportTab();
    transferTab.setBackground((Color) UIManager.get("ContactItem.background"));
    SwingWorker thread = new SwingWorker() {

        @Override
        public Object construct() {
            try {
                // Let's try and avoid any timing issues with the gateway presence.
                Thread.sleep(5000);
                populateTransports();
            } catch (Exception e) {
                Log.error(e);
                return false;
            }
            return true;
        }

        @Override
        public void finished() {
            transferTab.setLayout(new VerticalFlowLayout(0, 0, 0, true, false));
            Boolean transportExists = (Boolean) get();
            if (!transportExists) {
                return;
            }
            if (TransportUtils.getTransports().size() > 0 && useTab) {
                SparkManager.getWorkspace().getWorkspacePane().addTab(Res.getString("title.transports"), SparkRes.getImageIcon(SparkRes.TRANSPORT_ICON), transferTab);
            }
            for (final Transport transport : TransportUtils.getTransports()) {
                addTransport(transport);
            }
            // Register presences.
            registerPresenceListener();
        }
    };
    thread.start();
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) SmackException(org.jivesoftware.smack.SmackException) VerticalFlowLayout(org.jivesoftware.spark.component.VerticalFlowLayout)

Example 48 with SwingWorker

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

the class BookmarkItem method addConferenceRoom.

public void addConferenceRoom(final BookmarkedConference bookmark) {
    imageLabel.setIcon(SparkRes.getImageIcon(SparkRes.CONFERENCE_IMAGE_16x16));
    nameLabel.setText(bookmark.getName());
    descriptionLabel.setText(bookmark.getJid().toString());
    action = new AbstractAction() {

        private static final long serialVersionUID = 4324785627112595384L;

        @Override
        public void actionPerformed(ActionEvent e) {
            SwingWorker worker = new SwingWorker() {

                @Override
                public Object construct() {
                    try {
                        Thread.sleep(10);
                    } catch (InterruptedException e1) {
                        Log.error(e1);
                    }
                    return "ok";
                }

                @Override
                public void finished() {
                    ConferenceUtils.joinConferenceOnSeperateThread(bookmark.getName(), bookmark.getJid(), bookmark.getPassword());
                }
            };
            worker.start();
        }
    };
}
Also used : ActionEvent(java.awt.event.ActionEvent) SwingWorker(org.jivesoftware.spark.util.SwingWorker) AbstractAction(javax.swing.AbstractAction)

Example 49 with SwingWorker

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

the class VCardManager method viewProfile.

/**
 * Displays <code>VCardViewer</code> for a particular JID.
 *
 * @param jid    the jid of the user to display.
 * @param parent the parent component to use for displaying dialog.
 */
public void viewProfile(final BareJid jid, final JComponent parent) {
    final SwingWorker vcardThread = new SwingWorker() {

        VCard vcard = new VCard();

        @Override
        public Object construct() {
            vcard = getVCard(jid);
            return vcard;
        }

        @Override
        public void finished() {
            if (vcard == null) {
                // Show vcard not found
                UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                JOptionPane.showMessageDialog(parent, Res.getString("message.unable.to.load.profile", jid), Res.getString("title.profile.not.found"), JOptionPane.ERROR_MESSAGE);
            } else {
                editor.displayProfile(jid, vcard, parent);
            }
        }
    };
    vcardThread.start();
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker) VCard(org.jivesoftware.smackx.vcardtemp.packet.VCard)

Example 50 with SwingWorker

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

the class SoundPreference method load.

@Override
public void load() {
    if (soundPanel == null) {
        soundPanel = new SoundPanel();
    }
    SwingWorker worker = new SwingWorker() {

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

        @Override
        public void finished() {
            // Set default settings
            soundPanel.setIncomingMessageSound(preferences.getIncomingSound());
            soundPanel.playIncomingSound(preferences.isPlayIncomingSound());
            soundPanel.setOutgoingMessageSound(preferences.getOutgoingSound());
            soundPanel.playOutgoingSound(preferences.isPlayOutgoingSound());
            soundPanel.setOfflineSound(preferences.getOfflineSound());
            soundPanel.playOfflineSound(preferences.isPlayOfflineSound());
            soundPanel.setInvitationSound(preferences.getIncomingInvitationSoundFile());
            soundPanel.setPlayInvitationSound(preferences.playIncomingInvitationSound());
        }
    };
    worker.start();
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker)

Aggregations

SwingWorker (org.jivesoftware.spark.util.SwingWorker)78 SmackException (org.jivesoftware.smack.SmackException)21 XMPPException (org.jivesoftware.smack.XMPPException)17 Presence (org.jivesoftware.smack.packet.Presence)12 MouseAdapter (java.awt.event.MouseAdapter)11 MouseEvent (java.awt.event.MouseEvent)11 GridBagConstraints (java.awt.GridBagConstraints)10 Insets (java.awt.Insets)10 JLabel (javax.swing.JLabel)10 ActionEvent (java.awt.event.ActionEvent)9 JPanel (javax.swing.JPanel)9 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)9 IOException (java.io.IOException)8 ArrayList (java.util.ArrayList)8 EntityBareJid (org.jxmpp.jid.EntityBareJid)8 Collection (java.util.Collection)7 Action (javax.swing.Action)7 GridBagLayout (java.awt.GridBagLayout)6 AbstractAction (javax.swing.AbstractAction)6 JDialog (javax.swing.JDialog)6