Author: jflesch
Date: 2007-03-10 17:00:44 +0000 (Sat, 10 Mar 2007)
New Revision: 12087
Modified:
trunk/apps/Thaw/src/thaw/core/ConfigWindow.java
trunk/apps/Thaw/src/thaw/core/Core.java
trunk/apps/Thaw/src/thaw/core/MDNSDiscoveryPanel.java
trunk/apps/Thaw/src/thaw/core/NodeConfigPanel.java
trunk/apps/Thaw/src/thaw/i18n/thaw.properties
Log:
Fix ZeroConf dialog
Modified: trunk/apps/Thaw/src/thaw/core/ConfigWindow.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/ConfigWindow.java 2007-03-10 02:51:18 UTC
(rev 12086)
+++ trunk/apps/Thaw/src/thaw/core/ConfigWindow.java 2007-03-10 17:00:44 UTC
(rev 12087)
@@ -78,7 +78,7 @@
tabs.setSize(600, 360);
okButton.setSize(100, 40);
- configWin.setSize(600, 400);
+ configWin.setSize(600, 450);
configWin.setResizable(false);
okButton.addActionListener(this);
Modified: trunk/apps/Thaw/src/thaw/core/Core.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Core.java 2007-03-10 02:51:18 UTC (rev
12086)
+++ trunk/apps/Thaw/src/thaw/core/Core.java 2007-03-10 17:00:44 UTC (rev
12087)
@@ -143,7 +143,6 @@
if(!config.loadConfig()){
config.setDefaultValues();
- new MDNSDiscoveryPanel(config).run();
}
return true;
Modified: trunk/apps/Thaw/src/thaw/core/MDNSDiscoveryPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/MDNSDiscoveryPanel.java 2007-03-10
02:51:18 UTC (rev 12086)
+++ trunk/apps/Thaw/src/thaw/core/MDNSDiscoveryPanel.java 2007-03-10
17:00:44 UTC (rev 12087)
@@ -14,13 +14,16 @@
import javax.swing.DefaultListModel;
import java.awt.GridLayout;
import java.awt.BorderLayout;
+import javax.swing.JPanel;
import javax.swing.JFrame;
+import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
-import javax.swing.event.ListSelectionEvent;
-import javax.swing.event.ListSelectionListener;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+import javax.swing.JButton;
import thaw.core.Config;
import thaw.core.Logger;
@@ -42,16 +45,15 @@
* TODO: implement the "Manual" mode
* TODO: maybe we should have a small progressbar shown in a new popup to
introduce a "delay" at startup
*/
-public class MDNSDiscoveryPanel extends JFrame implements
ListSelectionListener {
+public class MDNSDiscoveryPanel extends JDialog implements ActionListener,
Runnable {
private static final long serialVersionUID = 1L;
private static final String FCP_SERVICE_TYPE = "_fcp._tcp.local.";
private boolean goon = true;
+ private boolean validated = false;
private ServiceInfo selectedValue;
- private final JScrollPane panel;
- private final JProgressBar progressBar;
private final JList list;
private final DefaultListModel listModel;
private final JLabel label;
@@ -60,7 +62,14 @@
private final HashMap foundNodes;
private final JmDNS jmdns;
- public MDNSDiscoveryPanel(Config conf) {
+ private JButton okButton;
+ private JButton cancelButton;
+
+
+ public MDNSDiscoveryPanel(java.awt.Dialog owner, Config conf) {
+ super(owner, "ZeroConf");
+
+
this.config = conf;
this.foundNodes = new HashMap();
try {
@@ -76,35 +85,41 @@
}
// The UI
- panel = new JScrollPane();
- progressBar = new JProgressBar(0, 30);
list = new JList();
listModel = new DefaultListModel();
label = new JLabel();
- listModel.addElement("Manual configuration (not recommended) :
NotYetImplemented ;)");
-
list.setModel(listModel);
list.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
- list.addListSelectionListener(this);
- label.setText("Select the freenet node you want to connect to
from the list below :");
+ label.setText(I18n.getMessage("thaw.zeroconf.searchingNode")
+ +" ; "+
+ I18n.getMessage("thaw.zeroconf.nodeList"));
- panel.setLayout(new BorderLayout());
- panel.add(label, BorderLayout.NORTH);
- panel.add(list, BorderLayout.CENTER);
- panel.add(progressBar, BorderLayout.SOUTH);
+ getContentPane().setLayout(new BorderLayout());
+ getContentPane().add(label, BorderLayout.NORTH);
+ getContentPane().add(new JScrollPane(list),
BorderLayout.CENTER);
- setContentPane(panel);
+ okButton = new JButton(I18n.getMessage("thaw.common.ok"));
+ cancelButton = new
JButton(I18n.getMessage("thaw.common.cancel"));
+ okButton.addActionListener(this);
+ cancelButton.addActionListener(this);
+
+ JPanel buttonPanel = new JPanel(new GridLayout(1, 2));
+ buttonPanel.add(okButton);
+ buttonPanel.add(cancelButton);
+
+ getContentPane().add(buttonPanel, BorderLayout.SOUTH);
+
+
pack();
super.setLocationRelativeTo(this.getParent());
- this.setTitle("ZeroConf discovery plugin... Please hold on");
-
this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+
this.setDefaultCloseOperation(javax.swing.WindowConstants.HIDE_ON_CLOSE);
this.setVisible(true);
- Logger.notice(this, "The configuration file doesn't seems to be
valid... MDNSDiscovery is starting!");
+ Logger.notice(this, "Starting MDNSDiscovery");
}
@@ -147,17 +162,18 @@
/**
* The user has selected something: notify the main loop and process
the data.
*/
- public void valueChanged(ListSelectionEvent e) {
- if (e.getValueIsAdjusting() == false) {
- if(list.getSelectedValue() == null) return; // Ignore
the user if he clicks nowhere
+ public void actionPerformed(ActionEvent e) {
+ synchronized (this) {
+ selectedValue = (ServiceInfo)
foundNodes.get(list.getSelectedValue());
+ goon = false;
- synchronized (this) {
- selectedValue = (ServiceInfo)
foundNodes.get(list.getSelectedValue());
- goon = false;
- notify();
- }
- Logger.debug(this, "User has selected :
"+foundNodes.get(list.getSelectedValue()));
+ validated = (e.getSource() == okButton);
+
+ notify();
}
+ Logger.debug(this, "User has selected :
"+foundNodes.get(list.getSelectedValue()));
+
+ setVisible(false);
}
/**
@@ -180,7 +196,9 @@
list.repaint();
}
- if(selectedValue == null) continue; // TODO: implement
the "manual" popup there
+ if(selectedValue == null
+ || !validated)
+ continue;
Logger.debug(this, "We got something from the UI :
let's try to connect");
@@ -217,7 +235,7 @@
* Convenient testing function function.
*/
public static void main(String[] args) {
- new MDNSDiscoveryPanel(new Config("/tmp/conf.ini")).run();
+ new MDNSDiscoveryPanel(null, new Config("/tmp/conf.ini")).run();
System.exit(0);
}
}
Modified: trunk/apps/Thaw/src/thaw/core/NodeConfigPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/NodeConfigPanel.java 2007-03-10 02:51:18 UTC
(rev 12086)
+++ trunk/apps/Thaw/src/thaw/core/NodeConfigPanel.java 2007-03-10 17:00:44 UTC
(rev 12087)
@@ -1,6 +1,7 @@
package thaw.core;
import java.awt.GridLayout;
+import java.awt.BorderLayout;
import java.util.Observable;
import java.util.Observer;
@@ -8,12 +9,13 @@
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
+import javax.swing.JButton;
/**
* NodeConfigPanel. Creates and manages the panel containing all the things to
configure
* the settings to access the node.
*/
-public class NodeConfigPanel implements Observer {
+public class NodeConfigPanel implements Observer,
java.awt.event.ActionListener {
private Core core;
private JPanel nodeConfigPanel = null;
@@ -36,6 +38,8 @@
"thawId"
};
+ private JButton autodetect;
+
/**
* a check is done on the first value, be warned
*/
@@ -50,6 +54,7 @@
private JCheckBox multipleSockets = null;
private JCheckBox sameComputer = null; /* if thaw and the node are on
the same computer */
+
public NodeConfigPanel(final ConfigWindow configWindow, final Core
core) {
this.core = core;
this.configWindow = configWindow;
@@ -72,8 +77,21 @@
NodeConfigPanel.currentValues[i] = value;
nodeConfigPanel.add(paramLabels[i]);
- nodeConfigPanel.add(paramFields[i]);
+ if (i != 0) {
+ nodeConfigPanel.add(paramFields[i]);
+ } else {
+ /* autodetection button ! :) */
+ autodetect = new
JButton(I18n.getMessage("thaw.common.autodetect"));
+ autodetect.addActionListener(this);
+
+ JPanel sub = new JPanel(new BorderLayout());
+ sub.add(paramFields[i], BorderLayout.CENTER);
+ sub.add(autodetect, BorderLayout.EAST);
+
+ nodeConfigPanel.add(sub);
+ }
+
if (i == 0) { /* just after the node address */
nodeConfigPanel.add(sameComputer);
nodeConfigPanel.add(new JLabel(""));
@@ -152,17 +170,42 @@
if(arg == core.getConfigWindow().getCancelButton()) {
- for(int i=0;i < NodeConfigPanel.paramNames.length;i++) {
- String value;
+ resetValues();
+ }
+ }
- if( (value =
core.getConfig().getValue(NodeConfigPanel.configNames[i])) == null)
- value = "";
- paramFields[i].setText(value);
- }
+ public void resetValues() {
+ for(int i=0;i < NodeConfigPanel.paramNames.length;i++) {
+ String value;
-
multipleSockets.setSelected(Boolean.valueOf(core.getConfig().getValue("multipleSockets")).booleanValue());
+ if( (value =
core.getConfig().getValue(NodeConfigPanel.configNames[i])) == null)
+ value = "";
+
+ paramFields[i].setText(value);
}
+
+
multipleSockets.setSelected(Boolean.valueOf(core.getConfig().getValue("multipleSockets")).booleanValue());
}
+
+
+ protected class MDNSDiscovery implements Runnable {
+ public MDNSDiscovery() { }
+
+ public void run() {
+ (new
MDNSDiscoveryPanel(core.getConfigWindow().getFrame(), core.getConfig())).run();
+ resetValues();
+ }
+ }
+
+
+
+ public void actionPerformed(java.awt.event.ActionEvent event) {
+ if (event.getSource() == autodetect) {
+ Thread th = new Thread(new
NodeConfigPanel.MDNSDiscovery());
+ th.start();
+ }
+ }
+
}
Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-03-10 02:51:18 UTC
(rev 12086)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties 2007-03-10 17:00:44 UTC
(rev 12087)
@@ -72,6 +72,10 @@
thaw.common.paste=Paste
+
+thaw.common.autodetect=Auto-detect
+
+
## Errors
thaw.error.idAlreadyUsed=Unable to connect. Our Id is already used by another
client connected to the node.
@@ -302,3 +306,7 @@
thaw.plugin.peerMonitor.peerMonitor=Peer management
+
+
+thaw.zeroconf.searchingNode=Searching freenet nodes ...
+thaw.zeroconf.nodeList=Nodes found: