Search in sources :

Example 81 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.

the class LayoutEdgeTest method testLayoutEdgeConstructor2.

@Test
public void testLayoutEdgeConstructor2() {
    CyNetworkFactory nFactory = support.getNetworkFactory();
    CyNetwork newNetwork = nFactory.createNetwork();
    CyNode s = newNetwork.addNode();
    CyNode t = newNetwork.addNode();
    CyEdge e = newNetwork.addEdge(s, t, true);
    final CyNetworkViewFactory viewFactory = support.getNetworkViewFactory();
    CyNetworkView newView = viewFactory.createNetworkView(newNetwork);
    final View<CyNode> sourceView = newView.getNodeView(s);
    final View<CyNode> targetView = newView.getNodeView(t);
    assertNotNull(sourceView);
    assertNotNull(targetView);
    CyRow sRow = newNetwork.getRow(s);
    CyRow tRow = newNetwork.getRow(t);
    final LayoutNode layoutNodeS = new LayoutNode(sourceView, 0, sRow);
    final LayoutNode layoutNodeT = new LayoutNode(targetView, 1, tRow);
    final LayoutEdge layoutEdge2 = new LayoutEdge(e, layoutNodeS, layoutNodeT, newNetwork.getRow(e));
    assertNotNull(layoutEdge2);
}
Also used : CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkFactory(org.cytoscape.model.CyNetworkFactory) CyNode(org.cytoscape.model.CyNode) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge) CyNetworkView(org.cytoscape.view.model.CyNetworkView) Test(org.junit.Test)

Example 82 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.

the class PartitionUtilTest method testPartition.

@Test
public void testPartition() {
    NetworkViewTestSupport networkSupport = new NetworkViewTestSupport();
    CyNetwork network = networkSupport.getNetworkFactory().createNetwork();
    {
        // Partition 1
        CyNode n1 = network.addNode();
        CyNode n2 = network.addNode();
        CyNode n3 = network.addNode();
        CyNode n4 = network.addNode();
        network.addEdge(n1, n2, false);
        network.addEdge(n2, n3, false);
        network.addEdge(n3, n4, false);
    }
    {
        // Partition 2
        CyNode n1 = network.addNode();
        CyNode n2 = network.addNode();
        CyNode n3 = network.addNode();
        CyNode n4 = network.addNode();
        network.addEdge(n1, n2, false);
        network.addEdge(n2, n3, false);
        network.addEdge(n3, n4, false);
        // cycle
        network.addEdge(n4, n1, false);
    }
    {
        // Partition 3
        CyNode n1 = network.addNode();
        CyNode n2 = network.addNode();
        CyNode n3 = network.addNode();
        CyNode n4 = network.addNode();
        network.addEdge(n1, n2, true);
        network.addEdge(n1, n3, true);
        network.addEdge(n1, n4, true);
        network.addEdge(n2, n3, true);
        network.addEdge(n3, n4, true);
        network.addEdge(n4, n1, true);
    }
    CyNetworkView networkView = networkSupport.getNetworkViewFactory().createNetworkView(network);
    EdgeWeighter edgeWeighter = new EdgeWeighter();
    List<LayoutPartition> result = PartitionUtil.partition(networkView, false, edgeWeighter);
    assertNotNull(result);
    assertEquals(3, result.size());
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyNode(org.cytoscape.model.CyNode) NetworkViewTestSupport(org.cytoscape.ding.NetworkViewTestSupport) CyNetworkView(org.cytoscape.view.model.CyNetworkView) Test(org.junit.Test)

Example 83 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.

the class ImportTablePanel method attributeRadioButtonActionPerformed.

private void attributeRadioButtonActionPerformed(ActionEvent evt) {
    final CyNetwork network = serviceRegistrar.getService(CyApplicationManager.class).getCurrentNetwork();
    if (nodeRadioButton.isSelected()) {
        if (network != null)
            selectedAttributes = network.getDefaultNodeTable();
        objType = NODE;
    } else if (edgeRadioButton.isSelected()) {
        if (network != null)
            selectedAttributes = network.getDefaultEdgeTable();
        objType = EDGE;
    } else {
        logger.info("\nNote: ImportTextTableFDialog.attributeRadioButtonActionPerformed():Import network table not implemented yet!\n");
        objType = NETWORK;
    }
    updateMappingAttributeComboBox();
    setKeyList();
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNetwork(org.cytoscape.model.CyNetwork)

Example 84 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.

the class PopupMenuHelper method selectElementsFromSelectedRows.

private void selectElementsFromSelectedRows(final JTable table, final Class<? extends CyIdentifiable> tableType) {
    final Thread t = new Thread() {

        @Override
        public void run() {
            final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
            final CyNetwork net = applicationManager.getCurrentNetwork();
            if (net != null) {
                final BrowserTableModel tableModel = (BrowserTableModel) table.getModel();
                final int[] selectedRows = table.getSelectedRows();
                final Set<CyRow> targetRows = new HashSet<CyRow>();
                for (final int rowIndex : selectedRows) {
                    // Getting the row from data table solves the problem with hidden or moved SUID column.
                    // However, since the rows might be sorted we need to convert the index to model.
                    final ValidatedObjectAndEditString selected = (ValidatedObjectAndEditString) tableModel.getValueAt(table.convertRowIndexToModel(rowIndex), CyNetwork.SUID);
                    targetRows.add(tableModel.getRow(selected.getValidatedObject()));
                }
                final CyTable cyTable = tableType == CyNode.class ? net.getDefaultNodeTable() : net.getDefaultEdgeTable();
                for (final CyRow cyRow : cyTable.getAllRows()) cyRow.set(CyNetwork.SELECTED, targetRows.contains(cyRow));
                final CyNetworkView view = applicationManager.getCurrentNetworkView();
                if (view != null) {
                    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
                    eventHelper.flushPayloadEvents();
                    view.updateView();
                }
            }
        }
    };
    t.start();
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) ValidatedObjectAndEditString(org.cytoscape.browser.internal.util.ValidatedObjectAndEditString) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) Point(java.awt.Point) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView) HashSet(java.util.HashSet)

Example 85 with CyNetwork

use of org.cytoscape.model.CyNetwork in project cytoscape-impl by cytoscape.

the class TableBrowserToolBar method createNewAttribute.

private void createNewAttribute(final String type, boolean isShared) {
    try {
        final String[] existingAttrs = getAttributeArray();
        String newAttribName = null;
        do {
            newAttribName = JOptionPane.showInputDialog(this, "Column Name: ", "Create New " + type + " Column", JOptionPane.QUESTION_MESSAGE);
            if (newAttribName == null)
                return;
            newAttribName = newAttribName.trim();
            if (newAttribName.isEmpty()) {
                JOptionPane.showMessageDialog(null, "Column name must not be blank.", "Error", JOptionPane.ERROR_MESSAGE);
                newAttribName = null;
            } else if (Arrays.binarySearch(existingAttrs, newAttribName) >= 0) {
                JOptionPane.showMessageDialog(null, "Column " + newAttribName + " already exists.", "Error", JOptionPane.ERROR_MESSAGE);
                newAttribName = null;
            }
        } while (newAttribName == null);
        final CyTable attrs;
        if (isShared) {
            final CyNetwork network = serviceRegistrar.getService(CyApplicationManager.class).getCurrentNetwork();
            if (network instanceof CySubNetwork) {
                final CyRootNetwork rootNetwork = ((CySubNetwork) network).getRootNetwork();
                CyTable sharedTable = null;
                if (this.objType == CyNode.class)
                    sharedTable = rootNetwork.getSharedNodeTable();
                else if (this.objType == CyEdge.class)
                    sharedTable = rootNetwork.getSharedEdgeTable();
                else if (this.objType == CyNetwork.class)
                    sharedTable = rootNetwork.getSharedNetworkTable();
                else
                    throw new IllegalStateException("Object type is not valid.  This should not happen.");
                attrs = sharedTable;
            } else {
                throw new IllegalArgumentException("This is not a CySubNetwork and there is no shared table.");
            }
        } else {
            attrs = browserTableModel.getDataTable();
        }
        if (type.equals("String"))
            attrs.createColumn(newAttribName, String.class, false);
        else if (type.equals("Floating Point"))
            attrs.createColumn(newAttribName, Double.class, false);
        else if (type.equals("Integer"))
            attrs.createColumn(newAttribName, Integer.class, false);
        else if (type.equals("Long Integer"))
            attrs.createColumn(newAttribName, Long.class, false);
        else if (type.equals("Boolean"))
            attrs.createColumn(newAttribName, Boolean.class, false);
        else if (type.equals("String List"))
            attrs.createListColumn(newAttribName, String.class, false);
        else if (type.equals("Floating Point List"))
            attrs.createListColumn(newAttribName, Double.class, false);
        else if (type.equals("Integer List"))
            attrs.createListColumn(newAttribName, Integer.class, false);
        else if (type.equals("Long Integer List"))
            attrs.createListColumn(newAttribName, Long.class, false);
        else if (type.equals("Boolean List"))
            attrs.createListColumn(newAttribName, Boolean.class, false);
        else
            throw new IllegalArgumentException("unknown column type \"" + type + "\".");
    } catch (IllegalArgumentException e) {
        JOptionPane.showMessageDialog(null, e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
    }
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork)

Aggregations

CyNetwork (org.cytoscape.model.CyNetwork)517 CyNode (org.cytoscape.model.CyNode)183 CyNetworkView (org.cytoscape.view.model.CyNetworkView)129 CyEdge (org.cytoscape.model.CyEdge)108 Test (org.junit.Test)107 ArrayList (java.util.ArrayList)87 CyTable (org.cytoscape.model.CyTable)75 CyApplicationManager (org.cytoscape.application.CyApplicationManager)70 CyIdentifiable (org.cytoscape.model.CyIdentifiable)57 CyRow (org.cytoscape.model.CyRow)48 HashSet (java.util.HashSet)45 CyNetworkManager (org.cytoscape.model.CyNetworkManager)40 HashMap (java.util.HashMap)35 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)35 CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)32 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)31 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)30 AbstractNetworkReaderTest (org.cytoscape.io.internal.read.AbstractNetworkReaderTest)27 TaskIterator (org.cytoscape.work.TaskIterator)27 List (java.util.List)26