Search in sources :

Example 21 with TitlePanel

use of org.jivesoftware.spark.component.TitlePanel in project Spark by igniterealtime.

the class RoomCreationDialog method createGroupChat.

public MultiUserChat createGroupChat(Component parent, final DomainBareJid serviceName) {
    final JOptionPane pane;
    final JDialog dlg;
    TitlePanel titlePanel;
    // Create the title panel for this dialog
    titlePanel = new TitlePanel(Res.getString("title.create.or.join"), Res.getString("message.create.or.join.room"), SparkRes.getImageIcon(SparkRes.BLANK_24x24), 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("create"), Res.getString("close") };
    pane = new JOptionPane(this, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
    mainPanel.add(pane, BorderLayout.CENTER);
    JOptionPane p = new JOptionPane();
    dlg = p.createDialog(parent, Res.getString("title.conference.rooms"));
    dlg.pack();
    dlg.setSize(400, 350);
    dlg.setContentPane(mainPanel);
    dlg.setLocationRelativeTo(parent);
    PropertyChangeListener changeListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent e) {
            Object o = pane.getValue();
            if (o instanceof Integer) {
                dlg.setVisible(false);
                return;
            }
            String value = (String) pane.getValue();
            if (Res.getString("close").equals(value)) {
                dlg.setVisible(false);
            } else if (Res.getString("create").equals(value)) {
                boolean isValid = validatePanel();
                if (isValid) {
                    String roomJidString = nameField.getText().replaceAll(" ", "_") + "@" + serviceName;
                    EntityBareJid room;
                    try {
                        room = JidCreate.entityBareFrom(roomJidString);
                    } catch (XmppStringprepException ex) {
                        throw new IllegalStateException(ex);
                    }
                    try {
                        MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getRoomInfo(room);
                        // JOptionPane.showMessageDialog(dlg, "Room already exists. Please specify a unique room name.", "Room Exists", JOptionPane.ERROR_MESSAGE);
                        // pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
                        pane.removePropertyChangeListener(this);
                        dlg.setVisible(false);
                        ConferenceUtils.joinConferenceRoom(room.toString(), room);
                        return;
                    } catch (XMPPException | SmackException | InterruptedException e1) {
                    // Nothing to do
                    }
                    groupChat = createGroupChat(nameField.getText(), serviceName);
                    if (groupChat == null) {
                        showError("Could not join chat " + nameField.getText());
                        pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
                    } else {
                        pane.removePropertyChangeListener(this);
                        dlg.setVisible(false);
                    }
                } else {
                    pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
                }
            }
        }
    };
    pane.addPropertyChangeListener(changeListener);
    nameField.requestFocusInWindow();
    dlg.setVisible(true);
    dlg.toFront();
    dlg.requestFocus();
    return groupChat;
}
Also used : JPanel(javax.swing.JPanel) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) XmppStringprepException(org.jxmpp.stringprep.XmppStringprepException) JOptionPane(javax.swing.JOptionPane) TitlePanel(org.jivesoftware.spark.component.TitlePanel) BorderLayout(java.awt.BorderLayout) EntityBareJid(org.jxmpp.jid.EntityBareJid) JDialog(javax.swing.JDialog)

Example 22 with TitlePanel

use of org.jivesoftware.spark.component.TitlePanel 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 23 with TitlePanel

use of org.jivesoftware.spark.component.TitlePanel in project Spark by igniterealtime.

the class ConferenceServiceBrowser method getSelectedService.

public String getSelectedService() {
    final JLabel serverAddressLabel = new JLabel();
    final JTextField serverAddress = new JTextField();
    final RolloverButton findButton = new RolloverButton();
    ResourceUtils.resLabel(serverAddressLabel, serverAddress, Res.getString("label.server.address"));
    ResourceUtils.resButton(findButton, Res.getString("button.find"));
    final JPanel mainPanel = new JPanel();
    mainPanel.setLayout(new GridBagLayout());
    mainPanel.add(serverAddressLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
    mainPanel.add(serverAddress, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 0, 5), 0, 0));
    mainPanel.add(findButton, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
    mainPanel.add(new JLabel("ex. jivesoftware.com"), new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 5, 0, 5), 0, 0));
    // Add Empty CheckBox List
    final DefaultListModel<String> model = new DefaultListModel<>();
    final JList<String> list = new JList<>(model);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane scrollPane = new JScrollPane(list);
    scrollPane.setBorder(BorderFactory.createTitledBorder(Res.getString("group.conferences.found")));
    mainPanel.add(scrollPane, new GridBagConstraints(0, 3, 3, 1, 1.0, 1.0, GridBagConstraints.WEST, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0));
    // Add Listener to find button
    findButton.addActionListener(e -> {
        String address = serverAddress.getText();
        if (ModelUtil.hasLength(address)) {
            try {
                Collection<String> col = getConferenceServices(address);
                for (String aCol : col) {
                    model.addElement(aCol);
                }
            } catch (Exception e1) {
                Log.error(e1);
            }
        }
    });
    // The user should only be able to close this dialog.
    Object[] options = { Res.getString("ok"), Res.getString("close") };
    final JOptionPane pane = new JOptionPane(mainPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());
    TitlePanel titlePanel = new TitlePanel(Res.getString("title.browse.conference.services"), Res.getString("message.find.conference.services"), SparkRes.getImageIcon(SparkRes.BLANK_IMAGE), true);
    topPanel.add(titlePanel, BorderLayout.NORTH);
    topPanel.add(pane, BorderLayout.CENTER);
    final JOptionPane p = new JOptionPane();
    final JDialog dlg = p.createDialog(SparkManager.getMainWindow(), Res.getString("title.find.conference.service"));
    dlg.setModal(true);
    dlg.pack();
    dlg.setSize(600, 400);
    dlg.setResizable(true);
    dlg.setContentPane(topPanel);
    dlg.setLocationRelativeTo(SparkManager.getMainWindow());
    PropertyChangeListener changeListener = new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent e) {
            String value = (String) pane.getValue();
            if ("Close".equals(value)) {
                list.clearSelection();
                pane.removePropertyChangeListener(this);
                dlg.dispose();
            } else if ("Ok".equals(value)) {
                pane.removePropertyChangeListener(this);
                dlg.dispose();
            }
        }
    };
    pane.addPropertyChangeListener(changeListener);
    serverAddress.requestFocusInWindow();
    dlg.setVisible(true);
    dlg.toFront();
    return list.getSelectedValue();
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) PropertyChangeEvent(java.beans.PropertyChangeEvent) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) PropertyChangeListener(java.beans.PropertyChangeListener) JLabel(javax.swing.JLabel) DefaultListModel(javax.swing.DefaultListModel) JTextField(javax.swing.JTextField) RolloverButton(org.jivesoftware.spark.component.RolloverButton) JOptionPane(javax.swing.JOptionPane) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException) TitlePanel(org.jivesoftware.spark.component.TitlePanel) BorderLayout(java.awt.BorderLayout) JList(javax.swing.JList) JDialog(javax.swing.JDialog)

Example 24 with TitlePanel

use of org.jivesoftware.spark.component.TitlePanel in project Spark by igniterealtime.

the class RosterDialog method showRosterDialog.

/**
 * Display the RosterDialog using a parent container.
 *
 * @param parent the parent Frame.
 */
public void showRosterDialog(JFrame parent) {
    TitlePanel titlePanel = new TitlePanel(Res.getString("title.add.contact"), Res.getString("message.add.contact.to.list"), null, true);
    JPanel mainPanel = new JPanel() {

        private static final long serialVersionUID = -7489967438182277375L;

        @Override
        public Dimension getPreferredSize() {
            final Dimension size = super.getPreferredSize();
            size.width = 450;
            return size;
        }
    };
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(titlePanel, BorderLayout.NORTH);
    mainPanel.add(panel, BorderLayout.CENTER);
    JButton addbutton = new JButton(Res.getString("add"));
    addbutton.addActionListener(e -> addContactButton());
    JButton cancelbutton = new JButton(Res.getString("cancel"));
    cancelbutton.addActionListener(e -> dialog.dispose());
    JPanel buttonpanel = new JPanel(new FlowLayout());
    buttonpanel.add(addbutton);
    buttonpanel.add(cancelbutton);
    mainPanel.add(buttonpanel, BorderLayout.SOUTH);
    dialog = new JDialog(parent, Res.getString("title.add.contact"), false);
    dialog.setContentPane(mainPanel);
    dialog.pack();
    dialog.setLocationRelativeTo(parent);
    dialog.setVisible(true);
    dialog.toFront();
    dialog.requestFocus();
    jidField.requestFocus();
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) BorderLayout(java.awt.BorderLayout) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) TitlePanel(org.jivesoftware.spark.component.TitlePanel) JDialog(javax.swing.JDialog)

Example 25 with TitlePanel

use of org.jivesoftware.spark.component.TitlePanel in project Spark by igniterealtime.

the class RosterPickList method showRoster.

/**
 * Displays a pick list of available users within their roster.
 *
 * @param parent the parent container.
 * @return all items choosen in the pick list.
 */
public Collection<String> showRoster(JDialog parent) {
    final List<ContactItem> userList = new ArrayList<>();
    // Populate Invite Panel with Available users.
    final Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
    for (RosterEntry entry : roster.getEntries()) {
        Presence presence = PresenceManager.getPresence(entry.getJid());
        if (presence.isAvailable()) {
            ContactItem item = UIComponentRegistry.createContactItem(entry.getName(), null, entry.getJid());
            item.setPresence(presence);
            userList.add(item);
        }
    }
    // Sort Users
    userList.sort(itemComparator);
    for (ContactItem item : userList) {
        model.addElement(item);
    }
    final JOptionPane pane;
    TitlePanel titlePanel;
    // Create the title panel for this dialog
    titlePanel = new TitlePanel(Res.getString("title.roster"), Res.getString("message.select.one.or.more"), 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("ok"), 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(parent, Res.getString("title.roster"));
    dlg.setModal(true);
    dlg.pack();
    dlg.setSize(350, 450);
    dlg.setResizable(true);
    dlg.setContentPane(mainPanel);
    dlg.setLocationRelativeTo(parent);
    PropertyChangeListener changeListener = e -> {
        String value = (String) pane.getValue();
        if (Res.getString("cancel").equals(value)) {
            rosterList.clearSelection();
            pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
            dlg.dispose();
        } else if (Res.getString("ok").equals(value)) {
            pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
            dlg.dispose();
        }
    };
    pane.addPropertyChangeListener(changeListener);
    dlg.setVisible(true);
    dlg.toFront();
    dlg.requestFocus();
    List<String> selectedContacts = new ArrayList<>();
    Object[] values = rosterList.getSelectedValuesList().toArray();
    for (Object value : values) {
        try {
            ContactItem item = (ContactItem) value;
            selectedContacts.add(item.getJid().toString());
        } catch (NullPointerException e) {
            Log.error(e);
        }
    }
    return selectedContacts;
}
Also used : JContactItemRenderer(org.jivesoftware.spark.component.renderer.JContactItemRenderer) java.util(java.util) Presence(org.jivesoftware.smack.packet.Presence) SparkRes(org.jivesoftware.resource.SparkRes) Res(org.jivesoftware.resource.Res) UIComponentRegistry(org.jivesoftware.spark.util.UIComponentRegistry) Log(org.jivesoftware.spark.util.log.Log) TitlePanel(org.jivesoftware.spark.component.TitlePanel) ResourceUtils(org.jivesoftware.spark.util.ResourceUtils) java.awt(java.awt) List(java.util.List) Roster(org.jivesoftware.smack.roster.Roster) PropertyChangeListener(java.beans.PropertyChangeListener) SparkManager(org.jivesoftware.spark.SparkManager) PresenceManager(org.jivesoftware.spark.PresenceManager) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) javax.swing(javax.swing) PropertyChangeListener(java.beans.PropertyChangeListener) TitlePanel(org.jivesoftware.spark.component.TitlePanel) Roster(org.jivesoftware.smack.roster.Roster) Presence(org.jivesoftware.smack.packet.Presence) RosterEntry(org.jivesoftware.smack.roster.RosterEntry)

Aggregations

TitlePanel (org.jivesoftware.spark.component.TitlePanel)25 JPanel (javax.swing.JPanel)19 JOptionPane (javax.swing.JOptionPane)17 JDialog (javax.swing.JDialog)15 PropertyChangeListener (java.beans.PropertyChangeListener)14 BorderLayout (java.awt.BorderLayout)13 GridBagConstraints (java.awt.GridBagConstraints)13 Insets (java.awt.Insets)13 GridBagLayout (java.awt.GridBagLayout)12 JLabel (javax.swing.JLabel)11 SmackException (org.jivesoftware.smack.SmackException)11 Res (org.jivesoftware.resource.Res)10 SparkManager (org.jivesoftware.spark.SparkManager)10 SparkRes (org.jivesoftware.resource.SparkRes)8 XMPPException (org.jivesoftware.smack.XMPPException)8 Log (org.jivesoftware.spark.util.log.Log)8 JScrollPane (javax.swing.JScrollPane)7 JTextField (javax.swing.JTextField)7 ResourceUtils (org.jivesoftware.spark.util.ResourceUtils)7 SwingWorker (org.jivesoftware.spark.util.SwingWorker)7