Search in sources :

Example 11 with RenderingEngineManager

use of org.cytoscape.view.presentation.RenderingEngineManager in project cytoscape-impl by cytoscape.

the class VisualStyleSerializerTest method setUp.

@Before
public void setUp() throws Exception {
    evtHelper = mock(CyEventHelper.class);
    twoDRoot = new NullVisualProperty("2D_ROOT", "2D Root Visual Property");
    lexicon = new BasicVisualLexicon(twoDRoot);
    VisualStyle defaultStyle = new DummyVisualStyle(DEFAULT_STYLE_NAME);
    final VisualStyleFactory visualStyleFactory = mockVisualStyleFactory(defaultStyle);
    final VisualMappingFunctionFactory discreteMappingFactory = mockMappingFunctionFactory(DiscreteMapping.class);
    final VisualMappingFunctionFactory continuousMappingFactory = mockMappingFunctionFactory(ContinuousMapping.class);
    final VisualMappingFunctionFactory passthroughMappingFactory = mockMappingFunctionFactory(PassthroughMapping.class);
    final RenderingEngineManager renderingEngineManager = mock(RenderingEngineManager.class);
    when(renderingEngineManager.getDefaultVisualLexicon()).thenReturn(lexicon);
    serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(evtHelper);
    when(serviceRegistrar.getService(VisualStyleFactory.class)).thenReturn(visualStyleFactory);
    when(serviceRegistrar.getService(RenderingEngineManager.class)).thenReturn(renderingEngineManager);
    when(serviceRegistrar.getService(VisualMappingFunctionFactory.class, "(mapping.type=discrete)")).thenReturn(discreteMappingFactory);
    when(serviceRegistrar.getService(VisualMappingFunctionFactory.class, "(mapping.type=continuous)")).thenReturn(continuousMappingFactory);
    when(serviceRegistrar.getService(VisualMappingFunctionFactory.class, "(mapping.type=passthrough)")).thenReturn(passthroughMappingFactory);
    final CalculatorConverterFactory calcFactory = new CalculatorConverterFactory();
    serializer = new VisualStyleSerializer(calcFactory, serviceRegistrar);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) NullVisualProperty(org.cytoscape.view.presentation.property.NullVisualProperty) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VisualStyleFactory(org.cytoscape.view.vizmap.VisualStyleFactory) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) Before(org.junit.Before)

Example 12 with RenderingEngineManager

use of org.cytoscape.view.presentation.RenderingEngineManager in project cytoscape-impl by cytoscape.

the class CySessionManagerImpl method restoreVisualStyles.

private void restoreVisualStyles(final CySession sess) {
    logger.debug("Restoring visual styles...");
    // Register visual styles
    final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
    final VisualStyle defStyle = vmMgr.getDefaultVisualStyle();
    final String DEFAULT_STYLE_NAME = defStyle.getTitle();
    final Set<VisualStyle> styles = sess.getVisualStyles();
    final Map<String, VisualStyle> stylesMap = new HashMap<>();
    final RenderingEngineManager engineManager = serviceRegistrar.getService(RenderingEngineManager.class);
    if (styles != null) {
        for (VisualStyle vs : styles) {
            if (vs.getTitle().equals(DEFAULT_STYLE_NAME)) {
                // Update the current default style, because it can't be replaced or removed
                updateVisualStyle(vs, defStyle, engineManager);
                vs = defStyle;
            }
            stylesMap.put(vs.getTitle(), vs);
            if (!vs.equals(defStyle))
                vmMgr.addVisualStyle(vs);
        }
    }
    // Set visual styles to network views
    final Map<CyNetworkView, String> viewStyleMap = sess.getViewVisualStyleMap();
    if (viewStyleMap != null) {
        for (Entry<CyNetworkView, String> entry : viewStyleMap.entrySet()) {
            final CyNetworkView netView = entry.getKey();
            final String stName = entry.getValue();
            VisualStyle vs = stylesMap.get(stName);
            if (vs == null)
                vs = defStyle;
            if (vs != null) {
                vmMgr.setVisualStyle(vs, netView);
                vs.apply(netView);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 13 with RenderingEngineManager

use of org.cytoscape.view.presentation.RenderingEngineManager in project cytoscape-impl by cytoscape.

the class NetworkViewMediator method findStylesWithMappedColumn.

private Set<VisualStyle> findStylesWithMappedColumn(final String columnName) {
    final Set<VisualStyle> styles = new HashSet<>();
    if (columnName != null) {
        final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
        final RenderingEngineManager engineMgr = serviceRegistrar.getService(RenderingEngineManager.class);
        final RenderingEngine<CyNetwork> renderer = appMgr.getCurrentRenderingEngine();
        final VisualLexicon lexicon = renderer != null ? renderer.getVisualLexicon() : engineMgr.getDefaultVisualLexicon();
        final Set<VisualProperty<?>> properties = lexicon.getAllVisualProperties();
        final VisualMappingManager vmm = serviceRegistrar.getService(VisualMappingManager.class);
        for (final VisualStyle vs : vmm.getAllVisualStyles()) {
            for (final VisualProperty<?> vp : properties) {
                // Check VisualMappingFunction
                final VisualMappingFunction<?, ?> fn = vs.getVisualMappingFunction(vp);
                if (fn != null && fn.getMappingColumnName().equalsIgnoreCase(columnName)) {
                    styles.add(vs);
                    break;
                }
                // Check MappableVisualPropertyValue
                final Object defValue = vs.getDefaultValue(vp);
                if (defValue instanceof MappableVisualPropertyValue) {
                    ((MappableVisualPropertyValue) defValue).update();
                    styles.add(vs);
                    break;
                }
            }
        }
    }
    return styles;
}
Also used : BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualLexicon(org.cytoscape.view.model.VisualLexicon) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) CyNetwork(org.cytoscape.model.CyNetwork) CyApplicationManager(org.cytoscape.application.CyApplicationManager) MappableVisualPropertyValue(org.cytoscape.view.presentation.property.values.MappableVisualPropertyValue) VisualProperty(org.cytoscape.view.model.VisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 14 with RenderingEngineManager

use of org.cytoscape.view.presentation.RenderingEngineManager in project cytoscape-impl by cytoscape.

the class NewNetworkSelectedNodesOnlyTaskFactoryTest method testObserver.

@Test
public void testObserver() throws Exception {
    NetworkViewTestSupport viewSupport = new NetworkViewTestSupport();
    NetworkTestSupport networkSupport = new NetworkTestSupport();
    CyNetworkFactory networkFactory = networkSupport.getNetworkFactory();
    UndoSupport undoSupport = mock(UndoSupport.class);
    CyRootNetworkManager crnf = new CyRootNetworkManagerImpl();
    CyNetworkViewFactory cnvf = viewSupport.getNetworkViewFactory();
    CyNetworkManager netmgr = mock(CyNetworkManager.class);
    CyNetworkViewManager networkViewManager = mock(CyNetworkViewManager.class);
    CyNetworkNaming naming = mock(CyNetworkNaming.class);
    VisualMappingManager vmm = mock(VisualMappingManager.class);
    CyApplicationManager appManager = mock(CyApplicationManager.class);
    CyEventHelper eventHelper = mock(CyEventHelper.class);
    CyGroupManager groupMgr = mock(CyGroupManager.class);
    RenderingEngineManager renderingEngineMgr = mock(RenderingEngineManager.class);
    CyLayoutAlgorithm defLayout = mock(CyLayoutAlgorithm.class);
    CyLayoutAlgorithmManager layoutMgr = mock(CyLayoutAlgorithmManager.class);
    when(layoutMgr.getDefaultLayout()).thenReturn(defLayout);
    CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(CyLayoutAlgorithmManager.class)).thenReturn(layoutMgr);
    NewNetworkSelectedNodesOnlyTaskFactoryImpl factory = new NewNetworkSelectedNodesOnlyTaskFactoryImpl(undoSupport, crnf, cnvf, netmgr, networkViewManager, naming, vmm, appManager, eventHelper, groupMgr, renderingEngineMgr, serviceRegistrar);
    CyNetwork network = networkFactory.createNetwork();
    CyNode node = network.addNode();
    network.getRow(node).set(CyNetwork.SELECTED, true);
    TaskObserver observer = mock(TaskObserver.class);
    TaskMonitor taskMonitor = mock(TaskMonitor.class);
    TaskIterator iterator = factory.createTaskIterator(network);
    while (iterator.hasNext()) {
        Task t = iterator.next();
        t.run(taskMonitor);
        if (t instanceof ObservableTask)
            observer.taskFinished((ObservableTask) t);
    }
    verify(observer, times(1)).taskFinished(any(ObservableTask.class));
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) Task(org.cytoscape.work.Task) ObservableTask(org.cytoscape.work.ObservableTask) CyNetwork(org.cytoscape.model.CyNetwork) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) ObservableTask(org.cytoscape.work.ObservableTask) TaskIterator(org.cytoscape.work.TaskIterator) TaskMonitor(org.cytoscape.work.TaskMonitor) CyLayoutAlgorithm(org.cytoscape.view.layout.CyLayoutAlgorithm) CyNode(org.cytoscape.model.CyNode) CyGroupManager(org.cytoscape.group.CyGroupManager) CyRootNetworkManager(org.cytoscape.model.subnetwork.CyRootNetworkManager) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) CyRootNetworkManagerImpl(org.cytoscape.model.internal.CyRootNetworkManagerImpl) NetworkTestSupport(org.cytoscape.model.NetworkTestSupport) NetworkViewTestSupport(org.cytoscape.ding.NetworkViewTestSupport) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyApplicationManager(org.cytoscape.application.CyApplicationManager) TaskObserver(org.cytoscape.work.TaskObserver) CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CyLayoutAlgorithmManager(org.cytoscape.view.layout.CyLayoutAlgorithmManager) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) CyNetworkFactory(org.cytoscape.model.CyNetworkFactory) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) Test(org.junit.Test)

Example 15 with RenderingEngineManager

use of org.cytoscape.view.presentation.RenderingEngineManager in project cytoscape-impl by cytoscape.

the class GroupIO method getVisualLexicon.

private VisualLexicon getVisualLexicon(final CyNetworkView netView) {
    final RenderingEngineManager rendererMgr = groupMgr.getService(RenderingEngineManager.class);
    final Collection<RenderingEngine<?>> renderingEngines = rendererMgr.getRenderingEngines(netView);
    if (renderingEngines != null && !renderingEngines.isEmpty())
        return renderingEngines.iterator().next().getVisualLexicon();
    return rendererMgr.getDefaultVisualLexicon();
}
Also used : RenderingEngine(org.cytoscape.view.presentation.RenderingEngine) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager)

Aggregations

RenderingEngineManager (org.cytoscape.view.presentation.RenderingEngineManager)19 CyApplicationManager (org.cytoscape.application.CyApplicationManager)10 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)8 CyNetwork (org.cytoscape.model.CyNetwork)7 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)7 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)7 CyNetworkManager (org.cytoscape.model.CyNetworkManager)6 CyNetworkViewFactory (org.cytoscape.view.model.CyNetworkViewFactory)6 CyEventHelper (org.cytoscape.event.CyEventHelper)5 CyGroupManager (org.cytoscape.group.CyGroupManager)5 CyNetworkFactory (org.cytoscape.model.CyNetworkFactory)5 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)5 CyLayoutAlgorithmManager (org.cytoscape.view.layout.CyLayoutAlgorithmManager)5 RenderingEngine (org.cytoscape.view.presentation.RenderingEngine)5 TaskIterator (org.cytoscape.work.TaskIterator)5 TaskMonitor (org.cytoscape.work.TaskMonitor)5 NetworkViewTestSupport (org.cytoscape.ding.NetworkViewTestSupport)4 CyNode (org.cytoscape.model.CyNode)4 NetworkTestSupport (org.cytoscape.model.NetworkTestSupport)4 CyNetworkNaming (org.cytoscape.session.CyNetworkNaming)4