use of org.jivesoftware.spark.ChatManager in project Spark by igniterealtime.
the class UserSearchResults method openChatRoom.
private void openChatRoom(int row) {
String jid = (String) resultsTable.getValueAt(row, 0);
String nickname = XmppStringUtils.parseLocalpart(jid);
TableColumn column;
try {
column = resultsTable.getColumn("nick");
int col = column.getModelIndex();
nickname = (String) resultsTable.getValueAt(row, col);
if (!ModelUtil.hasLength(nickname)) {
nickname = XmppStringUtils.parseLocalpart(jid);
}
} catch (Exception e1) {
// Ignore e1
}
ChatManager chatManager = SparkManager.getChatManager();
ChatRoom chatRoom = chatManager.createChatRoom(jid, nickname, nickname);
ChatContainer chatRooms = chatManager.getChatContainer();
chatRooms.activateChatRoom(chatRoom);
}
use of org.jivesoftware.spark.ChatManager in project Spark by igniterealtime.
the class OnlineAgents method activateChat.
/**
* Activate a chat room with the selected user.
*/
private void activateChat(final String userJID, final String nickname) {
if (!ModelUtil.hasLength(userJID)) {
return;
}
SwingWorker worker = new SwingWorker() {
final ChatManager chatManager = SparkManager.getChatManager();
ChatRoom chatRoom;
public Object construct() {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
Log.error("Error in activate chat.", e);
}
ChatContainer chatRooms = chatManager.getChatContainer();
try {
chatRoom = chatRooms.getChatRoom(userJID);
} catch (ChatRoomNotFoundException e) {
Log.warning("Room not found for jid: " + userJID, e);
}
return chatRoom;
}
public void finished() {
if (chatRoom == null) {
chatRoom = new ChatRoomImpl(userJID, nickname, nickname);
chatManager.getChatContainer().addChatRoom(chatRoom);
}
chatManager.getChatContainer().activateChatRoom(chatRoom);
}
};
worker.start();
}
use of org.jivesoftware.spark.ChatManager in project Spark by igniterealtime.
the class TranscriptWindow method poppingUp.
/**
* Adds Print and Clear actions.
*
* @param object the TransferWindow
* @param popup the popup menu to add to.
*/
public void poppingUp(final Object object, JPopupMenu popup) {
popup.addSeparator();
popup.add(new AbstractAction(Res.getString("action.print"), SparkRes.getImageIcon(SparkRes.PRINTER_IMAGE_16x16)) {
public void actionPerformed(ActionEvent actionEvent) {
SparkManager.printChatTranscript((TranscriptWindow) object);
}
});
if (!Default.getBoolean("HIDE_HISTORY_SETTINGS") && Enterprise.containsFeature(Enterprise.HISTORY_SETTINGS_FEATURE) && !Default.getBoolean("HISTORY_DISABLED") && Enterprise.containsFeature(Enterprise.HISTORY_TRANSCRIPTS_FEATURE)) {
popup.add(new AbstractAction(Res.getString("action.clear"), SparkRes.getImageIcon(SparkRes.ERASER_IMAGE)) {
public void actionPerformed(ActionEvent actionEvent) {
String user = null;
try {
ChatManager manager = SparkManager.getChatManager();
ChatRoom room = manager.getChatContainer().getActiveChatRoom();
user = room.getRoomname();
int ok = JOptionPane.showConfirmDialog((TranscriptWindow) object, Res.getString("delete.permanently"), Res.getString("delete.log.permanently"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if (ok == JOptionPane.YES_OPTION) {
// This actions must be move into Transcript Plugin!
File transcriptDir = new File(SparkManager.getUserDirectory(), "transcripts");
File transcriptFile = new File(transcriptDir, user + ".xml");
transcriptFile.delete();
transcriptFile = new File(transcriptDir, user + "_current.xml");
transcriptFile.delete();
clear();
}
} catch (Exception ex) {
Log.error("An exception occurred while trying to clear history for a chat room " + user, ex);
}
}
});
}
// History window
if (!Default.getBoolean("HISTORY_DISABLED") && Enterprise.containsFeature(Enterprise.HISTORY_TRANSCRIPTS_FEATURE)) {
popup.add(new AbstractAction(Res.getString("action.viewlog")) {
@Override
public void actionPerformed(ActionEvent e) {
ChatRoom room = null;
try {
room = SparkManager.getChatManager().getChatContainer().getActiveChatRoom();
HistoryWindow hw = new HistoryWindow(SparkManager.getUserDirectory(), room.getRoomname());
hw.showWindow();
} catch (Exception ex) {
Log.error("An exception occurred while trying to open history window for room " + room, ex);
}
}
});
}
}
use of org.jivesoftware.spark.ChatManager in project Spark by igniterealtime.
the class ContactItem method updatePresenceIcon.
/**
* Updates the icon of the user based on their presence.
*
* @param presence the users presence.
*/
public void updatePresenceIcon(Presence presence) {
ChatManager chatManager = SparkManager.getChatManager();
boolean handled = chatManager.fireContactItemPresenceChanged(this, presence);
if (handled) {
return;
}
String status = presence.getStatus();
Icon statusIcon = SparkRes.getImageIcon(SparkRes.GREEN_BALL);
boolean isAvailable = false;
if (status == null && presence.isAvailable()) {
Presence.Mode mode = presence.getMode();
if (mode == Presence.Mode.available) {
status = Res.getString("status.online");
isAvailable = true;
} else if (mode == Presence.Mode.away) {
status = Res.getString("status.away");
statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
} else if (mode == Presence.Mode.chat) {
status = Res.getString("status.free.to.chat");
} else if (mode == Presence.Mode.dnd) {
status = Res.getString("status.do.not.disturb");
statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
} else if (mode == Presence.Mode.xa) {
status = Res.getString("status.extended.away");
statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
}
}
if (presence.isAvailable() && (presence.getMode() == Presence.Mode.dnd || presence.getMode() == Presence.Mode.away || presence.getMode() == Presence.Mode.xa)) {
statusIcon = SparkRes.getImageIcon(SparkRes.IM_AWAY);
} else if (presence.isAvailable()) {
isAvailable = true;
} else if (!presence.isAvailable()) {
getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
getNicknameLabel().setForeground((Color) UIManager.get("ContactItemOffline.color"));
RosterEntry entry = Roster.getInstanceFor(SparkManager.getConnection()).getEntry(getJID());
if (entry != null && (entry.getType() == RosterPacket.ItemType.none || entry.getType() == RosterPacket.ItemType.from) && RosterPacket.ItemStatus.SUBSCRIPTION_PENDING == entry.getStatus()) {
// Do not move out of group.
setIcon(SparkRes.getImageIcon(SparkRes.SMALL_QUESTION));
getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
setStatusText(Res.getString("status.pending"));
} else {
// We should keep the offline bullet (not available) instead of putting icon null.
setIcon(SparkRes.getImageIcon(SparkRes.CLEAR_BALL_ICON));
setFont(new Font("Dialog", Font.PLAIN, fontSize));
getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
setAvailable(false);
if (ModelUtil.hasLength(status)) {
setStatusText(status);
} else {
setStatusText("");
}
}
sideIcon.setIcon(null);
setAvailable(false);
return;
}
Icon sIcon = PresenceManager.getIconFromPresence(presence);
if (sIcon != null) {
setIcon(sIcon);
} else {
setIcon(statusIcon);
}
if (status != null) {
setStatus(status);
}
if (PresenceManager.isOnPhone(presence)) {
statusIcon = SparkRes.getImageIcon(SparkRes.ON_PHONE_IMAGE);
setIcon(statusIcon);
}
// Always change nickname label to black.
getNicknameLabel().setForeground((Color) UIManager.get("ContactItemNickname.foreground"));
if (isAvailable) {
getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
if (Res.getString("status.online").equals(status) || Res.getString("available").equalsIgnoreCase(status)) {
setStatusText("");
} else {
setStatusText(status);
}
} else if (presence.isAvailable()) {
LocalPreferences pref = SettingsManager.getLocalPreferences();
if (pref.isGrayingOutEnabled()) {
getNicknameLabel().setFont(new Font("Dialog", Font.ITALIC, fontSize));
getNicknameLabel().setForeground(Color.gray);
} else {
getNicknameLabel().setFont(new Font("Dialog", Font.PLAIN, fontSize));
getNicknameLabel().setForeground(Color.black);
}
if (status != null) {
setStatusText(status);
}
}
setAvailable(true);
}
use of org.jivesoftware.spark.ChatManager in project Spark by igniterealtime.
the class SparkTransferManager method addSendFileButton.
private void addSendFileButton() {
final ChatManager chatManager = SparkManager.getChatManager();
chatManager.addChatRoomListener(new ChatRoomListenerAdapter() {
public void chatRoomOpened(final ChatRoom room) {
if (!(room instanceof ChatRoomImpl)) {
return;
}
// Otherwise,
new ChatRoomTransferDecorator(room);
}
public void chatRoomClosed(ChatRoom room) {
}
});
}
Aggregations