use of org.jivesoftware.spark.ui.ChatRoom in project Spark by igniterealtime.
the class ReversiPlugin method addToolbarButton.
/**
* Adds the Reversi toolbar button.
*/
private void addToolbarButton() {
ChatManager manager = SparkManager.getChatManager();
chatRoomListener = new ChatRoomListenerAdapter() {
ImageIcon icon = ReversiRes.getImageIcon(ReversiRes.REVERSI_ICON);
public void chatRoomOpened(final ChatRoom room) {
if (!(room instanceof ChatRoomImpl)) {
// Don't do anything if this is not a 1on1-Chat
return;
}
ChatRoomButton button = new ChatRoomButton(icon);
button.setToolTipText("Reversi");
room.getToolBar().addChatRoomButton(button);
// Add a button listener that sends out a game invite on a user
// click.
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// Show "requesting a game panel"
final JPanel request = new JPanel();
request.setLayout(new BorderLayout());
JPanel requestPanel = new JPanel() {
private static final long serialVersionUID = 4490592207923738251L;
protected void paintComponent(Graphics g) {
g.drawImage(icon.getImage(), 0, 0, null);
}
};
requestPanel.setPreferredSize(new Dimension(24, 24));
request.add(requestPanel, BorderLayout.WEST);
String opponentJID = ((ChatRoomImpl) room).getJID();
// TODO:
String opponentName = "[" + opponentJID + "]";
// convert
// to
// more
// readable
// name.
final JPanel content = new JPanel(new BorderLayout());
final JLabel label = new JLabel("Requesting a Reversi game with " + opponentName + ", please wait...");
content.add(label, BorderLayout.CENTER);
JPanel buttonPanel = new JPanel();
final JButton cancelButton = new JButton("Cancel");
cancelButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
GameOffer reply = new GameOffer();
reply.setTo(((ChatRoomImpl) room).getJID());
reply.setType(IQ.Type.error);
try {
SparkManager.getConnection().sendStanza(reply);
} catch (SmackException.NotConnectedException e1) {
Log.warning("Unable to send invitation cancellation to " + reply.getTo(), e1);
}
cancelButton.setText("Canceled");
cancelButton.setEnabled(false);
}
});
buttonPanel.add(cancelButton, BorderLayout.SOUTH);
content.add(buttonPanel, BorderLayout.SOUTH);
request.add(content, BorderLayout.CENTER);
room.getTranscriptWindow().addComponent(request);
final GameOffer offer = new GameOffer();
offer.setTo(opponentJID);
// Add a listener for a reply to our offer.
SparkManager.getConnection().addAsyncStanzaListener(new StanzaListener() {
public void processPacket(Stanza stanza) {
GameOffer offerReply = ((GameOffer) stanza);
if (offerReply.getType() == IQ.Type.result) {
// Remove the offer panel
room.getTranscriptWindow().remove(request);
content.remove(1);
label.setText("Starting game...");
// Show game board (using original offer!).
showReversiBoard(offer.getGameID(), room, offer.isStartingPlayer(), offerReply.getFrom());
} else if (offerReply.getType() == IQ.Type.error) {
cancelButton.setVisible(false);
JPanel userDeclinedPanel = new JPanel(new BorderLayout());
JLabel userDeclined = new JLabel("User declined...");
userDeclinedPanel.add(userDeclined, BorderLayout.SOUTH);
request.add(userDeclinedPanel, BorderLayout.SOUTH);
}
// TODO: Handle error case
}
}, new StanzaIdFilter(offer.getStanzaId()));
try {
SparkManager.getConnection().sendStanza(offer);
} catch (SmackException.NotConnectedException e1) {
Log.warning("Unable to send invitation to " + offer.getTo(), e1);
}
}
});
}
public void chatRoomClosed(ChatRoom room) {
super.chatRoomClosed(room);
// TODO: if game is in progress, close it down. What we need is
// an API that lets us see
// TODO: if there's a transcript alert currently there.
}
};
manager.addChatRoomListener(chatRoomListener);
}
use of org.jivesoftware.spark.ui.ChatRoom in project Spark by igniterealtime.
the class RoarMessageListener method messageReceived.
@Override
public void messageReceived(ChatRoom room, Message message) {
try {
ChatRoom activeroom = SparkManager.getChatManager().getChatContainer().getActiveChatRoom();
int framestate = SparkManager.getChatManager().getChatContainer().getChatFrame().getState();
if (framestate == JFrame.NORMAL && activeroom.equals(room) && room.isShowing() && (isOldGroupChat(room) || isMessageFromRoom(room, message))) {
// Do Nothing
} else {
decideForRoomAndMessage(room, message);
}
} catch (ChatRoomNotFoundException e) {
// i dont care
}
}
use of org.jivesoftware.spark.ui.ChatRoom in project Spark by igniterealtime.
the class NonRosterPanel method callStarted.
/**
* Called when a new call is established.
*/
private void callStarted() {
redialButton.setVisible(false);
hangUpButton.setVisible(true);
hangUpButton.setEnabled(true);
muteButton.setEnabled(true);
holdButton.setEnabled(true);
transferButton.setEnabled(true);
setStatus(CONNECTED, false);
// Show History
historyPanel.removeAll();
historyPanel.addPreviousConversations(phoneNumber);
// Add notification to ChatRoom if one exists.
final ChatRoom chatRoom = callManager.getAssociatedChatRoom(this);
if (chatRoom != null) {
final SimpleDateFormat formatter = new SimpleDateFormat("h:mm a");
String time = formatter.format(new Date());
chatRoom.getTranscriptWindow().insertNotificationMessage(PhoneRes.getIString("phone.callstartedat") + " " + time, ChatManager.NOTIFICATION_COLOR);
}
}
use of org.jivesoftware.spark.ui.ChatRoom in project Spark by igniterealtime.
the class NonRosterPanel method callEnded.
/**
* Called when the call is ended. This does basic container cleanup.
*/
public void callEnded() {
if (!callWasTransferred) {
historyPanel.callEnded();
setStatus(PhoneRes.getIString("phone.callended"), new Color(211, 0, 0));
}
hangUpButton.setVisible(false);
redialButton.setVisible(true);
muteButton.setEnabled(false);
holdButton.setEnabled(false);
transferButton.setEnabled(false);
// Add notification to ChatRoom if one exists.
final ChatRoom chatRoom = callManager.getAssociatedChatRoom(this);
if (chatRoom != null) {
final SimpleDateFormat formatter = new SimpleDateFormat("h:mm a");
String time = formatter.format(new Date());
chatRoom.getTranscriptWindow().insertNotificationMessage(PhoneRes.getIString("phone.callendedat") + " " + time, ChatManager.NOTIFICATION_COLOR);
}
changeState(CallRoomState.callWasEnded);
}
use of org.jivesoftware.spark.ui.ChatRoom in project Spark by igniterealtime.
the class SoftPhoneTabHandler method handleChatRoom.
private void handleChatRoom(Component component, SparkTab tab, boolean chatFrameFocused, boolean isSelectedTab) {
final ChatRoom chatRoom = (ChatRoom) component;
if (!chatFrameFocused || !isSelectedTab) {
if (chatRoom.getUnreadMessageCount() > 0) {
// Make tab red.
tab.setTitleColor(Color.red);
tab.setTabBold(true);
}
// Handle unread message count.
int unreadMessageCount = chatRoom.getUnreadMessageCount();
String appendedMessage = "";
if (unreadMessageCount > 1) {
appendedMessage = " (" + unreadMessageCount + ")";
}
tab.setTabTitle(chatRoom.getTabTitle() + appendedMessage);
}
// and the tab is the selected component.
if (isSelectedTab && chatFrameFocused) {
tab.setTitleColor(Color.black);
tab.setTabFont(tab.getDefaultFont());
tab.setTabTitle(chatRoom.getTabTitle());
// Clear unread message count.
chatRoom.clearUnreadMessageCount();
}
}
Aggregations