Search in sources :

Example 6 with ChatManager

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);
}
Also used : ChatContainer(org.jivesoftware.spark.ui.ChatContainer) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) TableColumn(javax.swing.table.TableColumn) ChatManager(org.jivesoftware.spark.ChatManager)

Example 7 with ChatManager

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();
}
Also used : ChatContainer(org.jivesoftware.spark.ui.ChatContainer) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException) SwingWorker(org.jivesoftware.spark.util.SwingWorker) ChatManager(org.jivesoftware.spark.ChatManager) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Example 8 with ChatManager

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);
                }
            }
        });
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) HistoryWindow(org.jivesoftware.spark.ui.history.HistoryWindow) ChatManager(org.jivesoftware.spark.ChatManager) File(java.io.File)

Example 9 with ChatManager

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);
}
Also used : Presence(org.jivesoftware.smack.packet.Presence) RosterEntry(org.jivesoftware.smack.roster.RosterEntry) ImageIcon(javax.swing.ImageIcon) Icon(javax.swing.Icon) LocalPreferences(org.jivesoftware.sparkimpl.settings.local.LocalPreferences) ChatManager(org.jivesoftware.spark.ChatManager) Font(java.awt.Font)

Example 10 with ChatManager

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) {
        }
    });
}
Also used : ChatRoomListenerAdapter(org.jivesoftware.spark.ui.ChatRoomListenerAdapter) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) ChatManager(org.jivesoftware.spark.ChatManager) ChatRoomImpl(org.jivesoftware.spark.ui.rooms.ChatRoomImpl)

Aggregations

ChatManager (org.jivesoftware.spark.ChatManager)19 ChatRoom (org.jivesoftware.spark.ui.ChatRoom)8 ChatRoomImpl (org.jivesoftware.spark.ui.rooms.ChatRoomImpl)7 SmackException (org.jivesoftware.smack.SmackException)6 ChatContainer (org.jivesoftware.spark.ui.ChatContainer)5 MultiUserChatManager (org.jivesoftware.smackx.muc.MultiUserChatManager)4 GroupChatRoom (org.jivesoftware.spark.ui.rooms.GroupChatRoom)4 ActionEvent (java.awt.event.ActionEvent)3 Message (org.jivesoftware.smack.packet.Message)3 ChatRoomListenerAdapter (org.jivesoftware.spark.ui.ChatRoomListenerAdapter)3 ChatRoomNotFoundException (org.jivesoftware.spark.ui.ChatRoomNotFoundException)3 LocalPreferences (org.jivesoftware.sparkimpl.settings.local.LocalPreferences)3 BorderLayout (java.awt.BorderLayout)2 File (java.io.File)2 ImageIcon (javax.swing.ImageIcon)2 JButton (javax.swing.JButton)2 JComboBox (javax.swing.JComboBox)2 JLabel (javax.swing.JLabel)2 JPanel (javax.swing.JPanel)2 Presence (org.jivesoftware.smack.packet.Presence)2