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