View Javadoc

1   /*
2    *  XNap - A P2P framework and client.
3    *
4    *  See the file AUTHORS for copyright information.
5    *
6    *  This program is free software; you can redistribute it and/or modify
7    *  it under the terms of the GNU General Public License as published by
8    *  the Free Software Foundation.
9    *
10   *  This program is distributed in the hope that it will be useful,
11   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   *  GNU General Public License for more details.
14   *
15   *  You should have received a copy of the GNU General Public License
16   *  along with this program; if not, write to the Free Software
17   *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package org.xnap.gui.action;
21  
22  import java.awt.event.ActionEvent;
23  
24  import javax.swing.AbstractAction;
25  import javax.swing.Action;
26  import javax.swing.JOptionPane;
27  
28  import org.xnap.XNap;
29  import org.xnap.chat.ChatProvider;
30  import org.xnap.gui.util.IconHelper;
31  
32  /***
33   * Provides an action that prompts the user for a channel name and
34   * then joins a channel on a {@link ChatProvider} object by calling
35   * {@link ChatProvider#join(String)}.  
36   */
37  public class JoinChannelAction extends AbstractAction 
38  {
39      
40      //--- Constant(s) ---
41      
42      //--- Data field(s) ---
43  
44      private ChatProvider cp;
45  
46      //--- Constructor(s) ---
47      
48      public JoinChannelAction(ChatProvider cp) 
49      {
50  		this.cp = cp;
51  
52  		putValue(Action.NAME, XNap.tr("Create/Join Channel") + "...");
53  		putValue(Action.SHORT_DESCRIPTION, 
54  				 XNap.tr("Prompts for a channel name."));
55  		putValue(IconHelper.XNAP_ICON, "filenew.png");
56      }
57  
58      //--- Method(s) ---
59  
60      public void actionPerformed(ActionEvent event) 
61      {
62  		String name = JOptionPane.showInputDialog
63  			(null, XNap.tr("Name"), 
64  			 XNap.tr("Join Channel"), JOptionPane.QUESTION_MESSAGE);
65  	
66  		if (name != null && name.trim().length() > 0) {
67  			cp.join(name.trim());
68  		}
69      }
70      
71  }