use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.
the class PhoneManager method chatRoomOpened.
public void chatRoomOpened(final ChatRoom room) {
if (!phones.isEmpty() && room instanceof ChatRoomImpl) {
final ChatRoomImpl chatRoomImpl = (ChatRoomImpl) room;
final ChatRoomButton dialButton = new ChatRoomButton(SparkRes.getImageIcon(SparkRes.DIAL_PHONE_IMAGE_24x24));
dialButton.setToolTipText(Res.getString("tooltip.place.voice.call"));
final List<Action> actions = new ArrayList<>();
SwingWorker actionWorker = new SwingWorker() {
public Object construct() {
for (Phone phone : phones) {
final Collection<Action> phoneActions = phone.getPhoneActions(chatRoomImpl.getParticipantJID());
if (phoneActions != null) {
for (Action action : phoneActions) {
actions.add(action);
}
}
}
return actions;
}
public void finished() {
if (!actions.isEmpty()) {
room.addChatRoomButton(dialButton, true);
}
}
};
actionWorker.start();
dialButton.addMouseListener(new MouseAdapter() {
public void mousePressed(final MouseEvent e) {
SwingWorker worker = new SwingWorker() {
public Object construct() {
try {
Thread.sleep(50);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
return true;
}
public void finished() {
// Handle actions.
if (actions.size() > 0) {
// Display PopupMenu
final JPopupMenu menu = new JPopupMenu();
for (Action action : actions) {
menu.add(action);
}
menu.show(dialButton, e.getX(), e.getY());
}
}
};
worker.start();
}
});
}
}
use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.
the class TicTacToePlugin method addButtonToToolBar.
/**
* Add the TTT-Button to every opening Chatroom
* and create Listeners for it
*/
private void addButtonToToolBar() {
_chatRoomListener = new ChatRoomListenerAdapter() {
@Override
public void chatRoomOpened(final ChatRoom room) {
if (!(room instanceof ChatRoomImpl)) {
// Don't do anything if this is not a 1on1-Chat
return;
}
final ChatRoomButton sendGameButton = new ChatRoomButton(buttonimg);
room.getToolBar().addChatRoomButton(sendGameButton);
final String opponentJID = ((ChatRoomImpl) room).getJID();
sendGameButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (_currentInvitations.contains(XmppStringUtils.parseBareJid(opponentJID))) {
return;
}
final GameOfferPacket offer = new GameOfferPacket();
offer.setTo(opponentJID);
offer.setType(IQ.Type.get);
_currentInvitations.add(XmppStringUtils.parseBareJid(opponentJID));
room.getTranscriptWindow().insertCustomText(TTTRes.getString("ttt.request.sent"), false, false, Color.BLUE);
try {
SparkManager.getConnection().sendStanza(offer);
} catch (SmackException.NotConnectedException e1) {
Log.warning("Unable to send offer to " + opponentJID, e1);
}
SparkManager.getConnection().addAsyncStanzaListener(new StanzaListener() {
@Override
public void processPacket(Stanza stanza) {
GameOfferPacket answer = (GameOfferPacket) stanza;
answer.setStartingPlayer(offer.isStartingPlayer());
answer.setGameID(offer.getGameID());
if (answer.getType() == IQ.Type.result) {
// ACCEPT
_currentInvitations.remove(XmppStringUtils.parseBareJid(opponentJID));
room.getTranscriptWindow().insertCustomText(TTTRes.getString("ttt.request.accept"), false, false, Color.BLUE);
createTTTWindow(answer, opponentJID);
} else {
// DECLINE
room.getTranscriptWindow().insertCustomText(TTTRes.getString("ttt.request.decline"), false, false, Color.RED);
_currentInvitations.remove(XmppStringUtils.parseBareJid(opponentJID));
}
}
}, new PacketIDFilter(offer.getPacketID()));
}
});
}
@Override
public void chatRoomClosed(ChatRoom room) {
if (room instanceof ChatRoomImpl) {
ChatRoomImpl cri = (ChatRoomImpl) room;
_currentInvitations.remove(cri.getParticipantJID());
}
}
};
SparkManager.getChatManager().addChatRoomListener(_chatRoomListener);
}
use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.
the class TranslatorPlugin method initialize.
/**
* Called after Spark is loaded to initialize the new plugin.
*/
public void initialize() {
// Retrieve ChatManager from the SparkManager
final ChatManager chatManager = SparkManager.getChatManager();
// Add to a new ChatRoom when the ChatRoom opens.
chatManager.addChatRoomListener(new ChatRoomListenerAdapter() {
public void chatRoomOpened(ChatRoom room) {
// only do the translation for single chat
if (room instanceof ChatRoomImpl) {
final ChatRoomImpl roomImpl = (ChatRoomImpl) room;
// Create a new ChatRoomButton.
final JComboBox<TranslatorUtil.TranslationType> translatorBox = new JComboBox<>(TranslatorUtil.TranslationType.getTypes());
translatorBox.addActionListener(e -> {
// Set the focus back to the message box.
roomImpl.getChatInputEditor().requestFocusInWindow();
});
roomImpl.addChatRoomComponent(translatorBox);
// do the translation for outgoing messages.
final MessageEventListener messageListener = new MessageEventListener() {
public void sendingMessage(Message message) {
String currentBody = message.getBody();
String oldBody = message.getBody();
TranslatorUtil.TranslationType type = (TranslatorUtil.TranslationType) translatorBox.getSelectedItem();
if (type != null && type != TranslatorUtil.TranslationType.None) {
message.setBody(null);
currentBody = TranslatorUtil.translate(currentBody, type);
TranscriptWindow transcriptWindow = chatManager.getChatRoom(XmppStringUtils.parseBareJid(message.getTo())).getTranscriptWindow();
if (oldBody.equals(currentBody.substring(0, currentBody.length() - 1))) {
transcriptWindow.insertNotificationMessage("Could not translate: " + currentBody, ChatManager.ERROR_COLOR);
} else {
transcriptWindow.insertNotificationMessage("-> " + currentBody, Color.gray);
message.setBody(currentBody);
}
}
}
public void receivingMessage(Message message) {
// do nothing
}
};
roomImpl.addMessageEventListener(messageListener);
}
}
});
}
use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.
the class ChatManager method cancelledNotification.
public void cancelledNotification(final String from, final ChatState state) {
SwingUtilities.invokeLater(() -> {
ContactList contactList = SparkManager.getWorkspace().getContactList();
ChatRoom chatRoom;
try {
chatRoom = getChatContainer().getChatRoom(XmppStringUtils.parseBareJid(from));
if (chatRoom != null && chatRoom instanceof ChatRoomImpl) {
typingNotificationList.remove(chatRoom);
// Notify Decorators
notifySparkTabHandlers(chatRoom);
((ChatRoomImpl) chatRoom).notifyChatStateChange(state);
}
} catch (ChatRoomNotFoundException e) {
// Do nothing
}
contactList.useDefaults(from);
});
}
use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.
the class DefaultTabHandler method isTabHandled.
public boolean isTabHandled(SparkTab tab, Component component, boolean isSelectedTab, boolean chatFrameFocused) {
if (component instanceof ChatRoom) {
ChatRoom room = (ChatRoom) component;
boolean isStaleRoom = SparkManager.getChatManager().isStaleRoom(room);
boolean isTyping = SparkManager.getChatManager().containsTypingNotification((ChatRoom) component);
// Check if is typing.
if (isTyping) {
tab.setIcon(SparkRes.getImageIcon(SparkRes.SMALL_MESSAGE_EDIT_IMAGE));
} else if (room instanceof ChatRoomImpl && !isStaleRoom) {
// User is not typing, therefore show default presence icon.
String participantJID = ((ChatRoomImpl) room).getParticipantJID();
Presence presence = PresenceManager.getPresence(participantJID);
Icon icon = PresenceManager.getIconFromPresence(presence);
tab.setIcon(icon);
}
if (!chatFrameFocused || !isSelectedTab) {
if (room.getUnreadMessageCount() > 0) {
// Make tab red.
tab.setTitleColor((Color) UIManager.get("Chat.unreadMessageColor"));
tab.setTabBold(true);
}
// Handle unread message count.
int unreadMessageCount = room.getUnreadMessageCount();
String appendedMessage = "";
if (unreadMessageCount > 1) {
appendedMessage = " (" + unreadMessageCount + ")";
}
tab.setTabTitle(room.getTabTitle() + appendedMessage);
}
// Check if the room is stale.
if (isStaleRoom && component instanceof ChatRoomImpl) {
decorateStaleTab(tab, (ChatRoom) component);
} else // and the tab is the selected component.
if (isSelectedTab && chatFrameFocused) {
tab.setTitleColor(Color.black);
// tab.setTabFont(tab.getDefaultFont());
tab.setTabTitle(room.getTabTitle());
// Clear unread message count.
room.clearUnreadMessageCount();
}
} else {
if (!chatFrameFocused || !isSelectedTab) {
// Make tab red.
tab.setTitleColor((Color) UIManager.get("Chat.unreadMessageColor"));
tab.setTabBold(true);
}
if (isSelectedTab && chatFrameFocused) {
tab.setTitleColor(Color.black);
tab.setTabFont(tab.getDefaultFont());
}
}
return true;
}
Aggregations