Author: jflesch
Date: 2007-03-13 09:40:33 +0000 (Tue, 13 Mar 2007)
New Revision: 12106
Modified:
trunk/apps/Thaw/src/thaw/i18n/thaw.properties
trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java
Log:
PeerMonitor now displays details about peers
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-03-13 08:44:56 UTC
(rev 12105)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-03-13 09:40:33 UTC
(rev 12106)
@@ -310,7 +310,8 @@
thaw.plugin.peerMonitor.copyReference=Copy your reference to the clipboard
thaw.plugin.peerMonitor.nodeStats=Node statistics
thaw.plugin.peerMonitor.peerList=Peers:
+thaw.plugin.peerMonitor.nodeInfos=Node informations:
+thaw.plugin.peerMonitor.peerInfos=Informations relative to peer
-
thaw.zeroconf.searchingNode=Searching freenet nodes ...
thaw.zeroconf.nodeList=Nodes found:
Modified: trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java
2007-03-13 08:44:56 UTC (rev 12105)
+++ trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java
2007-03-13 09:40:33 UTC (rev 12106)
@@ -10,6 +10,9 @@
import javax.swing.ListCellRenderer;
import javax.swing.BorderFactory;
+import javax.swing.event.ListSelectionListener;
+import javax.swing.event.ListSelectionEvent;
+
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.BorderLayout;
@@ -25,7 +28,7 @@
import thaw.core.Config;
import thaw.core.I18n;
-public class PeerMonitorPanel implements ActionListener
+public class PeerMonitorPanel implements ActionListener, ListSelectionListener
{
/* must match with color list */
public final static String[] STR_STATUS = {
@@ -47,6 +50,13 @@
Color.PINK /* NEVER CONNECTED */
};
+ public final static Color JLIST_NODE_STAT_BACKGROUND = Color.WHITE;
+ public final static Color JLIST_PEER_BACKGROUND = new
Color(240,240,240);
+
+ public final static int STR_INFO_MAX_LNG = 40;
+ public final static int STR_NODENAME_MAX_LNG = 15;
+
+
private JPanel panel;
private JPanel mainPanel;
@@ -57,7 +67,10 @@
private JList peerList;
private JProgressBar memBar;
+ private JLabel detailsLabel;
+ private JPanel detailsPanel;
+
public PeerMonitorPanel(Config config) {
panel = new JPanel(new BorderLayout(10, 10));
@@ -67,6 +80,7 @@
peerList = new JList();
peerList.setCellRenderer(new PeerCellRenderer());
+ peerList.addListSelectionListener(this);
Vector v = new Vector();
v.add(I18n.getMessage("thaw.plugin.peerMonitor.nodeStats"));
@@ -91,14 +105,22 @@
refArea = new JTextArea("*Put the node ref here*");
refArea.setEditable(false);
- refArea.setBackground(new Color(250,250,250));
+ refArea.setBackground(new Color(240,240,240));
refPanel.add(refTitle, BorderLayout.NORTH);
- refPanel.add(refArea, BorderLayout.CENTER);
+ refPanel.add(new JScrollPane(refArea), BorderLayout.CENTER);
mainPanel.add(refPanel);
- mainPanel.add(new JLabel("*Put details about the peer here*"));
+ detailsLabel = new JLabel();
+ detailsPanel = new JPanel();
+
+ JPanel globalDetailsPanel = new JPanel(new BorderLayout(5, 5));
+ globalDetailsPanel.add(detailsLabel, BorderLayout.NORTH);
+ globalDetailsPanel.add(new JScrollPane(detailsPanel),
BorderLayout.CENTER);
+
+ mainPanel.add(globalDetailsPanel);
+
memBar = new JProgressBar(0, 100);
setMemBar(0, 134217728);
memBar.setStringPainted(true);
@@ -154,6 +176,10 @@
return textColor;
}
+ public Hashtable getParameters() {
+ return parameters;
+ }
+
public String toString() {
return displayName;
}
@@ -176,19 +202,21 @@
if (value instanceof String) {
setText((String)value);
setForeground(Color.BLACK);
+ setBackground(JLIST_NODE_STAT_BACKGROUND);
}
if (value instanceof Peer) {
setText(((Peer)value).toString());
setForeground(((Peer)value).getTextColor());
+ setBackground(JLIST_PEER_BACKGROUND);
}
// Set a border if the
//list item is selected
if (iss)
-
setBorder(BorderFactory.createLineBorder(Color.BLUE, 2));
+
setBorder(BorderFactory.createLineBorder(Color.BLACK, 1));
else
-
setBorder(BorderFactory.createLineBorder(list.getBackground(), 2));
+
setBorder(BorderFactory.createLineBorder(list.getBackground(), 1));
return this;
}
@@ -196,28 +224,36 @@
+ private Vector peers;
+ private Hashtable nodeInfos = null;
+
/**
* \param peers : Vectors containing Hashmap containing the parameter
list
*/
- public synchronized void setPeerList(Hashtable peers)
+ public synchronized void setPeerList(Hashtable pL)
{
- Vector results = new Vector();
+ peers = new Vector();
+ peers.add(I18n.getMessage("thaw.plugin.peerMonitor.nodeStats"));
+
/* TODO : dirty : should use comparator, etc */
for (int i = 0 ; i < STR_STATUS.length ; i++) {
- for (Enumeration e = peers.elements();
+ for (Enumeration e = pL.elements();
e.hasMoreElements();) {
Hashtable ht = (Hashtable)e.nextElement();
if
(STR_STATUS[i].equals(ht.get("volatile.status"))) {
- results.add(new Peer(ht));
+ peers.add(new Peer(ht));
}
}
}
- peerList.setListData(results);
+ peerList.setListData(peers);
}
+ public synchronized void setNodeInfos(Hashtable infos) {
+ nodeInfos = infos;
+ }
public JPanel getPanel() {
@@ -230,4 +266,49 @@
thaw.gui.GUIHelper.copyToClipboard(refArea.getText());
}
}
+
+
+ private static JLabel makeInfoLabel(String txt) {
+ if (txt.length() > STR_INFO_MAX_LNG)
+ txt = txt.substring(0, STR_INFO_MAX_LNG);
+
+ JLabel lb = new JLabel(txt);
+ return lb;
+ }
+
+
+ public void displayInfos(String title, Hashtable ht) {
+ if (ht == null)
+ return;
+
+ detailsPanel.removeAll();
+
+ detailsPanel.setLayout(new GridLayout(ht.size()+1, 2, 5, 5));
+
+ detailsLabel.setText(title);
+
+ for (Enumeration e = ht.keys();
+ e.hasMoreElements(); ) {
+ String key = (String)e.nextElement();
+
+ detailsPanel.add(makeInfoLabel(key + ":"));
+ detailsPanel.add(makeInfoLabel((String)ht.get(key)));
+ }
+
+ mainPanel.validate();
+ detailsPanel.validate();
+ }
+
+
+
+ public void valueChanged(ListSelectionEvent e) {
+ if (e.getFirstIndex() == 0) {
+
displayInfos(I18n.getMessage("thaw.plugin.peerMonitor.nodeInfos"), nodeInfos);
+ } else {
+ String peerName =
peers.get(e.getFirstIndex()).toString();
+
+
displayInfos(I18n.getMessage("thaw.plugin.peerMonitor.peerInfos") + " '" +
peerName + "':",
+
((Peer)peers.get(e.getFirstIndex())).getParameters());
+ }
+ }
}