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();
}
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();
}
};
}
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();
}
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();
}
}
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);
}
Aggregations