use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class ConferenceRoomBrowser method addRoomToTable.
/**
* Adds a room to the room table.
*
* @param jid
* the jid of the conference room.
* @param roomName
* the name of the conference room.
* @param numberOfOccupants
* the number of occupants in the conference room. If -1 is
* specified, the the occupant count will show as n/a.
*/
private void addRoomToTable(final EntityBareJid jid, final CharSequence roomName, final int numberOfOccupants) {
SwingWorker addRoomThread = new SwingWorker() {
@Override
public Object construct() {
JLabel iconLabel = new JLabel();
iconLabel.setAlignmentX(JLabel.RIGHT_ALIGNMENT);
boolean isbookmark = false;
boolean ispassword = false;
ImageIcon bookmarkicon = SparkRes.getImageIcon(SparkRes.BOOKMARK_ICON);
ImageIcon passwordicon = SparkRes.getImageIcon(SparkRes.LOCK_16x16);
if (isBookmarked(jid)) {
isbookmark = true;
iconLabel.setIcon(SparkRes.getImageIcon(SparkRes.BOOKMARK_ICON));
}
if (isPasswordProtected(jid)) {
ispassword = true;
}
if (isbookmark && ispassword) {
Image img = ImageCombiner.combine(bookmarkicon, passwordicon);
iconLabel.setIcon(new ImageIcon(img));
} else if (isbookmark) {
iconLabel.setIcon(bookmarkicon);
} else if (ispassword) {
Image img = ImageCombiner.returnTransparentImage(passwordicon.getIconWidth(), passwordicon.getIconHeight());
Image combined = ImageCombiner.combine(new ImageIcon(img), passwordicon);
iconLabel.setIcon(new ImageIcon(combined));
}
String occupants = Integer.toString(numberOfOccupants);
if (numberOfOccupants == -1) {
occupants = "n/a";
}
return new Object[] { iconLabel, roomName.toString(), jid.getLocalpart().toString(), occupants };
}
@Override
public void finished() {
Object[] insertRoom = (Object[]) get();
roomsTable.getTableModel().addRow(insertRoom);
}
};
addRoomThread.start();
}
use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class ConferenceRoomBrowser method startLoadingImg.
private void startLoadingImg() {
SwingWorker startLoading = new SwingWorker() {
@Override
public Object construct() {
return null;
}
@Override
public void finished() {
refreshButton.setIcon(SparkRes.getImageIcon(SparkRes.BUSY_IMAGE));
refreshButton.validate();
refreshButton.repaint();
refreshItem.setIcon(SparkRes.getImageIcon(SparkRes.BUSY_IMAGE));
refreshItem.validate();
refreshItem.repaint();
}
};
startLoading.start();
}
use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class JoinConferenceRoomDialog method joinRoom.
public void joinRoom(final EntityBareJid roomJID, final String roomName) {
final LocalPreferences pref = SettingsManager.getLocalPreferences();
// Set default nickname
nicknameField.setText(pref.getNickname().toString());
// Enable password field if a password is required
passwordField.setVisible(false);
passwordLabel.setVisible(false);
roomNameDescription.setText(roomName);
final JOptionPane pane;
TitlePanel titlePanel;
// Create the title panel for this dialog
titlePanel = new TitlePanel(Res.getString("title.join.conference.room"), Res.getString("message.specify.information.for.conference"), SparkRes.getImageIcon(SparkRes.BLANK_IMAGE), true);
// Construct main panel w/ layout.
final JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
mainPanel.add(titlePanel, BorderLayout.NORTH);
// The user should only be able to close this dialog.
Object[] options = { Res.getString("join"), Res.getString("cancel") };
pane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
mainPanel.add(pane, BorderLayout.CENTER);
final JOptionPane p = new JOptionPane();
final JDialog dlg = p.createDialog(SparkManager.getMainWindow(), Res.getString("title.conference.rooms"));
dlg.setModal(false);
dlg.pack();
dlg.setSize(350, 250);
dlg.setResizable(true);
dlg.setContentPane(mainPanel);
dlg.setLocationRelativeTo(SparkManager.getMainWindow());
PropertyChangeListener changeListener = e -> {
String value = (String) pane.getValue();
if (Res.getString("cancel").equals(value)) {
pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
dlg.dispose();
} else if (Res.getString("join").equals(value)) {
pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
dlg.dispose();
ConferenceUtils.joinConferenceOnSeperateThread(roomName, roomJID, null);
}
};
pane.addPropertyChangeListener(changeListener);
dlg.setVisible(true);
dlg.toFront();
dlg.requestFocus();
SwingWorker worker = new SwingWorker() {
boolean requiresPassword;
@Override
public Object construct() {
requiresPassword = ConferenceUtils.isPasswordRequired(roomJID);
return requiresPassword;
}
@Override
public void finished() {
passwordField.setVisible(requiresPassword);
passwordLabel.setVisible(requiresPassword);
}
};
worker.start();
}
use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class ContactList method switchAllUserOfflineNoGroupEntry.
/**
* Switches all Users to Offline and Creates an Icon in the CommandBar
*/
private synchronized void switchAllUserOfflineNoGroupEntry(final boolean onError) {
SwingWorker worker = new SwingWorker() {
@Override
public Object construct() {
_reconnectpanelicon.getPanel().add(_reconnectpanelicon.getButton(), 0);
_reconnectpanelicon.getPanel().revalidate();
final Collection<RosterEntry> roster = Roster.getInstanceFor(SparkManager.getConnection()).getEntries();
for (RosterEntry r : roster) {
Presence p = new Presence(Presence.Type.unavailable);
moveToOfflineGroup(p, r.getJid());
}
return true;
}
};
worker.start();
}
use of org.jivesoftware.spark.util.SwingWorker in project Spark by igniterealtime.
the class ReconnectPanelIcon method remove.
public void remove() {
SwingWorker worker = new SwingWorker() {
@Override
public Object construct() {
return 42;
}
@Override
public void finished() {
_commandpanel.remove(_icon);
}
};
worker.start();
}
Aggregations