Search in sources :

Example 1 with TitlePanel

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

the class BroadcastDialog method invokeDialog.

/**
 * Displays the broadcast dialog.
 */
public void invokeDialog() {
    final JDialog dlg;
    TitlePanel titlePanel;
    // Create the title panel for this dialog
    titlePanel = new TitlePanel(Res.getString("title.broadcast.message"), Res.getString("message.enter.broadcast.message"), null, 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.
    JButton okButton = new JButton(Res.getString("ok"));
    JButton closeButton = new JButton(Res.getString("close"));
    mainPanel.add(this, BorderLayout.CENTER);
    JPanel buttonpanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    buttonpanel.add(okButton);
    buttonpanel.add(closeButton);
    mainPanel.add(buttonpanel, BorderLayout.SOUTH);
    dlg = new JDialog(SparkManager.getMainWindow(), Res.getString("broadcast"));
    dlg.setContentPane(mainPanel);
    dlg.pack();
    final Rectangle bounds = LayoutSettingsManager.getLayoutSettings().getBroadcastMessageBounds();
    if (bounds == null || bounds.width <= 0 || bounds.height <= 0) {
        // Use default settings.
        dlg.setSize(800, 600);
        dlg.setLocationRelativeTo(null);
    } else {
        dlg.setBounds(bounds);
    }
    dlg.addComponentListener(new ComponentAdapter() {

        @Override
        public void componentResized(ComponentEvent e) {
            LayoutSettingsManager.getLayoutSettings().setBroadcastMessageBounds(dlg.getBounds());
        }

        @Override
        public void componentMoved(ComponentEvent e) {
            LayoutSettingsManager.getLayoutSettings().setBroadcastMessageBounds(dlg.getBounds());
        }
    });
    dlg.setResizable(false);
    // Add listener
    okButton.addActionListener(e -> {
        try {
            if (sendBroadcasts(dlg)) {
                dlg.setVisible(false);
            }
        } catch (SmackException.NotConnectedException e1) {
            Log.warning("Unable to broadcast.", e1);
        }
    });
    closeButton.addActionListener(e -> dlg.setVisible(false));
    dlg.setVisible(true);
    dlg.toFront();
    dlg.requestFocus();
    messageBox.requestFocus();
}
Also used : JPanel(javax.swing.JPanel) SmackException(org.jivesoftware.smack.SmackException) JButton(javax.swing.JButton) ComponentEvent(java.awt.event.ComponentEvent) JDialog(javax.swing.JDialog) TitlePanel(org.jivesoftware.spark.component.TitlePanel) ComponentAdapter(java.awt.event.ComponentAdapter)

Example 2 with TitlePanel

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

the class InputTextAreaDialog method getInput.

/**
 * Prompt and return input.
 *
 * @param title       the title of the dialog.
 * @param description the dialog description.
 * @param icon        the icon to use.
 * @param parent      the parent to use.
 * @return the user input.
 */
public String getInput(String title, String description, Icon icon, Component parent) {
    textArea = new JTextArea();
    textArea.setLineWrap(true);
    TitlePanel titlePanel = new TitlePanel(title, description, icon, 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.
    final Object[] options = { Res.getString("ok"), Res.getString("cancel") };
    optionPane = new JOptionPane(new JScrollPane(textArea), JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
    mainPanel.add(optionPane, BorderLayout.CENTER);
    // Let's make sure that the dialog is modal. Cannot risk people
    // losing this dialog.
    JOptionPane p = new JOptionPane();
    dialog = p.createDialog(parent, title);
    dialog.setModal(true);
    dialog.pack();
    dialog.setSize(width, height);
    dialog.setContentPane(mainPanel);
    dialog.setLocationRelativeTo(parent);
    optionPane.addPropertyChangeListener(this);
    // Add Key Listener to Send Field
    textArea.addKeyListener(new KeyAdapter() {

        public void keyPressed(KeyEvent e) {
            if (e.getKeyChar() == KeyEvent.VK_TAB) {
                optionPane.requestFocus();
            } else if (e.getKeyChar() == KeyEvent.VK_ESCAPE) {
                dialog.dispose();
            }
        }
    });
    textArea.requestFocus();
    dialog.setVisible(true);
    return stringValue;
}
Also used : JScrollPane(javax.swing.JScrollPane) KeyEvent(java.awt.event.KeyEvent) JPanel(javax.swing.JPanel) JTextArea(javax.swing.JTextArea) BorderLayout(java.awt.BorderLayout) KeyAdapter(java.awt.event.KeyAdapter) JOptionPane(javax.swing.JOptionPane) TitlePanel(org.jivesoftware.spark.component.TitlePanel)

Example 3 with TitlePanel

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

the class JoinConferenceRoomDialog method joinRoom.

public void joinRoom(final String roomJID, final String roomName) {
    final LocalPreferences pref = SettingsManager.getLocalPreferences();
    // Set default nickname
    nicknameField.setText(pref.getNickname());
    // 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;

        public Object construct() {
            requiresPassword = ConferenceUtils.isPasswordRequired(roomJID);
            return requiresPassword;
        }

        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) 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 4 with TitlePanel

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

the class RoomBrowser method setupRoomInformationUI.

private void setupRoomInformationUI(String roomJID, final RoomInfo roomInfo, final DiscoverItems items) {
    descriptionValue.setText(Res.getString("message.no.description.available"));
    subjectValue.setText(Res.getString("message.no.subject.available"));
    occupantsValue.setText("n/a");
    roomNameValue.setText("n/a");
    try {
        descriptionValue.setText(roomInfo.getDescription());
        subjectValue.setText(roomInfo.getSubject());
        if (roomInfo.getOccupantsCount() == -1) {
            occupantsValue.setText("n/a");
        } else {
            occupantsValue.setText(Integer.toString(roomInfo.getOccupantsCount()));
        }
        roomNameValue.setText(roomInfo.getRoom());
        for (DiscoverItems.Item item : items.getItems()) {
            String jid = item.getEntityID();
            rootNode.add(new JiveTreeNode(jid, false, SparkRes.getImageIcon(SparkRes.SMALL_USER1_INFORMATION)));
        }
        tree.expandRow(0);
    } catch (Exception e) {
        Log.error(e);
    }
    final JOptionPane pane;
    // Create the title panel for this dialog
    TitlePanel titlePanel = new TitlePanel(Res.getString("title.view.room.information"), Res.getString("message.room.information.for", roomJID), 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("close") };
    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.view.room.information"));
    dlg.setModal(false);
    dlg.pack();
    dlg.setSize(450, 400);
    dlg.setResizable(true);
    dlg.setContentPane(mainPanel);
    dlg.setLocationRelativeTo(SparkManager.getMainWindow());
    PropertyChangeListener changeListener = e -> {
        String value = (String) pane.getValue();
        if (Res.getString("close").equals(value)) {
            pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
            dlg.dispose();
        }
    };
    pane.addPropertyChangeListener(changeListener);
    dlg.setVisible(true);
    dlg.toFront();
    dlg.requestFocus();
}
Also used : SmackException(org.jivesoftware.smack.SmackException) Color(java.awt.Color) JiveTreeCellRenderer(org.jivesoftware.spark.component.JiveTreeCellRenderer) Insets(java.awt.Insets) JDialog(javax.swing.JDialog) Res(org.jivesoftware.resource.Res) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) Log(org.jivesoftware.spark.util.log.Log) BorderLayout(java.awt.BorderLayout) JiveTreeNode(org.jivesoftware.spark.component.JiveTreeNode) RoomInfo(org.jivesoftware.smackx.muc.RoomInfo) SparkRes(org.jivesoftware.resource.SparkRes) ServiceDiscoveryManager(org.jivesoftware.smackx.disco.ServiceDiscoveryManager) Tree(org.jivesoftware.spark.component.Tree) SwingWorker(org.jivesoftware.spark.util.SwingWorker) JOptionPane(javax.swing.JOptionPane) GridBagConstraints(java.awt.GridBagConstraints) TitlePanel(org.jivesoftware.spark.component.TitlePanel) MultiUserChatManager(org.jivesoftware.smackx.muc.MultiUserChatManager) PropertyChangeListener(java.beans.PropertyChangeListener) SparkManager(org.jivesoftware.spark.SparkManager) JLabel(javax.swing.JLabel) GridBagLayout(java.awt.GridBagLayout) JPanel(javax.swing.JPanel) XMPPException(org.jivesoftware.smack.XMPPException) JPanel(javax.swing.JPanel) PropertyChangeListener(java.beans.PropertyChangeListener) DiscoverItems(org.jivesoftware.smackx.disco.packet.DiscoverItems) JOptionPane(javax.swing.JOptionPane) SmackException(org.jivesoftware.smack.SmackException) XMPPException(org.jivesoftware.smack.XMPPException) TitlePanel(org.jivesoftware.spark.component.TitlePanel) BorderLayout(java.awt.BorderLayout) JiveTreeNode(org.jivesoftware.spark.component.JiveTreeNode) JDialog(javax.swing.JDialog)

Example 5 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 String 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() {

        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 room = nameField.getText().replaceAll(" ", "_") + "@" + serviceName;
                    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, room);
                        return;
                    } catch (XMPPException | SmackException 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) BorderLayout(java.awt.BorderLayout) PropertyChangeListener(java.beans.PropertyChangeListener) JOptionPane(javax.swing.JOptionPane) JDialog(javax.swing.JDialog) TitlePanel(org.jivesoftware.spark.component.TitlePanel)

Aggregations

TitlePanel (org.jivesoftware.spark.component.TitlePanel)20 JPanel (javax.swing.JPanel)14 JOptionPane (javax.swing.JOptionPane)12 JDialog (javax.swing.JDialog)11 PropertyChangeListener (java.beans.PropertyChangeListener)10 BorderLayout (java.awt.BorderLayout)9 GridBagConstraints (java.awt.GridBagConstraints)9 Insets (java.awt.Insets)9 GridBagLayout (java.awt.GridBagLayout)8 SmackException (org.jivesoftware.smack.SmackException)8 JLabel (javax.swing.JLabel)7 JScrollPane (javax.swing.JScrollPane)6 Res (org.jivesoftware.resource.Res)6 XMPPException (org.jivesoftware.smack.XMPPException)6 SparkManager (org.jivesoftware.spark.SparkManager)6 PropertyChangeEvent (java.beans.PropertyChangeEvent)5 SparkRes (org.jivesoftware.resource.SparkRes)5 Log (org.jivesoftware.spark.util.log.Log)5 Collection (java.util.Collection)4 JButton (javax.swing.JButton)4