Changeset 288


Ignore:
Timestamp:
Mar 21, 2012, 3:30:53 PM (5 years ago)
Author:
tim.te.beek@…
Message:

Add mode to select source/target nodes for selected edges

Location:
trunk/piqc-plugin/src/main/java/nl/nbic/brs/piqc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/piqc-plugin/src/main/java/nl/nbic/brs/piqc/PIQCPlugin.java

    r287 r288  
    2424
    2525                                // Add Source/Target node selection in the select menu
    26                                 JMenu selectMenu = Cytoscape.getDesktop().getCyMenus().getSelectMenu();
    27                                 selectMenu.add(new SelectSourceTargetNodeAction(true));
    28                                 selectMenu.add(new SelectSourceTargetNodeAction(false));
     26                                JMenu selectMenu = new JMenu("Source/Target nodes selection");
     27                                selectMenu.add(new SelectSourceTargetNodeAction(true, false));
     28                                selectMenu.add(new SelectSourceTargetNodeAction(false, false));
     29                                selectMenu.add(new SelectSourceTargetNodeAction(true, true));
     30                                selectMenu.add(new SelectSourceTargetNodeAction(false, true));
     31                                Cytoscape.getDesktop().getCyMenus().getSelectMenu().add(selectMenu);
    2932                        }
    3033                });
  • trunk/piqc-plugin/src/main/java/nl/nbic/brs/piqc/SelectSourceTargetNodeAction.java

    r287 r288  
    33import java.awt.event.ActionEvent;
    44import java.util.ArrayList;
     5import java.util.Collection;
    56import java.util.List;
    67import java.util.Set;
     
    1314import cytoscape.view.CyNetworkView;
    1415
     16/**
     17 * CytoscapeAction to select Source or Target nodes either within an entire network, or only for selected edges.
     18 */
    1519public class SelectSourceTargetNodeAction extends CytoscapeAction {
    1620        private final boolean   source;
     21        private final boolean   forSelectedEdges;
    1722
    18         public SelectSourceTargetNodeAction(final boolean source) {
    19                 super("All " + (source ? "Source" : "Target") + " nodes");
     23        /**
     24         * Construct a SelectSourceTargetNodeAction with specified parameters.
     25         *
     26         * @param source
     27         *            select Source nodes if true, Target nodes if false
     28         * @param forSelectedEdges
     29         *            only select source/target nodes of selected edges
     30         */
     31        public SelectSourceTargetNodeAction(final boolean source, final boolean forSelectedEdges) {
     32                super("Select " + //
     33                (forSelectedEdges ? "" : "All ") + //
     34                (source ? "Source" : "Target") + //
     35                " nodes" + //
     36                (forSelectedEdges ? " for selected edges" : ""));
    2037                this.source = source;
     38                this.forSelectedEdges = forSelectedEdges;
    2139        }
    2240
     
    2846
    2947                // Change selection in the current network
    30                 selectNodes(network, source);
     48                selectNodes(network, source, forSelectedEdges);
    3149
    3250                // Update view to show change in selection for currentNetwork
     
    3553
    3654        /**
    37          * Select Source or Target nodes in
     55         * Select Source or Target nodes in network using the source & forSelectedEdges toggles.
    3856         *
    3957         * @param network
     
    4159         * @param source
    4260         *            select Source nodes if true, Target nodes if false
     61         * @param forSelectedEdges
     62         *            only select source/target nodes of selected edges
    4363         */
    44         public static void selectNodes(final CyNetwork network, final boolean source) {
    45                 // Clear currently selected nodes before we (re)select nodes
    46                 @SuppressWarnings("unchecked")
     64        @SuppressWarnings("unchecked")
     65        public static void selectNodes(final CyNetwork network, final boolean source, final boolean forSelectedEdges) {
     66                // Deselect currently selected nodes before we (re)select nodes
    4767                Set<CyNode> selectedNodes = network.getSelectedNodes();
    4868                // New list to prevent concurrent modification deep within Cytoscape
    4969                network.setSelectedNodeState(new ArrayList<CyNode>(selectedNodes), false);
    5070
    51                 // Retrieve edges, as from them we can retrieve nodes
    52                 @SuppressWarnings("unchecked")
    53                 List<CyEdge> edgesToLookThrough = network.edgesList();
     71                // The edges for which to retrieve nodes
     72                final Collection<CyEdge> edgesToLookThrough;
     73                if (forSelectedEdges)
     74                        // Use the user selected edged
     75                        edgesToLookThrough = network.getSelectedEdges();
     76                else
     77                        // Retrieve all edges
     78                        edgesToLookThrough = network.edgesList();
    5479
    5580                // Find the nodes we want to select by looking through edges
Note: See TracChangeset for help on using the changeset viewer.