LimeWirePanel.java
| Index Score | ||
|---|---|---|
![]() |
![]() |
org.xnap.plugin.limewire |
![]() |
![]() |
XNap 3 |
View: Reasons, Metrics, Source Code
These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.
/*
* XNap - A P2P framework and client.
*
* See the file AUTHORS for copyright information.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.xnap.plugin.limewire;
import java.awt.BorderLayout;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import org.xnap.XNap;
import org.xnap.gui.ActionProvider;
import org.xnap.gui.component.ValidatedTextField;
import org.xnap.gui.component.XNapButton;
import org.xnap.gui.util.GUIHelper;
import org.xnap.gui.util.GridBagHelper;
import org.xnap.gui.util.IconHelper;
import org.xnap.util.Formatter;
import org.xnap.util.StringHelper;
import com.limegroup.gnutella.RouterService;
public class LimeWirePanel extends JPanel implements ActionProvider {
// --- Data Field(s) ---
private LimeWireConnectionTableModel tmConnections;
private JTable jtConnections;
private JLabel jlStatus;
private JTextField jtfHost;
private ValidatedTextField vtfPort;
private Action acConnect = new ConnectAction();
private Action acDisconnect = new DisconnectAction();
// --- Constructor(s) ---
public LimeWirePanel()
{
setLayout(new GridBagLayout());
// status
JPanel jpStatus = new JPanel(new GridBagLayout());
jpStatus.setBorder(GUIHelper.createDefaultBorder(XNap.tr("Status")));
GridBagHelper.add(this, jpStatus);
jlStatus = new JLabel();
GridBagHelper.add(jpStatus, jlStatus);
GridBagHelper.addComponent
(jpStatus, new XNapButton(new UpdateAction()));
// connections
JPanel jpConnections = new JPanel(new BorderLayout());
jpConnections.setBorder
(GUIHelper.createDefaultBorder(XNap.tr("Connections")));
GridBagHelper.addPanel(this, jpConnections);
tmConnections = new LimeWireConnectionTableModel();
jtConnections = tmConnections.createTable
(LimeWirePlugin.getPreferences(), "connection");
jpConnections.add(new JScrollPane(jtConnections), BorderLayout.CENTER);
// add servant Panel
JPanel jpConnect = new JPanel(new GridBagLayout());
GridBagHelper.add(this, jpConnect);
Action acAdd = new AddServantAction();
GridBagHelper.addLabel(jpConnect, XNap.tr("Host"));
jtfHost = new JTextField("localhost", 15);
GUIHelper.bindEnterKey(jtfHost, acAdd);
GridBagHelper.addComponent(jpConnect, jtfHost);
GridBagHelper.addLabel(jpConnect, XNap.tr("Port"));
vtfPort = new ValidatedTextField("6346", 5, StringHelper.NUMBERS_INT);
GUIHelper.bindEnterKey(vtfPort, acAdd);
GridBagHelper.addComponent(jpConnect, vtfPort);
GridBagHelper.addLabel(jpConnect, "");
JButton jbAdd = new XNapButton(acAdd);
GridBagHelper.addComponent(jpConnect, jbAdd);
// button
GridBagHelper.addComponent(this, new XNapButton(acConnect));
GridBagHelper.addComponent(this, new XNapButton(acDisconnect));
GridBagHelper.addVerticalSpacer(this);
// initialize
updateStatus();
}
// --- Method(s) ---
/**
* Called by {@link LimeWirePlugin} when a connection to the network
* is established or lost. Updates the actions.
*/
public void setConnected(boolean connected)
{
acConnect.setEnabled(!connected);
acDisconnect.setEnabled(connected);
tmConnections.setConnected(connected);
}
public Action[] getActions()
{
return new Action[] { acConnect, acDisconnect, };
}
public LimeWireConnectionTableModel getTableModel()
{
return tmConnections;
}
public void updateStatus()
{
StringBuffer sb = new StringBuffer();
sb.append("<html>");
sb.append("Listening on port " + RouterService.getPort() + ", ");
sb.append(RouterService.getNumFiles() + " Files, ");
sb.append(RouterService.getNumHosts() + " Hosts, ");
sb.append(RouterService.getNumSharedFiles() + " Files Shared ("
+ Formatter.formatSize(RouterService.getSharedFileSize())
+ ")");
if (RouterService.getNumPendingShared() > 0) {
sb.append(", " + RouterService.getNumPendingShared() + " pending");
}
jlStatus.setText(sb.toString());
}
// --- Inner Class(es) ---
/**
* Connects to a servant.
*/
private class AddServantAction extends AbstractAction {
public AddServantAction()
{
putValue(Action.NAME, XNap.tr("Add Servant"));
putValue(Action.SHORT_DESCRIPTION,
XNap.tr("Connects to host:port."));
}
public void actionPerformed(ActionEvent event)
{
String host = jtfHost.getText();
int port = vtfPort.getIntValue();
RouterService.connectToHostAsynchronously(host, port);
}
}
/**
* Connects to the network.
*/
private class ConnectAction extends AbstractAction
{
public ConnectAction()
{
putValue(Action.NAME, XNap.tr("Connect"));
putValue(Action.SHORT_DESCRIPTION,
XNap.tr("Connects to the gnutella network."));
putValue(IconHelper.XNAP_ICON, "connect_creating.png");
}
public void actionPerformed(ActionEvent event)
{
LimeWirePlugin.getInstance().connect();
}
}
/**
* Disconnects from the network.
*/
private class DisconnectAction extends AbstractAction
{
public DisconnectAction()
{
putValue(Action.NAME, XNap.tr("Disconnect"));
putValue(Action.SHORT_DESCRIPTION,
XNap.tr("Disconnects from the gnutella network."));
putValue(IconHelper.XNAP_ICON, "connect_no.png");
}
public void actionPerformed(ActionEvent event)
{
LimeWirePlugin.getInstance().disconnect();
}
}
public class UpdateAction extends AbstractAction
{
public UpdateAction()
{
putValue(Action.NAME, XNap.tr("Update"));
putValue(Action.SHORT_DESCRIPTION,
XNap.tr("Updates status."));
putValue(IconHelper.XNAP_ICON, "reload.png");
}
public void actionPerformed(ActionEvent event)
{
updateStatus();
}
}
}
The table below shows all metrics for LimeWirePanel.java.




