openfire+spark二次开发 spark聊天窗口的构建


// Create new room
                    // 创建新的房间
                    ChatRoom chatRoom = new ChatRoomImpl( message.getFrom(), userNickname, roomTitle );
                    SparkManager.getChatManager().getChatContainer().addChatRoom( chatRoom );

                    SparkManager.getChatManager().getChatContainer().activateChatRoom( chatRoom );
                    chatRoom.insertMessage( message );

GroupChatRoom.java    private void handleMessagePacket( Stanza stanza )

SparkManager.java

 public static ChatManager getChatManager() {
        if (chatManager == null) {
            chatManager = ChatManager.getInstance();
        }
        return chatManager;
    }

ChatManager.java

 public ChatContainer getChatContainer() {
        return chatContainer;
    }

ChatContainer.java

 /**
     * Adds a new ChatRoom to Spark.
     * 给Spark添加了一个新的聊天室。
     *
     * @param room the ChatRoom to add.
     */
    public synchronized void addChatRoom(final ChatRoom room) {
        createFrameIfNeeded();
        // 设置边框,高亮灰
        room.setBorder(BorderFactory.createMatteBorder(1, 0, 0, 0, Color.LIGHT_GRAY));
        AndFilter presenceFilter = new AndFilter(new StanzaTypeFilter(Presence.class), FromMatchesFilter.createBare( room.getRoomname()));

        // Next, create a packet listener. We use an anonymous inner class for brevity.
        StanzaListener myListener = stanza -> SwingUtilities.invokeLater( () -> handleRoomPresence((Presence)stanza) );

        room.registeredToFrame(chatFrame);
        
        SparkManager.getConnection().addAsyncStanzaListener(myListener, presenceFilter);

        // Add to PresenceMap
        presenceMap.put(room.getRoomname(), myListener);

        String tooltip;
        if (room instanceof ChatRoomImpl) {
            tooltip = ((ChatRoomImpl)room).getParticipantJID();
            String nickname = SparkManager.getUserManager().getUserNicknameFromJID(((ChatRoomImpl)room).getParticipantJID());

            tooltip = "<html><body><b>Contact: </b>" + nickname + "<br><b>JID: </b>" + tooltip;
        }
        else {
            tooltip = room.getRoomname();
        }

        // Create ChatRoom UI and dock
        SparkTab tab = addTab(room.getTabTitle(), room.getTabIcon(), room, tooltip);
        tab.addMouseListener(new MouseAdapter() {
            public void mouseReleased(MouseEvent e) {
                checkTabPopup(e);
            }

            public void mousePressed(MouseEvent e) {
                checkTabPopup(e);
            }
        });

        room.addMessageListener(this);

        // Remove brand panel
        final String title = getTabAt(0).getActualText();
        if (title.equals(WELCOME_TITLE)) {
            chatFrame.setTitle(room.getRoomTitle());
        }


        final TimerTask visibleTask = new SwingTimerTask() {
            public void doRun() {
                checkVisibility(room);
            }
        };

        TaskEngine.getInstance().schedule(visibleTask, 100);

        // Add to ChatRoomList
        chatRoomList.add(room);

        // Notify users that the chat room has been opened.
        // 通知用户聊天室已经打开。
        fireChatRoomOpened(room);

        // Focus Chat
        focusChat();

        // Add Room listeners to override issue with input maps and keybinding on the mac.
        // 添加房间监听器以覆盖在mac上的输入映射和键绑定问题。
        if (Spark.isMac()) {
            room.getChatInputEditor().addKeyListener(this);
        }
    }








评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值