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