use of org.jivesoftware.spark.ChatManager in project Spark by igniterealtime.
the class ConferenceServices method addChatRoomListener.
private void addChatRoomListener() {
ChatManager chatManager = SparkManager.getChatManager();
chatManager.addChatRoomListener(new ChatRoomListener() {
public void chatRoomOpened(final ChatRoom room) {
if (room instanceof ChatRoomImpl) {
final ChatRoomDecorator decorator = new ChatRoomDecorator(room);
decorator.decorate();
}
}
public void chatRoomLeft(ChatRoom room) {
}
public void chatRoomClosed(ChatRoom room) {
}
public void chatRoomActivated(ChatRoom room) {
}
public void userHasJoined(ChatRoom room, String userid) {
}
public void userHasLeft(ChatRoom room, String userid) {
}
});
}
use of org.jivesoftware.spark.ChatManager in project Spark by igniterealtime.
the class BroadcastPlugin method broadcastInChat.
/**
* Displays the Serverbroadcast like all other messages
* in its on chatcontainer with transcript history
* @param message
* @param from
*/
private void broadcastInChat(Message message) {
String from = message.getFrom() != null ? message.getFrom() : "";
ChatManager chatManager = SparkManager.getChatManager();
ChatContainer container = chatManager.getChatContainer();
ChatRoomImpl chatRoom;
try {
chatRoom = (ChatRoomImpl) container.getChatRoom(from);
} catch (ChatRoomNotFoundException e) {
String windowtitle = message.getSubject() != null ? message.getSubject() : Res.getString("administrator");
chatRoom = new ChatRoomImpl("serveralert@" + from, Res.getString("broadcast"), windowtitle);
chatRoom.getBottomPanel().setVisible(false);
chatRoom.hideToolbar();
SparkManager.getChatManager().getChatContainer().addChatRoom(chatRoom);
}
chatRoom.getTranscriptWindow().insertNotificationMessage(message.getBody(), ChatManager.NOTIFICATION_COLOR);
broadcastRooms.add(chatRoom);
}
use of org.jivesoftware.spark.ChatManager in project Spark by igniterealtime.
the class ReversiPlugin method removeToolbarButton.
/**
* Removes the Reversi toolbar button.
*/
private void removeToolbarButton() {
ChatManager manager = SparkManager.getChatManager();
manager.removeChatRoomListener(chatRoomListener);
// TODO: remove actual buttons from toolbar.
}
use of org.jivesoftware.spark.ChatManager 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.ChatManager in project Spark by igniterealtime.
the class UserInvitationPane method startFastpathChat.
private void startFastpathChat(String fullRoomJID, String roomName) {
// Add to Chat window
ChatManager chatManager = SparkManager.getChatManager();
GroupChatRoom chatRoom;
try {
chatRoom = chatManager.getGroupChat(fullRoomJID);
if (!chatRoom.isActive()) {
// Remove old room, add new room.
chatManager.removeChat(chatRoom);
MultiUserChat chat = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getMultiUserChat(fullRoomJID);
chatRoom = new GroupChatRoom(chat);
} else {
// Already in the room, do not process invitation
try {
offer.reject();
} catch (SmackException.NotConnectedException e) {
Log.warning("Unable to reject offer " + offer, e);
}
return;
}
} catch (ChatNotFoundException e) {
MultiUserChat chat = MultiUserChatManager.getInstanceFor(SparkManager.getConnection()).getMultiUserChat(fullRoomJID);
chatRoom = new GroupChatRoom(chat);
}
chatRoom.getSplitPane().setDividerSize(5);
chatRoom.getSplitPane().getRightComponent().setVisible(true);
chatRoom.getBottomPanel().setVisible(true);
chatRoom.getScrollPaneForTranscriptWindow().setVisible(true);
chatRoom.getEditorBar().setVisible(true);
chatRoom.getChatInputEditor().setEnabled(true);
chatRoom.getToolBar().setVisible(true);
chatRoom.getVerticalSlipPane().setDividerLocation(0.8);
chatRoom.getSplitPane().setDividerLocation(0.6);
try {
chatRoom.setTabTitle(roomName);
chatRoom.getConferenceRoomInfo().setNicknameChangeAllowed(false);
chatRoom.getToolBar().setVisible(true);
chatRoom.getEditorBar().setVisible(true);
chatRoom.getChatInputEditor().setEnabled(true);
ChatContainer chatContainer = SparkManager.getChatManager().getChatContainer();
chatContainer.addChatRoom(chatRoom);
FastpathPlugin.getLitWorkspace().addFastpathChatRoom(chatRoom, Workpane.RoomState.activeRoom);
chatContainer.setChatRoomTitle(chatRoom, roomName);
if (chatContainer.getActiveChatRoom() == chatRoom) {
chatContainer.getChatFrame().setTitle(roomName);
}
} catch (Exception e) {
Log.error(e);
}
ConferenceUtils.enterRoomOnSameThread(roomName, fullRoomJID, null);
removeOwner(chatRoom.getMultiUserChat());
FastpathPlugin.getLitWorkspace().checkForDecoration(chatRoom, offer.getSessionID());
if (listener != null) {
listener.yesOption();
listener = null;
}
}
Aggregations