Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package coolmapplugin.actions; import com.google.common.collect.Range; import coolmap.application.CoolMapMaster; import coolmap.application.widget.impl.console.CMConsole; import coolmap.canvas.CoolMapView; import coolmap.data.CoolMapObject; import coolmapplugin.util.CMCyCommunicationUtil; import java.awt.event.ActionEvent; import java.util.List; import javax.swing.AbstractAction; import java.util.LinkedList; /** * * @author Keqiang Li */ public class MapSelectedToCytoscape extends AbstractAction { @Override public void actionPerformed(ActionEvent e) { List<Object> selectedElements = getSelectedColumnAndRowNames(); if (selectedElements == null || selectedElements.isEmpty()) { return; } Long curNetwork = CMCyCommunicationUtil.getSelectedNetwork(); boolean result = CMCyCommunicationUtil.setNodesSelectedByNodeNames(curNetwork.toString(), selectedElements, true); if (!result) { CMConsole.logError("Failed to Map. Couldn't communicate with Cytoscape"); } } private LinkedList<Object> getSelectedColumnAndRowNames() { try { CoolMapObject obj = CoolMapMaster.getActiveCoolMapObject(); CoolMapView coolMapView = obj.getCoolMapView(); List<Range<Integer>> columnList = coolMapView.getSelectedColumns(); List<Range<Integer>> rowList = coolMapView.getSelectedRows(); LinkedList<Object> names = new LinkedList<>(); for (Range<Integer> range : columnList) { for (int i = range.lowerEndpoint(); i < range.upperEndpoint(); ++i) { String columnName = obj.getViewNodeColumn(i).getName(); names.add(columnName); } } for (Range<Integer> range : rowList) { for (int i = range.lowerEndpoint(); i < range.upperEndpoint(); ++i) { String rowName = obj.getViewNodeRow(i).getName(); names.add(rowName); } } return names; } catch (Exception e) { CMConsole.logError("Failed to get selected columns and rows. Internal Error : " + e.getMessage()); } return null; } }