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.plugin.overnet.gui.action;
21  
22  import javax.swing.Action;
23  import javax.swing.JOptionPane;
24  
25  import java.awt.event.ActionEvent;
26  
27  import org.apache.log4j.Logger;
28  import org.xnap.XNap;
29  import org.xnap.action.AbstractXNapAction;
30  import org.xnap.event.StateEvent;
31  import org.xnap.event.StateListener;
32  import org.xnap.gui.XNapFrame;
33  import org.xnap.gui.util.IconHelper;
34  import org.xnap.plugin.overnet.OvernetPlugin;
35  import org.xnap.plugin.overnet.net.OvernetCore;
36  import org.xnap.plugin.overnet.net.msg.client.CommandMessage;
37  import org.xnap.util.State;
38  
39  public class DownloadLinkAction extends AbstractXNapAction
40  	implements StateListener
41  {
42  	//--- Constant(s) ---
43  
44  	//--- Data field(s) ---
45  	
46  	private OvernetCore core = OvernetPlugin.getInstance().getCore();
47  
48      private static Logger logger = Logger.getLogger(DownloadLinkAction.class);
49  	
50  	//--- Constructor(s) ---
51  
52      public DownloadLinkAction()
53  	{
54  		putValue(Action.NAME, XNap.tr("Download Link") + "...");
55  		putValue(IconHelper.XNAP_ICON, "down.png");
56  		core.addStateListener(this);
57  		stateChanged(null);
58  	}
59  
60      //--- Method(s) ---
61  
62  	public void actionPerformed(ActionEvent event)
63  	{
64  		Object[] message = new Object[] {
65  			XNap.tr("Link")
66  		};
67  
68  		String link = JOptionPane.showInputDialog
69  			(XNapFrame.getInstance().getRootPane(), message,
70  			 XNap.tr("Download Link"), JOptionPane.PLAIN_MESSAGE);
71  		
72  		/* I switched to the easier implemenation because it handles annoying
73             url encoding for us, though it gives less feedback.  */
74  		if (link != null) {
75  			OvernetCore.send(new CommandMessage("dllink " + link));
76  		}
77  	}
78  
79  	public void stateChanged(StateEvent e)
80  	{
81  		setEnabledLater(core.getState() == State.CONNECTED);
82  	}
83  }