Author: jflesch
Date: 2007-09-24 16:51:11 +0000 (Mon, 24 Sep 2007)
New Revision: 15289

Added:
   trunk/apps/Thaw/src/thaw/plugins/IndexTreeRebuilder.java
Modified:
   trunk/apps/Thaw/src/thaw/core/PluginManager.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/Hsqldb.java
   trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/Node.java
Log:
Revert the part from r15133 relative to the index web grapher + Start a new 
plugin to rebuild the index tree when broken (rare but may happen)

Modified: trunk/apps/Thaw/src/thaw/core/PluginManager.java
===================================================================
--- trunk/apps/Thaw/src/thaw/core/PluginManager.java    2007-09-24 13:12:02 UTC 
(rev 15288)
+++ trunk/apps/Thaw/src/thaw/core/PluginManager.java    2007-09-24 16:51:11 UTC 
(rev 15289)
@@ -33,6 +33,7 @@
                "thaw.plugins.Signatures",
                "thaw.plugins.IndexBrowser",
                "thaw.plugins.IndexExporter",
+               "thaw.plugins.IndexTreeRebuilder",
                "thaw.plugins.MiniFrost",
                "thaw.plugins.Restarter",
                "thaw.plugins.TransferLogs",

Modified: trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-09-24 
13:12:02 UTC (rev 15288)
+++ trunk/apps/Thaw/src/thaw/i18n/source.thaw_fr.properties     2007-09-24 
16:51:11 UTC (rev 15289)
@@ -688,3 +688,6 @@
 thaw.plugin.indexWebGrapher.fanFan.3=C'?tait du gateau !
 thaw.plugin.indexWebGrapher.fanFan.4=Joli, n'est-ce pas ? :)

+## Index tree rebuilder
+
+thaw.plugin.index.treeRebuilder=R?parateur d'arbre d'indexes

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-09-24 13:12:02 UTC 
(rev 15288)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw.properties       2007-09-24 16:51:11 UTC 
(rev 15289)
@@ -702,3 +702,8 @@
 thaw.plugin.indexWebGrapher.fanFan.2=Mooahah, I'm so good !
 thaw.plugin.indexWebGrapher.fanFan.3=Piece of cake !
 thaw.plugin.indexWebGrapher.fanFan.4=Nice, isn't it ? :)
+
+
+## Tree rebuilder
+
+thaw.plugin.index.treeRebuilder=Index tree rebuilder

Modified: trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties
===================================================================
--- trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2007-09-24 13:12:02 UTC 
(rev 15288)
+++ trunk/apps/Thaw/src/thaw/i18n/thaw_fr.properties    2007-09-24 16:51:11 UTC 
(rev 15289)
@@ -688,3 +688,6 @@
 thaw.plugin.indexWebGrapher.fanFan.3=C'\u00e9tait du gateau !
 thaw.plugin.indexWebGrapher.fanFan.4=Joli, n'est-ce pas ? :)

+## Index tree rebuilder
+
+thaw.plugin.index.treeRebuilder=R\u00e9parateur d'arbre d'indexes

Modified: trunk/apps/Thaw/src/thaw/plugins/Hsqldb.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/Hsqldb.java        2007-09-24 13:12:02 UTC 
(rev 15288)
+++ trunk/apps/Thaw/src/thaw/plugins/Hsqldb.java        2007-09-24 16:51:11 UTC 
(rev 15289)
@@ -61,18 +61,13 @@

                connection = 
DriverManager.getConnection(core.getConfig().getValue("hsqldb.url"),
                                                         "sa", "");
-
-               PreparedStatement st = connection.prepareStatement("SET LOGSIZE 
50");
-               st.execute();
        }

        public void disconnect() throws java.sql.SQLException {
                synchronized(dbLock) {
                        connection.commit();
-                       //executeQuery("SHUTDOWN COMPACT");
                        executeQuery("SHUTDOWN");
                        connection.close();
-                       //connection = null;
                }
        }


Added: trunk/apps/Thaw/src/thaw/plugins/IndexTreeRebuilder.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/IndexTreeRebuilder.java                    
        (rev 0)
+++ trunk/apps/Thaw/src/thaw/plugins/IndexTreeRebuilder.java    2007-09-24 
16:51:11 UTC (rev 15289)
@@ -0,0 +1,63 @@
+package thaw.plugins;
+
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+
+import thaw.core.Core;
+import thaw.core.Logger;
+import thaw.core.Plugin;
+import thaw.core.ThawThread;
+import thaw.core.ThawRunnable;
+import thaw.core.I18n;
+import thaw.gui.IconBox;
+
+import thaw.plugins.Hsqldb;
+
+import java.sql.*;
+
+
+public class IndexTreeRebuilder implements Plugin, ActionListener {
+       private Core core;
+       private Hsqldb db;
+
+       public IndexTreeRebuilder() {
+       }
+
+       public boolean run(Core core) {
+               this.core = core;
+
+               if(core.getPluginManager().getPlugin("thaw.plugins.Hsqldb") == 
null) {
+                       Logger.info(this, "Loading Hsqldb plugin");
+
+                       
if(core.getPluginManager().loadPlugin("thaw.plugins.Hsqldb") == null
+                          || 
!core.getPluginManager().runPlugin("thaw.plugins.Hsqldb")) {
+                               Logger.error(this, "Unable to load 
thaw.plugins.Hsqldb !");
+                               return false;
+                       }
+               }
+
+               db = 
(Hsqldb)core.getPluginManager().getPlugin("thaw.plugins.Hsqldb");
+               db.registerChild(this);
+
+               return true;
+       }
+
+       public void stop() {
+
+               if (db != null)
+                       db.unregisterChild(this);
+       }
+
+       public void actionPerformed(ActionEvent e) {
+
+       }
+
+       public String getNameForUser() {
+               return I18n.getMessage("thaw.plugin.index.treeRebuilder");
+       }
+
+       public javax.swing.ImageIcon getIcon() {
+               return null;
+       }
+}
+

Modified: trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/Node.java
===================================================================
--- trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/Node.java  2007-09-24 
13:12:02 UTC (rev 15288)
+++ trunk/apps/Thaw/src/thaw/plugins/indexWebGrapher/Node.java  2007-09-24 
16:51:11 UTC (rev 15289)
@@ -119,7 +119,7 @@
        private double velocityX = 0.0;
        private double velocityY = 0.0;

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

        /**
-        * see http://en.wikipedia.org/wiki/Force-based_algorithms       * 
@return velocity
+        * attracted by its peers/neightbours
         */
+       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;

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

-                       for (Iterator it = linkTo.iterator();
-                            it.hasNext();) {
-                               Node node = (Node)it.next();
-                               sumX += node.getX();
-                               sumY += node.getY();
-                       }

-                       for (Iterator it = linkedFrom.iterator();
-                            it.hasNext();) {
-                               Node node = (Node)it.next();
-                               sumX += node.getX();
-                               sumY += node.getY();
-                       }
+                       if (node == this)
+                               continue;

-                       double centerX = sumX / (linkedFrom.size() + 
linkTo.size());
-                       double centerY = sumY / (linkedFrom.size() + 
linkTo.size());
+                       double[] repuls = repulsion(node);
+                       netForceX += repuls[0];
+                       netForceY += repuls[1];
+               }

-                       netForceX = centerX - x;
-                       netForceY = centerY - y;
-               }
+              /* attraction */
+              for (Iterator it = linkTo.iterator();
+                    it.hasNext();) {
+                       Node node = (Node)it.next();

-               //velocityX = velocityX/FACTOR_DECELERATION;
-               //velocityY = velocityY/FACTOR_DECELERATION;
+                       if (node == this)
+                               continue;

-               velocityX = netForceX;
-               velocityY = netForceY;
+                       double[] attr = attraction(node);
+                       netForceX += attr[0];
+                       netForceY += attr[1];
+              }

-               return Math.sqrt( Math.pow(velocityX,2) + Math.pow(velocityY, 
2));
+              /* attraction */
+              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));
        }

        /**


Reply via email to