Author: jflesch
Date: 2007-04-11 16:02:07 +0000 (Wed, 11 Apr 2007)
New Revision: 12577

Added:
   trunk/apps/Thaw/src/thaw/core/MDNSDiscovery.java
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/plugins/index/IndexConfigPanel.java
Log:
Move MDNSDiscovery out of the Core

Modified: trunk/apps/Thaw/src/thaw/core/ConfigWindow.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/ConfigWindow.java     2007-04-11 13:51:02 UTC 
(rev 12576)
+++ trunk/apps/Thaw/src/thaw/core/ConfigWindow.java     2007-04-11 16:02:07 UTC 
(rev 12577)
@@ -31,9 +31,9 @@
        private JButton okButton;
        private JButton cancelButton;

-       protected ThawConfigPanel thawConfigPanel;
-       protected NodeConfigPanel nodeConfigPanel;
-       protected PluginConfigPanel pluginConfigPanel;
+       private ThawConfigPanel thawConfigPanel;
+       private NodeConfigPanel nodeConfigPanel;
+       private PluginConfigPanel pluginConfigPanel;

        private Core core;

@@ -41,6 +41,7 @@

        private boolean needConnectionReset = false;

+
        public ConfigWindow(final Core core) {
                this.core = core;
                needConnectionReset = false;
@@ -113,6 +114,10 @@
                }

                configWin.setVisible(v);
+
+               if (v == false) {
+                       configWin.dispose();
+               }
        }

        public boolean addTab(final String name, final java.awt.Component 
panel) {
@@ -138,6 +143,13 @@
        }

        /**
+        * Used to update the MDNSPanel
+        */
+       public NodeConfigPanel getNodeConfigPanel() {
+               return nodeConfigPanel;
+       }
+
+       /**
         * Get a ref to validation button.
         */
        public JButton getOkButton() {

Modified: trunk/apps/Thaw/src/thaw/core/Core.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/Core.java     2007-04-11 13:51:02 UTC (rev 
12576)
+++ trunk/apps/Thaw/src/thaw/core/Core.java     2007-04-11 16:02:07 UTC (rev 
12577)
@@ -5,10 +5,6 @@
 import java.util.Observable;
 import java.util.Observer;

-import javax.jmdns.JmDNS;
-import javax.jmdns.ServiceEvent;
-import javax.jmdns.ServiceInfo;
-import javax.jmdns.ServiceListener;
 import javax.swing.JDialog;
 import javax.swing.JFrame;
 import javax.swing.JOptionPane;
@@ -49,42 +45,8 @@
        private ReconnectionManager reconnectionManager = null;

        // MDNS stuffs
-       private final JmDNS jmdns;
-       // SYNC IT!!!
-       protected final LinkedList foundNodes;
+       private MDNSDiscovery discovery;

-       private class FCPMDNSListener implements ServiceListener {
-               public void serviceAdded(ServiceEvent event) {
-                       Logger.notice(this, "Service added   : " + 
event.getName()+"."+event.getType());
-                       // Force the gathering of informations
-                       
jmdns.getServiceInfo(MDNSDiscoveryPanel.FCP_SERVICE_TYPE, event.getName());
-               }
-
-               public void serviceRemoved(ServiceEvent event) {
-                       Logger.notice(this, "Service removed : " + 
event.getName()+"."+event.getType());
-                       ServiceInfo service = event.getInfo();
-
-                       synchronized (foundNodes) {
-                               foundNodes.remove(service);
-                               synchronized 
(configWindow.nodeConfigPanel.mdnsPanel) {
-                                       
configWindow.nodeConfigPanel.mdnsPanel.notifyAll();
-                               }
-                       }
-               }
-
-               public void serviceResolved(ServiceEvent event) {
-                       Logger.debug(this, "Service resolved: " + 
event.getInfo());
-                       ServiceInfo service = event.getInfo();
-
-                       synchronized (foundNodes) {
-                               foundNodes.add(service);
-                               synchronized 
(configWindow.nodeConfigPanel.mdnsPanel) {
-                                       
configWindow.nodeConfigPanel.mdnsPanel.notifyAll();
-                               }
-                       }
-               }
-       }
-
        /**
         * Creates a core, but do nothing else (no initialization).
         */
@@ -92,29 +54,8 @@
                Logger.info(this, "Thaw, version "+Main.VERSION, true);
                Logger.info(this, "2006(c) Freenet project", true);
                Logger.info(this, "Released under GPL license version 2 or 
later (see http://www.fsf.org/licensing/licenses/gpl.html)", true);
-
-               this.foundNodes = new LinkedList();
-               try {
-                       // Spawn the mdns listener
-                       Logger.info(this, "Starting JMDNS ...");
-                       this.jmdns = new JmDNS();
-
-                       // Start listening for new nodes
-                       
jmdns.addServiceListener(MDNSDiscoveryPanel.FCP_SERVICE_TYPE, new 
FCPMDNSListener());
-
-               } catch (Exception e) {
-                       e.printStackTrace();
-                       throw new RuntimeException("Error loading 
MDNSDiscoveryPanel : " + e.getMessage());
-               }
        }

-       protected boolean isHasTheSameIPAddress(ServiceInfo host) {
-               try{
-                       return (jmdns.getInterface().equals(host.getAddress()) 
? true : false);
-               } catch (IOException e) {
-                       return false;
-               }
-       }

        /**
         * Gives a ref to the object containing the config.
@@ -172,20 +113,24 @@
                if (!initializeLookAndFeel())
                        return false;

-               splashScreen.setProgressionAndStatus(20, "Connecting ...");
+               splashScreen.setProgressionAndStatus(20, "Starting node 
autodection ...");
                splashScreen.addIcon(IconBox.connectAction);
+               if (!initMDNS())
+                       return false;
+
+               splashScreen.setProgressionAndStatus(25, "Connecting ...");
                if(!initConnection())
                        new thaw.gui.WarningWindow(this, 
I18n.getMessage("thaw.warning.unableToConnectTo")+
                                                   " "+ 
config.getValue("nodeAddress")+
                                                   ":"+ 
config.getValue("nodePort"));


-               splashScreen.setProgressionAndStatus(30, "Preparing the main 
window ...");
+               splashScreen.setProgressionAndStatus(40, "Preparing the main 
window ...");
                splashScreen.addIcon(IconBox.mainWindow);
                if(!initGraphics())
                        return false;

-               splashScreen.setProgressionAndStatus(40, "Loading plugins ...");
+               splashScreen.setProgressionAndStatus(50, "Loading plugins ...");
                if(!initPluginManager())
                        return false;

@@ -203,7 +148,18 @@
        }


+       public boolean initMDNS() {
+               discovery = new MDNSDiscovery(this);

+               return true;
+       }
+
+
+       public MDNSDiscovery getMDNSDiscovery() {
+               return discovery;
+       }
+
+
        /**
         * Init configuration. May re-set I18n.
         */
@@ -515,9 +471,9 @@
                                        return;
                        }
                }
-               Logger.info(this, "Stopping JMDNS ...");
-               jmdns.close();

+               discovery.stop();
+
                Logger.info(this, "Stopping scheduler ...");
                if(queueManager != null)
                    queueManager.stopScheduler();

Added: trunk/apps/Thaw/src/thaw/core/MDNSDiscovery.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/MDNSDiscovery.java                            
(rev 0)
+++ trunk/apps/Thaw/src/thaw/core/MDNSDiscovery.java    2007-04-11 16:02:07 UTC 
(rev 12577)
@@ -0,0 +1,90 @@
+/* This code is part of Freenet. It is distributed under the GNU General
+ * Public License, version 2 (or at your option any later version). See
+ * http://www.gnu.org/ for further details of the GPL. */
+
+package thaw.core;
+
+
+import java.util.LinkedList;
+
+import javax.jmdns.JmDNS;
+import javax.jmdns.ServiceEvent;
+import javax.jmdns.ServiceInfo;
+import javax.jmdns.ServiceListener;
+
+
+public class MDNSDiscovery {
+       // SYNC IT!!!
+       private final LinkedList foundNodes;
+       private final JmDNS jmdns;
+       private Core core;
+
+       public MDNSDiscovery(Core core) {
+               this.core = core;
+               this.foundNodes = new LinkedList();
+
+               try {
+                       // Spawn the mdns listener
+                       Logger.info(this, "Starting JMDNS ...");
+                       this.jmdns = new JmDNS();
+
+                       // Start listening for new nodes
+                       
jmdns.addServiceListener(MDNSDiscoveryPanel.FCP_SERVICE_TYPE, new 
FCPMDNSListener());
+
+               } catch (Exception e) {
+                       e.printStackTrace();
+                       throw new RuntimeException("Error loading 
MDNSDiscoveryPanel : " + e.getMessage());
+               }
+       }
+
+
+       private class FCPMDNSListener implements ServiceListener {
+               public void serviceAdded(ServiceEvent event) {
+                       Logger.notice(this, "Service added   : " + 
event.getName()+"."+event.getType());
+                       // Force the gathering of informations
+                       
jmdns.getServiceInfo(MDNSDiscoveryPanel.FCP_SERVICE_TYPE, event.getName());
+               }
+
+               public void serviceRemoved(ServiceEvent event) {
+                       Logger.notice(this, "Service removed : " + 
event.getName()+"."+event.getType());
+                       ServiceInfo service = event.getInfo();
+
+                       synchronized (foundNodes) {
+                               foundNodes.remove(service);
+                               synchronized 
(core.getConfigWindow().getNodeConfigPanel().getMdnsPanel()) {
+                                       
core.getConfigWindow().getNodeConfigPanel().getMdnsPanel().notifyAll();
+                               }
+                       }
+               }
+
+               public void serviceResolved(ServiceEvent event) {
+                       Logger.debug(this, "Service resolved: " + 
event.getInfo());
+                       ServiceInfo service = event.getInfo();
+
+                       synchronized (foundNodes) {
+                               foundNodes.add(service);
+                               synchronized 
(core.getConfigWindow().getNodeConfigPanel().getMdnsPanel()) {
+                                       
core.getConfigWindow().getNodeConfigPanel().getMdnsPanel().notifyAll();
+                               }
+                       }
+               }
+       }
+
+
+       public boolean isHasTheSameIPAddress(ServiceInfo host) {
+               try{
+                       return (jmdns.getInterface().equals(host.getAddress()) 
? true : false);
+               } catch (java.io.IOException e) {
+                       return false;
+               }
+       }
+
+       public LinkedList getFoundNodes() {
+               return foundNodes;
+       }
+
+       public void stop() {
+               Logger.info(this, "Stopping JMDNS ...");
+               jmdns.close();
+       }
+}

Modified: trunk/apps/Thaw/src/thaw/core/MDNSDiscoveryPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/MDNSDiscoveryPanel.java       2007-04-11 
13:51:02 UTC (rev 12576)
+++ trunk/apps/Thaw/src/thaw/core/MDNSDiscoveryPanel.java       2007-04-11 
16:02:07 UTC (rev 12577)
@@ -109,14 +109,13 @@
        }


-       

        /**
         * The user has selected something: notify the main loop and process 
the data.
         */
        public void actionPerformed(ActionEvent e) {
                Object source = e.getSource();
-               
+
                if ((source == okButton) || (source == cancelButton)){
                        goon = false;
                        if(source == okButton) {
@@ -124,7 +123,7 @@
                                selectedValue = (ServiceInfo) 
displayedServiceInfos.get(list.getSelectedValue());
                        } else
                                cancelledByUser = true;
-                       
+
                        synchronized (this) {
                                notifyAll();
                        }
@@ -140,28 +139,28 @@
                super.setLocationRelativeTo(this.getParent());
                this.setVisible(true);
                owner.setEnabled(false);
-               
+
                Logger.notice(this, "Show the MDNSDiscoveryPanel");
                Socket testSocket = null;
                boolean isConfigValid = false;
                goon = true;
-               
+
                do {
                        // Loop until a selection is done
                        while(goon) {
-                               synchronized (core.foundNodes) {
-                                       if(core.foundNodes.size() > 0) {
+                               synchronized 
(core.getMDNSDiscovery().getFoundNodes()) {
+                                       
if(core.getMDNSDiscovery().getFoundNodes().size() > 0) {
                                                listModel.clear();
-                                               Iterator it = 
core.foundNodes.iterator();
+                                               Iterator it = 
core.getMDNSDiscovery().getFoundNodes().iterator();
                                                while(it.hasNext()) {
                                                        ServiceInfo current = 
(ServiceInfo) it.next();
                                                        
listModel.addElement(current.getName());
                                                        
displayedServiceInfos.put(current.getName(), current);
                                                }
                                                list.repaint();
-                                       }       
+                                       }
                                }
-                                                               
+
                                try {
                                        synchronized (this) {
                                                wait(Integer.MAX_VALUE);
@@ -185,12 +184,12 @@
                        } catch (IOException e) {
                                isConfigValid = false;
                        }
-                       
+
                        Logger.debug(this, "isConfigValid ="+isConfigValid);

                        // Reload, just in  case it failed...
                        goon = true;
-                       list.removeSelectionInterval(0, core.foundNodes.size());
+                       list.removeSelectionInterval(0, 
core.getMDNSDiscovery().getFoundNodes().size());
                } while(!isConfigValid);


@@ -202,7 +201,7 @@
                        // Save the config. now that we know it's valid
                        core.getConfig().setValue("nodeAddress", 
selectedValue.getHostAddress());
                        core.getConfig().setValue("nodePort", new 
Integer(selectedValue.getPort()).toString());
-                       core.getConfig().setValue("sameComputer", 
String.valueOf(core.isHasTheSameIPAddress(selectedValue)));
+                       core.getConfig().setValue("sameComputer", 
String.valueOf(core.getMDNSDiscovery().isHasTheSameIPAddress(selectedValue)));


                        Logger.info(this, "We are done : configuration has been 
saved sucessfully.");
@@ -212,4 +211,6 @@
                cb.onMDNSDiscoverPanelClosure(cancelledByUser);
                Logger.notice(this, "We got back from the MDNSDiscoveryPanel 
callback");
        }
+
+
 }

Modified: trunk/apps/Thaw/src/thaw/core/NodeConfigPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/NodeConfigPanel.java  2007-04-11 13:51:02 UTC 
(rev 12576)
+++ trunk/apps/Thaw/src/thaw/core/NodeConfigPanel.java  2007-04-11 16:02:07 UTC 
(rev 12577)
@@ -20,7 +20,7 @@
 public class NodeConfigPanel implements Observer, 
java.awt.event.ActionListener, MDNSDiscoveryPanelCallback {
        private Core core;
        private JPanel nodeConfigPanel = null;
-       protected final MDNSDiscoveryPanel mdnsPanel;
+       private final MDNSDiscoveryPanel mdnsPanel;
        private boolean isMDNSPanerShown = false;


@@ -119,6 +119,10 @@
                return nodeConfigPanel;
        }

+       public MDNSDiscoveryPanel getMdnsPanel() {
+               return mdnsPanel;
+       }
+
        private void setVisibility(final boolean advancedMode) {
                for(int i= 2; i < NodeConfigPanel.paramNames.length;i++) {
                        paramLabels[i].setVisible(advancedMode);

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigPanel.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigPanel.java        
2007-04-11 13:51:02 UTC (rev 12576)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexConfigPanel.java        
2007-04-11 16:02:07 UTC (rev 12577)
@@ -162,8 +162,8 @@
                }

                if (e.getSource() == editBlackList) {
+                       indexBrowser.getBlackList().displayPanel();
                        configWindow.close();
-                       indexBrowser.getBlackList().displayPanel();
                }
        }



Reply via email to