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);
}
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);
}
}
}
}
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;
}
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));
}
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();
}
Aggregations