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.azureus;
21  
22  import java.awt.BorderLayout;
23  import java.awt.GridBagLayout;
24  import java.awt.event.ActionEvent;
25  import java.io.File;
26  
27  import javax.swing.AbstractAction;
28  import javax.swing.Action;
29  import javax.swing.JFileChooser;
30  import javax.swing.JPanel;
31  import javax.swing.JScrollPane;
32  import javax.swing.JTable;
33  
34  import org.gudy.azureus2.core3.tracker.host.TRHostFactory;
35  import org.xnap.XNap;
36  import org.xnap.gui.ActionProvider;
37  import org.xnap.gui.component.XNapButton;
38  import org.xnap.gui.util.GUIHelper;
39  import org.xnap.gui.util.GridBagHelper;
40  import org.xnap.gui.util.IconHelper;
41  
42  public class AzureusTorrentPanel extends JPanel implements ActionProvider {
43  
44      // --- Data Field(s) ---
45  
46  	private Action openTorrentFileAction = new OpenTorrentFileAction();
47  	private JFileChooser fileChooser = new JFileChooser();
48  	private AzureusTrackerTableModel trackerTableModel;
49  
50      // --- Constructor(s) ---
51  
52      public AzureusTorrentPanel() 
53      {
54          setLayout(new GridBagLayout());
55          
56  		JPanel trackerPanel = new JPanel(new BorderLayout());
57  		trackerPanel.setBorder
58  			(GUIHelper.createDefaultBorder(XNap.tr("Tracker")));
59  		GridBagHelper.addPanel(this, trackerPanel);
60  
61  		trackerTableModel = new AzureusTrackerTableModel();
62  		JTable trackerTable = trackerTableModel.createTable
63  			(AzureusPlugin.getPreferences(), "connection");
64  		trackerPanel.add(new JScrollPane(trackerTable), BorderLayout.CENTER);
65  
66  		TRHostFactory.create().addListener(trackerTableModel);
67  
68  		GridBagHelper.addVerticalSpacer(this);
69  
70  		// buttons
71  		GridBagHelper.addComponent
72  			(this, new XNapButton(openTorrentFileAction));
73      }
74  
75      // --- Method(s) ---
76  
77      public Action[] getActions()
78      {
79  		return new Action[] { openTorrentFileAction, };
80      }
81  
82      // --- Inner Class(es) ---
83  
84      /***
85       * Connects to a servant.
86       */
87      private class OpenTorrentFileAction extends AbstractAction {
88  
89          public OpenTorrentFileAction() 
90  		{
91              putValue(Action.NAME, XNap.tr("Open Torrent File"));
92              putValue(IconHelper.XNAP_ICON, "fileopen.png");
93              putValue(Action.SHORT_DESCRIPTION, 
94  					 XNap.tr("Downloads a torrent from a file."));
95          }
96  
97          public void actionPerformed(ActionEvent event) 
98  		{
99  			if (fileChooser.showOpenDialog(AzureusTorrentPanel.this)
100 				== JFileChooser.APPROVE_OPTION) {
101 
102 				File file = fileChooser.getSelectedFile();
103 				AzureusPlugin.getGlobalManager().addDownloadManager
104 					(file.getAbsolutePath(),
105 					org.xnap.util.Preferences.getInstance().getIncompleteDir());
106 			}
107         }
108 
109     } 
110 
111 }