use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl 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.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.
the class BuzzRoomDecorator method actionPerformed.
public void actionPerformed(ActionEvent e) {
final String jid = ((ChatRoomImpl) chatRoom).getParticipantJID();
Message message = new Message();
message.setTo(jid);
message.addExtension(new BuzzPacket());
try {
SparkManager.getConnection().sendStanza(message);
} catch (SmackException.NotConnectedException e1) {
Log.warning("Unable to send stanza to " + jid, e1);
}
chatRoom.getTranscriptWindow().insertNotificationMessage(Res.getString("message.buzz.sent"), ChatManager.NOTIFICATION_COLOR);
buzzButton.setEnabled(false);
// Enable the button after 30 seconds to prevent abuse.
final TimerTask enableTask = new SwingTimerTask() {
public void doRun() {
buzzButton.setEnabled(true);
}
};
TaskEngine.getInstance().schedule(enableTask, 30000);
}
use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl 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.rooms.ChatRoomImpl in project Spark by igniterealtime.
the class OTRManager method chatRoomClosed.
@Override
public void chatRoomClosed(ChatRoom room) {
super.chatRoomClosed(room);
if (OTRProperties.getInstance().getOTRCloseOnChatClose()) {
if (room instanceof ChatRoomImpl) {
ChatRoomImpl myroom = (ChatRoomImpl) room;
if (_activeSessions.containsKey(myroom.getParticipantJID())) {
OTRSession searchedSession = _activeSessions.get(myroom.getParticipantJID());
searchedSession.stopSession();
_activeSessions.remove(myroom.getParticipantJID());
}
}
}
}
use of org.jivesoftware.spark.ui.rooms.ChatRoomImpl in project Spark by igniterealtime.
the class PhonePlugin method setupPhoneSystem.
private void setupPhoneSystem() {
// Add Dial Menu
final JMenu viewMenu = SparkManager.getMainWindow().getMenuByName(Res.getString("menuitem.actions"));
JMenuItem dialNumberMenu = new JMenuItem(SparkRes.getImageIcon(SparkRes.ON_PHONE_IMAGE));
ResourceUtils.resButton(dialNumberMenu, Res.getString("button.dial.number"));
// Add Listener
dialNumberMenu.addActionListener(e -> {
dialPanel = new DialPanel();
dialPanel.getDialButton().addActionListener(e1 -> {
String number = dialPanel.getNumberToDial();
if (ModelUtil.hasLength(number)) {
dialPanel.setText(Res.getString("message.calling", number));
dialPanel.changeToRinging();
callExtension(number);
}
});
dialDialog = PhoneDialog.invoke(dialPanel, Res.getString("title.dial.phone"), Res.getString("message.number.to.call"), null);
dialPanel.getDialField().requestFocusInWindow();
dialPanel.getDialField().addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyChar() == KeyEvent.VK_ENTER) {
try {
String number = dialPanel.getNumberToDial();
if (ModelUtil.hasLength(number)) {
dialPanel.setText(Res.getString("message.calling", number));
dialPanel.changeToRinging();
callExtension(number);
}
e.consume();
} catch (Exception ex) {
Log.error(ex);
}
}
}
});
});
viewMenu.add(dialNumberMenu);
// Add ChatRoomListener to call users based on JID
SparkManager.getChatManager().addChatRoomListener(new ChatRoomListenerAdapter() {
public void chatRoomOpened(final ChatRoom room) {
if (room instanceof ChatRoomImpl) {
final ChatRoomButton callButton = new ChatRoomButton("", SparkRes.getImageIcon(SparkRes.TELEPHONE_24x24));
callButton.setToolTipText(Res.getString("tooltip.place.a.call"));
final ChatRoomImpl chatRoom = (ChatRoomImpl) room;
boolean phoneEnabled = false;
try {
phoneEnabled = phoneClient.isPhoneEnabled(XmppStringUtils.parseBareJid(chatRoom.getParticipantJID()));
} catch (Exception e) {
Log.error(e);
}
if (phoneEnabled) {
room.addChatRoomButton(callButton);
callButton.addActionListener(e -> callJID(chatRoom.getParticipantJID()));
}
}
}
});
ContactList contactList = SparkManager.getWorkspace().getContactList();
contactList.addContextMenuListener(new ContextMenuListener() {
public void poppingUp(Object object, final JPopupMenu popup) {
if (object instanceof ContactItem) {
final ContactItem item = (ContactItem) object;
boolean phoneEnabled = false;
try {
phoneEnabled = phoneClient.isPhoneEnabled(item.getJID());
} catch (Exception e) {
Log.error("There was an error retrieving phone information.", e);
}
if (phoneEnabled) {
Action callAction = new AbstractAction() {
private static final long serialVersionUID = 7221741748743018431L;
public void actionPerformed(ActionEvent e) {
callJID(item.getJID());
}
};
callAction.putValue(Action.NAME, "Call");
callAction.putValue(Action.SMALL_ICON, SparkRes.getImageIcon(SparkRes.ON_PHONE_IMAGE));
popup.add(callAction);
}
}
}
public void poppingDown(JPopupMenu popup) {
}
public boolean handleDefaultAction(MouseEvent e) {
return false;
}
});
}
Aggregations