Search in sources :

Example 6 with TitlePanel

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

the class RoomBrowser method setupRoomInformationUI.

private void setupRoomInformationUI(EntityBareJid 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().toString());
        for (DiscoverItems.Item item : items.getItems()) {
            Jid jid = item.getEntityID();
            rootNode.add(new JiveTreeNode(jid.toString(), 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) EntityBareJid(org.jxmpp.jid.EntityBareJid) JiveTreeNode(org.jivesoftware.spark.component.JiveTreeNode) RoomInfo(org.jivesoftware.smackx.muc.RoomInfo) SparkRes(org.jivesoftware.resource.SparkRes) Jid(org.jxmpp.jid.Jid) 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) EntityBareJid(org.jxmpp.jid.EntityBareJid) Jid(org.jxmpp.jid.Jid) 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 7 with TitlePanel

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

the class SubscriptionDialog method invoke.

public void invoke(final BareJid jid) throws SmackException.NotConnectedException, InterruptedException {
    this.jid = jid;
    final Roster roster = Roster.getInstanceFor(SparkManager.getConnection());
    // If User is already in roster, do not show.
    RosterEntry entry = roster.getEntry(jid);
    if (entry != null && entry.getType() == RosterPacket.ItemType.to) {
        Presence response = new Presence(Presence.Type.subscribed);
        response.setTo(jid);
        SparkManager.getConnection().sendStanza(response);
        return;
    }
    String message = Res.getString("message.approve.subscription", jid.asUnescapedString());
    Transport transport = TransportUtils.getTransport(jid.asDomainBareJid());
    Icon icon = null;
    if (transport != null) {
        icon = transport.getIcon();
    }
    TitlePanel messageLabel = new TitlePanel("", message, icon, true);
    // Add Message Label
    mainPanel.add(messageLabel, new GridBagConstraints(0, 0, 6, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    UserManager userManager = SparkManager.getUserManager();
    String username = userManager.getNickname(jid);
    username = username == null ? XmppStringUtils.parseLocalpart(jid.asUnescapedString()) : username;
    usernameLabelValue.setText(jid.asUnescapedString());
    nicknameField.setText(username);
    acceptButton.addActionListener(e -> {
        if (!rosterBox.isSelected()) {
            Presence response = new Presence(Presence.Type.subscribed);
            response.setTo(jid);
            try {
                SparkManager.getConnection().sendStanza(response);
            } catch (SmackException.NotConnectedException | InterruptedException e1) {
                Log.warning("Unable to send stanza accepting subscription from " + jid, e1);
            }
            dialog.dispose();
            return;
        }
        boolean addEntry = addEntry();
        if (addEntry) {
            Presence response = new Presence(Presence.Type.subscribed);
            response.setTo(jid);
            try {
                SparkManager.getConnection().sendStanza(response);
            } catch (SmackException.NotConnectedException | InterruptedException e1) {
                Log.warning("Unable to send stanza accepting subscription from " + jid, e1);
            }
        } else {
            dialog.dispose();
        }
    });
    denyButton.addActionListener(e -> {
        // Send subscribed
        unsubscribeAndClose();
    });
    viewInfoButton.addActionListener(e -> SparkManager.getVCardManager().viewProfile(jid, mainPanel));
    dialog = new JFrame(Res.getString("title.subscription.request")) {

        private static final long serialVersionUID = 5713933518069623228L;

        @Override
        public Dimension getPreferredSize() {
            final Dimension dim = super.getPreferredSize();
            dim.width = 400;
            return dim;
        }
    };
    dialog.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    dialog.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            unsubscribeAndClose();
        }
    });
    KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    ActionListener action = e -> unsubscribeAndClose();
    dialog.getRootPane().registerKeyboardAction(action, key, JComponent.WHEN_FOCUSED);
    dialog.setIconImage(SparkManager.getApplicationImage().getImage());
    dialog.getContentPane().add(mainPanel);
    dialog.pack();
    dialog.setLocationRelativeTo(SparkManager.getMainWindow());
    if (SparkManager.getMainWindow().isFocused()) {
        dialog.setState(Frame.NORMAL);
        dialog.setVisible(true);
    } else if (!SparkManager.getMainWindow().isVisible() || !SparkManager.getMainWindow().isFocused()) {
        if (Spark.isWindows()) {
            dialog.setFocusable(false);
            dialog.setState(Frame.ICONIFIED);
        }
        SparkManager.getNativeManager().flashWindowStopOnFocus(dialog);
        dialog.setVisible(true);
    }
}
Also used : SmackException(org.jivesoftware.smack.SmackException) UserManager(org.jivesoftware.spark.UserManager) UIManager(javax.swing.UIManager) Insets(java.awt.Insets) ActionListener(java.awt.event.ActionListener) RosterPacket(org.jivesoftware.smack.roster.packet.RosterPacket) JTextField(javax.swing.JTextField) Res(org.jivesoftware.resource.Res) Transport(org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport) Log(org.jivesoftware.spark.util.log.Log) ResourceUtils(org.jivesoftware.spark.util.ResourceUtils) RosterGroup(org.jivesoftware.smack.roster.RosterGroup) JComboBox(javax.swing.JComboBox) JFrame(javax.swing.JFrame) RolloverButton(org.jivesoftware.spark.component.RolloverButton) JComponent(javax.swing.JComponent) KeyStroke(javax.swing.KeyStroke) Presence(org.jivesoftware.smack.packet.Presence) ModelUtil(org.jivesoftware.spark.util.ModelUtil) Frame(java.awt.Frame) BorderFactory(javax.swing.BorderFactory) Icon(javax.swing.Icon) JOptionPane(javax.swing.JOptionPane) GridBagConstraints(java.awt.GridBagConstraints) KeyEvent(java.awt.event.KeyEvent) WindowAdapter(java.awt.event.WindowAdapter) TitlePanel(org.jivesoftware.spark.component.TitlePanel) XmppStringUtils(org.jxmpp.util.XmppStringUtils) WindowEvent(java.awt.event.WindowEvent) Spark(org.jivesoftware.Spark) TransportUtils(org.jivesoftware.sparkimpl.plugin.gateways.transports.TransportUtils) Dimension(java.awt.Dimension) Roster(org.jivesoftware.smack.roster.Roster) SparkManager(org.jivesoftware.spark.SparkManager) JLabel(javax.swing.JLabel) JCheckBox(javax.swing.JCheckBox) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) BareJid(org.jxmpp.jid.BareJid) GridBagLayout(java.awt.GridBagLayout) JPanel(javax.swing.JPanel) XMPPException(org.jivesoftware.smack.XMPPException) ComponentTitledBorder(org.jivesoftware.spark.component.borders.ComponentTitledBorder) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) WindowAdapter(java.awt.event.WindowAdapter) Dimension(java.awt.Dimension) TitlePanel(org.jivesoftware.spark.component.TitlePanel) Roster(org.jivesoftware.smack.roster.Roster) ActionListener(java.awt.event.ActionListener) JFrame(javax.swing.JFrame) UserManager(org.jivesoftware.spark.UserManager) WindowEvent(java.awt.event.WindowEvent) KeyStroke(javax.swing.KeyStroke) Presence(org.jivesoftware.smack.packet.Presence) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) Icon(javax.swing.Icon) Transport(org.jivesoftware.sparkimpl.plugin.gateways.transports.Transport)

Example 8 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 9 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() {

        @Override
        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 10 with TitlePanel

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

the class PrivacyAddDialogUI method showRoster.

/**
 * Displays a pick list of available users within their roster.
 *
 * @param parent
 *            the parent container.
 * @return all items chosen in the pick list.
 */
public Collection<PrivacyItem> showRoster(Component parent, boolean showGroups) {
    _showGroups = showGroups;
    // Populate Invite Panel with Available users.
    createList();
    // Sort Users
    final JOptionPane pane;
    TitlePanel titlePanel;
    // Create the title panel for this dialog
    titlePanel = new TitlePanel(Res.getString("privacy.title.add.picker"), Res.getString("privacy.pick.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("privacy.title.add.picker"));
    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<PrivacyItem> selectedContacts = new ArrayList<>();
    Object[] values = rosterList.getSelectedValuesList().toArray();
    for (Object value : values) {
        try {
            ContactItem item = (ContactItem) value;
            PrivacyItem.Type type = _showGroups ? PrivacyItem.Type.group : PrivacyItem.Type.jid;
            PrivacyItem pitem = new PrivacyItem(type, item.getJid().toString(), false, 999);
            pitem.setFilterIQ(_blockIQ.isSelected());
            pitem.setFilterMessage(_blockMsg.isSelected());
            pitem.setFilterPresenceIn(_blockPIn.isSelected());
            pitem.setFilterPresenceOut(_blockPOout.isSelected());
            selectedContacts.add(pitem);
        } catch (NullPointerException e) {
            Log.error(e);
        }
    }
    return selectedContacts;
}
Also used : Insets(java.awt.Insets) JDialog(javax.swing.JDialog) Res(org.jivesoftware.resource.Res) Log(org.jivesoftware.spark.util.log.Log) ContactItem(org.jivesoftware.spark.ui.ContactItem) ArrayList(java.util.ArrayList) PresenceManager(org.jivesoftware.spark.PresenceManager) RosterGroup(org.jivesoftware.smack.roster.RosterGroup) BorderLayout(java.awt.BorderLayout) PrivacyItem(org.jivesoftware.smackx.privacy.packet.PrivacyItem) Presence(org.jivesoftware.smack.packet.Presence) SparkRes(org.jivesoftware.resource.SparkRes) Collection(java.util.Collection) JList(javax.swing.JList) BorderFactory(javax.swing.BorderFactory) GridBagConstraints(java.awt.GridBagConstraints) JOptionPane(javax.swing.JOptionPane) Component(java.awt.Component) TitlePanel(org.jivesoftware.spark.component.TitlePanel) JScrollPane(javax.swing.JScrollPane) List(java.util.List) DefaultListModel(javax.swing.DefaultListModel) PropertyChangeListener(java.beans.PropertyChangeListener) Roster(org.jivesoftware.smack.roster.Roster) SparkManager(org.jivesoftware.spark.SparkManager) JCheckBox(javax.swing.JCheckBox) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) GridBagLayout(java.awt.GridBagLayout) Comparator(java.util.Comparator) JPanel(javax.swing.JPanel) JPanel(javax.swing.JPanel) PropertyChangeListener(java.beans.PropertyChangeListener) ContactItem(org.jivesoftware.spark.ui.ContactItem) ArrayList(java.util.ArrayList) JOptionPane(javax.swing.JOptionPane) TitlePanel(org.jivesoftware.spark.component.TitlePanel) BorderLayout(java.awt.BorderLayout) PrivacyItem(org.jivesoftware.smackx.privacy.packet.PrivacyItem) JDialog(javax.swing.JDialog)

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