Search in sources :

Example 36 with SwingWorker

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

the class GatewayPlugin method initialize.

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() {

        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;
        }

        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 37 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());
    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 38 with SwingWorker

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

the class PluginViewer method loadAvailablePlugins.

private void loadAvailablePlugins() {
    availablePanel.removeAll();
    availablePanel.invalidate();
    availablePanel.validate();
    availablePanel.repaint();
    JLabel label = new JLabel(Res.getString("message.loading.please.wait"));
    availablePanel.add(label);
    SwingWorker worker = new SwingWorker() {

        Collection<PublicPlugin> pluginList = null;

        public Object construct() {
            // Prepare HTTP post
            final GetMethod post = new GetMethod(retrieveListURL);
            // Get HTTP client
            Protocol.registerProtocol("https", new Protocol("https", new EasySSLProtocolSocketFactory(), 443));
            final HttpClient httpclient = new HttpClient();
            if (Default.getBoolean("PLUGIN_REPOSITORY_USE_PROXY")) {
                String proxyHost = System.getProperty("http.proxyHost");
                String proxyPort = System.getProperty("http.proxyPort");
                if (ModelUtil.hasLength(proxyHost) && ModelUtil.hasLength(proxyPort)) {
                    try {
                        httpclient.getHostConfiguration().setProxy(proxyHost, Integer.parseInt(proxyPort));
                    } catch (NumberFormatException e) {
                        Log.error(e);
                    }
                }
            }
            try {
                int result = httpclient.executeMethod(post);
                if (result != 200) {
                    return null;
                }
                pluginList = getPluginList(post.getResponseBodyAsStream());
            } catch (Exception ex) {
            // Nothing to do
            }
            return "ok";
        }

        public void finished() {
            final PluginManager pluginManager = PluginManager.getInstance();
            if (pluginList == null) {
                availablePanel.removeAll();
                availablePanel.invalidate();
                availablePanel.validate();
                availablePanel.repaint();
                UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
                JOptionPane.showMessageDialog(availablePanel, Res.getString("message.plugins.not.available"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
                return;
            }
            Iterator<PublicPlugin> plugs = pluginList.iterator();
            availablePanel.removeAll();
            while (plugs.hasNext()) {
                PublicPlugin plugin = plugs.next();
                if (!pluginManager.isInstalled(plugin)) {
                    SparkPlugUI ui = new SparkPlugUI(plugin);
                    availablePanel.add(ui);
                    addSparkPlugUIListener(ui);
                }
            }
            availablePanel.invalidate();
            availablePanel.validate();
            availablePanel.repaint();
        }
    };
    worker.start();
}
Also used : PublicPlugin(org.jivesoftware.spark.plugin.PublicPlugin) DocumentException(org.dom4j.DocumentException) EasySSLProtocolSocketFactory(org.jivesoftware.sparkimpl.updater.EasySSLProtocolSocketFactory) PluginManager(org.jivesoftware.spark.PluginManager) HttpClient(org.apache.commons.httpclient.HttpClient) GetMethod(org.apache.commons.httpclient.methods.GetMethod) SwingWorker(org.jivesoftware.spark.util.SwingWorker) Collection(java.util.Collection) Protocol(org.apache.commons.httpclient.protocol.Protocol)

Example 39 with SwingWorker

use of org.jivesoftware.spark.util.SwingWorker 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 40 with SwingWorker

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

the class JinglePlugin method initialize.

public void initialize() {
    // Add Jingle to discovered items list.
    SparkManager.addFeature(JINGLE_NAMESPACE);
    final LocalPreferences localPref = SettingsManager.getLocalPreferences();
    // If there is a server entered in spark.properties use it as fallback
    if (!localPref.getStunFallbackHost().equals("")) {
        fallbackStunEnabled = true;
    }
    // Get the default port
    stunPort = localPref.getStunFallbackPort();
    // Set Jingle Enabled
    JingleManager.setJingleServiceEnabled();
    JingleManager.setServiceEnabled(SparkManager.getConnection(), true);
    // Add to PhoneManager
    PhoneManager.getInstance().addPhone(this);
    // Adds a tab handler.
    SparkManager.getChatManager().addSparkTabHandler(new JingleTabHandler());
    final SwingWorker jingleLoadingThread = new SwingWorker() {

        public Object construct() {
            if (fallbackStunEnabled) {
                stunServer = localPref.getStunFallbackHost();
                readyToConnect = true;
            }
            try {
                if (STUN.serviceAvailable(SparkManager.getConnection())) {
                    STUN stun = STUN.getSTUNServer(SparkManager.getConnection());
                    if (stun != null) {
                        List<STUN.StunServerAddress> servers = stun.getServers();
                        if (servers.size() > 0) {
                            stunServer = servers.get(0).getServer();
                            stunPort = Integer.parseInt(servers.get(0).getPort());
                            readyToConnect = true;
                        }
                    }
                }
                if (readyToConnect) {
                    JingleTransportManager transportManager = new ICETransportManager(SparkManager.getConnection(), stunServer, stunPort);
                    List<JingleMediaManager> mediaManagers = new ArrayList<>();
                    // Get the Locator from the Settings
                    String locator = SettingsManager.getLocalPreferences().getAudioDevice();
                    mediaManagers.add(new JmfMediaManager(locator, transportManager));
                    mediaManagers.add(new SpeexMediaManager(transportManager));
                    // mediaManagers.add(new ScreenShareMediaManager(transportManager));
                    jingleManager = new JingleManager(SparkManager.getConnection(), mediaManagers);
                    if (transportManager instanceof BridgedTransportManager) {
                        jingleManager.addCreationListener((BridgedTransportManager) transportManager);
                    } else if (transportManager instanceof ICETransportManager) {
                        jingleManager.addCreationListener((ICETransportManager) transportManager);
                    }
                }
            } catch (XMPPException | SmackException e) {
                Log.error("Unable to initialize", e);
            }
            return true;
        }

        public void finished() {
            addListeners();
        }
    };
    jingleLoadingThread.start();
    // Add Presence listener for better service discovery.
    addPresenceListener();
    SparkManager.getConnection().addConnectionListener(this);
}
Also used : JmfMediaManager(org.jivesoftware.smackx.jingleold.mediaimpl.jmf.JmfMediaManager) ICETransportManager(org.jivesoftware.smackx.jingleold.nat.ICETransportManager) JingleMediaManager(org.jivesoftware.smackx.jingleold.media.JingleMediaManager) SwingWorker(org.jivesoftware.spark.util.SwingWorker) JingleManager(org.jivesoftware.smackx.jingleold.JingleManager) SpeexMediaManager(org.jivesoftware.smackx.jingleold.mediaimpl.jspeex.SpeexMediaManager) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) STUN(org.jivesoftware.smackx.jingleold.nat.STUN) JingleTransportManager(org.jivesoftware.smackx.jingleold.nat.JingleTransportManager) BridgedTransportManager(org.jivesoftware.smackx.jingleold.nat.BridgedTransportManager)

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