Author: ghuck
Date: 2011-05-25 17:23:57 -0700 (Wed, 25 May 2011)
New Revision: 25542

Modified:
   
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
Log:


Modified: 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
===================================================================
--- 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
       2011-05-25 23:36:34 UTC (rev 25541)
+++ 
csplugins/trunk/soc/ghuck/IgraphPlugin/src/cytoscape/plugins/igraph/IgraphPlugin.java
       2011-05-26 00:23:57 UTC (rev 25542)
@@ -29,14 +29,13 @@
 import java.io.*;
 import java.util.jar.*;
 import java.util.zip.*;
+import java.lang.reflect.Field;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 
 
-/** ---------------------------LabelLayoutPlugin-----------------------------
- * Takes the current network and reorganizes it so that the new network is more
- * readable.  This will be done through the repositioning of network labels,
- * and subtle repositioning of nodes.
+/** ---------------------------IgraphPlugin-----------------------------
+ * This plugin allows to call some of igraph functions from Cytoscape
  * @author Gerardo Huck
  *
  */
@@ -51,8 +50,11 @@
        // Make sure Igraph library is extracted in the plugins folder
        checkLib();
 
+       // Load igraph
+       loadIgraph();
+
        // Add layouts
-       
+       //CyLayouts.addLayout(new sampleLayout(), "Igraph");    
     }
 
     private boolean isOldVersion(){
@@ -96,6 +98,54 @@
            JOptionPane.showMessageDialog( Cytoscape.getDesktop(), message);    
   
        }
        return;
+    } // checkLib
+
+
+    protected void loadIgraph() {
+
+       // Reset the "sys_paths" field of the ClassLoader to null.
+       Class clazz = ClassLoader.class;
+       Field field;
+       try {
+           field = clazz.getDeclaredField("sys_paths");
+           boolean accessible = field.isAccessible();
+           if (!accessible)
+               field.setAccessible(true);
+           Object original = field.get(clazz);
+
+           // Get original PATH
+           String orig_path = System.getProperty("java.library.path");
+           
+           // Reset it to null so that whenever "System.loadLibrary" is 
called, it will be reconstructed with the changed value
+           field.set(clazz, null);
+           try {
+               // Change the value and load the library.
+               System.setProperty("java.library.path", "./plugins" + ":" + ":" 
+ orig_path);
+               System.loadLibrary("igraph");
+           }
+
+           catch (UnsatisfiedLinkError error){
+               String message = "Problem detected while loading igraph 
Library.\n"                 
+                   + error.getMessage() 
+                   + "\nPlease check your plugins folder.";
+               JOptionPane.showMessageDialog(Cytoscape.getDesktop(), message);
+               
+               // Revert back the changes
+               field.set(clazz, original);
+               field.setAccessible(accessible);
+               
+               // Exit
+               return;
+           }           
+
+           finally {
+               // Revert back the changes
+               field.set(clazz, original);
+               field.setAccessible(accessible);   
+           }
+       }
+       catch (Exception exception){
+       }
     }
         
 }
\ No newline at end of file

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to