Search in sources :

Example 1 with PresenceListener

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

the class ApplePlugin method handleIdle.

private void handleIdle() {
    SparkManager.getMainWindow().addComponentListener(new ComponentListener() {

        public void componentResized(ComponentEvent componentEvent) {
            setActivity();
        }

        public void componentMoved(ComponentEvent componentEvent) {
            setActivity();
        }

        public void componentShown(ComponentEvent componentEvent) {
            setActivity();
        }

        public void componentHidden(ComponentEvent componentEvent) {
            setActivity();
        }
    });
    SparkManager.getChatManager().addChatRoomListener(new ChatRoomListenerAdapter() {

        public void chatRoomOpened(ChatRoom room) {
            if (!addedFrameListener) {
                chatFrame = SparkManager.getChatManager().getChatContainer().getChatFrame();
                chatFrame.addComponentListener(new ComponentListener() {

                    public void componentResized(ComponentEvent componentEvent) {
                        setActivity();
                    }

                    public void componentMoved(ComponentEvent componentEvent) {
                        setActivity();
                    }

                    public void componentShown(ComponentEvent componentEvent) {
                        setActivity();
                    }

                    public void componentHidden(ComponentEvent componentEvent) {
                        setActivity();
                    }
                });
                addedFrameListener = true;
            }
            setActivity();
        }

        public void chatRoomClosed(ChatRoom room) {
            setActivity();
        }
    });
    SparkManager.getSessionManager().addPresenceListener(new PresenceListener() {

        public void presenceChanged(Presence presence) {
            if (presence.isAvailable() && !presence.isAway()) {
                lastActive = System.currentTimeMillis();
            }
        }
    });
    final Timer timer = new Timer();
    timer.scheduleAtFixedRate(new TimerTask() {

        public void run() {
            sparkIsIdle();
        }
    }, 10000, 10000);
    lastActive = System.currentTimeMillis();
}
Also used : PresenceListener(org.jivesoftware.spark.ui.PresenceListener) ComponentListener(java.awt.event.ComponentListener) ChatRoomListenerAdapter(org.jivesoftware.spark.ui.ChatRoomListenerAdapter) Timer(java.util.Timer) TimerTask(java.util.TimerTask) ChatRoom(org.jivesoftware.spark.ui.ChatRoom) Presence(org.jivesoftware.smack.packet.Presence) ComponentEvent(java.awt.event.ComponentEvent)

Aggregations

ComponentEvent (java.awt.event.ComponentEvent)1 ComponentListener (java.awt.event.ComponentListener)1 Timer (java.util.Timer)1 TimerTask (java.util.TimerTask)1 Presence (org.jivesoftware.smack.packet.Presence)1 ChatRoom (org.jivesoftware.spark.ui.ChatRoom)1 ChatRoomListenerAdapter (org.jivesoftware.spark.ui.ChatRoomListenerAdapter)1 PresenceListener (org.jivesoftware.spark.ui.PresenceListener)1