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.limewire;
21  
22  import java.awt.event.MouseEvent;
23  
24  import javax.swing.SwingUtilities;
25  
26  import org.xnap.XNap;
27  import org.xnap.gui.StatusPanel;
28  import org.xnap.util.Formatter;
29  
30  import com.limegroup.gnutella.RouterService;
31  
32  public class LimeWireStatusPanel extends StatusPanel {
33  
34  	// --- Data Field(s) ---
35  
36  	/***
37  	 * Make sure the first updateStatus() call sets the properties.
38  	 */
39  	private boolean connected = RouterService.isConnected();
40  
41  	// --- Constructor(s) ---
42  
43  	public LimeWireStatusPanel() 
44  	{
45  		setName(LimeWirePlugin.getInstance().getInfo().getName());
46  
47  		updateStatus(connected);
48  	}
49  
50  	// --- Method(s) ---
51  
52  	public void updateStatus()
53  	{
54  		Runnable runner = new Runnable()
55  		{
56  			public void run() 
57  			{
58  				boolean newStatus = RouterService.isConnected();
59  				if (newStatus != connected) {
60  					connected = newStatus;
61  					updateStatus(connected);
62  				}
63  			}
64  		};
65  		SwingUtilities.invokeLater(runner);
66  	}
67  
68  	private void updateStatus(boolean connected)
69  	{
70  		setIcon((connected) ? ICON_OK : ICON_ERROR);
71  		setText((connected)
72  				? XNap.tr("{0} connected", "LimeWire")
73  				: XNap.tr("{0} not connected", "LimeWire"));
74  	}
75  
76  	/***
77  	 * @see javax.swing.JComponent#getToolTipText(MouseEvent)
78  	 */
79  	public String getToolTipText(MouseEvent event) {
80  		StringBuffer tooltip = new StringBuffer();
81  		tooltip.append("<html>");
82  		tooltip.append(RouterService.getNumFiles() + " Files, ");
83  		tooltip.append(RouterService.getNumHosts() + " Hosts, ");
84  		tooltip.append(RouterService.getNumSharedFiles() + " Files Shared (" 
85  				+ Formatter.formatSize(RouterService.getSharedFileSize()) 
86  				+ ")");
87  		if (RouterService.getNumPendingShared() > 0) {
88  			tooltip.append(", " + RouterService.getNumPendingShared() + " pending");
89  		}
90  		
91  		return tooltip.toString();
92  	}
93  
94  }