Search in sources :

Example 1 with TranscriptWindow

use of org.jivesoftware.spark.ui.TranscriptWindow in project Spark by igniterealtime.

the class BroadcastPlugin method showAlert.

/**
 * Show Server Alert.
 *
 * @param message the message to show.
 * @param type
 */
private void showAlert(Message message) {
    Type type = message.getType();
    // Do not show alert if the message is an error.
    if (message.getError() != null) {
        return;
    }
    final String body = message.getBody();
    String subject = message.getSubject();
    StringBuilder buf = new StringBuilder();
    if (subject != null) {
        buf.append(Res.getString("subject")).append(": ").append(subject);
        buf.append("\n\n");
    }
    buf.append(body);
    String from = message.getFrom() != null ? message.getFrom() : "";
    final TranscriptWindow window = new TranscriptWindow();
    window.insertNotificationMessage(buf.toString(), ChatManager.TO_COLOR);
    JPanel p = new JPanel();
    p.setLayout(new BorderLayout());
    p.add(window, BorderLayout.CENTER);
    p.setBorder(BorderFactory.createLineBorder(Color.lightGray));
    // Count the number of linebreaks <br> and \n
    String s = message.getBody();
    s = s.replace("<br/>", "\n");
    s = s.replace("<br>", "\n");
    int linebreaks = org.jivesoftware.spark.util.StringUtils.countNumberOfOccurences(s, '\n');
    // Currently Serverbroadcasts dont contain Subjects, so this might be a MOTD message
    boolean mightbeMOTD = message.getSubject() != null;
    if (!from.contains("@")) {
        // if theres no "@" it means the message came from the server
        if (Default.getBoolean(Default.BROADCAST_IN_CHATWINDOW) || linebreaks > 20 || message.getBody().length() > 1000 || mightbeMOTD) {
            // if we have more than 20 linebreaks or the message is longer
            // than 1000characters we should broadcast
            // in a normal chatwindow
            broadcastInChat(message);
        } else {
            broadcastWithPanel(message);
        }
    } else if (message.getFrom() != null) {
        userToUserBroadcast(message, type, from);
    }
}
Also used : JPanel(javax.swing.JPanel) Type(org.jivesoftware.smack.packet.Message.Type) BorderLayout(java.awt.BorderLayout) TranscriptWindow(org.jivesoftware.spark.ui.TranscriptWindow)

Example 2 with TranscriptWindow

use of org.jivesoftware.spark.ui.TranscriptWindow in project Spark by igniterealtime.

the class InviteSwingWorker method finished.

@Override
public void finished() {
    final String roomName = XmppStringUtils.parseBareJid(roomJID);
    try {
        final ChatRoom room = SparkManager.getChatManager().getChatContainer().getChatRoom(roomName);
        final TranscriptWindow transcriptWindow = room.getTranscriptWindow();
        for (final String jid : (Set<String>) getValue()) {
            final String notification = Res.getString("message.waiting.for.user.to.join", jid);
            transcriptWindow.insertNotificationMessage(notification, ChatManager.NOTIFICATION_COLOR);
        }
    } catch (ChatRoomNotFoundException e) {
        Log.error("Unable to identify chat room tab by name: " + roomName);
    }
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) TranscriptWindow(org.jivesoftware.spark.ui.TranscriptWindow) ChatRoomNotFoundException(org.jivesoftware.spark.ui.ChatRoomNotFoundException)

Example 3 with TranscriptWindow

use of org.jivesoftware.spark.ui.TranscriptWindow in project Spark by igniterealtime.

the class JinglePlugin method placeCall.

public void placeCall(String jid) throws SmackException {
    // cancel call request if no Media Locator available
    if (PhoneManager.isUseStaticLocator() && PhoneManager.isUsingMediaLocator()) {
        return;
    }
    PhoneManager.setUsingMediaLocator(true);
    jid = SparkManager.getUserManager().getFullJID(jid);
    ChatRoom room = SparkManager.getChatManager().getChatRoom(XmppStringUtils.parseBareJid(jid));
    if (JingleStateManager.getInstance().getJingleRoomState(room) != null) {
        return;
    }
    SparkManager.getChatManager().getChatContainer().activateChatRoom(room);
    // Create a new Jingle Call with a full JID
    JingleSession session = null;
    try {
        session = jingleManager.createOutgoingJingleSession(jid);
    } catch (XMPPException e) {
        Log.error(e);
    }
    TranscriptWindow transcriptWindow = room.getTranscriptWindow();
    StyledDocument doc = (StyledDocument) transcriptWindow.getDocument();
    Style style = doc.addStyle("StyleName", null);
    OutgoingCall outgoingCall = new OutgoingCall();
    outgoingCall.handleOutgoingCall(session, room, jid);
    StyleConstants.setComponent(style, outgoingCall);
    // Insert the image at the end of the text
    try {
        doc.insertString(doc.getLength(), "ignored text", style);
        doc.insertString(doc.getLength(), "\n", null);
    } catch (BadLocationException e) {
        Log.error(e);
    }
    room.scrollToBottom();
}
Also used : ChatRoom(org.jivesoftware.spark.ui.ChatRoom) TranscriptWindow(org.jivesoftware.spark.ui.TranscriptWindow) StyledDocument(javax.swing.text.StyledDocument) JingleSession(org.jivesoftware.smackx.jingleold.JingleSession) Style(javax.swing.text.Style) BadLocationException(javax.swing.text.BadLocationException)

Example 4 with TranscriptWindow

use of org.jivesoftware.spark.ui.TranscriptWindow in project Spark by igniterealtime.

the class SparkManager method printChatRoomTranscript.

/**
 * Prints the transcript of a given chat room.
 *
 * @param room the chat room that contains the transcript to print.
 */
public static void printChatRoomTranscript(ChatRoom room) {
    final ChatPrinter printer = new ChatPrinter();
    final TranscriptWindow currentWindow = room.getTranscriptWindow();
    if (currentWindow != null) {
        printer.print(currentWindow);
    }
}
Also used : TranscriptWindow(org.jivesoftware.spark.ui.TranscriptWindow) ChatPrinter(org.jivesoftware.spark.ui.ChatPrinter)

Example 5 with TranscriptWindow

use of org.jivesoftware.spark.ui.TranscriptWindow in project Spark by igniterealtime.

the class SparkTransferManager method handleTransferRequest.

private void handleTransferRequest(FileTransferRequest request, ContactList contactList) {
    // Check if a listener handled this request
    if (fireTransferListeners(request)) {
        return;
    }
    String requestor = request.getRequestor();
    String bareJID = XmppStringUtils.parseBareJid(requestor);
    String fileName = request.getFileName();
    ContactItem contactItem = contactList.getContactItemByJID(bareJID);
    ChatRoom chatRoom;
    if (contactItem != null) {
        chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, contactItem.getDisplayName(), contactItem.getDisplayName());
    } else {
        chatRoom = SparkManager.getChatManager().createChatRoom(bareJID, bareJID, bareJID);
    }
    TranscriptWindow transcriptWindow = chatRoom.getTranscriptWindow();
    transcriptWindow.insertCustomText(Res.getString("message.file.transfer.chat.window"), true, false, Color.BLACK);
    final ReceiveFileTransfer receivingMessageUI = new ReceiveFileTransfer();
    receivingMessageUI.acceptFileTransfer(request);
    chatRoom.addClosingListener(() -> receivingMessageUI.cancelTransfer());
    transcriptWindow.addComponent(receivingMessageUI);
    chatRoom.increaseUnreadMessageCount();
    chatRoom.scrollToBottom();
    String fileTransMsg = contactItem.getDisplayName() + " " + Res.getString("message.file.transfer.short.message") + " " + fileName;
    SparkManager.getChatManager().getChatContainer().fireNotifyOnMessage(chatRoom, true, fileTransMsg, Res.getString("message.file.transfer.notification"));
}
Also used : ReceiveFileTransfer(org.jivesoftware.sparkimpl.plugin.filetransfer.transfer.ui.ReceiveFileTransfer) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) TranscriptWindow(org.jivesoftware.spark.ui.TranscriptWindow) ContactItem(org.jivesoftware.spark.ui.ContactItem)

Aggregations

TranscriptWindow (org.jivesoftware.spark.ui.TranscriptWindow)7 ChatRoom (org.jivesoftware.spark.ui.ChatRoom)5 Color (java.awt.Color)2 Message (org.jivesoftware.smack.packet.Message)2 ChatManager (org.jivesoftware.spark.ChatManager)2 SparkManager (org.jivesoftware.spark.SparkManager)2 ChatRoomListenerAdapter (org.jivesoftware.spark.ui.ChatRoomListenerAdapter)2 ChatRoomImpl (org.jivesoftware.spark.ui.rooms.ChatRoomImpl)2 XmppStringUtils (org.jxmpp.util.XmppStringUtils)2 AWTException (java.awt.AWTException)1 BorderLayout (java.awt.BorderLayout)1 Cursor (java.awt.Cursor)1 Desktop (java.awt.Desktop)1 FileDialog (java.awt.FileDialog)1 Frame (java.awt.Frame)1 GraphicsDevice (java.awt.GraphicsDevice)1 GraphicsEnvironment (java.awt.GraphicsEnvironment)1 Rectangle (java.awt.Rectangle)1 Robot (java.awt.Robot)1 Toolkit (java.awt.Toolkit)1