001    /*
002            Copyright (C) 2003 Adam Olsen
003    
004            This program is free software; you can redistribute it and/or modify
005            it under the terms of the GNU General Public License as published by
006            the Free Software Foundation; either version 1, or (at your option)
007            any later version.
008    
009            This program is distributed in the hope that it will be useful,
010            but WITHOUT ANY WARRANTY; without even the implied warranty of
011            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012            GNU General Public License for more details.
013    
014            You should have received a copy of the GNU General Public License
015            along with this program; if not, write to the Free Software
016            Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
017    */
018    package com.valhalla.jbother.menus;
019    
020    import java.awt.*;
021    import java.awt.event.*;
022    import java.net.URL;
023    import java.util.*;
024    
025    import javax.swing.*;
026    
027    import org.jivesoftware.smack.*;
028    import org.jivesoftware.smack.packet.*;
029    
030    import com.valhalla.gui.*;
031    import com.valhalla.jbother.*;
032    import com.valhalla.jbother.*;
033    import com.valhalla.jbother.jabber.BuddyStatus;
034    import com.valhalla.settings.Settings;
035    
036    /**
037     * The menu that pops up if someone right clicks on a user in a groupchat
038     *
039     * @author Adam Olsen
040     * @version 1.0
041    */
042    public class NickListPopupMenu extends JPopupMenu
043    {
044            private ResourceBundle resources = ResourceBundle.getBundle( "JBotherBundle", Locale.getDefault() );
045            private JMenuItem messageItem = new JMenuItem( resources.getString( "openChatDialog" ) );
046            private JMenuItem logItem = new JMenuItem( resources.getString( "viewLog" ) );
047            private JMenuItem infoItem = new JMenuItem( resources.getString( "getInfo" ) );
048            private BuddyStatus buddy;
049    
050            /**
051             * Sets up the popup menu
052            */
053            public NickListPopupMenu()
054            {
055                    MenuActionListener listener = new MenuActionListener();
056    
057                    infoItem.addActionListener( listener );
058                    messageItem.addActionListener( listener );
059                    logItem.addActionListener( listener );
060    
061                    add( messageItem );
062                    add( infoItem );
063                    add( logItem );
064            }
065    
066            /**
067             * Listens for a double mouse click, or a right click
068             * @author Adam Olsen
069             * @version 1.0
070            */
071            class MenuActionListener implements ActionListener
072            {
073                    public void actionPerformed( ActionEvent e )
074                    {
075                            if( e.getSource() == messageItem )
076                            {
077                                    if( buddy.getConversation() == null )
078                                    {
079                                            ChatPanel conver = new ChatPanel( buddy );
080                                            conver.setVisible( true );
081                                            buddy.setConversation( conver );
082                                            MessageDelegator.getInstance().showPanel( buddy.getConversation() );
083                                            MessageDelegator.getInstance().frontFrame( buddy.getConversation() );
084                                    }
085                                    else
086                                    {
087                                            MessageDelegator.getInstance().showPanel( buddy.getConversation() );
088                                            MessageDelegator.getInstance().frontFrame( buddy.getConversation() );
089    
090                                    }
091                            }
092                            else if( e.getSource() == infoItem )
093                            {
094                                    new InformationViewerDialog( buddy.getUser() ).show();
095                            }
096                            else if( e.getSource() == logItem )
097                            {
098                                    new LogViewerDialog( null, buddy.getUser() );
099                            }
100                    }
101            }
102    
103            /**
104             * Displays the popup menu
105             * @param comp the component to pop the menu up on
106             * @param x the x coordinate
107             * @param y the y coordinate of the menu
108             * @param buddy the BuddyStatus that was clicked on
109            */
110            public void showMenu( Component comp, int x, int y, BuddyStatus buddy )
111            {
112                    this.buddy = buddy;
113                    validate();
114                    show( comp, x, y );
115            }
116    }