use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.
the class NotificationPlugin method processPacket.
public void processPacket(Stanza stanza) {
final Presence presence = (Presence) stanza;
String jid = presence.getFrom();
if (jid == null) {
return;
}
// Make sure the user is in the contact list.
ContactItem contactItem = SparkManager.getWorkspace().getContactList().getContactItemByJID(jid);
if (contactItem == null) {
return;
}
jid = XmppStringUtils.parseBareJid(jid);
boolean isOnline = onlineUsers.contains(jid);
if (presence.isAvailable()) {
if (preferences.isOnlineNotificationsOn()) {
if (!isOnline) {
notifyUserOnline(jid, presence);
}
}
onlineUsers.add(jid);
} else {
if (preferences.isOfflineNotificationsOn() && isOnline) {
notifyUserOffline(jid, presence);
}
onlineUsers.remove(jid);
}
}
use of org.jivesoftware.spark.ui.ContactItem 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.getSelectedValues();
final int no = values != null ? values.length : 0;
for (int i = 0; i < no; i++) {
try {
ContactItem item = (ContactItem) values[i];
PrivacyItem.Type type = _showGroups ? PrivacyItem.Type.group : PrivacyItem.Type.jid;
PrivacyItem pitem = new PrivacyItem(type, item.getJID(), 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;
}
use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.
the class ConversationHistoryPlugin method initialize.
public void initialize() {
transcriptDir = new File(SparkManager.getUserDirectory(), "transcripts");
conFile = new File(transcriptDir, "conversations.xml");
contacts = new JList(model);
contacts.setCellRenderer(new InternalRenderer());
window = new Window(SparkManager.getMainWindow());
final JPanel mainPanel = new JPanel(new BorderLayout());
final JLabel titleLabel = new JLabel(Res.getString("label.recent.conversation"));
titleLabel.setFont(new Font("Dialog", Font.BOLD, 11));
titleLabel.setHorizontalAlignment(JLabel.CENTER);
mainPanel.add(titleLabel, BorderLayout.NORTH);
mainPanel.add(contacts, BorderLayout.CENTER);
mainPanel.setBorder(BorderFactory.createLineBorder(Color.gray));
window.add(mainPanel);
// Add Listeners
contacts.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
contacts.setSelectedIndex(contacts.locationToIndex(e.getPoint()));
String user = jidMap.get(contacts.getSelectedValue());
ContactItem contact = SparkManager.getContactList().getContactItemByJID(user);
SparkManager.getContactList().setSelectedUser(contact.getJID());
SparkManager.getContactList().showPopup(contacts, e, contact);
}
if (e.getClickCount() == 2) {
final JLabel label = (JLabel) contacts.getSelectedValue();
String user = jidMap.get(label);
if (user != null) {
final String contactUsername = SparkManager.getUserManager().getUserNicknameFromJID(user);
SparkManager.getChatManager().activateChat(user, contactUsername);
window.dispose();
}
}
}
});
contacts.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
final JLabel label = (JLabel) contacts.getSelectedValue();
String user = jidMap.get(label);
if (user != null) {
final String contactUsername = SparkManager.getUserManager().getUserNicknameFromJID(user);
SparkManager.getChatManager().activateChat(user, contactUsername);
window.dispose();
}
} else if (e.getKeyChar() == KeyEvent.VK_ESCAPE) {
window.dispose();
}
}
});
contacts.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
}
public void focusLost(FocusEvent e) {
window.dispose();
}
});
// Load Previous History
loadPreviousHistory();
// Add Keymapping to ContactList
SparkManager.getMainWindow().getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_E, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "historyPeople");
SparkManager.getMainWindow().getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_E, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "historyPeople");
SparkManager.getMainWindow().getRootPane().getActionMap().put("historyPeople", new AbstractAction("historyPeople") {
private static final long serialVersionUID = 2465628887318732082L;
public void actionPerformed(ActionEvent e) {
// Show History Popup
showHistoryPopup();
}
});
// Persist order of conversations.
SparkManager.getChatManager().addMessageFilter(new MessageFilter() {
public void filterOutgoing(ChatRoom room, Message message) {
addUserToHistory(room);
}
public void filterIncoming(ChatRoom room, Message message) {
addUserToHistory(room);
}
});
}
use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.
the class ConversationHistoryPlugin method showHistoryPopup.
/**
* Displays the Previous Conversation Window.
*/
private void showHistoryPopup() {
// Get Transcript Directory
if (!transcriptDir.exists()) {
return;
}
jidMap.clear();
model.clear();
final ContactList contactList = SparkManager.getWorkspace().getContactList();
int limit = historyList.size() > 10 ? 10 : historyList.size();
for (final String user : historyList.subList(0, limit)) {
ContactItem contactItem = contactList.getContactItemByJID(user);
Icon icon;
if (contactItem != null) {
icon = contactItem.getIcon();
if (icon == null) {
icon = SparkRes.getImageIcon(SparkRes.CLEAR_BALL_ICON);
}
JLabel label = new JLabel();
label.setText(contactItem.getDisplayName());
label.setIcon(icon);
model.addElement(label);
jidMap.put(label, user);
}
}
window.setSize(200, 200);
GraphicUtils.centerWindowOnComponent(window, SparkManager.getMainWindow());
if (model.size() > 0) {
contacts.setSelectedIndex(0);
}
window.setVisible(true);
}
use of org.jivesoftware.spark.ui.ContactItem in project Spark by igniterealtime.
the class FrequentContactsPlugin method initialize.
public void initialize() {
transcriptDir = new File(SparkManager.getUserDirectory(), "transcripts");
contacts = new JList(model);
contacts.setCellRenderer(new InternalRenderer());
window = new Window(SparkManager.getMainWindow());
final JPanel mainPanel = new JPanel(new BorderLayout());
final JLabel titleLabel = new JLabel(Res.getString("label.frequent.contacts"));
titleLabel.setFont(new Font("Dialog", Font.BOLD, 11));
titleLabel.setHorizontalAlignment(JLabel.CENTER);
mainPanel.add(titleLabel, BorderLayout.NORTH);
mainPanel.add(contacts, BorderLayout.CENTER);
mainPanel.setBorder(BorderFactory.createLineBorder(Color.gray));
window.add(mainPanel);
// Add Listeners
contacts.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (SwingUtilities.isRightMouseButton(e)) {
contacts.setSelectedIndex(contacts.locationToIndex(e.getPoint()));
String user = jidMap.get(contacts.getSelectedValue());
ContactItem contact = SparkManager.getContactList().getContactItemByJID(user);
SparkManager.getContactList().setSelectedUser(contact.getJID());
SparkManager.getContactList().showPopup(contacts, e, contact);
}
if (e.getClickCount() == 2) {
final JLabel label = (JLabel) contacts.getSelectedValue();
String user = jidMap.get(label);
if (user != null) {
final String contactUsername = SparkManager.getUserManager().getUserNicknameFromJID(user);
SparkManager.getChatManager().activateChat(user, contactUsername);
window.dispose();
}
}
}
});
contacts.addKeyListener(new KeyAdapter() {
public void keyReleased(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
final JLabel label = (JLabel) contacts.getSelectedValue();
String user = jidMap.get(label);
if (user != null) {
final String contactUsername = SparkManager.getUserManager().getUserNicknameFromJID(user);
SparkManager.getChatManager().activateChat(user, contactUsername);
window.dispose();
}
} else if (e.getKeyChar() == KeyEvent.VK_ESCAPE) {
window.dispose();
}
}
});
contacts.addFocusListener(new FocusListener() {
public void focusGained(FocusEvent e) {
}
public void focusLost(FocusEvent e) {
window.dispose();
}
});
// Add KeyMappings
SparkManager.getMainWindow().getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_T, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "favoritePeople");
SparkManager.getMainWindow().getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_T, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "favoritePeople");
SparkManager.getMainWindow().getRootPane().getActionMap().put("favoritePeople", new AbstractAction("favoritePeople") {
private static final long serialVersionUID = 6836584242669218932L;
public void actionPerformed(ActionEvent e) {
// Show History Popup
showPopup();
}
});
}
Aggregations