1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
45
46 private Action openTorrentFileAction = new OpenTorrentFileAction();
47 private JFileChooser fileChooser = new JFileChooser();
48 private AzureusTrackerTableModel trackerTableModel;
49
50
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
71 GridBagHelper.addComponent
72 (this, new XNapButton(openTorrentFileAction));
73 }
74
75
76
77 public Action[] getActions()
78 {
79 return new Action[] { openTorrentFileAction, };
80 }
81
82
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 }