Search in sources :

Example 6 with CySubNetwork

use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.

the class NullNetworkViewPanel method update.

private void update() {
    if (networkView != null) {
        getInfoIconLabel().setText(ICON_EXTERNAL_LINK_SQUARE);
        getInfoIconLabel().setToolTipText("This view is detached");
    } else if (network != null) {
        getInfoIconLabel().setText(ICON_SHARE_ALT);
        getInfoIconLabel().setToolTipText(network instanceof CySubNetwork ? "This network has no views" : "A network collection cannot have views");
    } else {
        getInfoIconLabel().setText(null);
        getInfoIconLabel().setToolTipText(null);
    }
    getInfoIconLabel().setVisible(networkView != null || network != null);
    getInfoLabel().setVisible(network == null && networkView == null);
    getCreateViewButton().setVisible(networkView == null && network instanceof CySubNetwork);
    getReattachViewButton().setVisible(networkView != null);
    sep2.setVisible(networkView != null);
    if (networkView != null)
        getTitleLabel().setText(ViewUtil.getTitle(networkView));
    else if (network != null)
        getTitleLabel().setText(ViewUtil.getName(network));
    else
        getTitleLabel().setText(null);
    final Dimension d = new Dimension(1, network != null && networkView == null ? getCreateViewButton().getPreferredSize().height : 0);
    getGapLabel().setPreferredSize(d);
    getGapLabel().setMinimumSize(d);
    getGapLabel().setMaximumSize(d);
    getGapLabel().setSize(d);
    getToolBar().updateUI();
}
Also used : Dimension(java.awt.Dimension) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Example 7 with CySubNetwork

use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.

the class NetworkViewMainPanel method init.

private void init() {
    setBorder(BorderFactory.createMatteBorder(0, 1, 1, 1, UIManager.getColor("Separator.foreground")));
    setLayout(new BorderLayout());
    add(getContentPane(), BorderLayout.CENTER);
    // Add Listeners
    nullViewPanel.getCreateViewButton().addActionListener(evt -> {
        if (nullViewPanel.getNetwork() instanceof CySubNetwork) {
            final CreateNetworkViewTaskFactory factory = serviceRegistrar.getService(CreateNetworkViewTaskFactory.class);
            final DialogTaskManager taskManager = serviceRegistrar.getService(DialogTaskManager.class);
            taskManager.execute(factory.createTaskIterator(Collections.singleton(nullViewPanel.getNetwork())));
        }
    });
    nullViewPanel.getInfoIconLabel().addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (!e.isPopupTrigger() && nullViewPanel.getNetworkView() != null) {
                final NetworkViewFrame frame = getNetworkViewFrame(nullViewPanel.getNetworkView());
                if (frame != null)
                    showViewFrame(frame);
            }
        }
    });
    nullViewPanel.getReattachViewButton().addActionListener(evt -> {
        if (nullViewPanel.getNetworkView() != null)
            reattachNetworkView(nullViewPanel.getNetworkView());
    });
    networkViewGrid.addPropertyChangeListener("selectedNetworkViews", evt -> {
        // Just fire the same event
        firePropertyChange("selectedNetworkViews", evt.getOldValue(), evt.getNewValue());
    });
    networkViewGrid.addPropertyChangeListener("currentNetworkView", evt -> {
        final CyNetworkView curView = (CyNetworkView) evt.getNewValue();
        for (NetworkViewContainer vc : getAllNetworkViewContainers()) vc.setCurrent(vc.getNetworkView().equals(curView));
    });
    Toolkit.getDefaultToolkit().addAWTEventListener(mousePressedAWTEventListener, MouseEvent.MOUSE_EVENT_MASK);
    // Update
    updateGrid();
}
Also used : CreateNetworkViewTaskFactory(org.cytoscape.task.create.CreateNetworkViewTaskFactory) MouseEvent(java.awt.event.MouseEvent) BorderLayout(java.awt.BorderLayout) MouseAdapter(java.awt.event.MouseAdapter) DialogTaskManager(org.cytoscape.work.swing.DialogTaskManager) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Example 8 with CySubNetwork

use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.

the class CyNetworkAutoDeleteTest method testUndoDeletedEdge.

@Test
public void testUndoDeletedEdge() {
    CyNetwork network1 = TestCyNetworkFactory.getInstance();
    CyRootNetwork rootNetwork = ((CySubNetwork) network1).getRootNetwork();
    CyNode n1 = network1.addNode();
    CyNode n2 = network1.addNode();
    CyNode n3 = network1.addNode();
    CyEdge e1 = network1.addEdge(n1, n2, false);
    CyEdge e2 = network1.addEdge(n2, n3, false);
    CyNetwork network2 = rootNetwork.addSubNetwork(Arrays.asList(n1, n2, n3), Arrays.asList(e1, e2));
    network1.removeNodes(Collections.singleton(n1));
    network2.removeNodes(Collections.singleton(n1));
    assertFalse(rootNetwork.containsEdge(e1));
    assertFalse(rootNetwork.containsNode(n1));
    // restoring the edge should automatically restore its source and target nodes as well
    ((CySubNetwork) network1).addEdge(e1);
    assertTrue(rootNetwork.containsNode(n1));
    assertTrue(network1.containsNode(n1));
    assertFalse(network2.containsNode(n1));
    assertTrue(rootNetwork.containsEdge(e1));
    assertTrue(network1.containsEdge(e1));
    assertFalse(network2.containsEdge(e1));
}
Also used : CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) Test(org.junit.Test)

Example 9 with CySubNetwork

use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.

the class CyNetworkAutoDeleteTest method testRestoreEdge.

@Test
public void testRestoreEdge() {
    CyNetwork network1 = TestCyNetworkFactory.getInstance();
    CyRootNetwork rootNetwork = ((CySubNetwork) network1).getRootNetwork();
    CyNode n1 = network1.addNode();
    CyNode n2 = network1.addNode();
    CyNode n3 = network1.addNode();
    CyEdge e1 = network1.addEdge(n1, n2, false);
    CyEdge e2 = network1.addEdge(n2, n3, false);
    CyNetwork network2 = rootNetwork.addSubNetwork(Arrays.asList(n1, n2, n3), Arrays.asList(e1, e2));
    network1.removeEdges(Arrays.asList(e1));
    network2.removeEdges(Arrays.asList(e1));
    assertFalse(rootNetwork.containsEdge(e1));
    rootNetwork.restoreEdge(e1);
    assertTrue(rootNetwork.containsEdge(e1));
}
Also used : CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) Test(org.junit.Test)

Example 10 with CySubNetwork

use of org.cytoscape.model.subnetwork.CySubNetwork in project cytoscape-impl by cytoscape.

the class CyNetworkAutoDeleteTest method testSubnetworkWorkaround.

@Test
public void testSubnetworkWorkaround() {
    CyNetwork network1 = TestCyNetworkFactory.getInstance();
    CyRootNetwork rootNetwork = ((CySubNetwork) network1).getRootNetwork();
    CyNode n1 = network1.addNode();
    CyNode n2 = network1.addNode();
    CyNode n3 = network1.addNode();
    CyNode n4 = network1.addNode();
    CyEdge e1 = network1.addEdge(n1, n2, false);
    CyEdge e2 = network1.addEdge(n2, n3, false);
    CyNetwork network2 = rootNetwork.addSubNetwork(Arrays.asList(n1, n2, n3, n4), Arrays.asList(e1, e2));
    // will also cause n2 to be saved because its attached to e1
    rootNetwork.addSubNetwork(Arrays.asList(n1), Arrays.asList(e1));
    network1.removeEdges(Arrays.asList(e1));
    network2.removeEdges(Arrays.asList(e1));
    // additional subnetwork keeps e1 alive
    assertTrue(rootNetwork.containsEdge(e1));
    assertTrue(rootNetwork.containsNode(n1));
    assertTrue(rootNetwork.containsNode(n2));
    assertTrue(rootNetwork.containsNode(n3));
    assertTrue(rootNetwork.containsNode(n4));
    assertTrue(rootNetwork.containsEdge(e2));
    rootNetwork.removeSubNetwork((CySubNetwork) network1);
    rootNetwork.removeSubNetwork((CySubNetwork) network2);
    // should flush nodes/edges not in the additional subnetwork
    assertTrue(rootNetwork.containsEdge(e1));
    assertTrue(rootNetwork.containsNode(n1));
    assertTrue(rootNetwork.containsNode(n2));
    assertFalse(rootNetwork.containsNode(n3));
    assertFalse(rootNetwork.containsNode(n4));
    assertFalse(rootNetwork.containsEdge(e2));
}
Also used : CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) Test(org.junit.Test)

Aggregations

CySubNetwork (org.cytoscape.model.subnetwork.CySubNetwork)88 CyNode (org.cytoscape.model.CyNode)44 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)35 CyNetwork (org.cytoscape.model.CyNetwork)31 CyEdge (org.cytoscape.model.CyEdge)28 Test (org.junit.Test)19 CyRow (org.cytoscape.model.CyRow)15 ArrayList (java.util.ArrayList)12 CyTable (org.cytoscape.model.CyTable)11 CyNetworkView (org.cytoscape.view.model.CyNetworkView)11 HashSet (java.util.HashSet)7 CyGroup (org.cytoscape.group.CyGroup)7 HashMap (java.util.HashMap)6 CyNetworkManager (org.cytoscape.model.CyNetworkManager)6 CyApplicationManager (org.cytoscape.application.CyApplicationManager)5 CyEventHelper (org.cytoscape.event.CyEventHelper)5 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)5 Dimension (java.awt.Dimension)3 GroupCollapsedEvent (org.cytoscape.group.events.GroupCollapsedEvent)3 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)3