use of org.cytoscape.view.model.CyNetworkView in project cytoscape-api by cytoscape.
the class NetworkViewAboutToBeDestroyedEventTest method testGetNetworkView.
@Test
public final void testGetNetworkView() {
final CyNetworkViewManager networkViewManager = mock(CyNetworkViewManager.class);
final CyNetworkView networkView = mock(CyNetworkView.class);
final NetworkViewAboutToBeDestroyedEvent event = new NetworkViewAboutToBeDestroyedEvent(networkViewManager, networkView);
assertEquals("Network returned by getNetworkView() is *not* the one passed into the constructor!", networkView, event.getNetworkView());
}
use of org.cytoscape.view.model.CyNetworkView in project cytoscape-api by cytoscape.
the class NetworkViewAddedEventTest method testGetNetworkView.
@Test
public final void testGetNetworkView() {
final CyNetworkViewManager networkViewManager = mock(CyNetworkViewManager.class);
final CyNetworkView networkView = mock(CyNetworkView.class);
final NetworkViewAddedEvent event = new NetworkViewAddedEvent(networkViewManager, networkView);
assertEquals("Network returned by getNetworkView() is *not* the one passed into the constructor!", networkView, event.getNetworkView());
}
use of org.cytoscape.view.model.CyNetworkView in project cytoscape-api by cytoscape.
the class AbstractRenderingEngineManagerTest method testGetRendringEngines.
@Test
public void testGetRendringEngines() throws Exception {
// First, create mock view models.
final CyNetworkView networkView1 = mock(CyNetworkView.class);
final CyNetworkView networkView2 = mock(CyNetworkView.class);
final RenderingEngine<CyNetwork> engine1 = mock(RenderingEngine.class);
when(engine1.getViewModel()).thenReturn(networkView1);
final RenderingEngine<CyNetwork> engine2 = mock(RenderingEngine.class);
when(engine2.getViewModel()).thenReturn(networkView1);
final RenderingEngine<CyNetwork> engine3 = mock(RenderingEngine.class);
when(engine3.getViewModel()).thenReturn(networkView2);
manager.addRenderingEngine(engine1);
manager.addRenderingEngine(engine2);
manager.addRenderingEngine(engine3);
final Collection<RenderingEngine<?>> allEngines = manager.getAllRenderingEngines();
assertNotNull(allEngines);
final Collection<RenderingEngine<?>> engines = manager.getRenderingEngines(networkView1);
assertNotNull(engines);
assertEquals(2, engines.size());
when(engine1.getViewModel()).thenReturn(networkView1);
manager.addRenderingEngine(engine1);
assertTrue(manager.getRenderingEngines(networkView1).contains(engine1));
// Remove from manager
manager.removeRenderingEngine(engine1);
manager.removeRenderingEngine(engine3);
assertEquals(1, manager.getRenderingEngines(networkView1).size());
assertEquals(0, manager.getRenderingEngines(networkView2).size());
manager.removeRenderingEngine(engine2);
assertEquals(0, manager.getRenderingEngines(networkView1).size());
}
use of org.cytoscape.view.model.CyNetworkView in project EnrichmentMapApp by BaderLab.
the class EMStyleBuilder method setNodeColors.
private void setNodeColors(VisualStyle vs, EMStyleOptions options) {
String prefix = options.getAttributePrefix();
List<AbstractDataSet> dataSets = options.getDataSets().stream().filter(// Ignore Signature Data Sets in charts
ds -> ds instanceof EMDataSet).collect(Collectors.toList());
if (dataSets.size() == 1) {
// Only 1 Data Set? Use node colour instead of charts...
EMDataSet ds = (EMDataSet) dataSets.iterator().next();
// Create boundary conditions
BoundaryRangeValues<Paint> bv3a = new BoundaryRangeValues<>(Colors.MAX_PHENOTYPE_2, Colors.MAX_PHENOTYPE_2, Colors.MAX_PHENOTYPE_2);
BoundaryRangeValues<Paint> bv3b = new BoundaryRangeValues<>(Colors.LIGHTER_PHENOTYPE_2, Colors.LIGHTER_PHENOTYPE_2, Colors.MAX_PHENOTYPE_2);
BoundaryRangeValues<Paint> bv3c = new BoundaryRangeValues<>(Colors.LIGHTEST_PHENOTYPE_2, Colors.LIGHTEST_PHENOTYPE_2, Colors.LIGHTER_PHENOTYPE_2);
BoundaryRangeValues<Paint> bv3d = new BoundaryRangeValues<>(Colors.LIGHTEST_PHENOTYPE_2, Colors.OVER_COLOR, Colors.OVER_COLOR);
BoundaryRangeValues<Paint> bv3e = new BoundaryRangeValues<>(Colors.OVER_COLOR, Colors.OVER_COLOR, Colors.OVER_COLOR);
BoundaryRangeValues<Paint> bv3f = new BoundaryRangeValues<>(Colors.OVER_COLOR, Colors.OVER_COLOR, Colors.LIGHTEST_PHENOTYPE_1);
BoundaryRangeValues<Paint> bv3g = new BoundaryRangeValues<>(Colors.LIGHTEST_PHENOTYPE_1, Colors.LIGHTEST_PHENOTYPE_1, Colors.LIGHTER_PHENOTYPE_1);
BoundaryRangeValues<Paint> bv3h = new BoundaryRangeValues<>(Colors.LIGHTER_PHENOTYPE_1, Colors.LIGHTER_PHENOTYPE_1, Colors.MAX_PHENOTYPE_1);
BoundaryRangeValues<Paint> bv3i = new BoundaryRangeValues<>(Colors.MAX_PHENOTYPE_1, Colors.MAX_PHENOTYPE_1, Colors.MAX_PHENOTYPE_1);
// Continuous Mapping - set node colour based on the sign of the ES score of the dataset
ContinuousMapping<Double, Paint> cm = (ContinuousMapping<Double, Paint>) cmFactory.createVisualMappingFunction(Columns.NODE_COLOURING.with(prefix, ds.getName()), Double.class, BasicVisualLexicon.NODE_FILL_COLOR);
// Silence events fired by this mapping to prevent unnecessary style and view updates
eventHelper.silenceEventSource(cm);
try {
// Set the attribute point values associated with the boundary values
cm.addPoint(-1.0, bv3a);
cm.addPoint(-0.995, bv3b);
cm.addPoint(-0.95, bv3c);
cm.addPoint(-0.9, bv3d);
cm.addPoint(0.0, bv3e);
cm.addPoint(0.9, bv3f);
cm.addPoint(0.95, bv3g);
cm.addPoint(0.995, bv3h);
cm.addPoint(1.0, bv3i);
} finally {
eventHelper.unsilenceEventSource(cm);
}
vs.addVisualMappingFunction(cm);
// Then we need to use bypass to colour the hub nodes (signature genesets)
List<EMSignatureDataSet> signatureDataSets = options.getEnrichmentMap().getSignatureSetList();
CyNetworkView netView = options.getNetworkView();
CyNetwork net = netView.getModel();
for (EMSignatureDataSet sds : signatureDataSets) {
for (Long suid : sds.getNodeSuids()) {
CyNode node = net.getNode(suid);
if (node != null) {
View<CyNode> nv = netView.getNodeView(node);
if (nv != null)
nv.setLockedValue(NODE_FILL_COLOR, Colors.SIG_NODE_COLOR);
}
}
}
} else {
// 2 or more Data Sets? Use simple node colours and charts...
// Add mapping function for node fill color
DiscreteMapping<String, Paint> dm = (DiscreteMapping<String, Paint>) dmFactory.createVisualMappingFunction(Columns.NODE_GS_TYPE.with(prefix, null), String.class, NODE_FILL_COLOR);
// Silence events fired by this mapping to prevent unnecessary style and view updates
eventHelper.silenceEventSource(dm);
try {
dm.putMapValue(Columns.NODE_GS_TYPE_ENRICHMENT, Colors.DEF_NODE_COLOR);
dm.putMapValue(Columns.NODE_GS_TYPE_SIGNATURE, Colors.SIG_NODE_COLOR);
} finally {
eventHelper.unsilenceEventSource(dm);
}
vs.addVisualMappingFunction(dm);
}
}
use of org.cytoscape.view.model.CyNetworkView in project EnrichmentMapApp by BaderLab.
the class ControlPanelMediator method getOptionsMenu.
private JPopupMenu getOptionsMenu() {
final JPopupMenu menu = new JPopupMenu();
{
final JMenuItem mi = new JCheckBoxMenuItem("Show Legend");
mi.addActionListener(evt -> {
if (legendPanelMediatorProvider.get().getDialog().isVisible()) {
legendPanelMediatorProvider.get().hideDialog();
} else {
CyNetworkView netView = getCurrentEMView();
EMViewControlPanel viewPanel = getControlPanel().getViewControlPanel(netView);
legendPanelMediatorProvider.get().showDialog(createStyleOptions(netView), getFilteredDataSets(viewPanel));
}
});
mi.setSelected(legendPanelMediatorProvider.get().getDialog().isVisible());
menu.add(mi);
}
menu.addSeparator();
for (FilterMode mode : FilterMode.values()) {
final JMenuItem mi = new JCheckBoxMenuItem(mode.toString());
mi.addActionListener(evt -> setFilterMode(mode));
mi.setSelected(filterMode == mode);
menu.add(mi);
}
return menu;
}
Aggregations