Search in sources :

Example 51 with CySubNetwork

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

the class NetworkMainPanel method maybeShowViewPopup.

private void maybeShowViewPopup(final SubNetworkPanel item) {
    final CySubNetwork network = item.getModel().getNetwork();
    if (viewDialog != null) {
        if (// Clicking the same item--will probably never happen
        viewDialog.getNetwork().equals(network))
            return;
        viewDialog.dispose();
    }
    if (item.getModel().getViewCount() > 0) {
        final Window windowAncestor = SwingUtilities.getWindowAncestor(item);
        final CyNetworkView currentView = serviceRegistrar.getService(CyApplicationManager.class).getCurrentNetworkView();
        viewDialog = new NetworkViewPreviewDialog(network, currentView, windowAncestor, serviceRegistrar);
        viewDialog.addWindowFocusListener(new WindowFocusListener() {

            @Override
            public void windowLostFocus(WindowEvent e) {
                viewDialog.dispose();
            }

            @Override
            public void windowGainedFocus(WindowEvent e) {
            }
        });
        viewDialog.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosed(WindowEvent e) {
                viewDialog = null;
            }
        });
        viewDialog.addKeyListener(new KeyAdapter() {

            @Override
            public void keyPressed(KeyEvent e) {
                if (e.getKeyCode() == KeyEvent.VK_ESCAPE)
                    viewDialog.dispose();
            }
        });
        viewDialog.addPropertyChangeListener("currentNetworkView", (PropertyChangeEvent evt) -> {
            // TODO Move to NetworkSelectionMediator
            serviceRegistrar.getService(CyApplicationManager.class).setCurrentNetworkView((CyNetworkView) evt.getNewValue());
        });
        final Point screenPt = item.getViewIconLabel().getLocationOnScreen();
        final Point compPt = item.getViewIconLabel().getLocation();
        int xOffset = screenPt.x - compPt.x - item.getViewIconLabel().getWidth() / 2;
        int yOffset = screenPt.y - compPt.y + item.getViewIconLabel().getBounds().height - 2;
        final Point pt = item.getViewIconLabel().getBounds().getLocation();
        pt.translate(xOffset, yOffset);
        viewDialog.setLocation(pt);
        viewDialog.setVisible(true);
        viewDialog.requestFocusInWindow();
    }
}
Also used : Window(java.awt.Window) PropertyChangeEvent(java.beans.PropertyChangeEvent) KeyAdapter(java.awt.event.KeyAdapter) WindowAdapter(java.awt.event.WindowAdapter) Point(java.awt.Point) Point(java.awt.Point) CyApplicationManager(org.cytoscape.application.CyApplicationManager) KeyEvent(java.awt.event.KeyEvent) WindowEvent(java.awt.event.WindowEvent) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) WindowFocusListener(java.awt.event.WindowFocusListener)

Example 52 with CySubNetwork

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

the class RootNetworkPanel method getDepth.

private int getDepth(final CySubNetwork net) {
    int depth = -1;
    CySubNetwork parent = net;
    do {
        parent = ViewUtil.getParent(parent, serviceRegistrar);
        depth++;
    } while (parent != null);
    return depth;
}
Also used : CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Example 53 with CySubNetwork

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

the class RootNetworkPanel method addItem.

public SubNetworkPanel addItem(final CySubNetwork network) {
    if (!getItems().containsKey(network)) {
        final SubNetworkPanelModel model = new SubNetworkPanelModel(network, serviceRegistrar);
        final SubNetworkPanel subNetPanel = new SubNetworkPanel(model, showIndentation, serviceRegistrar);
        subNetPanel.setAlignmentX(LEFT_ALIGNMENT);
        final CySubNetwork parentNet = ViewUtil.getParent(network, serviceRegistrar);
        if (parentNet == null) {
            // No parent network? So just add it to the end of the list...
            getSubNetListPanel().add(subNetPanel);
            getItems().put(network, subNetPanel);
        } else {
            // It has a parent network, so let's find the position where it must be inserted...
            final LinkedHashMap<CySubNetwork, SubNetworkPanel> newItems = new LinkedHashMap<>();
            // New item added to the map?
            boolean newItemAdded = false;
            boolean parentItemFound = false;
            for (Entry<CySubNetwork, SubNetworkPanel> entry : getItems().entrySet()) {
                if (!newItemAdded) {
                    if (!parentItemFound && entry.getKey().equals(parentNet)) {
                        // We found the parent of the new item
                        parentItemFound = true;
                    } else if (parentItemFound) {
                        // we know this is the position where the new item must be inserted
                        if (!entry.getValue().isDescendantOf(parentNet)) {
                            newItems.put(network, subNetPanel);
                            newItemAdded = true;
                        }
                    }
                }
                newItems.put(entry.getKey(), entry.getValue());
            }
            if (!newItemAdded) {
                // Just add the new item to the end...
                getSubNetListPanel().add(subNetPanel);
                getItems().put(network, subNetPanel);
            } else {
                // Rebuild the whole list...
                getSubNetListPanel().removeAll();
                getItems().clear();
                for (Entry<CySubNetwork, SubNetworkPanel> entry : newItems.entrySet()) {
                    getSubNetListPanel().add(entry.getValue());
                    getItems().put(entry.getKey(), entry.getValue());
                }
            }
        }
        updateRootPanel();
    }
    return getItems().get(network);
}
Also used : CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork) LinkedHashMap(java.util.LinkedHashMap)

Example 54 with CySubNetwork

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

the class NetworkMediator method handleEvent.

@Override
public void handleEvent(final NetworkAddedEvent e) {
    if (loadingSession)
        return;
    final CyNetwork net = e.getNetwork();
    invokeOnEDT(() -> {
        if (net instanceof CySubNetwork) {
            networkMainPanel.addNetwork((CySubNetwork) net);
            networkMainPanel.updateNodeEdgeCount();
        }
    });
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

Example 55 with CySubNetwork

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

the class NetworkLineParser method createNode.

private CyNode createNode(final String[] parts, final Integer nodeIndex) {
    CyNode node = null;
    if (nodeIndex.equals(-1) == false && (nodeIndex <= (parts.length - 1)) && (parts[nodeIndex] != null)) {
        if (this.nMap.get(parts[nodeIndex]) == null) {
            // Node does not exist yet, create it
            node = network.addNode();
            network.getRow(node).set("name", parts[nodeIndex]);
            nMap.put(parts[nodeIndex], rootNetwork.getNode(node.getSUID()));
            nodeList.add(node.getSUID());
        } else {
            // Node already exists in parent network
            CyNode parentNode = this.nMap.get(parts[nodeIndex]);
            CySubNetwork subnet = (CySubNetwork) network;
            subnet.addNode(parentNode);
            node = subnet.getNode(parentNode.getSUID());
        }
    }
    return node;
}
Also used : CyNode(org.cytoscape.model.CyNode) CySubNetwork(org.cytoscape.model.subnetwork.CySubNetwork)

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