use of org.jivesoftware.spark.component.TitlePanel in project Spark by igniterealtime.
the class SubscriptionDialog method invoke.
public void invoke(final String jid) throws SmackException.NotConnectedException {
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", UserManager.unescapeJID(jid));
Transport transport = TransportUtils.getTransport(XmppStringUtils.parseDomain(jid));
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(userManager.getFullJID(jid));
username = username == null ? XmppStringUtils.parseLocalpart(UserManager.unescapeJID(jid)) : username;
usernameLabelValue.setText(UserManager.unescapeJID(jid));
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 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 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;
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 VCardEditor method editProfile.
/**
* Displays the VCard for an individual.
*
* @param vCard
* the users vcard.
* @param parent
* the parent component, used for location.
*/
public void editProfile(final VCard vCard, JComponent parent) {
final JTabbedPane tabbedPane = new JTabbedPane();
// Initialize Panels
personalPanel = new PersonalPanel();
personalPanel.showJID(false);
tabbedPane.addTab(Res.getString("tab.personal"), personalPanel);
businessPanel = new BusinessPanel();
tabbedPane.addTab(Res.getString("tab.business"), businessPanel);
homePanel = new HomePanel();
tabbedPane.addTab(Res.getString("tab.home"), homePanel);
// See if we should remove the Avatar tab in profile dialog
if (!Default.getBoolean(Default.DISABLE_AVATAR_TAB) && Enterprise.containsFeature(Enterprise.AVATAR_TAB_FEATURE)) {
avatarPanel = new AvatarPanel();
tabbedPane.addTab(Res.getString("tab.avatar"), avatarPanel);
}
// Build the UI
buildUI(vCard);
final JOptionPane pane;
final JDialog dlg;
TitlePanel titlePanel;
ImageIcon icon = VCardManager.getAvatarIcon(vCard);
if (icon == null) {
icon = SparkRes.getImageIcon(SparkRes.BLANK_24x24);
}
// Create the title panel for this dialog
titlePanel = new TitlePanel(Res.getString("title.edit.profile"), Res.getString("message.save.profile"), 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.
Object[] options = { Res.getString("save"), Res.getString("cancel") };
pane = new JOptionPane(tabbedPane, 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.profile.information"));
dlg.setModal(false);
dlg.pack();
dlg.setResizable(true);
dlg.setContentPane(mainPanel);
final Rectangle bounds = LayoutSettingsManager.getLayoutSettings().getVCardEditorBounds();
if (bounds == null || bounds.width <= 0 || bounds.height <= 0) {
// Use default settings.
dlg.setLocationRelativeTo(parent);
dlg.setSize(600, 400);
} else {
dlg.setBounds(bounds);
}
dlg.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
LayoutSettingsManager.getLayoutSettings().setVCardEditorBounds(dlg.getBounds());
}
@Override
public void componentMoved(ComponentEvent e) {
LayoutSettingsManager.getLayoutSettings().setVCardEditorBounds(dlg.getBounds());
}
});
PropertyChangeListener changeListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent e) {
String value = (String) pane.getValue();
if (Res.getString("cancel").equals(value)) {
pane.removePropertyChangeListener(this);
dlg.dispose();
} else if (Res.getString("save").equals(value)) {
pane.removePropertyChangeListener(this);
dlg.dispose();
saveVCard();
}
}
};
pane.addPropertyChangeListener(changeListener);
// See if we should remove the Avatar tab in profile dialog
if (!Default.getBoolean(Default.DISABLE_AVATAR_TAB) && Enterprise.containsFeature(Enterprise.AVATAR_TAB_FEATURE))
avatarPanel.setParentDialog(dlg);
dlg.setVisible(true);
dlg.toFront();
dlg.requestFocus();
personalPanel.focus();
}
use of org.jivesoftware.spark.component.TitlePanel in project Spark by igniterealtime.
the class VCardEditor method viewFullProfile.
/**
* Displays the VCard for an individual.
*
* @param vCard
* the users vcard.
* @param parent
* the parent component, used for location.
*/
public void viewFullProfile(final VCard vCard, JComponent parent) {
final JTabbedPane tabbedPane = new JTabbedPane();
// Initialize Panels
personalPanel = new PersonalPanel();
personalPanel.allowEditing(false);
personalPanel.showJID(false);
tabbedPane.addTab(Res.getString("tab.personal"), personalPanel);
businessPanel = new BusinessPanel();
businessPanel.allowEditing(false);
tabbedPane.addTab(Res.getString("tab.business"), businessPanel);
homePanel = new HomePanel();
homePanel.allowEditing(false);
tabbedPane.addTab(Res.getString("tab.home"), homePanel);
// See if we should remove the Avatar tab in profile dialog
if (!Default.getBoolean(Default.DISABLE_AVATAR_TAB) && Enterprise.containsFeature(Enterprise.AVATAR_TAB_FEATURE)) {
avatarPanel = new AvatarPanel();
avatarPanel.allowEditing(false);
tabbedPane.addTab(Res.getString("tab.avatar"), avatarPanel);
}
// Build the UI
buildUI(vCard);
final JOptionPane pane;
final JDialog dlg;
TitlePanel titlePanel;
ImageIcon icon = VCardManager.getAvatarIcon(vCard);
if (icon == null) {
icon = SparkRes.getImageIcon(SparkRes.BLANK_24x24);
}
// Create the title panel for this dialog
titlePanel = new TitlePanel(Res.getString("title.profile.information"), "", 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.
Object[] options = { Res.getString("close"), Res.getString("refresh") };
pane = new JOptionPane(tabbedPane, 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.profile.information"));
dlg.setModal(false);
dlg.pack();
dlg.setSize(600, 400);
dlg.setResizable(true);
dlg.setContentPane(mainPanel);
dlg.setLocationRelativeTo(parent);
PropertyChangeListener changeListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent e) {
Object o = pane.getValue();
if (o instanceof Integer) {
pane.removePropertyChangeListener(this);
dlg.dispose();
return;
}
String value = (String) pane.getValue();
if (Res.getString("close").equals(value)) {
pane.removePropertyChangeListener(this);
dlg.dispose();
}
if (Res.getString("refresh").equals(value)) {
VCardManager manager = SparkManager.getVCardManager();
BareJid bareJid = JidCreate.bareFromOrThrowUnchecked(vCard.getJabberId());
VCard card = manager.reloadVCard(bareJid);
fillUI(card);
}
}
};
pane.addPropertyChangeListener(changeListener);
dlg.setVisible(true);
dlg.toFront();
dlg.requestFocus();
personalPanel.focus();
}
use of org.jivesoftware.spark.component.TitlePanel in project Spark by igniterealtime.
the class ConferenceRoomBrowser method invoke.
/**
* Displays the ConferenceRoomBrowser.
*/
public void invoke() {
startLoadingImg();
TimerTask invokeThread = new TimerTask() {
Map<EntityBareJid, HostedRoom> rooms;
@Override
public void run() {
try {
rooms = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getRoomsHostedBy(serviceName);
if (rooms == null) {
UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
JOptionPane.showMessageDialog(conferences, Res.getString("message.conference.info.error"), Res.getString("title.error"), JOptionPane.ERROR_MESSAGE);
if (dlg != null) {
dlg.dispose();
}
} else {
try {
for (Map.Entry<EntityBareJid, HostedRoom> room : rooms.entrySet()) {
String roomName = room.getValue().getName();
EntityBareJid roomJID = room.getValue().getJid();
int numberOfOccupants = -1;
// service.
if (!partialDiscovery) {
RoomInfo roomInfo = null;
try {
roomInfo = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getRoomInfo(roomJID);
} catch (Exception e) {
// Nothing to do
}
if (roomInfo != null) {
numberOfOccupants = roomInfo.getOccupantsCount();
}
if (roomInfo == null || numberOfOccupants == -1) {
partialDiscovery = true;
}
}
addRoomToTable(roomJID, roomName, numberOfOccupants);
}
} catch (Exception e) {
Log.error("Error setting up GroupChatTable", e);
}
}
} catch (Exception e) {
Log.error("Unable to retrieve list of rooms.", e);
}
stopLoadingImg();
}
};
final JOptionPane pane;
TitlePanel titlePanel;
// Create the title panel for this dialog
titlePanel = new TitlePanel(Res.getString("title.create.or.bookmark.room"), Res.getString("message.add.favorite.room"), 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();
dlg = p.createDialog(SparkManager.getMainWindow(), Res.getString("title.browse.room.service", serviceName));
dlg.setModal(false);
dlg.addComponentListener(this);
dlg.setResizable(true);
dlg.setContentPane(mainPanel);
dlg.setLocationRelativeTo(SparkManager.getMainWindow());
PropertyChangeListener changeListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent e) {
String value = (String) pane.getValue();
if (Res.getString("close").equals(value)) {
pane.removePropertyChangeListener(this);
dlg.dispose();
} else if (Res.getString("close").equals(value)) {
pane.setValue(JOptionPane.UNINITIALIZED_VALUE);
}
}
};
pane.addPropertyChangeListener(changeListener);
dlg.addKeyListener(new KeyAdapter() {
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ESCAPE) {
dlg.dispose();
}
}
});
// will need that, when the window is smaller then the buttons width...
setButtonsWidth();
showHiddenButtons.setVisible(false);
dlg.pack();
final Rectangle bounds = LayoutSettingsManager.getLayoutSettings().getConferenceRoomBrowserBounds();
if (bounds == null || bounds.width <= 0 || bounds.height <= 0) {
/*
* looking up which bundle is used to set the size of the Window (not
* using Localpreferences getLanguage() because sometimes language is
* not saved in the properties file and so the method only returns an
* empty String)
*/
if (Res.getBundle().getLocale().toString().equals("de")) {
dlg.setSize(700, 400);
} else {
dlg.setSize(500, 400);
}
} else {
dlg.setBounds(bounds);
}
dlg.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
LayoutSettingsManager.getLayoutSettings().setConferenceRoomBrowserBounds(dlg.getBounds());
}
@Override
public void componentMoved(ComponentEvent e) {
LayoutSettingsManager.getLayoutSettings().setConferenceRoomBrowserBounds(dlg.getBounds());
}
});
dlg.setVisible(true);
dlg.toFront();
dlg.requestFocus();
TaskEngine.getInstance().submit(invokeThread);
}
use of org.jivesoftware.spark.component.TitlePanel in project Spark by igniterealtime.
the class LoginSettingDialog method invoke.
/**
* Invokes the OptionsDialog.
*
* @param owner the parent owner of this dialog. This is used for correct
* parenting.
* @return true if the options have been changed.
*/
public boolean invoke(JFrame owner) {
TitlePanel titlePanel;
// Create the title panel for this dialog
titlePanel = new TitlePanel(Res.getString("title.advanced.connection.preferences"), "", SparkRes.getImageIcon(SparkRes.BLANK_24x24), true);
tabbedPane.addTab(Res.getString("tab.general"), generalPanel);
tabbedPane.addTab(Res.getString("tab.security"), securityPanel);
if (!Default.getBoolean(Default.PROXY_DISABLED)) {
tabbedPane.addTab(Res.getString("tab.proxy"), proxyPanel);
}
if (!Default.getBoolean(Default.SSO_DISABLED)) {
tabbedPane.addTab(Res.getString("tab.sso"), ssoPanel);
}
if (!Default.getBoolean(Default.CERTIFICATES_MANAGER_DISABLED)) {
tabbedPane.addTab(Res.getString("tab.certificates"), certManagerPanel);
}
if (!Default.getBoolean(Default.MUTUAL_AUTH_DISABLED)) {
tabbedPane.addTab(Res.getString("tab.mutual.auth"), mutAuthPanel);
}
// 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"), Res.getString("use.default") };
optionPane = new JOptionPane(tabbedPane, JOptionPane.PLAIN_MESSAGE, JOptionPane.OK_CANCEL_OPTION, null, options, options[0]);
mainPanel.add(optionPane, BorderLayout.CENTER);
optionsDialog = new JDialog(owner, Res.getString("title.preferences"), true);
optionsDialog.setModalityType(ModalityType.DOCUMENT_MODAL);
optionsDialog.setContentPane(mainPanel);
optionsDialog.pack();
optionsDialog.setLocationRelativeTo(owner);
optionPane.addPropertyChangeListener(this);
optionsDialog.setResizable(false);
optionsDialog.setVisible(true);
optionsDialog.toFront();
optionsDialog.requestFocus();
return true;
}
Aggregations