Search in sources :

Example 1 with NetworkViewRenderer

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

the class NewEmptyNetworkTask method run.

@Override
public void run(final TaskMonitor tm) {
    tm.setProgress(0.0);
    final String networkCollectionName = rootNetworkList.getSelectedValue();
    if (networkCollectionName == null || networkCollectionName.equalsIgnoreCase(CRERATE_NEW_COLLECTION_STRING)) {
        // This is a new network collection, create a root network and a subnetwork, which is a base subnetwork
        subNetwork = (CySubNetwork) netFactory.createNetwork();
    } else {
        // Add a new subNetwork to the given collection
        subNetwork = this.name2RootMap.get(networkCollectionName).addSubNetwork();
    }
    tm.setProgress(0.2);
    final String networkName = namingUtil.getSuggestedNetworkTitle(name);
    subNetwork.getRow(subNetwork).set(CyNetwork.NAME, networkName);
    if (networkCollectionName == null || networkCollectionName.equalsIgnoreCase(CRERATE_NEW_COLLECTION_STRING)) {
        // Set the name of new root network
        final CyNetwork rootNetwork = subNetwork.getRootNetwork();
        rootNetwork.getRow(rootNetwork).set(CyNetwork.NAME, networkName);
    }
    NetworkViewRenderer nvRenderer = null;
    try {
        nvRenderer = renderers.getSelectedValue();
    } catch (ClassCastException cce) {
        tm.showMessage(TaskMonitor.Level.WARN, "Unknown renderer: " + renderers.getSelectedValue() + " using default renderer.");
    }
    if (nvRenderer == null)
        nvRenderer = appMgr.getDefaultNetworkViewRenderer();
    final CyNetworkViewFactory netViewFactory = nvRenderer.getNetworkViewFactory();
    tm.setProgress(0.4);
    view = netViewFactory.createNetworkView(subNetwork);
    tm.setProgress(0.6);
    netMgr.addNetwork(subNetwork, false);
    appMgr.setCurrentNetwork(subNetwork);
    tm.setProgress(0.8);
    // get the current style before registering the view!
    final VisualStyle style = vmMgr.getCurrentVisualStyle();
    netViewMgr.addNetworkView(view);
    tm.setProgress(0.9);
    applyVisualStyle(style);
    tm.setProgress(1.0);
}
Also used : CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CyNetwork(org.cytoscape.model.CyNetwork) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer)

Example 2 with NetworkViewRenderer

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

the class CombineReaderAndMappingTask method run.

@Override
public void run(TaskMonitor taskMonitor) throws Exception {
    this.taskMonitor = taskMonitor;
    // Pass the tunable values from this task to the helper task
    final String rootNetName = getRootNetworkList().getSelectedValue();
    final String targetColumn = getTargetColumnList().getSelectedValue();
    final NetworkViewRenderer renderer = getNetworkViewRendererList().getSelectedValue();
    if (rootNetName != null) {
        ListSingleSelection<String> ls = new ListSingleSelection<>(Collections.singletonList(rootNetName));
        ls.setSelectedValue(rootNetName);
        collectionHelper.setRootNetworkList(ls);
    } else {
        collectionHelper.setRootNetworkList(new ListSingleSelection<>(Collections.emptyList()));
        collectionHelper.setTargetColumnList(new ListSingleSelection<>(Collections.emptyList()));
    }
    if (targetColumn != null) {
        ListSingleSelection<String> ls = new ListSingleSelection<>(Collections.singletonList(targetColumn));
        ls.setSelectedValue(targetColumn);
        collectionHelper.setTargetColumnList(ls);
    }
    if (renderer != null) {
        ListSingleSelection<NetworkViewRenderer> ls = new ListSingleSelection<>(Collections.singletonList(renderer));
        ls.setSelectedValue(renderer);
        collectionHelper.setNetworkViewRendererList(ls);
    }
    // Run the helper task
    collectionHelper.run(taskMonitor);
    // Run the Import task
    importTask.setNodeMap(collectionHelper.getNodeMap());
    importTask.setRootNetwork(collectionHelper.getRootNetwork());
    importTask.setNetworkViewFactory(collectionHelper.getNetworkViewFactory());
    importTask.run(taskMonitor);
}
Also used : ListSingleSelection(org.cytoscape.work.util.ListSingleSelection) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer)

Example 3 with NetworkViewRenderer

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

the class DefaultNetworkViewFactory method createNetworkView.

@Override
public CyNetworkView createNetworkView(CyNetwork network) {
    NetworkViewRenderer renderer = applicationManager.getDefaultNetworkViewRenderer();
    CyNetworkViewFactory viewFactory = renderer.getNetworkViewFactory();
    return viewFactory.createNetworkView(network);
}
Also used : CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer)

Example 4 with NetworkViewRenderer

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

the class CyApplicationManagerImplTest method testGetDefaultViewRenderer.

@Test
public void testGetDefaultViewRenderer() {
    NetworkViewRenderer renderer1 = mock(NetworkViewRenderer.class);
    when(renderer1.getId()).thenReturn("C");
    NetworkViewRenderer renderer2 = mock(NetworkViewRenderer.class);
    when(renderer2.getId()).thenReturn("B");
    NetworkViewRenderer renderer3 = mock(NetworkViewRenderer.class);
    when(renderer3.getId()).thenReturn("A");
    appMgr.addNetworkViewRenderer(renderer1, Collections.EMPTY_MAP);
    appMgr.addNetworkViewRenderer(renderer2, Collections.EMPTY_MAP);
    appMgr.addNetworkViewRenderer(renderer3, Collections.EMPTY_MAP);
    assertEquals(3, appMgr.getNetworkViewRendererSet().size());
    assertEquals(renderer1, appMgr.getDefaultNetworkViewRenderer());
}
Also used : NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer) Test(org.junit.Test)

Example 5 with NetworkViewRenderer

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

the class VisualStyleTest method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    NetworkViewTestSupport nvts = new NetworkViewTestSupport();
    network = nvts.getNetworkFactory().createNetwork();
    node1 = network.addNode();
    node2 = network.addNode();
    node3 = network.addNode();
    edge = network.addEdge(node1, node2, true);
    CyTable nodeTable = network.getDefaultNodeTable();
    nodeTable.createColumn(attrName, String.class, true);
    nodeTable.getRow(node1.getSUID()).set(attrName, "red");
    nodeTable.getRow(node2.getSUID()).set(attrName, "green");
    nodeTable.getRow(node3.getSUID()).set(attrName, "foo");
    networkView = nvts.getNetworkViewFactory().createNetworkView(network);
    // Create root node.
    final NullVisualProperty minimalRoot = new NullVisualProperty("MINIMAL_ROOT", "Minimal Root Visual Property");
    final BasicVisualLexicon minimalLex = new BasicVisualLexicon(minimalRoot);
    final Set<VisualLexicon> lexSet = new HashSet<VisualLexicon>();
    lexSet.add(minimalLex);
    final VisualMappingFunctionFactory ptFactory = mock(VisualMappingFunctionFactory.class);
    eventHelper = mock(CyEventHelper.class);
    final RenderingEngineFactory<CyNetwork> reFatory = mock(RenderingEngineFactory.class);
    when(reFatory.getVisualLexicon()).thenReturn(minimalLex);
    final NetworkViewRenderer nvRenderer = mock(NetworkViewRenderer.class);
    when(nvRenderer.getRenderingEngineFactory(NetworkViewRenderer.DEFAULT_CONTEXT)).thenReturn(reFatory);
    final CyApplicationManager appManager = mock(CyApplicationManager.class);
    when(appManager.getCurrentNetworkViewRenderer()).thenReturn(nvRenderer);
    final CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
    when(serviceRegistrar.getService(CyApplicationManager.class)).thenReturn(appManager);
    VisualProperty<NullDataType> rootVisualProperty = mock(VisualProperty.class);
    BasicVisualLexicon lexicon = new BasicVisualLexicon(rootVisualProperty);
    vpSet = new HashSet<VisualProperty<Paint>>();
    vpSet.add(BasicVisualLexicon.NODE_BORDER_PAINT);
    vpSet.add(BasicVisualLexicon.NODE_FILL_COLOR);
    dependency = new VisualPropertyDependency<Paint>("dep1", "Dep 1", vpSet, lexicon);
    final VisualStyleFactoryImpl visualStyleFactory = new VisualStyleFactoryImpl(serviceRegistrar, ptFactory);
    originalTitle = "Style 1";
    newTitle = "Style 2";
    style = visualStyleFactory.createVisualStyle(originalTitle);
    style.setDefaultValue(NODE_SIZE, DEF_NODE_SIZE);
    style.setDefaultValue(NODE_FILL_COLOR, DEF_NODE_COLOR);
    reset(eventHelper);
}
Also used : NullVisualProperty(org.cytoscape.view.presentation.property.NullVisualProperty) CyEventHelper(org.cytoscape.event.CyEventHelper) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualLexicon(org.cytoscape.view.model.VisualLexicon) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) CyNetwork(org.cytoscape.model.CyNetwork) Paint(java.awt.Paint) NetworkViewTestSupport(org.cytoscape.ding.NetworkViewTestSupport) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) NullDataType(org.cytoscape.view.model.NullDataType) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualProperty(org.cytoscape.view.model.VisualProperty) NullVisualProperty(org.cytoscape.view.presentation.property.NullVisualProperty) HashSet(java.util.HashSet) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer) Before(org.junit.Before)

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