Author: jflesch
Date: 2007-04-15 15:46:58 +0000 (Sun, 15 Apr 2007)
New Revision: 12749
Modified:
trunk/apps/Thaw/src/thaw/fcp/FCPListPeers.java
trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
trunk/apps/Thaw/src/thaw/i18n/thaw.properties
trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java
trunk/apps/Thaw/src/thaw/plugins/peerMonitor/Peer.java
trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerHelper.java
trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java
Log:
Make possible to add and remove peers thanks to the PeerMonitor plugin
Modified: trunk/apps/Thaw/src/thaw/fcp/FCPListPeers.java
===================================================================
--- trunk/apps/Thaw/src/thaw/fcp/FCPListPeers.java 2007-04-15 15:04:53 UTC
(rev 12748)
+++ trunk/apps/Thaw/src/thaw/fcp/FCPListPeers.java 2007-04-15 15:46:58 UTC
(rev 12749)
@@ -15,8 +15,11 @@
private Hashtable peers; /* key : peer name -> hashtable : key :
parameter name -> parameter value */
+ private boolean endList;
public FCPListPeers(boolean withMetadata, boolean withVolatile) {
+ endList = true;
+
this.withMetadata = withMetadata;
this.withVolatile = withVolatile;
peers = new Hashtable();
@@ -24,6 +27,9 @@
public boolean start(FCPQueueManager queueManager) {
+ endList = false;
+ peers = new Hashtable();
+
FCPMessage msg = new FCPMessage();
msg.setMessageName("ListPeers");
@@ -45,18 +51,26 @@
if (o instanceof FCPQueryManager) {
final FCPMessage msg = (FCPMessage)param;
- if (msg.getMessageName() == null
- || !msg.getMessageName().equals("Peer"))
+ if (msg.getMessageName() == null)
return;
- peers.put(msg.getValue("identity"), msg.getValues());
+ if (msg.getMessageName().equals("Peer")) {
+ peers.put(msg.getValue("identity"),
msg.getValues());
+ }
- setChanged();
- notifyObservers(this);
+ if (msg.getMessageName().equals("EndListPeers")) {
+ endList = true;
+ setChanged();
+ notifyObservers(this);
+ }
}
}
+ public boolean hasEnded() {
+ return endList;
+ }
+
public Hashtable getPeers() {
return peers;
}
Modified: trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties 2007-04-15
15:04:53 UTC (rev 12748)
+++ trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties 2007-04-15
15:46:58 UTC (rev 12749)
@@ -361,8 +361,10 @@
thaw.plugin.peerMonitor.infos.nodeThreads=Threads (node)
thaw.plugin.peerMonitor.infos.thawThreads=Threads (Thaw)
+thaw.plugin.peerMonitor.invalidRef=Reference invalide. D?sol?.
+
thaw.plugin.themeSelector.themeSelector=S?lecteur de th?me
thaw.plugin.themeSelector.selectATheme=Selectionnez un th?me:
thaw.plugin.themeSelector.theme=Th?me
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-04-15 15:04:53 UTC
(rev 12748)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-04-15 15:46:58 UTC
(rev 12749)
@@ -78,7 +78,6 @@
thaw.common.autodetect=Auto-detect
-
## Errors
thaw.error.idAlreadyUsed=Unable to connect. Our Id is already used by another
client connected to the node.
@@ -354,6 +353,10 @@
thaw.plugin.peerMonitor.removePeer=Remove this peer
thaw.plugin.peerMonitor.enterRef=Reference:
+thaw.plugin.peerMonitor.invalidRef=Invalid reference, sorry.
+thaw.plugin.peerMonitor.confirmationForRemove=Are you sure that you want to
remove this peer ?
+
+
thaw.plugin.themeSelector.themeSelector=Theme selector
thaw.plugin.themeSelector.selectATheme=Select a theme:
thaw.plugin.themeSelector.theme=Theme
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2007-04-15 15:04:53 UTC
(rev 12748)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties 2007-04-15 15:46:58 UTC
(rev 12749)
@@ -361,8 +361,10 @@
thaw.plugin.peerMonitor.infos.nodeThreads=Threads (node)
thaw.plugin.peerMonitor.infos.thawThreads=Threads (Thaw)
+thaw.plugin.peerMonitor.invalidRef=Reference invalide. D\u00e9sol\u00e9.
+
thaw.plugin.themeSelector.themeSelector=S\u00e9lecteur de th\u00e8me
thaw.plugin.themeSelector.selectATheme=Selectionnez un th\u00e8me:
thaw.plugin.themeSelector.theme=Th\u00e8me
Modified: trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java 2007-04-15 15:04:53 UTC
(rev 12748)
+++ trunk/apps/Thaw/src/thaw/plugins/PeerMonitor.java 2007-04-15 15:46:58 UTC
(rev 12749)
@@ -55,7 +55,8 @@
listPeers.addObserver(this);
}
- listPeers.start(core.getQueueManager());
+ if (listPeers.hasEnded())
+ listPeers.start(core.getQueueManager());
try {
Thread.sleep(DEFAULT_REFRESH_RATE *
1000);
Modified: trunk/apps/Thaw/src/thaw/plugins/peerMonitor/Peer.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/peerMonitor/Peer.java 2007-04-15
15:04:53 UTC (rev 12748)
+++ trunk/apps/Thaw/src/thaw/plugins/peerMonitor/Peer.java 2007-04-15
15:46:58 UTC (rev 12749)
@@ -10,11 +10,14 @@
private String displayName = null;
private Color textColor = Color.BLACK;
+ private String identity = null;
+
private Hashtable parameters = null;
public Peer(Hashtable parameters) {
this.parameters = parameters;
displayName = (String)parameters.get("myName");
+ identity = (String)parameters.get("identity");
String status = (String)parameters.get("volatile.status");
@@ -24,18 +27,23 @@
}
}
+
public void setTextColor(Color c) {
textColor = c;
}
public Color getTextColor() {
return textColor;
- }
+ }
public Hashtable getParameters() {
return parameters;
- }
+ }
+ public String getIdentity() {
+ return identity;
+ }
+
public String toString() {
return displayName;
}
Modified: trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerHelper.java
2007-04-15 15:04:53 UTC (rev 12748)
+++ trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerHelper.java
2007-04-15 15:46:58 UTC (rev 12749)
@@ -7,7 +7,9 @@
import java.awt.BorderLayout;
import java.awt.GridLayout;
import javax.swing.JTextArea;
+import javax.swing.JTextField;
import javax.swing.JButton;
+import javax.swing.JOptionPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
@@ -35,6 +37,7 @@
private JButton okButton;
private JButton cancelButton;
private JTextArea refArea;
+ private JTextField urlField;
public PeerAdder(FCPQueueManager queueManager, MainWindow
mainWindow, AbstractButton actionSource) {
this.queueManager = queueManager;
@@ -54,8 +57,10 @@
dialog = new JDialog(mainWindow.getMainFrame(),
I18n.getMessage("thaw.plugin.peerMonitor.addPeer"));
- dialog.setLayout(new BorderLayout());
+ dialog.setLayout(new BorderLayout(5, 5));
+ JPanel centerPanel = new JPanel(new
BorderLayout());
+
JPanel buttonPanel = new JPanel(new
GridLayout(1, 2));
okButton = new
JButton(I18n.getMessage("thaw.common.ok"));
@@ -70,10 +75,25 @@
JLabel label = new
JLabel(I18n.getMessage("thaw.plugin.peerMonitor.enterRef"));
- dialog.getContentPane().add(label,
BorderLayout.NORTH);
- dialog.getContentPane().add(refArea,
BorderLayout.CENTER);
- dialog.getContentPane().add(buttonPanel,
BorderLayout.SOUTH);
+ centerPanel.add(label, BorderLayout.NORTH);
+ centerPanel.add(refArea, BorderLayout.CENTER);
+
+ JPanel southPanel = new JPanel(new
GridLayout(2, 1));
+
+ JPanel urlPanel = new JPanel(new
BorderLayout());
+ JLabel urlLabel = new JLabel("URL : ");
+ urlField = new JTextField("http://");
+
+ urlPanel.add(urlLabel, BorderLayout.WEST);
+ urlPanel.add(urlField, BorderLayout.CENTER);
+
+ southPanel.add(urlPanel);
+ southPanel.add(buttonPanel);
+
+ dialog.getContentPane().add(centerPanel,
BorderLayout.CENTER);
+ dialog.getContentPane().add(southPanel,
BorderLayout.SOUTH);
+
dialog.setSize(700, 300);
dialog.setVisible(true);
@@ -82,8 +102,24 @@
if (e.getSource() == okButton) {
- /* TODO */
- dialog.setVisible(false);
+ String ref;
+
+ ref = refArea.getText();
+
+ if (urlField.getText() != null
+ && !"http://".equals(urlField.getText())) {
+ ref = "URL="+urlField.getText();
+ }
+
+ ref = ref.trim();
+
+ if (looksValid(ref)) {
+ addPeer(queueManager, ref);
+ dialog.setVisible(false);
+ } else {
+ new thaw.gui.WarningWindow(null,
+
I18n.getMessage("thaw.plugin.peerMonitor.invalidRef"));
+ }
}
if (e.getSource() == cancelButton) {
@@ -93,10 +129,29 @@
}
+ public static boolean looksValid(String ref) {
+ if (ref.startsWith("URL=") || ref.endsWith("End"))
+ return true;
+
+ return false;
+ }
+
+
+ public static void addPeer(FCPQueueManager queueManager, String ref) {
+ FCPAddPeer addPeer = new FCPAddPeer(ref);
+ addPeer.start(queueManager);
+
+ /* see you later :) */
+ /* (ie when the next ListPeers will be done) */
+ }
+
+
public static class PeerRemover implements PeerAction {
private FCPQueueManager queueManager;
private AbstractButton src;
+ private Peer target;
+
public PeerRemover(FCPQueueManager queueManager, AbstractButton
actionSource) {
this.queueManager = queueManager;
this.src = actionSource;
@@ -109,12 +164,33 @@
if (src != null) {
src.setEnabled(peer != null);
}
+
+ target = peer;
}
public void actionPerformed(ActionEvent e) {
- /* TODO */
+ if (target == null)
+ return;
+
+ int ret = JOptionPane.showConfirmDialog(null,
+
I18n.getMessage("thaw.plugin.peerMonitor.confirmationForRemove"),
+
I18n.getMessage("thaw.warning.title"),
+
JOptionPane.YES_NO_OPTION,
+
JOptionPane.WARNING_MESSAGE);
+
+ if (ret != JOptionPane.YES_OPTION) {
+ return;
+ }
+
+ removePeer(queueManager, target.getIdentity());
}
}
+
+ public static void removePeer(FCPQueueManager queueManager, String
peer) {
+ FCPRemovePeer addPeer = new FCPRemovePeer(peer);
+ addPeer.start(queueManager);
+ }
+
}
Modified: trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java
2007-04-15 15:04:53 UTC (rev 12748)
+++ trunk/apps/Thaw/src/thaw/plugins/peerMonitor/PeerMonitorPanel.java
2007-04-15 15:46:58 UTC (rev 12749)
@@ -578,8 +578,10 @@
if(e.isPopupTrigger()) {
if (peerList.getSelectedValue() instanceof Peer) {
updateMenuState(((Peer)peerList.getSelectedValue()));
- rightClickMenu.show(e.getComponent(), e.getX(),
e.getY());
- }
+ } else
+ updateMenuState(null);
+
+ rightClickMenu.show(e.getComponent(), e.getX(),
e.getY());
}
}