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.io.File;
23  
24  import javax.swing.Action;
25  
26  import org.apache.log4j.Logger;
27  import org.gudy.azureus2.core3.peer.PEPeer;
28  import org.xnap.XNap;
29  import org.xnap.peer.Peer;
30  import org.xnap.plugin.Plugin;
31  import org.xnap.transfer.AbstractTransfer;
32  import org.xnap.transfer.Download;
33  
34  /***
35   * Downloads a file.
36   */
37  public class AzureusPeerDownload extends AbstractTransfer implements Download {
38  
39      //--- Constant(s) ---
40      
41      //--- Data field(s) ---
42  
43      private static Logger logger = Logger.getLogger(AzureusPeerDownload.class);
44  
45  	private AzureusDownloadContainer parent;
46      private PEPeer peer;
47  
48      //--- Constructor(s) ---
49      
50      public AzureusPeerDownload(AzureusDownloadContainer parent, PEPeer peer) 
51      {
52      	this.parent = parent;
53  		this.peer = peer;
54      }
55  
56      //--- Method(s) ---
57  
58      public long getBytesTransferred() 
59      {
60  		return peer.getStats().getTotalReceived();
61      }
62  
63      public Action[] getActions()
64      {
65  		return null;
66      }
67  
68      public File getFile()
69      {
70  		return parent.getFile();
71      }
72  
73      public String getFilename()
74      {
75  		return parent.getFilename();
76      }
77  
78      public long getFilesize()
79      {
80  		return parent.getFilesize();
81      }
82  
83      public Peer getPeer()
84      {
85  		return null;
86      }
87  
88      public Plugin getPlugin()
89      {
90  		return AzureusPlugin.getInstance();
91      }
92  
93      public String getStatus()
94      {
95  		switch (peer.getState()) {
96  		case PEPeer.CONNECTING :
97  			return XNap.tr("Connecting");
98  		case PEPeer.DISCONNECTED :
99  			return XNap.tr("Disconnected");
100 		case PEPeer.HANDSHAKING :
101 			return XNap.tr("Handshaking");
102 		case PEPeer.TRANSFERING :
103 			return XNap.tr("Downloading");
104 		default:
105 			return XNap.tr("Unknown State {0}", peer.getState());
106 		} 
107     }
108 
109     public long getTotalBytesTransferred()
110     {
111 		return getBytesTransferred();
112     }
113 
114     public boolean isDone()
115     {
116 		int s = peer.getState();
117 		return s == PEPeer.DISCONNECTED;
118     }
119 
120     public boolean isRunning()
121     {
122 		int s = peer.getState();
123 		return s == PEPeer.TRANSFERING;
124     }
125 
126     //--- Inner Class(es) ---
127 
128 }