use of org.jivesoftware.spark.ui.ChatRoom in project Spark by igniterealtime.
the class PresenceChangePlugin method initialize.
public void initialize() {
// Listen for right-clicks on ContactItem
final ContactList contactList = SparkManager.getWorkspace().getContactList();
final Action listenAction = new AbstractAction() {
private static final long serialVersionUID = 7705539667621148816L;
public void actionPerformed(ActionEvent e) {
for (ContactItem item : contactList.getSelectedUsers()) {
String bareAddress = XmppStringUtils.parseBareJid(item.getJID());
sparkContacts.add(bareAddress);
}
}
};
listenAction.putValue(Action.NAME, Res.getString("menuitem.alert.when.online"));
listenAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_ALARM_CLOCK));
final Action removeAction = new AbstractAction() {
private static final long serialVersionUID = -8726129089417116105L;
public void actionPerformed(ActionEvent e) {
for (ContactItem item : contactList.getSelectedUsers()) {
String bareAddress = XmppStringUtils.parseBareJid(item.getJID());
sparkContacts.remove(bareAddress);
}
}
};
removeAction.putValue(Action.NAME, Res.getString("menuitem.remove.alert.when.online"));
removeAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.SMALL_DELETE));
contactList.addContextMenuListener(new ContextMenuListener() {
public void poppingUp(Object object, JPopupMenu popup) {
if (object instanceof ContactItem) {
ContactItem item = (ContactItem) object;
String bareAddress = XmppStringUtils.parseBareJid(item.getJID());
if (!item.getPresence().isAvailable() || item.getPresence().isAway()) {
if (sparkContacts.contains(bareAddress)) {
popup.add(removeAction);
} else {
popup.add(listenAction);
}
}
}
}
public void poppingDown(JPopupMenu popup) {
}
public boolean handleDefaultAction(MouseEvent e) {
return false;
}
});
// Check presence changes
SparkManager.getConnection().addAsyncStanzaListener(stanza -> {
try {
Presence presence = (Presence) stanza;
if (!presence.isAvailable() || presence.isAway()) {
return;
}
String from = presence.getFrom();
ArrayList<String> removelater = new ArrayList<>();
for (final String jid : sparkContacts) {
if (jid.equals(XmppStringUtils.parseBareJid(from))) {
removelater.add(jid);
// sparkContacts.remove(jid);
String nickname = SparkManager.getUserManager().getUserNicknameFromJID(jid);
String time = SparkManager.DATE_SECOND_FORMATTER.format(new Date());
String infoText = Res.getString("message.user.now.available.to.chat", nickname, time);
if (localPref.getShowToasterPopup()) {
EventQueue.invokeLater(() -> {
SparkToaster toaster = new SparkToaster();
toaster.setDisplayTime(5000);
toaster.setBorder(BorderFactory.createBevelBorder(0));
toaster.setToasterHeight(150);
toaster.setToasterWidth(200);
toaster.setTitle(nickname);
toaster.showToaster(null, infoText);
toaster.setCustomAction(new AbstractAction() {
private static final long serialVersionUID = 4827542713848133369L;
@Override
public void actionPerformed(ActionEvent e) {
SparkManager.getChatManager().getChatRoom(jid);
}
});
});
}
ChatRoom room = SparkManager.getChatManager().getChatRoom(jid);
if (localPref.getWindowTakesFocus()) {
EventQueue.invokeLater(() -> SparkManager.getChatManager().activateChat(jid, nickname));
}
EventQueue.invokeLater(() -> room.getTranscriptWindow().insertNotificationMessage(infoText, ChatManager.NOTIFICATION_COLOR));
}
}
for (String s : removelater) {
sparkContacts.remove(s);
}
} catch (Exception ex) {
ex.printStackTrace();
}
}, new StanzaTypeFilter(Presence.class));
}
use of org.jivesoftware.spark.ui.ChatRoom in project Spark by igniterealtime.
the class EmoticonPlugin method chatRoomOpened.
public void chatRoomOpened(final ChatRoom room) {
// Check to see if emoticons are enabled.
if (!SettingsManager.getLocalPreferences().areEmoticonsEnabled()) {
return;
}
// final String activeEmoticonSetName =
// emoticonManager.getActiveEmoticonSetName();
emoticonManager = EmoticonManager.getInstance();
Collection<String> emoticonPacks;
emoticonPacks = emoticonManager.getEmoticonPacks();
if (emoticonPacks != null) {
// Add Emoticon button
final RolloverButton emoticonPicker = UIComponentRegistry.getButtonFactory().createEmoticonButton();
room.addEditorComponent(emoticonPicker);
emoticonPicker.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
// Show popup
final JPopupMenu popup = new JPopupMenu();
EmoticonUI emoticonUI = new EmoticonUI();
emoticonUI.setEmoticonPickListener(emoticon -> {
try {
popup.setVisible(false);
final ChatInputEditor editor = room.getChatInputEditor();
String currentText = editor.getText();
if (currentText.length() == 0 || currentText.endsWith(" ")) {
room.getChatInputEditor().insertText(emoticon + " ");
} else {
room.getChatInputEditor().insertText(" " + emoticon + " ");
}
room.getChatInputEditor().requestFocus();
} catch (BadLocationException e1) {
Log.error(e1);
}
});
popup.add(emoticonUI);
popup.show(emoticonPicker, e.getX(), e.getY());
}
});
room.addClosingListener(() -> room.removeEditorComponent(emoticonPicker));
}
}
use of org.jivesoftware.spark.ui.ChatRoom in project Spark by igniterealtime.
the class BroadcastPlugin method initialize.
public void initialize() {
// See if we should disable all "Broadcast" menu items
if (Default.getBoolean("DISABLE_BROADCAST_MENU_ITEM") || !Enterprise.containsFeature(Enterprise.BROADCAST_FEATURE))
return;
// Add as ContainerDecoratr
SparkManager.getChatManager().addSparkTabHandler(this);
StanzaFilter serverFilter = new StanzaTypeFilter(Message.class);
SparkManager.getConnection().addAsyncStanzaListener(this, serverFilter);
// Register with action menu
final JMenu actionsMenu = SparkManager.getMainWindow().getMenuByName(Res.getString("menuitem.actions"));
JMenuItem broadcastHistoryMenu = new JMenuItem(Res.getString("title.broadcast.history"), SparkRes.getImageIcon(SparkRes.HISTORY_16x16));
JMenuItem broadcastMenu = new JMenuItem(Res.getString("title.broadcast.message"), SparkRes.getImageIcon(SparkRes.MEGAPHONE_16x16));
ResourceUtils.resButton(broadcastMenu, Res.getString("title.broadcast.message"));
actionsMenu.add(broadcastHistoryMenu);
actionsMenu.add(broadcastMenu);
broadcastMenu.addActionListener(e -> broadcastToRoster());
broadcastHistoryMenu.addActionListener(e -> {
new BroadcastHistoryFrame().run();
});
// Register with action menu
JMenuItem startConversationtMenu = new JMenuItem("", SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_IMAGE));
ResourceUtils.resButton(startConversationtMenu, Res.getString("menuitem.start.a.chat"));
if (!Default.getBoolean("HIDE_START_A_CHAT") && Enterprise.containsFeature(Enterprise.START_A_CHAT_FEATURE)) {
actionsMenu.add(startConversationtMenu, 0);
}
startConversationtMenu.addActionListener(e -> {
ContactList contactList = SparkManager.getWorkspace().getContactList();
Collection<ContactItem> selectedUsers = contactList.getSelectedUsers();
String selectedUser = "";
Iterator<ContactItem> selectedUsersIterator = selectedUsers.iterator();
if (selectedUsersIterator.hasNext()) {
ContactItem contactItem = selectedUsersIterator.next();
selectedUser = contactItem.getJID();
}
UIManager.put("OptionPane.okButtonText", Res.getString("ok"));
UIManager.put("OptionPane.cancelButtonText", Res.getString("cancel"));
String jid = (String) JOptionPane.showInputDialog(SparkManager.getMainWindow(), Res.getString("label.enter.address"), Res.getString("title.start.chat"), JOptionPane.QUESTION_MESSAGE, null, null, selectedUser);
if (ModelUtil.hasLength(jid) && ModelUtil.hasLength(XmppStringUtils.parseDomain(jid))) {
if (ModelUtil.hasLength(jid) && jid.indexOf('@') == -1) {
// Append server address
jid = jid + "@" + SparkManager.getConnection().getServiceName();
}
String nickname = SparkManager.getUserManager().getUserNicknameFromJID(jid);
jid = UserManager.escapeJID(jid);
ChatRoom chatRoom = SparkManager.getChatManager().createChatRoom(jid, nickname, nickname);
SparkManager.getChatManager().getChatContainer().activateChatRoom(chatRoom);
}
});
// Add send to selected users.
final ContactList contactList = SparkManager.getWorkspace().getContactList();
contactList.addContextMenuListener(new ContextMenuListener() {
public void poppingUp(Object component, JPopupMenu popup) {
if (component instanceof ContactGroup) {
final ContactGroup group = (ContactGroup) component;
Action broadcastMessageAction = new AbstractAction() {
private static final long serialVersionUID = -6411248110270296726L;
public void actionPerformed(ActionEvent e) {
broadcastToGroup(group);
}
};
broadcastMessageAction.putValue(Action.NAME, Res.getString("menuitem.broadcast.to.group"));
broadcastMessageAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.MEGAPHONE_16x16));
popup.add(broadcastMessageAction);
}
}
public void poppingDown(JPopupMenu popup) {
}
public boolean handleDefaultAction(MouseEvent e) {
return false;
}
});
// Add Broadcast to roster
StatusBar statusBar = SparkManager.getWorkspace().getStatusBar();
RolloverButton broadcastToRosterButton = new RolloverButton(SparkRes.getImageIcon(SparkRes.MEGAPHONE_16x16));
broadcastToRosterButton.setToolTipText(Res.getString("message.send.a.broadcast"));
statusBar.invalidate();
statusBar.validate();
statusBar.repaint();
broadcastToRosterButton.addActionListener(e -> broadcastToRoster());
}
use of org.jivesoftware.spark.ui.ChatRoom in project Spark by igniterealtime.
the class BroadcastPlugin method isTabHandled.
public boolean isTabHandled(SparkTab tab, Component component, boolean isSelectedTab, boolean chatFrameFocused) {
if (component instanceof ChatRoom) {
ChatRoom chatroom = (ChatRoom) component;
if (broadcastRooms.contains(chatroom)) {
final ChatRoomImpl room = (ChatRoomImpl) component;
tab.setIcon(SparkRes.getImageIcon(SparkRes.INFORMATION_IMAGE));
String nickname = room.getTabTitle();
nickname = Res.getString("message.broadcast.from", nickname);
tab.setTabTitle(nickname);
if ((!chatFrameFocused || !isSelectedTab) && room.getUnreadMessageCount() > 0) {
// Make tab red.
tab.setTitleColor(Color.red);
tab.setTabBold(true);
} else {
tab.setTitleColor(Color.black);
tab.setTabFont(tab.getDefaultFont());
room.clearUnreadMessageCount();
}
return true;
}
}
return false;
}
use of org.jivesoftware.spark.ui.ChatRoom in project Spark by igniterealtime.
the class BuzzPlugin method shakeWindow.
private void shakeWindow(Message message) {
String bareJID = XmppStringUtils.parseBareJid(message.getFrom());
ContactItem contact = SparkManager.getWorkspace().getContactList().getContactItemByJID(bareJID);
String nickname = XmppStringUtils.parseLocalpart(bareJID);
if (contact != null) {
nickname = contact.getDisplayName();
}
ChatRoom room;
try {
room = SparkManager.getChatManager().getChatContainer().getChatRoom(bareJID);
} catch (ChatRoomNotFoundException e) {
// Create the room if it does not exist.
room = SparkManager.getChatManager().createChatRoom(bareJID, nickname, nickname);
}
ChatFrame chatFrame = SparkManager.getChatManager().getChatContainer().getChatFrame();
if (chatFrame != null) {
if (SettingsManager.getLocalPreferences().isBuzzEnabled()) {
chatFrame.buzz();
SparkManager.getChatManager().getChatContainer().activateChatRoom(room);
}
}
// Insert offline message
room.getTranscriptWindow().insertNotificationMessage(Res.getString("message.buzz.message", nickname), ChatManager.NOTIFICATION_COLOR);
room.scrollToBottom();
}
Aggregations