@SuppressWarnings({"rawtypes", "unchecked"}) private final void parseMappings( JsonNode mappings, VisualStyle style, VisualLexicon lexicon, MappingFactoryManager factoryManager) { for (final JsonNode mapping : mappings) { final String type = mapping.get(MAPPING_TYPE).textValue(); final String column = mapping.get(MAPPING_COLUMN).textValue(); final String colType = mapping.get(MAPPING_COLUMN_TYPE).textValue(); final String vpName = mapping.get(MAPPING_VP).textValue(); final VisualProperty vp = getVisualProperty(vpName, lexicon); final Class<?> columnType = MapperUtil.getColumnClass(colType); if (vp == null || columnType == null) { continue; } VisualMappingFunction newMapping = null; if (type.equals(MAPPING_DISCRETE)) { final VisualMappingFunctionFactory factory = factoryManager.getFactory(DiscreteMapping.class); newMapping = parseDiscrete(column, columnType, vp, factory, mapping.get(MAPPING_DISCRETE_MAP)); } else if (type.equals(MAPPING_CONTINUOUS)) { final VisualMappingFunctionFactory factory = factoryManager.getFactory(ContinuousMapping.class); newMapping = parseContinuous(column, columnType, vp, factory, mapping); } else if (type.equals(MAPPING_PASSTHROUGH)) { final VisualMappingFunctionFactory factory = factoryManager.getFactory(PassthroughMapping.class); newMapping = parsePassthrough(column, columnType, vp, factory); } if (newMapping != null) { if (style.getVisualMappingFunction(vp) != null) { style.removeVisualMappingFunction(vp); } style.addVisualMappingFunction(newMapping); } } }
@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")); }