Author: ghuck
Date: 2009-06-26 13:54:03 -0700 (Fri, 26 Jun 2009)
New Revision: 17121

Modified:
   csplugins/trunk/soc/ghuck/plugin/src/GpuLayout.java
Log:
Stub of plugin...



Modified: csplugins/trunk/soc/ghuck/plugin/src/GpuLayout.java
===================================================================
--- csplugins/trunk/soc/ghuck/plugin/src/GpuLayout.java 2009-06-26 19:41:36 UTC 
(rev 17120)
+++ csplugins/trunk/soc/ghuck/plugin/src/GpuLayout.java 2009-06-26 20:54:03 UTC 
(rev 17121)
@@ -20,116 +20,233 @@
 
**************************************************************************************/
 
 
-import java.util.*;
 import java.awt.event.ActionEvent;
-import javax.swing.JOptionPane;
 
-import giny.model.Node;
-import giny.view.NodeView;
-
+import cytoscape.Cytoscape;
 import cytoscape.plugin.CytoscapePlugin;
 import cytoscape.util.CytoscapeAction;
-import cytoscape.Cytoscape;
-import cytoscape.CyNetwork;
-import cytoscape.CyNode;
-import cytoscape.CyEdge;
-import cytoscape.view.CyNetworkView;
-import cytoscape.data.Semantics;
+import cytoscape.layout.CyLayouts;
+import cytoscape.layout.CyLayoutAlgorithm;
+import cytoscape.layout.AbstractLayout;
+import cytoscape.layout.LayoutProperties;
+import cytoscape.layout.Tunable;
 
-import cytoscape.plugin.CytoscapePlugin;
-import cytoscape.view.cytopanels.CytoPanelImp;
-import javax.swing.SwingConstants;
+import giny.model.GraphPerspective;
+import giny.model.Node;
+
+import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 
+import java.awt.GridLayout;
+import java.awt.Rectangle;
+import java.util.Iterator;
 
 
-/**
 
 
- */
 
 
-public class GpuLayout extends    CytoscapePlugin 
-                                 //implements CyGroupViewer,
-                                 //NodeContextMenuListener,
-                                 //PropertyChangeListener 
-{
-    /**
-     * This constructor creates an action and adds it to the Plugins menu.
-     */
-    public GpuLayout() {
+
+
+/**
+ * This plugin provides a GPU assited graph layout utility by calling CUDA C++ 
code
+ */
+public class GpuLayout extends CytoscapePlugin {
        
-       /*  Show message on screen    */
-       
-       String message = "GPU Graph Layout Loaded!";
+    private int coarseGraphSize         = 50;
+    private int interpolationIterations = 50;
+    private int levelConvergence        = 2;
+    private int edgeLen                 = 5;
+    private int initialNoIterations     = 300;
 
-       // Use the CytoscapeDesktop as parent for a Swing dialog
-       JOptionPane.showMessageDialog( Cytoscape.getDesktop(), message);
+    private int groupcount = 2;
 
+    private LayoutProperties layoutProperties;
+
        
-       /*    Add Button to Menu     */
+       /**
+        * 
+        */
+       public GpuLayout() {
+           //  Show message on screen    
+           String message = "GPU Graph Layout Loaded!\n" 
+                          +  coarseGraphSize + "\n" 
+                          + interpolationIterations + "\n"  
+                          + levelConvergence + "\n"         
+                          + edgeLen + "\n"                  
+                           + initialNoIterations; 
+           // Use the CytoscapeDesktop as parent for a Swing dialog
+           JOptionPane.showMessageDialog( Cytoscape.getDesktop(), message);
 
-        //create a new action to respond to menu activation
-        GpuLayoutAction action = new GpuLayoutAction();
+           // Add Layout to menu
+           CyLayouts.addLayout(new ForceDirected(), "GPU Assisted Layout");
+       }
+       
+       class ForceDirected extends AbstractLayout{
+               /**
+                * Creates a new layout object.
+                */
+               public ForceDirected() {
+                       super();
+                       layoutProperties = new LayoutProperties(getName());
+                       initialize_properties();
+               }
+               
+               protected void initialize_properties() {
+                       layoutProperties.add(new Tunable("", "Coarse Graph 
Size"           , Tunable.INTEGER, new Integer(45) ));
+                       layoutProperties.add(new Tunable("", "Interpolation 
Iterations"    , Tunable.INTEGER, new Integer(50) ));
+                       layoutProperties.add(new Tunable("", "Level 
Convergence"           , Tunable.INTEGER, new Integer(2)  ));
+                       layoutProperties.add(new Tunable("", "Ideal Edge 
Length"           , Tunable.INTEGER, new Integer(5)  ));
+                       layoutProperties.add(new Tunable("", "Initial Number of 
Iterations", Tunable.INTEGER, new Integer(300)));
 
-        //set the preferred menu
-       action.setPreferredMenu("Layout");
 
-        //and add it to the menus
-       Cytoscape.getDesktop().getCyMenus().addAction(action);
+                       layoutProperties.initializeProperties();
 
-    }
+                       updateSettings(true);
+               }
 
-    class MyPanel extends JPanel {
-       public MyPanel() {
-       }
-    }
+               /**
+                *  DOCUMENT ME!
+                */
+               public void updateSettings() {
+                       updateSettings(false);
+               }
 
+               /**
+                *  DOCUMENT ME!
+                *
+                * @param force DOCUMENT ME!
+                */
+               public void updateSettings(boolean force) {
+                       layoutProperties.updateValues();
+                       Tunable t;
 
+                       // Get coarseGraphSize
+                       t = layoutProperties.get("Coarse Graph Size");
+                       if ((t != null) && (t.valueChanged() || force))
+                           coarseGraphSize = ((Integer) 
t.getValue()).intValue();
 
+                       // Get interpolationIterations
+                       t = layoutProperties.get("Interpolation Iterations");
+                       if ((t != null) && (t.valueChanged() || force))
+                           interpolationIterations = ((Integer) 
t.getValue()).intValue();
 
-    
-    /**
-     * Gives a description of this plugin.
-     */
-    /*        public String describe() {
-        StringBuffer sb = new StringBuffer();
-        sb.append("Bla Bla... ");
-        sb.append(" more Bla.. ");
-        return sb.toString();
-    }
-    */
-    
-        
-    /**
-     * This class gets attached to the menu item.
-     */
-    public class GpuLayoutAction extends CytoscapeAction 
-    {
-       
-       /**
-        * The constructor sets the text that should appear on the menu item.
-        */
-    public GpuLayoutAction() {
-       super("GPU Layout Plugin");
-    }
-       
-       /**
-        * This method is called when the user selects the menu item.
-        */
-       public void actionPerformed(ActionEvent ae) {
+                       // Get levelConvergence
+                       t = layoutProperties.get("Level Convergence");
+                       if ((t != null) && (t.valueChanged() || force))
+                           levelConvergence = ((Integer) 
t.getValue()).intValue();
 
-       /*  Show message on screen    */
+                       // Get edgeLen
+                       t = layoutProperties.get("Ideal Edge Length");
+                       if ((t != null) && (t.valueChanged() || force))
+                           edgeLen = ((Integer) t.getValue()).intValue();
+
+                       // Get initialNoIterations
+                       t = layoutProperties.get("Initial Number of 
Iterations");
+                       if ((t != null) && (t.valueChanged() || force))
+                           initialNoIterations = ((Integer) 
t.getValue()).intValue();
        
-       String message = "Execute GPU Layout!";
-       // use the CytoscapeDesktop as parent for a Swing dialog
-       JOptionPane.showMessageDialog( Cytoscape.getDesktop(), message);
+                       //  Show message on screen    
+                       String message = "Preferences updated\n" 
+                           +  coarseGraphSize + "\n" 
+                           + interpolationIterations + "\n"  
+                           + levelConvergence + "\n"         
+                           + edgeLen + "\n"                  
+                           + initialNoIterations; 
+                       // Use the CytoscapeDesktop as parent for a Swing dialog
+                       JOptionPane.showMessageDialog( Cytoscape.getDesktop(), 
message);
+                       
+               }
 
+               /**
+                * Get the settings panel for this layout
+                */
+               public JPanel getSettingsPanel() {
+                       JPanel panel = new JPanel(new GridLayout(0, 5));
+                       panel.add(layoutProperties.getTunablePanel());
+
+                       return panel;
+               }
+
+               
+               /**
+                *  DOCUMENT ME!
+                */
+               public void revertSettings() {
+                       layoutProperties.revertProperties();
+               }
+
+               public LayoutProperties getSettings() {
+                       return layoutProperties;
+               }
+
+               /**
+                *  DOCUMENT ME!
+                */
+               public void construct() {
+                       taskMonitor.setStatus("Initializing");
+                       initialize(); // Calls initialize_local
+
        
+                       System.out.println("do layout here: groupcount = " + 
groupcount);
 
+                       if (groupcount<2) {
+                               return;
+                       }
 
+                       // Get the group center X
+                       double[] group_center_x = new double[groupcount];
+                       
+                       for (int i=0; i<groupcount; i++) {
+                               group_center_x[i] = i* maxwidth/(groupcount*2); 
+                       }
+                       
+                       double group_width = (maxwidth/groupcount)*0.6/2;
+                                               
+                       Iterator<Node> it = network.nodesIterator();
+                       
+                       int group_id = 0;
+                       
+                       while (it.hasNext()) {
+                               if (canceled)
+                                       return;
+
+                               group_id = (int) 
Math.round((groupcount-1)*Math.random());      
+                               
+                               double x = group_center_x[group_id] + 
(Math.random()-0.5)*group_width;
+                               
+                               Node node = (Node) it.next();
+                       
+                               //System.out.println(group_id);
+                               
+                               networkView.getNodeView(node).setXPosition(x);
+                       }
+               }
+
+               private double maxwidth = 5000.0;
+
+               /**
+                * getName is used to construct property strings
+                * for this layout.
+                */
+               public  String getName() {
+                       return "Force Directed GPU Layout";
+               }
+
+               /**
+                * toString is used to get the user-visible name
+                * of the layout
+                */
+               public  String toString(){
+                       return "Force Directed Layout";
+               }
        }
-       
-    }
 }
 
+
+
+
+
+
+
+


--~--~---------~--~----~------------~-------~--~----~
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