@Override public void addVisualMappingFunction(final VisualMappingFunction<?, ?> mapping) { mappings.put(mapping.getVisualProperty(), mapping); eventHelper.addEventPayload( (VisualStyle) this, new VisualStyleChangeRecord(), VisualStyleChangedEvent.class); }
@SuppressWarnings("unchecked") private void checkCurrentVisualStyle(final VisualStyle style) { assertNotNull(style); assertEquals("Sample3", style.getTitle()); Collection<VisualMappingFunction<?, ?>> mappings = style.getAllVisualMappingFunctions(); assertEquals(6, mappings.size()); // Test defaults NodeShape defaultShape = style.getDefaultValue(NODE_SHAPE); Paint nodeColor = style.getDefaultValue(NODE_FILL_COLOR); Integer fontSize = style.getDefaultValue(NODE_LABEL_FONT_SIZE); Integer transparency = style.getDefaultValue(NODE_TRANSPARENCY); Double w = style.getDefaultValue(NODE_WIDTH); Double h = style.getDefaultValue(NODE_HEIGHT); Paint edgeLabelColor = style.getDefaultValue(EDGE_LABEL_COLOR); assertEquals(new Color(255, 255, 204), edgeLabelColor); assertEquals(NodeShapeVisualProperty.ROUND_RECTANGLE, defaultShape); assertEquals(Color.WHITE, nodeColor); assertEquals(Integer.valueOf(16), fontSize); assertEquals(Integer.valueOf(180), transparency); assertEquals(Double.valueOf(80), w); assertEquals(Double.valueOf(30), h); // Check each mapping VisualMappingFunction<?, String> nodeLabelMapping = style.getVisualMappingFunction(NODE_LABEL); VisualMappingFunction<?, String> edgeLabelMapping = style.getVisualMappingFunction(EDGE_LABEL); assertTrue(nodeLabelMapping instanceof PassthroughMapping); assertTrue(edgeLabelMapping instanceof PassthroughMapping); assertEquals(CyNetwork.NAME, nodeLabelMapping.getMappingColumnName()); assertEquals(CyEdge.INTERACTION, edgeLabelMapping.getMappingColumnName()); assertEquals(String.class, nodeLabelMapping.getMappingColumnType()); assertEquals(String.class, edgeLabelMapping.getMappingColumnType()); // Node Color mapping VisualMappingFunction<?, Paint> nodeColorMapping = style.getVisualMappingFunction(NODE_FILL_COLOR); assertTrue(nodeColorMapping instanceof ContinuousMapping); assertEquals("gal4RGexp", nodeColorMapping.getMappingColumnName()); assertEquals(Number.class, nodeColorMapping.getMappingColumnType()); // Edge Color mapping VisualMappingFunction<?, Paint> edgeColorMapping = style.getVisualMappingFunction(EDGE_STROKE_UNSELECTED_PAINT); assertTrue(edgeColorMapping instanceof DiscreteMapping); assertEquals(CyEdge.INTERACTION, edgeColorMapping.getMappingColumnName()); assertEquals(String.class, edgeColorMapping.getMappingColumnType()); DiscreteMapping<String, Paint> disc1 = (DiscreteMapping<String, Paint>) edgeColorMapping; assertEquals(Color.WHITE, disc1.getMapValue("pp")); assertEquals(new Color(102, 255, 255), disc1.getMapValue("pd")); assertEquals(null, disc1.getMapValue("this is an invalid value")); // Numbers as Tooltip VisualMappingFunction<?, String> nodeTooltipMapping = style.getVisualMappingFunction(NODE_TOOLTIP); assertTrue(nodeTooltipMapping instanceof PassthroughMapping); assertEquals("gal4RGexp", nodeTooltipMapping.getMappingColumnName()); // Cy2 doesn't write the "controllerType" property for PassThroughMappings, // so it's always created as String (it shouldn't cause any issues) assertEquals(String.class, nodeTooltipMapping.getMappingColumnType()); VisualMappingFunction<?, LineType> edgeLineStyleMapping = style.getVisualMappingFunction(EDGE_LINE_TYPE); assertTrue(edgeLineStyleMapping instanceof DiscreteMapping); assertEquals(CyEdge.INTERACTION, edgeLineStyleMapping.getMappingColumnName()); assertEquals(String.class, edgeLineStyleMapping.getMappingColumnType()); DiscreteMapping<String, LineType> disc2 = (DiscreteMapping<String, LineType>) edgeLineStyleMapping; assertEquals(LineTypeVisualProperty.SOLID, disc2.getMapValue("pp")); assertEquals(LineTypeVisualProperty.LONG_DASH, disc2.getMapValue("pd")); assertEquals(null, disc2.getMapValue("this is an invalid value")); }