Created
November 10, 2014 00:37
-
-
Save keiono/e069b47869056c5a0156 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package edu.ucsf.rbvi.internal.myapp.tasks; | |
| import java.util.Collection; | |
| import org.cytoscape.application.CyApplicationManager; | |
| import org.cytoscape.model.CyIdentifiable; | |
| import org.cytoscape.model.CyNetwork; | |
| import org.cytoscape.model.CyNode; | |
| import org.cytoscape.model.events.RowsSetEvent; | |
| import org.cytoscape.model.events.RowsSetListener; | |
| import org.cytoscape.model.events.RowSetRecord; | |
| import org.cytoscape.view.model.CyNetworkView; | |
| import org.cytoscape.view.model.View; | |
| import org.cytoscape.view.presentation.property.BasicVisualLexicon; | |
| import org.cytoscape.view.presentation.property.NodeShapeVisualProperty; | |
| import org.cytoscape.view.presentation.property.values.NodeShape; | |
| public class MySelectionListener implements RowsSetListener { | |
| private static final NodeShape SHAPES[] = { | |
| NodeShapeVisualProperty.DIAMOND, NodeShapeVisualProperty.ELLIPSE, | |
| NodeShapeVisualProperty.HEXAGON, NodeShapeVisualProperty.OCTAGON, | |
| NodeShapeVisualProperty.PARALLELOGRAM, | |
| NodeShapeVisualProperty.RECTANGLE, NodeShapeVisualProperty.ROUND_RECTANGLE, | |
| NodeShapeVisualProperty.TRIANGLE | |
| }; | |
| private final CyApplicationManager manager; | |
| private int shapeCount; | |
| public MySelectionListener(final CyApplicationManager mgr) { | |
| manager = mgr; | |
| shapeCount = 0; | |
| } | |
| public void handleEvent(final RowsSetEvent event) { | |
| // First see if this even has anything to do with selections | |
| if (!event.containsColumn(CyNetwork.SELECTED)) { | |
| // Nope, we're done | |
| return; | |
| } | |
| // For each selected node, get the view in the current network | |
| // and change the shape | |
| final CyNetworkView currentNetworkView = manager.getCurrentNetworkView(); | |
| final CyNetwork currentNetwork = currentNetworkView.getModel(); | |
| // Respond only to node selection... | |
| if (event.getSource() != currentNetwork.getDefaultNodeTable()) | |
| return; | |
| final Collection<RowSetRecord> records = event.getColumnRecords(CyNetwork.SELECTED); | |
| for (RowSetRecord record : records) { | |
| final Long suid = record.getRow().get(CyIdentifiable.SUID, Long.class); | |
| final Boolean value = (Boolean) record.getValue(); | |
| if (value) { | |
| final CyNode node = currentNetwork.getNode(suid); | |
| final View<CyNode> nodeView = currentNetworkView.getNodeView(node); | |
| // Now change the shape | |
| final NodeShape newShape = SHAPES[shapeCount++]; | |
| if (shapeCount >= SHAPES.length) { | |
| shapeCount = 0; | |
| } | |
| nodeView.setLockedValue(BasicVisualLexicon.NODE_SHAPE, newShape); | |
| } | |
| } | |
| // Refresh view | |
| currentNetworkView.updateView(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment