Author: scooter
Date: 2011-09-17 21:12:16 -0700 (Sat, 17 Sep 2011)
New Revision: 26857

Added:
   
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/ui/GraphObjectSelectionListener.java
Modified:
   csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/StructureViz.java
   
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/actions/CyChimera.java
   
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/ui/CustomGraphicsUtil.java
Log:
Added support for node selection listeners to select associated residues.


Modified: 
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/StructureViz.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/StructureViz.java    
    2011-09-18 01:31:08 UTC (rev 26856)
+++ 
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/StructureViz.java    
    2011-09-18 04:12:16 UTC (rev 26857)
@@ -61,6 +61,7 @@
 // structureViz imports
 import structureViz.commands.StructureVizCommandHandler;
 import structureViz.ui.StructureVizMenuListener;
+import structureViz.ui.GraphObjectSelectionListener;
 
 /**
  * The StructureViz class provides the primary interface to the
@@ -82,12 +83,15 @@
        public static final int GETIMAGE = 9;
 
        private CyLogger logger = null;
+       private GraphObjectSelectionListener gvcListener = null;
 
   /**
    * Create our action and add it to the plugins menu
    */
   public StructureViz() {
                logger = CyLogger.getLogger(StructureViz.class);
+               gvcListener = new GraphObjectSelectionListener(logger);
+               
 
                try {
                        // Set ourselves up to listen for new networks
@@ -96,6 +100,7 @@
        
                        // Add ourselves to the current network context menu
                        
((DGraphView)Cytoscape.getCurrentNetworkView()).addNodeContextMenuListener(this);
+                       
Cytoscape.getCurrentNetworkView().addGraphViewChangeListener(gvcListener);
                } catch (ClassCastException e) {
                        logger.error(e.getMessage());
                }
@@ -119,8 +124,12 @@
         */
        public void propertyChange(PropertyChangeEvent evt) {
                if (evt.getPropertyName() == 
CytoscapeDesktop.NETWORK_VIEW_CREATED) {
+                       CyNetworkView view = (CyNetworkView)evt.getNewValue();
                        // Add menu to the context dialog
-                       
((CyNetworkView)evt.getNewValue()).addNodeContextMenuListener(this);
+                       view.addNodeContextMenuListener(this);
+                       // Add our graph view change listener
+                       view.removeGraphViewChangeListener(gvcListener);
+                       view.addGraphViewChangeListener(gvcListener);
                }
        }
 

Modified: 
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/actions/CyChimera.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/actions/CyChimera.java
   2011-09-18 01:31:08 UTC (rev 26856)
+++ 
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/actions/CyChimera.java
   2011-09-18 04:12:16 UTC (rev 26857)
@@ -81,6 +81,7 @@
        private static Map<String, Structure> smilesStructureMap = null;
        private static CyAttributes cyAttributes;
        private static CyLogger logger = null;
+       private static boolean enableNodeSelection = true;
 
        static List<GraphObject> selectedList = null;
 
@@ -363,6 +364,8 @@
 
                if (selectedList == null) selectedList = new 
ArrayList<GraphObject>();
 
+               enableNodeSelection = false;
+
                // We need to do this in two passes since some parts of a 
structure might be
                // selected and some might not.  Our selection model 
(unfortunately) only tells
                // us that something has changed, not what...
@@ -417,6 +420,7 @@
 */
 
                networkView.updateView();
+               enableNodeSelection = true;
        }
 
        /**
@@ -460,6 +464,14 @@
                return structure;
        }
 
+       public static boolean selectionEnabled() {
+               return enableNodeSelection;
+       }
+
+       public static void setSelectionEnabled(boolean enable) {
+               enableNodeSelection = enable;
+       }
+
        private static List<Structure> getStructures(CyNode node, 
                                                     List<Structure> 
structureList, 
                                                     String matchName) {

Modified: 
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/ui/CustomGraphicsUtil.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/ui/CustomGraphicsUtil.java
       2011-09-18 01:31:08 UTC (rev 26856)
+++ 
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/ui/CustomGraphicsUtil.java
       2011-09-18 04:12:16 UTC (rev 26857)
@@ -129,7 +129,7 @@
 
                // Now, delete the temp file we created
                tmpFile.delete();
-               Cytoscape.getCurrentNetworkView().redrawGraph(false, true);
+               Cytoscape.getCurrentNetworkView().updateView();
 
        }
 }

Added: 
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/ui/GraphObjectSelectionListener.java
===================================================================
--- 
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/ui/GraphObjectSelectionListener.java
                             (rev 0)
+++ 
csplugins/trunk/ucsf/scooter/structureViz/src/structureViz/ui/GraphObjectSelectionListener.java
     2011-09-18 04:12:16 UTC (rev 26857)
@@ -0,0 +1,119 @@
+/* vim: set ts=2: */
+/**
+ * Copyright (c) 2006 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions, and the following disclaimer.
+ *   2. Redistributions in binary form must reproduce the above
+ *      copyright notice, this list of conditions, and the following
+ *      disclaimer in the documentation and/or other materials provided
+ *      with the distribution.
+ *   3. Redistributions must acknowledge that this software was
+ *      originally developed by the UCSF Computer Graphics Laboratory
+ *      under support by the NIH National Center for Research Resources,
+ *      grant P41-RR01081.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
+ * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+ * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
+ * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+package structureViz.ui;
+
+import structureViz.actions.Chimera;
+import structureViz.actions.CyChimera;
+import structureViz.model.Structure;
+
+import java.util.List;
+
+import cytoscape.logger.CyLogger;
+import cytoscape.view.CyNetworkView;
+
+import giny.model.GraphObject;
+import giny.view.GraphView;
+import giny.view.GraphViewChangeEvent;
+import giny.view.GraphViewChangeListener;
+
+/**
+ * This class is used to implement the listener for the
+ * context menu on the ModelNavigatorDialog
+ */
+public class GraphObjectSelectionListener implements GraphViewChangeListener {
+       private CyLogger logger;
+
+       public GraphObjectSelectionListener(CyLogger logger) {
+               this.logger = logger;
+       }
+       
+       public void graphViewChanged(GraphViewChangeEvent event) {
+               if (!CyChimera.selectionEnabled())
+                       return;
+               CyChimera.setSelectionEnabled(false);
+               GraphView view = (GraphView)event.getSource();
+               if (event.isEdgesSelectedType()) {
+                       setSelection(view, event.getSelectedEdges(), true);
+               } else if (event.isEdgesUnselectedType()) {
+                       setSelection(view, event.getSelectedEdges(), false);
+               } else if (event.isNodesSelectedType()) {
+                       setSelection(view, event.getSelectedNodes(), true);
+               } else if (event.isNodesUnselectedType()) {
+                       setSelection(view, event.getSelectedNodes(), false);
+               }
+               CyChimera.setSelectionEnabled(true);
+       }
+
+       private void setSelection(GraphView view, GraphObject[] goArray, 
boolean selected) {
+               if (goArray == null || goArray.length == 0) return;
+
+               // Get the chimera instance for this view
+               Chimera chimera = 
Chimera.GetChimeraInstance((CyNetworkView)view, logger);
+
+               // Get all of the open structures
+               List<Structure> structureList = chimera.getOpenStructs();
+
+               // For each graph object, see if the selection has changed
+               for (Structure structure: structureList) {
+                       List<GraphObject> objList = 
structure.getGraphObjectList();
+                       for (int index = 0; index < goArray.length; index++ ) {
+                               GraphObject object = goArray[index];
+                               if (objList.contains(object) && 
structure.getResidueList(object) != null) {
+                                       setResidueSelection(chimera, structure, 
object, selected);
+                               } 
+                       }
+               }
+               chimera.modelChanged();
+       }
+
+       private void setResidueSelection(Chimera chimera, Structure structure, 
+                                        GraphObject object, boolean selected) {
+               String command = "select ";
+               if (!selected)
+                       command = "~select ";
+
+               List<String> residueList = structure.getResidueList(object);
+               if (residueList == null || residueList.size() == 0) return;
+
+               int model = structure.modelNumber();
+               if (chimera.getChimeraModel(model) == null) return;
+
+               String residues = "";
+               for (String residue: residueList) {
+                       residues = residues.concat(residue+",");
+               }
+               residues = residues.substring(0,residues.length()-1);
+               command = command.concat(" 
#"+structure.modelNumber()+":"+residues);
+               chimera.select(command);
+       }
+}

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