Author: jflesch
Date: 2007-09-13 08:53:58 +0000 (Thu, 13 Sep 2007)
New Revision: 15133

Added:
   trunk/apps/Thaw/src/thaw/plugins/MDNS/
   trunk/apps/Thaw/src/thaw/plugins/MDNS/MDNSDiscovery.java
   trunk/apps/Thaw/src/thaw/plugins/MDNS/MDNSDiscoveryPanel.java
Modified:
   trunk/apps/Thaw/src/thaw/plugins/index/FileList.java
   trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java
   trunk/apps/Thaw/src/thaw/plugins/index/Index.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexContainer.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
   trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java
   trunk/apps/Thaw/src/thaw/plugins/index/LinkList.java
   trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java
   trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java
   trunk/apps/Thaw/src/thaw/plugins/index/UnknownIndexList.java
   trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/Node.java
Log:
Index browser : Improve the performances with large indexes

Copied: trunk/apps/Thaw/src/thaw/plugins/MDNS/MDNSDiscovery.java (from rev 
14001, trunk/apps/Thaw/src/thaw/core/MDNSDiscovery.java)
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/MDNS/MDNSDiscovery.java                    
        (rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/MDNS/MDNSDiscovery.java    2007-09-13 
08:53:58 UTC (rev 15133)
@@ -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();
+       }
+}

Copied: trunk/apps/Thaw/src/thaw/plugins/MDNS/MDNSDiscoveryPanel.java (from rev 
14001, trunk/apps/Thaw/src/thaw/core/MDNSDiscoveryPanel.java)
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/MDNS/MDNSDiscoveryPanel.java               
                (rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/MDNS/MDNSDiscoveryPanel.java       
2007-09-13 08:53:58 UTC (rev 15133)
@@ -0,0 +1,216 @@
+/* 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 javax.jmdns.ServiceInfo;
+import javax.swing.DefaultListModel;
+
+import java.awt.Dialog;
+import java.awt.GridLayout;
+import java.awt.BorderLayout;
+import javax.swing.JPanel;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JScrollPane;
+import java.awt.event.ActionListener;
+import java.awt.event.ActionEvent;
+import java.io.IOException;
+import java.net.Socket;
+import java.util.HashMap;
+import java.util.Iterator;
+
+import javax.swing.JButton;
+
+import thaw.core.Logger;
+
+/**
+ * This panel implements Zeroconf (called Bonjour/RendezVous by apple) 
discovery for Thaw
+ *
+ * WARNING: for it to work, you must have a running freenet node on the same 
network subnet, using the MDNSDiscovery panel
+ *
+ * @author Florent Daignière <nextgens at freenetproject.org>
+ *
+ * @see http://wiki.freenetproject.org/MDNSDiscoverypanel
+ *
+ * @see http://www.dns-sd.org/ServiceTypes.html
+ * @see http://www.multicastdns.org/
+ * @see http://jmdns.sourceforge.net/
+ *
+ * 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 JDialog implements ActionListener, 
Runnable {
+       public interface MDNSDiscoveryPanelCallback {
+               /**
+                * Called upon exit from MDNSDiscoveryPanelCallback
+                * It runs on its own thread but still, don't abuse it :)
+                */
+               public void onMDNSDiscoverPanelClosure(boolean 
hasBeenCancelled);
+       }
+       private static final long serialVersionUID = 1L;
+
+       public static final String FCP_SERVICE_TYPE = "_fcp._tcp.local.";
+
+       private boolean goon;
+       private boolean cancelledByUser = false;
+       private ServiceInfo selectedValue;
+       private final MDNSDiscoveryPanelCallback cb;
+       private final Dialog owner;
+       private final HashMap displayedServiceInfos;
+
+       private final JList list;
+       private final DefaultListModel listModel;
+       private final JLabel label;
+
+       private final Core core;
+
+       private JButton okButton;
+       private JButton cancelButton;
+
+
+       public MDNSDiscoveryPanel(Dialog owner, Core core, 
MDNSDiscoveryPanelCallback cb) {
+               super(owner, "ZeroConf");
+               this.core = core;
+               this.owner = owner;
+               this.cb = cb;
+               this.displayedServiceInfos = new HashMap();
+
+               // The UI
+               list = new JList();
+               listModel = new DefaultListModel();
+               label = new JLabel();
+
+               list.setModel(listModel);
+               
list.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
+
+               label.setText(I18n.getMessage("thaw.zeroconf.searchingNode")
+                             +" ; "+
+                             I18n.getMessage("thaw.zeroconf.nodeList"));
+
+               getContentPane().setLayout(new BorderLayout());
+               getContentPane().add(label, BorderLayout.NORTH);
+               getContentPane().add(new JScrollPane(list), 
BorderLayout.CENTER);
+
+               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();
+       }
+
+
+
+       /**
+        * 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) {
+                               if(list.getSelectedValue() == null) return;
+                               selectedValue = (ServiceInfo) 
displayedServiceInfos.get(list.getSelectedValue());
+                       } else
+                               cancelledByUser = true;
+
+                       synchronized (this) {
+                               notifyAll();
+                       }
+                       Logger.info(this, "User has selected : " + 
selectedValue);
+               }
+       }
+
+       /**
+        * The main loop : TheRealMeat(TM)
+        *
+        */
+       public void run() {
+               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.getMDNSDiscovery().getFoundNodes()) {
+                                       
if(core.getMDNSDiscovery().getFoundNodes().size() > 0) {
+                                               listModel.clear();
+                                               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);
+                                       }
+                               } catch (InterruptedException e) {}
+                       }
+
+                       if(cancelledByUser) break;
+                       else if(selectedValue == null) continue;
+
+                       Logger.debug(this, "We got something from the UI : 
let's try to connect");
+
+                       try {
+                               // We try to connect to the server
+                               // TODO: implement a proper test!
+                               testSocket = new 
Socket(selectedValue.getHostAddress(), selectedValue.getPort());
+                               isConfigValid = testSocket.isConnected();
+
+                               // Close the fcp socket we have openned, cleanup
+                               testSocket.close();
+                       } catch (IOException e) {
+                               isConfigValid = false;
+                       }
+
+                       Logger.debug(this, "isConfigValid ="+isConfigValid);
+
+                       // Reload, just in  case it failed...
+                       goon = true;
+                       list.removeSelectionInterval(0, 
core.getMDNSDiscovery().getFoundNodes().size());
+               } while(!isConfigValid);
+
+
+               this.setVisible(false);
+               owner.setEnabled(true);
+
+               if (!cancelledByUser) {
+                       Logger.debug(this, "We got something that looks valid 
from the UI : let's propagate changes to  the config");
+                       // 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.getMDNSDiscovery().isHasTheSameIPAddress(selectedValue)));
+
+
+                       Logger.info(this, "We are done : configuration has been 
saved sucessfully.");
+
+               }else
+                       Logger.info(this, "The user has cancelled!");
+               cb.onMDNSDiscoverPanelClosure(cancelledByUser);
+               Logger.notice(this, "We got back from the MDNSDiscoveryPanel 
callback");
+       }
+
+
+}

Modified: trunk/apps/Thaw/src/thaw/plugins/index/FileList.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/FileList.java        2007-09-13 
06:19:00 UTC (rev 15132)
+++ trunk/apps/Thaw/src/thaw/plugins/index/FileList.java        2007-09-13 
08:53:58 UTC (rev 15133)
@@ -7,5 +7,5 @@
  */
 public interface FileList {

-       public Vector getFileList(String columnToSort, boolean asc);
+       public File[] getFileList(String columnToSort, boolean asc);
 }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java       2007-09-13 
06:19:00 UTC (rev 15132)
+++ trunk/apps/Thaw/src/thaw/plugins/index/FileTable.java       2007-09-13 
08:53:58 UTC (rev 15133)
@@ -206,11 +206,11 @@

        protected Vector getSelectedFiles(final int[] selectedRows) {
                //final Vector srcList = 
fileList.getFileList(fileListModel.getColumnNameInDb(columnToSort), sortAsc);
-               final Vector srcList = fileListModel.getFiles();
+               final File[] srcList = fileListModel.getFiles();
                final Vector files = new Vector();

                for(int i = 0 ; i < selectedRows.length ; i++) {
-                       files.add(srcList.get(selectedRows[i]));
+                       files.add(srcList[selectedRows[i]]);
                }

                return files;
@@ -310,7 +310,7 @@
                };


-               public Vector files = null; /* thaw.plugins.index.File Vector */
+               public File[] files = null;

                public FileList fileList;

@@ -324,7 +324,7 @@
                        refresh();
                }

-               public Vector getFiles() {
+               public File[] getFiles() {
                        return files;
                }

@@ -332,7 +332,7 @@
                        if (files == null)
                                return 0;

-                       return files.size();
+                       return files.length;
                }

                public int getColumnCount() {
@@ -363,10 +363,10 @@
                        if (files == null)
                                return null;

-                       if (row >= files.size())
+                       if (row >= files.length)
                                return null;

-                       final thaw.plugins.index.File file = 
(thaw.plugins.index.File)files.get(row);
+                       final thaw.plugins.index.File file = 
(thaw.plugins.index.File)files[row];

                        if(column == 0)
                                return file.getFilename();
@@ -428,7 +428,7 @@
                }

                public void run() {
-                       int i, max;
+                       int max;

                        while(running) {
                                try {
@@ -443,14 +443,11 @@
                                if (fileListModel.getFiles() == null)
                                        continue;

-                               i = 0;
+                               File[] files = fileListModel.getFiles();

-                               Vector files = fileListModel.getFiles();
+                               for (int i = 0 ; i < files.length ; i++) {
+                                       thaw.plugins.index.File file = 
(thaw.plugins.index.File)files[i];

-                               for (Iterator it = files.iterator() ;
-                                    it.hasNext(); i++) {
-                                       thaw.plugins.index.File file = 
(thaw.plugins.index.File)it.next();
-
                                        if (file.getPublicKey() == null
                                            || 
!FreenetURIHelper.isAKey(file.getPublicKey())) {
                                                FCPTransferQuery transfer;

Modified: trunk/apps/Thaw/src/thaw/plugins/index/Index.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2007-09-13 06:19:00 UTC 
(rev 15132)
+++ trunk/apps/Thaw/src/thaw/plugins/index/Index.java   2007-09-13 08:53:58 UTC 
(rev 15133)
@@ -1,7 +1,6 @@
 package thaw.plugins.index;


-import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.OutputStream;
@@ -44,9 +43,9 @@
 import thaw.plugins.Hsqldb;
 import thaw.plugins.insertPlugin.DefaultMIMETypes;
 import thaw.plugins.signatures.Identity;
+import thaw.plugins.index.File;


-
 public class Index extends Observable implements MutableTreeNode,
                                                 IndexTreeNode,
                                                 Observer,
@@ -726,7 +725,7 @@
                else
                        tmpdir = tmpdir + java.io.File.separator;

-               File targetFile = new java.io.File(tmpdir + getRealName() 
+".frdx");
+               java.io.File targetFile = new java.io.File(tmpdir + 
getRealName() +".frdx");


                Logger.info(this, "Generating index ...");
@@ -1159,15 +1158,15 @@

        ////// FILE LIST ////////

-       public Vector getFileList() {
+       public File[] getFileList() {
                return getFileList(null, false);
        }

-       public Vector getFileList(String columnToSort, boolean asc) {
+       public File[] getFileList(String columnToSort, boolean asc) {
                synchronized(db.dbLock) {

                        try {
-                               Vector files = new Vector();
+                               java.util.LinkedList files = new 
java.util.LinkedList();

                                PreparedStatement st;

@@ -1199,7 +1198,7 @@
                                        files.add(file);
                                }

-                               return files;
+                               return (File[])files.toArray(new File[0]);

                        } catch(SQLException e) {
                                Logger.error(this, "SQLException while getting 
file list: "+e.toString());
@@ -1244,15 +1243,15 @@

        //// LINKS ////

-       public Vector getLinkList() {
+       public Link[] getLinkList() {
                return getLinkList(null, false);
        }

-       public Vector getLinkList(String columnToSort, boolean asc) {
+       public Link[] getLinkList(String columnToSort, boolean asc) {
                synchronized(db.dbLock) {

                        try {
-                               Vector links = new Vector();
+                               java.util.LinkedList links = new 
java.util.LinkedList();

                                PreparedStatement st;

@@ -1270,7 +1269,7 @@
                                        links.add(l);
                                }

-                               return links;
+                               return (Link[])links.toArray(new Link[0]);

                        } catch(SQLException e) {
                                Logger.error(this, "SQLException while getting 
link list: "+e.toString());

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexContainer.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexContainer.java  2007-09-13 
06:19:00 UTC (rev 15132)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexContainer.java  2007-09-13 
08:53:58 UTC (rev 15133)
@@ -1,8 +1,8 @@
 package thaw.plugins.index;

 import java.util.Vector;
+import thaw.plugins.index.File;

-
 /**
  * This is what you need to implements to use IndexParser.
  */
@@ -11,12 +11,12 @@
        /**
         * @return a vector of FileContainer
         */
-       public Vector getFileList();
+       public File[] getFileList();

        /**
         * @return a vector of LinkContainer
         */
-       public Vector getLinkList();
+       public Link[] getLinkList();


        /**

Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java   
2007-09-13 06:19:00 UTC (rev 15132)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexManagementHelper.java   
2007-09-13 08:53:58 UTC (rev 15133)
@@ -1869,17 +1869,16 @@


                                        } else if (node instanceof Index) {
-                                               Vector files = 
((Index)node).getFileList(null, true);
+                                               thaw.plugins.index.File[] files 
= ((Index)node).getFileList(null, true);

-                                               nmbFilesInt = files.size();
-                                               nmbLinksInt = 
((Index)node).getLinkList(null, true).size();
+                                               nmbFilesInt = files.length;
+                                               nmbLinksInt = 
((Index)node).getLinkList(null, true).length;
                                                insertionDate = 
((Index)node).getDate();

                                                totalSize = 0;

-                                               for (Iterator it = 
files.iterator();
-                                                    it.hasNext();) {
-                                                       totalSize += 
((thaw.plugins.index.File)it.next()).getSize();
+                                               for (int i = 0 ; i < 
files.length ; i++) {
+                                                       totalSize += 
((thaw.plugins.index.File)files[i]).getSize();
                                                }
                                        }


Modified: trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java     2007-09-13 
06:19:00 UTC (rev 15132)
+++ trunk/apps/Thaw/src/thaw/plugins/index/IndexParser.java     2007-09-13 
08:53:58 UTC (rev 15133)
@@ -192,10 +192,10 @@
        public Element getXMLLinks(final Document xmlDoc) {
                final Element linksEl = xmlDoc.createElement("indexes");

-               Vector links = index.getLinkList();
+               LinkContainer[] links = index.getLinkList();

-               for(Iterator it = links.iterator(); it.hasNext() ; ) {
-                       LinkContainer link = (LinkContainer)it.next();
+               for(int i = 0 ; i < links.length ; i++) {
+                       LinkContainer link = links[i];

                        String key = 
index.findTheLatestKey(link.getPublicKey());

@@ -213,11 +213,11 @@
        public Element getXMLFileList(final Document xmlDoc) {
                final Element filesEl = xmlDoc.createElement("files");

-               Vector files = index.getFileList();
+               FileContainer[] files = index.getFileList();

-               for(Iterator it = files.iterator(); it.hasNext();) {
+               for(int i = 0 ; i < files.length ; i++) {

-                       FileContainer file = (FileContainer)it.next();
+                       FileContainer file = (FileContainer)files[i];

                        String pubKey = file.getPublicKey();


Modified: trunk/apps/Thaw/src/thaw/plugins/index/LinkList.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/LinkList.java        2007-09-13 
06:19:00 UTC (rev 15132)
+++ trunk/apps/Thaw/src/thaw/plugins/index/LinkList.java        2007-09-13 
08:53:58 UTC (rev 15133)
@@ -4,6 +4,6 @@

 public interface LinkList {

-       public Vector getLinkList(String columnToSort, boolean asc);
+       public Link[] getLinkList(String columnToSort, boolean asc);

 }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java       2007-09-13 
06:19:00 UTC (rev 15132)
+++ trunk/apps/Thaw/src/thaw/plugins/index/LinkTable.java       2007-09-13 
08:53:58 UTC (rev 15133)
@@ -171,11 +171,11 @@

        protected Vector getSelectedLinks(final int[] selectedRows) {
                //final Vector srcList = linkList.getLinkList(null, false);
-               final Vector srcList = linkListModel.getLinks();
+               final Link[] srcList = linkListModel.getLinks();
                final Vector links = new Vector();

                for(int i = 0 ; i < selectedRows.length ; i++) {
-                       final Link link = (Link)srcList.get(selectedRows[i]);
+                       final Link link = (Link)srcList[selectedRows[i]];
                        links.add(link);
                }

@@ -268,7 +268,7 @@

                public Vector columnNames;

-               public Vector links = null; /* thaw.plugins.index.Link Vector */
+               public Link[] links = null; /* thaw.plugins.index.Link Vector */

                public LinkList linkList;

@@ -290,7 +290,7 @@

                }

-               public Vector getLinks() {
+               public Link[] getLinks() {
                        return links;
                }

@@ -298,7 +298,7 @@
                        if (links == null)
                                return 0;

-                       return links.size();
+                       return links.length;
                }

                public int getColumnCount() {
@@ -310,7 +310,7 @@
                }

                public Object getValueAt(final int row, final int column) {
-                       final thaw.plugins.index.Link link = 
(thaw.plugins.index.Link)links.get(row);
+                       final thaw.plugins.index.Link link = 
(thaw.plugins.index.Link)links[row];

                        switch(column) {
                        case(0): return link.getIndexName();

Modified: trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java    2007-09-13 
06:19:00 UTC (rev 15132)
+++ trunk/apps/Thaw/src/thaw/plugins/index/SearchResult.java    2007-09-13 
08:53:58 UTC (rev 15133)
@@ -65,12 +65,12 @@
                }
        }

-       public Vector getFileList(String col, boolean asc) {
+       public File[] getFileList(String col, boolean asc) {

                if (col == null)
                        col = "filename";

-               Vector v = new Vector();
+               java.util.LinkedList v = new java.util.LinkedList();

                synchronized(db.dbLock) {
                        try {
@@ -100,11 +100,11 @@
                        }
                }

-               return v;
+               return (File[])v.toArray(new File[0]);
        }

-       public Vector getLinkList(String col, boolean asc) {
-               Vector v = new Vector();
+       public Link[] getLinkList(String col, boolean asc) {
+               java.util.LinkedList v = new java.util.LinkedList();

                synchronized(db.dbLock) {
                        try {
@@ -131,7 +131,7 @@
                        }
                }

-               return v;
+               return (Link[])v.toArray(new Link[0]);
        }

 }

Modified: trunk/apps/Thaw/src/thaw/plugins/index/UnknownIndexList.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/index/UnknownIndexList.java        
2007-09-13 06:19:00 UTC (rev 15132)
+++ trunk/apps/Thaw/src/thaw/plugins/index/UnknownIndexList.java        
2007-09-13 08:53:58 UTC (rev 15133)
@@ -34,7 +34,7 @@


 public class UnknownIndexList implements MouseListener, ActionListener {
-       private Vector linkList; /* only when < MAX_INDEXES */
+       private Vector linkList;

        private JPanel panel;
        private JList list;
@@ -162,30 +162,55 @@
                return true;
        }

-       /**
-        * will add the link from that index (if links link to unknown indexes)
-        */
-       public boolean addLinks(final LinkList index) {
-               boolean ret = false;
+       private class LinkAdder implements Runnable {
+               private LinkList index;
+               private boolean running;

-               if (index == null)
-                       return false;
+               public LinkAdder(LinkList index) {
+                       this.index = index;
+                       this.running = true;
+               }

-               final Vector ll = index.getLinkList(null, false);
+               public void run() {
+                       boolean ret = false;

-               if ((ll == null) || (ll.size() == 0))
-                       return false;
+                       final Link[] ll = index.getLinkList(null, false);

-               for (final Iterator it = ll.iterator();
-                    it.hasNext();) {
-                       if (addLink(((Link)it.next()), false))
-                               ret = true;
+                       if ((ll == null) || (ll.length == 0))
+                               return;
+
+                       for (int i = 0 ; i < ll.length && running ; i++) {
+                               if (addLink(ll[i], false))
+                                       ret = true;
+                       }
+
+                       if (ret)
+                               refresh();
+
+                       return;
                }

-               if (ret)
-                       refresh();
+               public void stop() {
+                       running = false;
+               }
+       }

-               return ret;
+       private LinkAdder lastLinkAdder = null;
+
+
+       /**
+        * will add the link from that index (if links link to unknown indexes)
+        */
+       public void addLinks(final LinkList index) {
+               if (index == null)
+                       return;
+
+               if (lastLinkAdder != null)
+                       lastLinkAdder.stop();
+
+               lastLinkAdder = new LinkAdder(index);
+               Thread th = new Thread(lastLinkAdder);
+               th.start();
        }



Modified: trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/Node.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/Node.java  2007-09-13 
06:19:00 UTC (rev 15132)
+++ trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/Node.java  2007-09-13 
08:53:58 UTC (rev 15133)
@@ -119,7 +119,7 @@
        private double velocityX = 0.0;
        private double velocityY = 0.0;

-       public final static double TIMESTEP                = 0.001;
+       public final static double TIMESTEP                = 0.01;
        public final static int NMB_STEPS                  = 50000;
        public final static double FACTOR_ATTRACTION       = 0.5;
        public final static double FACTOR_REPULSION        = 1;
@@ -129,106 +129,45 @@
        public final static double MIN_KINETIC             = 0.1; /* will stop 
if < */

        /**
-        * attracted by its peers/neightbours
+        * see http://en.wikipedia.org/wiki/Force-based_algorithms       * 
@return velocity
         */
-       private double[] attraction(Node node) {
-               double attrX = 0.0;
-               double attrY = 0.0;
-
-               attrX = (node.getX() - x)*FACTOR_ATTRACTION;
-               attrY = (node.getY() - y)*FACTOR_ATTRACTION;
-
-               return new double[] {attrX, attrY};
-       }
-
-       /**
-        * repulsed by all the node != peers / neightbours
-        */
-       private double[] repulsion(Node node) {
-               double repX = 0.0;
-               double repY = 0.0;
-
-               if (x != node.getX()) {
-                       repX = (1/(x-node.getX())*FACTOR_REPULSION);
-               }
-
-               if (y != node.getY()) {
-                       repY = (1/(y-node.getY())*FACTOR_REPULSION);
-               }
-
-
-               if (repX > REPULSE_LIMIT) repX = REPULSE_LIMIT;
-               if (repY > REPULSE_LIMIT) repY = REPULSE_LIMIT;
-               if (repX < -REPULSE_LIMIT) repX = -REPULSE_LIMIT;
-               if (repY < -REPULSE_LIMIT) repY = -REPULSE_LIMIT;
-
-
-               return new double[] {repX, repY};
-       }
-
-       /**
-        * see http://en.wikipedia.org/wiki/Force-based_algorithms
-        * @return velocity
-        */
        public double computeVelocity(Vector nodeList) {
                double netForceX = 0.0;
                double netForceY = 0.0;

-               /* repulsion */
-               for (Iterator it = nodeList.iterator();
-                    it.hasNext();) {
-                       Node node = (Node)it.next();
+               if ( ((linkTo.size() + linkedFrom.size()) > 1)
+                    && (linkTo.size() > 1 || linkedFrom.size() > 1) )
+               {
+                       double sumX = 0.0;
+                       double sumY = 0.0;

-                       /*
-                         if (node == this
-                           || linkTo.indexOf(node) >= 0
-                           || linkedFrom.indexOf(node) >= 0)
-                               continue;
-                       */
-                       if (node == this)
-                               continue;
+                       for (Iterator it = linkTo.iterator();
+                            it.hasNext();) {
+                               Node node = (Node)it.next();
+                               sumX += node.getX();
+                               sumY += node.getY();
+                       }

-                       double[] repuls = repulsion(node);
-                       netForceX += repuls[0];
-                       netForceY += repuls[1];
-               }
+                       for (Iterator it = linkedFrom.iterator();
+                            it.hasNext();) {
+                               Node node = (Node)it.next();
+                               sumX += node.getX();
+                               sumY += node.getY();
+                       }

-               /* attraction */
+                       double centerX = sumX / (linkedFrom.size() + 
linkTo.size());
+                       double centerY = sumY / (linkedFrom.size() + 
linkTo.size());

-               for (Iterator it = linkTo.iterator();
-                    it.hasNext();) {
-                       Node node = (Node)it.next();
-
-                       if (node == this)
-                               continue;
-
-                       double[] attr = attraction(node);
-                       netForceX += attr[0];
-                       netForceY += attr[1];
+                       netForceX = centerX - x;
+                       netForceY = centerY - y;
                }

+               //velocityX = velocityX/FACTOR_DECELERATION;
+               //velocityY = velocityY/FACTOR_DECELERATION;

-               /* attraction */
+               velocityX = netForceX;
+               velocityY = netForceY;

-               for (Iterator it = linkedFrom.iterator();
-                    it.hasNext();) {
-                       Node node = (Node)it.next();
-
-                       if (node == this || linkTo.indexOf(node) >= 0)
-                               continue;
-
-                       double[] attr = attraction(node);
-                       netForceX += attr[0];
-                       netForceY += attr[1];
-               }
-
-
-               velocityX = velocityX/FACTOR_DECELERATION;
-               velocityY = velocityY/FACTOR_DECELERATION;
-
-               velocityX += netForceX;
-               velocityY += netForceY;
-
                return Math.sqrt( Math.pow(velocityX,2) + Math.pow(velocityY, 
2));
        }

@@ -241,7 +180,6 @@

                x += velocityX * TIMESTEP;
                y += velocityY * TIMESTEP;
-
                return true;
        }



Reply via email to