Search in sources :

Example 11 with NetworkViewRenderer

use of org.cytoscape.application.NetworkViewRenderer in project cytoscape-impl by cytoscape.

the class LoadMultipleNetworksTask method init.

private void init() {
    // otherwise let the reader's tunables handle it.
    if (readers != null && readers.size() > 1) {
        // Initialize column list
        if (rootNetwork != null)
            setTargetColumnList(getTargetColumns(rootNetwork));
        else
            setTargetColumnList(new ListSingleSelection<>());
        // Initialize renderer list
        final List<NetworkViewRenderer> renderers = new ArrayList<>();
        NetworkViewRenderer defViewRenderer = null;
        final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
        final Set<NetworkViewRenderer> rendererSet = applicationManager.getNetworkViewRendererSet();
        // so the combo-box does not appear to the user, since there is nothing to select anyway.
        if (rendererSet.size() > 1) {
            renderers.addAll(rendererSet);
            Collections.sort(renderers, new Comparator<NetworkViewRenderer>() {

                @Override
                public int compare(NetworkViewRenderer r1, NetworkViewRenderer r2) {
                    return r1.toString().compareToIgnoreCase(r2.toString());
                }
            });
        }
        defViewRenderer = applicationManager.getDefaultNetworkViewRenderer();
        rendererList = new ListSingleSelection<>(renderers);
        if (defViewRenderer != null && renderers.contains(defViewRenderer))
            rendererList.setSelectedValue(defViewRenderer);
    }
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) ListSingleSelection(org.cytoscape.work.util.ListSingleSelection) ArrayList(java.util.ArrayList) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer)

Example 12 with NetworkViewRenderer

use of org.cytoscape.application.NetworkViewRenderer in project cytoscape-impl by cytoscape.

the class LoadMultipleNetworksTask method run.

@Override
public void run(TaskMonitor taskMonitor) throws Exception {
    this.taskMonitor = taskMonitor;
    if (readers == null && readers.isEmpty())
        throw new IllegalArgumentException("No network reader specified.");
    taskMonitor.setTitle("Import Networks");
    taskMonitor.setProgress(0.0);
    final String rootNetName = rootNetwork != null ? rootNetwork.getRow(rootNetwork).get(CyRootNetwork.NAME, String.class) : null;
    final String targetColumn = targetColumnList != null ? targetColumnList.getSelectedValue() : null;
    final NetworkViewRenderer renderer = rendererList != null ? rendererList.getSelectedValue() : null;
    final float total = readers.size();
    int count = 1;
    for (Entry<String, CyNetworkReader> entry : readers.entrySet()) {
        if (cancelled)
            return;
        final CyNetworkReader r = entry.getValue();
        if (r instanceof AbstractCyNetworkReader) {
            AbstractCyNetworkReader ar = (AbstractCyNetworkReader) r;
            if (rootNetName != null) {
                ListSingleSelection<String> ls = new ListSingleSelection<>(Collections.singletonList(rootNetName));
                ls.setSelectedValue(rootNetName);
                ar.setRootNetworkList(ls);
            } else {
                // Force "create new collection"
                ar.setRootNetworkList(new ListSingleSelection<>(Collections.emptyList()));
                ar.setTargetColumnList(new ListSingleSelection<>(Collections.emptyList()));
            }
            if (targetColumn != null) {
                ListSingleSelection<String> ls = new ListSingleSelection<>(Collections.singletonList(targetColumn));
                ls.setSelectedValue(targetColumn);
                ar.setTargetColumnList(ls);
            }
            if (renderer != null) {
                ListSingleSelection<NetworkViewRenderer> ls = new ListSingleSelection<>(Collections.singletonList(renderer));
                ls.setSelectedValue(renderer);
                ar.setNetworkViewRendererList(ls);
            }
        }
        name = entry.getKey();
        loadNetwork(r);
        taskMonitor.setProgress(count / total);
        count++;
    }
}
Also used : AbstractCyNetworkReader(org.cytoscape.io.read.AbstractCyNetworkReader) CyNetworkReader(org.cytoscape.io.read.CyNetworkReader) ListSingleSelection(org.cytoscape.work.util.ListSingleSelection) AbstractCyNetworkReader(org.cytoscape.io.read.AbstractCyNetworkReader) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer)

Example 13 with NetworkViewRenderer

use of org.cytoscape.application.NetworkViewRenderer in project cytoscape-impl by cytoscape.

the class AbstractNetworkFromSelectionTask method run.

@Override
public void run(TaskMonitor tm) {
    if (parentNetwork == null) {
        tm.showMessage(TaskMonitor.Level.ERROR, "Source network must be specified.");
        return;
    }
    tm.setProgress(0.0);
    final Collection<CyNetworkView> views = networkViewManager.getNetworkViews(parentNetwork);
    CyNetworkView sourceView = null;
    if (views.size() != 0)
        sourceView = views.iterator().next();
    tm.setProgress(0.1);
    // Get the selected nodes
    final Set<CyNode> nodes = getNodes(parentNetwork);
    tm.setProgress(0.2);
    if (// return;
    nodes.size() <= 0)
        throw new IllegalArgumentException("No nodes are selected.");
    // create subnetwork and add selected nodes and appropriate edges
    newNet = rootNetMgr.getRootNetwork(parentNetwork).addSubNetwork();
    // We need to cpy the columns to local tables, since copying them to default table will duplicate the virtual columns.
    addColumns(parentNetwork.getTable(CyNode.class, CyNetwork.LOCAL_ATTRS), newNet.getTable(CyNode.class, CyNetwork.LOCAL_ATTRS));
    addColumns(parentNetwork.getTable(CyEdge.class, CyNetwork.LOCAL_ATTRS), newNet.getTable(CyEdge.class, CyNetwork.LOCAL_ATTRS));
    addColumns(parentNetwork.getTable(CyNetwork.class, CyNetwork.LOCAL_ATTRS), newNet.getTable(CyNetwork.class, CyNetwork.LOCAL_ATTRS));
    tm.setProgress(0.3);
    for (final CyNode node : nodes) {
        newNet.addNode(node);
        cloneRow(parentNetwork.getRow(node), newNet.getRow(node));
        // Set rows and edges to not selected state to avoid conflicts with table browser
        newNet.getRow(node).set(CyNetwork.SELECTED, false);
        if (groupMgr.isGroup(node, parentNetwork)) {
            CyGroup group = groupMgr.getGroup(node, parentNetwork);
            GroupUtils.addGroupToNetwork(group, parentNetwork, newNet);
        }
    }
    tm.setProgress(0.4);
    for (final CyEdge edge : getEdges(parentNetwork)) {
        newNet.addEdge(edge);
        cloneRow(parentNetwork.getRow(edge), newNet.getRow(edge));
        // Set rows and edges to not selected state to avoid conflicts with table browser
        newNet.getRow(edge).set(CyNetwork.SELECTED, false);
    }
    tm.setProgress(0.5);
    newNet.getRow(newNet).set(CyNetwork.NAME, getNetworkName());
    DataUtils.saveParentNetworkSUID(newNet, parentNetwork.getSUID());
    networkManager.addNetwork(newNet, false);
    tm.setProgress(0.6);
    // create the view in a separate task
    final Set<CyNetwork> networks = new HashSet<CyNetwork>();
    networks.add(newNet);
    // Pick a CyNetworkViewFactory that is appropriate for the sourceView
    CyNetworkViewFactory sourceViewFactory = viewFactory;
    if (sourceView != null) {
        NetworkViewRenderer networkViewRenderer = appMgr.getNetworkViewRenderer(sourceView.getRendererId());
        if (networkViewRenderer != null) {
            sourceViewFactory = networkViewRenderer.getNetworkViewFactory();
        }
    }
    final CreateNetworkViewTask createViewTask = new CreateNetworkViewTask(undoSupport, networks, sourceViewFactory, networkViewManager, networkManager, null, eventHelper, vmMgr, renderingEngineMgr, appMgr, sourceView, serviceRegistrar);
    insertTasksAfterCurrentTask(createViewTask);
    /*
		insertTasksAfterCurrentTask(createViewTask, new AbstractTask() {
			@Override
			@SuppressWarnings("unchecked")
			public void run(final TaskMonitor tm) throws Exception {
				// Select the new view
				tm.setProgress(0.0);
				final List<CyNetworkView> createdViews = (List<CyNetworkView>) createViewTask.getResults(List.class);
				
				if (!createdViews.isEmpty()) {
					CyNetworkView nv = createdViews.get(createdViews.size() - 1);

					if (nv != null) {
						insertTasksAfterCurrentTask(new RegisterNetworkTask(nv, null, networkManager, vmMgr, appMgr, networkViewManager));
						return;
					}
				}
				insertTasksAfterCurrentTask(new RegisterNetworkTask(newNet, networkManager, vmMgr, appMgr, networkViewManager));
				
				tm.setProgress(1.0);
			}
		});
		*/
    tm.setProgress(1.0);
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) CyGroup(org.cytoscape.group.CyGroup) CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CreateNetworkViewTask(org.cytoscape.task.internal.view.CreateNetworkViewTask) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView) HashSet(java.util.HashSet) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer)

Example 14 with NetworkViewRenderer

use of org.cytoscape.application.NetworkViewRenderer in project cytoscape-impl by cytoscape.

the class GenericXGMMLReader method buildCyNetworkView.

@Override
public CyNetworkView buildCyNetworkView(final CyNetwork network) {
    NetworkViewRenderer networkViewRenderer = null;
    if (readDataMgr.getRendererId() != null)
        networkViewRenderer = cyApplicationManager.getNetworkViewRenderer(readDataMgr.getRendererId());
    // If the XGMML has no renderer ID info or a NetworkViewRenderer with that ID can't be found,
    // just use the passed CyNetworkViewFactory.
    // Otherwise use the factory provided by the specified NetworkViewRenderer.
    final CyNetworkViewFactory netViewFactory = networkViewRenderer != null ? networkViewRenderer.getNetworkViewFactory() : getNetworkViewFactory();
    final CyNetworkView netView = netViewFactory.createNetworkView(network);
    setNetworkViewProperties(netView);
    if (netView.getModel().getNodeCount() > 0) {
        final Collection<View<CyNode>> nodes = netView.getNodeViews();
        final Collection<View<CyEdge>> edges = netView.getEdgeViews();
        for (final View<CyNode> nodeView : nodes) setNodeViewProperties(netView, nodeView);
        for (final View<CyEdge> edgeView : edges) setEdgeViewProperties(netView, edgeView);
    }
    if (!readDataMgr.isSessionFormat())
        readDataMgr.updateGroupNodes(netView);
    return netView;
}
Also used : CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer)

Example 15 with NetworkViewRenderer

use of org.cytoscape.application.NetworkViewRenderer in project cytoscape-api by cytoscape.

the class AbstractCyNetworkReader method init.

private void init() {
    name2RootMap = getRootNetworkMap();
    nodeMap = new HashMap<>(10000);
    // initialize the network Collection
    final List<String> rootNames = new ArrayList<>();
    rootNames.addAll(name2RootMap.keySet());
    if (!rootNames.isEmpty()) {
        sort(rootNames);
        rootNames.add(0, CREATE_NEW_COLLECTION_STRING);
    }
    final ListSingleSelection<String> rootNetList = new ListSingleSelection<>(rootNames);
    final CyNetwork net = cyApplicationManager != null ? cyApplicationManager.getCurrentNetwork() : null;
    final CyRootNetwork rootNet = net != null ? cyRootNetworkManager.getRootNetwork(net) : null;
    final String name = rootNet != null ? rootNet.getRow(rootNet).get(CyRootNetwork.NAME, String.class) : CREATE_NEW_COLLECTION_STRING;
    if (rootNames.contains(name))
        rootNetList.setSelectedValue(name);
    else if (rootNames.contains(CREATE_NEW_COLLECTION_STRING))
        rootNetList.setSelectedValue(CREATE_NEW_COLLECTION_STRING);
    setRootNetworkList(rootNetList);
    // initialize renderer list
    final List<NetworkViewRenderer> renderers = new ArrayList<>();
    NetworkViewRenderer defViewRenderer = null;
    if (cyApplicationManager != null) {
        final Set<NetworkViewRenderer> rendererSet = cyApplicationManager.getNetworkViewRendererSet();
        // so the combo-box does not appear to the user, since there is nothing to select anyway.
        if (rendererSet.size() > 1) {
            renderers.addAll(rendererSet);
            Collections.sort(renderers, new Comparator<NetworkViewRenderer>() {

                @Override
                public int compare(NetworkViewRenderer r1, NetworkViewRenderer r2) {
                    return r1.toString().compareToIgnoreCase(r2.toString());
                }
            });
        }
        defViewRenderer = cyApplicationManager.getDefaultNetworkViewRenderer();
    }
    rendererList = new ListSingleSelection<>(renderers);
    if (defViewRenderer != null && renderers.contains(defViewRenderer))
        rendererList.setSelectedValue(defViewRenderer);
}
Also used : ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) ListSingleSelection(org.cytoscape.work.util.ListSingleSelection) CyRootNetwork(org.cytoscape.model.subnetwork.CyRootNetwork) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer)

Aggregations

NetworkViewRenderer (org.cytoscape.application.NetworkViewRenderer)15 CyNetwork (org.cytoscape.model.CyNetwork)7 CyApplicationManager (org.cytoscape.application.CyApplicationManager)6 ListSingleSelection (org.cytoscape.work.util.ListSingleSelection)5 CyNetworkViewFactory (org.cytoscape.view.model.CyNetworkViewFactory)4 ArrayList (java.util.ArrayList)3 CyNetworkView (org.cytoscape.view.model.CyNetworkView)3 VisualLexicon (org.cytoscape.view.model.VisualLexicon)3 BasicVisualLexicon (org.cytoscape.view.presentation.property.BasicVisualLexicon)3 HashSet (java.util.HashSet)2 CyEdge (org.cytoscape.model.CyEdge)2 CyNode (org.cytoscape.model.CyNode)2 CyRootNetwork (org.cytoscape.model.subnetwork.CyRootNetwork)2 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)2 Dimension (java.awt.Dimension)1 Paint (java.awt.Paint)1 LinkedHashSet (java.util.LinkedHashSet)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1 ChartType (org.baderlab.csplugins.enrichmentmap.style.ChartType)1