001    /*
002     * Copyright (C) 2003 Adam Olsen
003     *
004     * This program is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU General Public License as published by the Free Software
006     * Foundation; either version 1, or (at your option) any later version.
007     *
008     * This program is distributed in the hope that it will be useful, but WITHOUT
009     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
010     * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
011     * details.
012     *
013     * You should have received a copy of the GNU General Public License along with
014     * this program; if not, write to the Free Software Foundation, Inc., 675 Mass
015     * Ave, Cambridge, MA 02139, USA.
016     */
017    
018    package com.valhalla.jbother.menus;
019    
020    import java.awt.event.ActionEvent;
021    import java.awt.event.ActionListener;
022    
023    import javax.swing.JMenuItem;
024    import javax.swing.JSeparator;
025    
026    import org.jivesoftware.smack.packet.Presence;
027    
028    import com.valhalla.jbother.BuddyList;
029    
030    public class BuddyListTransportMenu extends BuddyListPopupMenu {
031        private JMenuItem signOnItem = new JMenuItem(resources.getString("signOn"));
032    
033        private JMenuItem signOffItem = new JMenuItem(resources
034                .getString("signOff"));
035    
036        public BuddyListTransportMenu() {
037            //insert(new JSeparator(), 6);
038            insert(signOnItem, 6);
039            insert(signOffItem, 7);
040    
041            TransportListener l = new TransportListener();
042            signOnItem.addActionListener(l);
043            signOffItem.addActionListener(l);
044        }
045    
046        class TransportListener implements ActionListener {
047            public void actionPerformed(ActionEvent e) {
048                if (e.getSource() == signOnItem) {
049                    Presence p = new Presence(Presence.Type.AVAILABLE);
050                    p.setTo(buddy.getUser());
051                    BuddyList.getInstance().getConnection().sendPacket(p);
052                } else if (e.getSource() == signOffItem) {
053                    Presence p = new Presence(Presence.Type.UNAVAILABLE);
054                    p.setTo(buddy.getUser());
055                    BuddyList.getInstance().getConnection().sendPacket(p);
056                }
057            }
058        }
059    }