Search in sources :

Example 66 with SwingWorker

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();
}
Also used : ImageIcon(javax.swing.ImageIcon) SwingWorker(org.jivesoftware.spark.util.SwingWorker) JLabel(javax.swing.JLabel)

Example 67 with SwingWorker

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();
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker)

Example 68 with SwingWorker

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();
}
Also used : Insets(java.awt.Insets) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) JDialog(javax.swing.JDialog) JTextField(javax.swing.JTextField) SparkRes(org.jivesoftware.resource.SparkRes) SettingsManager(org.jivesoftware.sparkimpl.settings.local.SettingsManager) Res(org.jivesoftware.resource.Res) SwingWorker(org.jivesoftware.spark.util.SwingWorker) GridBagConstraints(java.awt.GridBagConstraints) JOptionPane(javax.swing.JOptionPane) TitlePanel(org.jivesoftware.spark.component.TitlePanel) ResourceUtils(org.jivesoftware.spark.util.ResourceUtils) JPasswordField(javax.swing.JPasswordField) PropertyChangeListener(java.beans.PropertyChangeListener) SparkManager(org.jivesoftware.spark.SparkManager) JLabel(javax.swing.JLabel) BorderLayout(java.awt.BorderLayout) GridBagLayout(java.awt.GridBagLayout) EntityBareJid(org.jxmpp.jid.EntityBareJid) JPanel(javax.swing.JPanel) JPanel(javax.swing.JPanel) BorderLayout(java.awt.BorderLayout) PropertyChangeListener(java.beans.PropertyChangeListener) SwingWorker(org.jivesoftware.spark.util.SwingWorker) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) JOptionPane(javax.swing.JOptionPane) TitlePanel(org.jivesoftware.spark.component.TitlePanel) JDialog(javax.swing.JDialog)

Example 69 with SwingWorker

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();
}
Also used : SwingWorker(org.jivesoftware.spark.util.SwingWorker) Presence(org.jivesoftware.smack.packet.Presence) RosterEntry(org.jivesoftware.smack.roster.RosterEntry)

Example 70 with SwingWorker

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