use of org.cytoscape.view.vizmap.VisualStyle in project EnrichmentMapApp by BaderLab.
the class ApplyEMStyleTask method getVisualStyle.
private VisualStyle getVisualStyle(EnrichmentMap map) {
String vsName = EMStyleBuilder.getStyleName(map);
VisualStyle vs = getExistingVisualStyle(vsName);
if (vs == null) {
vs = visualStyleFactory.createVisualStyle(vsName);
visualMappingManager.addVisualStyle(vs);
}
return vs;
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class VisualStyleSerializerTest method testCy270Vizmap.
@Test
@SuppressWarnings("unchecked")
public void testCy270Vizmap() throws Exception {
Properties props = loadVizmapProps("v270_vizmap.props");
Set<VisualStyle> styles = serializer.createVisualStyles(props);
assertEquals(2, styles.size());
assertVisualStylesNotNull(styles, new String[] { "default", "Binary_SIF_Version_1" });
// Test visual styles (defaults, mappings and dependencies)
// -----
VisualStyle s = getVisualStyleByTitle(styles, "Binary_SIF_Version_1");
assertEquals(new Color(255, 153, 153), s.getDefaultValue(NODE_FILL_COLOR));
assertEquals(new Color(255, 255, 0), s.getDefaultValue(NODE_SELECTED_PAINT));
assertEquals(NodeShapeVisualProperty.ELLIPSE, s.getDefaultValue(NODE_SHAPE));
assertEquals(70, s.getDefaultValue(NODE_WIDTH).intValue());
assertEquals(30, s.getDefaultValue(NODE_HEIGHT).intValue());
assertEquals(35, s.getDefaultValue(NODE_SIZE).intValue());
assertEquals(125, s.getDefaultValue(NODE_TRANSPARENCY).intValue());
assertEquals(new Color(0, 0, 0), s.getDefaultValue(NODE_BORDER_PAINT));
assertEquals(1, s.getDefaultValue(NODE_BORDER_WIDTH).intValue());
assertEquals(255, s.getDefaultValue(NODE_BORDER_TRANSPARENCY).intValue());
assertEquals("", s.getDefaultValue(NODE_LABEL));
assertEquals(Font.decode("Default-PLAIN-12"), s.getDefaultValue(NODE_LABEL_FONT_FACE));
assertEquals(12, s.getDefaultValue(NODE_LABEL_FONT_SIZE).intValue());
assertEquals(new Color(0, 0, 0), s.getDefaultValue(NODE_LABEL_COLOR));
assertEquals(100, s.getDefaultValue(NODE_LABEL_WIDTH).intValue());
assertEquals(255, s.getDefaultValue(NODE_LABEL_TRANSPARENCY).intValue());
assertEquals(LineTypeVisualProperty.SOLID, s.getDefaultValue(NODE_BORDER_LINE_TYPE));
assertEquals("", s.getDefaultValue(NODE_TOOLTIP));
assertEquals(Boolean.TRUE, s.getDefaultValue(NODE_NESTED_NETWORK_IMAGE_VISIBLE));
assertEquals(4, s.getDefaultValue(EDGE_WIDTH).intValue());
assertEquals(new Color(0, 0, 0), s.getDefaultValue(EDGE_UNSELECTED_PAINT));
assertEquals(new Color(0, 0, 0), s.getDefaultValue(EDGE_STROKE_UNSELECTED_PAINT));
assertEquals(new Color(255, 0, 0), s.getDefaultValue(EDGE_STROKE_SELECTED_PAINT));
assertEquals(255, s.getDefaultValue(EDGE_TRANSPARENCY).intValue());
assertEquals(LineTypeVisualProperty.SOLID, s.getDefaultValue(EDGE_LINE_TYPE));
assertEquals("", s.getDefaultValue(EDGE_LABEL));
assertEquals(Font.decode("SanSerif-PLAIN-10"), s.getDefaultValue(EDGE_LABEL_FONT_FACE));
assertEquals(10, s.getDefaultValue(EDGE_LABEL_FONT_SIZE).intValue());
assertEquals(new Color(0, 0, 0), s.getDefaultValue(EDGE_LABEL_COLOR));
assertEquals(255, s.getDefaultValue(EDGE_LABEL_TRANSPARENCY).intValue());
assertEquals(ArrowShapeVisualProperty.NONE, s.getDefaultValue(EDGE_SOURCE_ARROW_SHAPE));
assertEquals(ArrowShapeVisualProperty.NONE, s.getDefaultValue(EDGE_TARGET_ARROW_SHAPE));
assertEquals("", s.getDefaultValue(EDGE_TOOLTIP));
PassthroughMapping<String, String> nLabelMp = (PassthroughMapping<String, String>) s.getVisualMappingFunction(NODE_LABEL);
assertEquals("biopax.node_label", nLabelMp.getMappingColumnName());
assertEquals(String.class, nLabelMp.getMappingColumnType());
assertNull(s.getVisualMappingFunction(EDGE_LABEL));
DiscreteMapping<String, Paint> nColorMp = (DiscreteMapping<String, Paint>) s.getVisualMappingFunction(NODE_FILL_COLOR);
assertEquals("biopax.entity_type", nColorMp.getMappingColumnName());
assertEquals(String.class, nColorMp.getMappingColumnType());
assertEquals(new Color(153, 153, 255), nColorMp.getMapValue("Complex"));
assertNull(nColorMp.getMapValue("Protein"));
DiscreteMapping<String, Paint> eColorMp = (DiscreteMapping<String, Paint>) s.getVisualMappingFunction(EDGE_STROKE_UNSELECTED_PAINT);
assertEquals(INTERACTION, eColorMp.getMappingColumnName());
assertEquals(String.class, eColorMp.getMappingColumnType());
// Test a few entries
assertEquals(new Color(255, 192, 0), eColorMp.getMapValue("COMPONENT_OF"));
assertEquals(new Color(255, 0, 0), eColorMp.getMapValue("CO_CONTROL_DEPENDENT_ANTI"));
assertEquals(new Color(0, 176, 80), eColorMp.getMapValue("CO_CONTROL_DEPENDENT_SIMILAR"));
assertEquals(new Color(253, 149, 166), eColorMp.getMapValue("CO_CONTROL_INDEPENDENT_ANTI"));
assertEquals(new Color(0, 176, 80), eColorMp.getMapValue("CO_CONTROL_DEPENDENT_SIMILAR"));
DiscreteMapping<String, ArrowShape> eTgtArrowMp = (DiscreteMapping<String, ArrowShape>) s.getVisualMappingFunction(EDGE_TARGET_ARROW_SHAPE);
assertEquals(INTERACTION, eTgtArrowMp.getMappingColumnName());
assertEquals(String.class, eTgtArrowMp.getMappingColumnType());
assertEquals(ArrowShapeVisualProperty.ARROW, eTgtArrowMp.getMapValue("COMPONENT_OF"));
assertEquals(ArrowShapeVisualProperty.ARROW, eTgtArrowMp.getMapValue("METABOLIC_CATALYSIS"));
assertEquals(ArrowShapeVisualProperty.ARROW, eTgtArrowMp.getMapValue("SEQUENTIAL_CATALYSIS"));
assertEquals(ArrowShapeVisualProperty.ARROW, eTgtArrowMp.getMapValue("SEQUENTIAL_CATALYSIS"));
assertEquals(ArrowShapeVisualProperty.ARROW, eTgtArrowMp.getMapValue("STATE_CHANGE"));
assertNull(eTgtArrowMp.getMapValue("INTERACTS_WITH"));
VisualPropertyDependency<?> dep1 = getDependency(s, NODE_SIZE_LOCKED_DEPENDENCY);
assertFalse(dep1.isDependencyEnabled());
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class VisualStyleSerializerTest method testCy252Vizmap.
@Test
@SuppressWarnings("unchecked")
public void testCy252Vizmap() throws Exception {
Properties props = loadVizmapProps("v252_vizmap.props");
Set<VisualStyle> styles = serializer.createVisualStyles(props);
assertEquals(5, styles.size());
assertVisualStylesNotNull(styles, new String[] { "default", "Sample1", "Sample2", "Sample3", "SimpleBioMoleculeEditor" });
// Test one style
// -----
VisualStyle s3 = getVisualStyleByTitle(styles, "Sample3");
assertEquals(new Color(0, 0, 0), s3.getDefaultValue(NETWORK_BACKGROUND_PAINT));
assertEquals(new Color(255, 255, 255), s3.getDefaultValue(NODE_FILL_COLOR));
assertEquals(new Color(255, 255, 0), s3.getDefaultValue(NODE_SELECTED_PAINT));
assertEquals(NodeShapeVisualProperty.ROUND_RECTANGLE, s3.getDefaultValue(NODE_SHAPE));
assertEquals(80, s3.getDefaultValue(NODE_WIDTH).intValue());
assertEquals(30, s3.getDefaultValue(NODE_HEIGHT).intValue());
assertEquals(180, s3.getDefaultValue(NODE_TRANSPARENCY).intValue());
assertEquals(new Color(153, 153, 255), s3.getDefaultValue(NODE_BORDER_PAINT));
assertEquals(2, s3.getDefaultValue(NODE_BORDER_WIDTH).intValue());
assertEquals(255, s3.getDefaultValue(NODE_BORDER_TRANSPARENCY).intValue());
assertEquals(new Font("Arial-BoldMT", Font.PLAIN, 12), s3.getDefaultValue(NODE_LABEL_FONT_FACE));
assertEquals(16, s3.getDefaultValue(NODE_LABEL_FONT_SIZE).intValue());
assertEquals(new Color(255, 255, 255), s3.getDefaultValue(NODE_LABEL_COLOR));
assertEquals(255, s3.getDefaultValue(NODE_LABEL_TRANSPARENCY).intValue());
assertEquals(LineTypeVisualProperty.SOLID, s3.getDefaultValue(NODE_BORDER_LINE_TYPE));
assertEquals("", s3.getDefaultValue(NODE_TOOLTIP));
assertEquals(1, s3.getDefaultValue(EDGE_WIDTH).intValue());
assertEquals(new Color(153, 153, 255), s3.getDefaultValue(EDGE_UNSELECTED_PAINT));
assertEquals(new Color(153, 153, 255), s3.getDefaultValue(EDGE_STROKE_UNSELECTED_PAINT));
assertEquals(new Color(255, 0, 0), s3.getDefaultValue(EDGE_STROKE_SELECTED_PAINT));
assertEquals(255, s3.getDefaultValue(EDGE_TRANSPARENCY).intValue());
assertEquals(LineTypeVisualProperty.SOLID, s3.getDefaultValue(EDGE_LINE_TYPE));
assertEquals(Font.decode("SanSerif-PLAIN-10"), s3.getDefaultValue(EDGE_LABEL_FONT_FACE));
assertEquals(14, s3.getDefaultValue(EDGE_LABEL_FONT_SIZE).intValue());
assertEquals(new Color(255, 255, 204), s3.getDefaultValue(EDGE_LABEL_COLOR));
assertEquals(255, s3.getDefaultValue(EDGE_LABEL_TRANSPARENCY).intValue());
assertEquals(ArrowShapeVisualProperty.NONE, s3.getDefaultValue(EDGE_SOURCE_ARROW_SHAPE));
assertEquals(ArrowShapeVisualProperty.NONE, s3.getDefaultValue(EDGE_TARGET_ARROW_SHAPE));
assertEquals("", s3.getDefaultValue(EDGE_TOOLTIP));
PassthroughMapping<String, String> nLabelMp = (PassthroughMapping<String, String>) s3.getVisualMappingFunction(NODE_LABEL);
assertEquals(NAME, nLabelMp.getMappingColumnName());
assertEquals(String.class, nLabelMp.getMappingColumnType());
PassthroughMapping<String, String> eLabelMp = (PassthroughMapping<String, String>) s3.getVisualMappingFunction(EDGE_LABEL);
assertEquals(INTERACTION, eLabelMp.getMappingColumnName());
assertEquals(String.class, eLabelMp.getMappingColumnType());
PassthroughMapping<String, String> nTooltipMp = (PassthroughMapping<String, String>) s3.getVisualMappingFunction(NODE_TOOLTIP);
assertEquals("gal4RGexp", nTooltipMp.getMappingColumnName());
assertEquals(String.class, nTooltipMp.getMappingColumnType());
ContinuousMapping<Double, Paint> nColorMp = (ContinuousMapping<Double, Paint>) s3.getVisualMappingFunction(NODE_FILL_COLOR);
assertEquals("gal4RGexp", nColorMp.getMappingColumnName());
assertEquals(Number.class, nColorMp.getMappingColumnType());
assertEquals(3, nColorMp.getPointCount());
assertEquals(-2.4059998989105242, nColorMp.getPoint(0).getValue(), 0.0001);
assertEquals(new Color(0, 153, 0), nColorMp.getPoint(0).getRange().equalValue);
assertEquals(new Color(0, 153, 0), nColorMp.getPoint(0).getRange().greaterValue);
assertEquals(Color.BLACK, nColorMp.getPoint(0).getRange().lesserValue);
assertEquals(-3.254413627473696E-8, nColorMp.getPoint(1).getValue(), 0.0001);
assertEquals(Color.WHITE, nColorMp.getPoint(1).getRange().equalValue);
assertEquals(Color.WHITE, nColorMp.getPoint(1).getRange().greaterValue);
assertEquals(Color.WHITE, nColorMp.getPoint(1).getRange().lesserValue);
assertEquals(1.2239999999999998, nColorMp.getPoint(2).getValue(), 0.0001);
assertEquals(new Color(255, 0, 0), nColorMp.getPoint(2).getRange().equalValue);
assertEquals(new Color(255, 255, 255), nColorMp.getPoint(2).getRange().greaterValue);
assertEquals(new Color(255, 0, 0), nColorMp.getPoint(2).getRange().lesserValue);
DiscreteMapping<String, Paint> eColorMp = (DiscreteMapping<String, Paint>) s3.getVisualMappingFunction(EDGE_STROKE_UNSELECTED_PAINT);
assertEquals(INTERACTION, eColorMp.getMappingColumnName());
assertEquals(String.class, eColorMp.getMappingColumnType());
assertEquals(new Color(102, 255, 255), eColorMp.getMapValue("pd"));
assertEquals(new Color(255, 255, 255), eColorMp.getMapValue("pp"));
DiscreteMapping<String, LineType> eTypeMp = (DiscreteMapping<String, LineType>) s3.getVisualMappingFunction(EDGE_LINE_TYPE);
assertEquals(INTERACTION, eTypeMp.getMappingColumnName());
assertEquals(LineTypeVisualProperty.LONG_DASH, eTypeMp.getMapValue("pd"));
assertEquals(LineTypeVisualProperty.SOLID, eTypeMp.getMapValue("pp"));
VisualPropertyDependency<?> dep1 = getDependency(s3, NODE_SIZE_LOCKED_DEPENDENCY);
assertFalse(dep1.isDependencyEnabled());
}
use of org.cytoscape.view.vizmap.VisualStyle 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.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class CySessionManagerImpl method setCurrentSession.
@Override
public void setCurrentSession(CySession sess, final String fileName) {
// Always remove the current session first
if (!disposed)
disposeCurrentSession();
if (sess == null) {
logger.debug("Creating empty session...");
final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
final Set<VisualStyle> styles = vmMgr.getAllVisualStyles();
final Set<CyProperty<?>> props = getAllProperties();
sess = new CySession.Builder().properties(props).visualStyles(styles).build();
} else {
logger.debug("Restoring the session...");
// Save the selected networks first, so the selection state can be restored later.
final List<CyNetwork> selectedNetworks = new ArrayList<>();
final Set<CyNetwork> networks = sess.getNetworks();
for (CyNetwork n : networks) {
final Boolean selected = n.getDefaultNetworkTable().getRow(n.getSUID()).get(CyNetwork.SELECTED, Boolean.class);
if (Boolean.TRUE.equals(selected))
selectedNetworks.add(n);
}
restoreProperties(sess);
restoreNetworks(sess);
restoreTables(sess);
restoreNetworkViews(sess, selectedNetworks);
restoreNetworkSelection(sess, selectedNetworks);
restoreVisualStyles(sess);
restoreCurrentVisualStyle();
}
currentFileName = fileName;
disposed = false;
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
eventHelper.fireEvent(new SessionLoadedEvent(this, sess, getCurrentSessionFileName()));
}
Aggregations