Search in sources :

Example 1 with DiscreteMappingImpl

use of org.cytoscape.view.vizmap.internal.mappings.DiscreteMappingImpl in project cytoscape-impl by cytoscape.

the class VisualStyleFactoryImpl method createDiscrete.

@SuppressWarnings({ "rawtypes", "unchecked" })
private <K, V> VisualMappingFunction<K, V> createDiscrete(final DiscreteMapping<K, V> originalMapping) {
    final String attrName = originalMapping.getMappingColumnName();
    final Class<K> colType = originalMapping.getMappingColumnType();
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    final DiscreteMapping<K, V> copyMapping = new DiscreteMappingImpl(attrName, colType, originalMapping.getVisualProperty(), eventHelper);
    copyMapping.putAll(originalMapping.getAll());
    return copyMapping;
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) DiscreteMappingImpl(org.cytoscape.view.vizmap.internal.mappings.DiscreteMappingImpl)

Example 2 with DiscreteMappingImpl

use of org.cytoscape.view.vizmap.internal.mappings.DiscreteMappingImpl in project cytoscape-impl by cytoscape.

the class VisualStyleFactoryTest method testCopyVisualStyle.

@Test
@SuppressWarnings("unchecked")
public void testCopyVisualStyle() {
    final VisualStyle vs1 = new VisualStyleImpl("Style 1", serviceRegistrar);
    // Add a few default values
    vs1.setDefaultValue(NODE_FILL_COLOR, Color.LIGHT_GRAY);
    vs1.setDefaultValue(NODE_SIZE, 64.0);
    vs1.setDefaultValue(EDGE_LABEL_COLOR, Color.GREEN);
    vs1.setDefaultValue(EDGE_LABEL_FONT_SIZE, 32);
    vs1.setDefaultValue(NETWORK_BACKGROUND_PAINT, Color.YELLOW);
    // Add a mapping
    final DiscreteMapping<String, Paint> dm1 = new DiscreteMappingImpl<>("myattr1", String.class, NODE_FILL_COLOR, eventHelper);
    dm1.putMapValue("a", Color.CYAN);
    dm1.putMapValue("b", Color.BLUE);
    vs1.addVisualMappingFunction(dm1);
    // Add a dependency
    final Set<VisualProperty<Double>> depProps = new HashSet<>();
    depProps.add(NODE_WIDTH);
    depProps.add(NODE_HEIGHT);
    final VisualPropertyDependency<Double> dep1 = new VisualPropertyDependency<>("nodeSizeDep", "Lock Node W/H", depProps, lexicon);
    dep1.setDependency(false);
    vs1.addVisualPropertyDependency(dep1);
    // Copy the style and test it
    final VisualStyle vs2 = factory.createVisualStyle(vs1);
    assertNotEquals(vs1, vs2);
    assertEquals(vs1.getTitle(), vs2.getTitle());
    assertEquals(Color.LIGHT_GRAY, vs2.getDefaultValue(NODE_FILL_COLOR));
    assertEquals(new Double(64.0), vs2.getDefaultValue(NODE_SIZE));
    assertEquals(Color.GREEN, vs2.getDefaultValue(EDGE_LABEL_COLOR));
    assertEquals(new Integer(32), vs2.getDefaultValue(EDGE_LABEL_FONT_SIZE));
    assertEquals(Color.YELLOW, vs2.getDefaultValue(NETWORK_BACKGROUND_PAINT));
    final DiscreteMapping<String, Paint> dm2 = (DiscreteMapping<String, Paint>) vs2.getVisualMappingFunction(NODE_FILL_COLOR);
    assertEquals("myattr1", dm2.getMappingColumnName());
    assertEquals(2, dm2.getAll().size());
    assertEquals(Color.CYAN, dm2.getMapValue("a"));
    assertEquals(Color.BLUE, dm2.getMapValue("b"));
    final Set<VisualPropertyDependency<?>> depSet2 = vs2.getAllVisualPropertyDependencies();
    assertEquals(vs1.getAllVisualPropertyDependencies().size(), depSet2.size());
    boolean depFound = false;
    for (final VisualPropertyDependency<?> dep : depSet2) {
        if (dep.getIdString().equals("nodeSizeDep")) {
            depFound = true;
            assertTrue("The copied dependency is not a new instance", dep != dep1);
            assertEquals(dep1.getDisplayName(), dep.getDisplayName());
            assertEquals(dep1.getParentVisualProperty(), dep.getParentVisualProperty());
            assertFalse(dep.isDependencyEnabled());
            assertEquals(2, dep.getVisualProperties().size());
            assertTrue(dep.getVisualProperties().contains(NODE_WIDTH));
            assertTrue(dep.getVisualProperties().contains(NODE_HEIGHT));
            break;
        }
    }
    assertTrue("VisualPropertyDependency was not copied.", depFound);
}
Also used : DiscreteMappingImpl(org.cytoscape.view.vizmap.internal.mappings.DiscreteMappingImpl) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) Paint(java.awt.Paint) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) VisualProperty(org.cytoscape.view.model.VisualProperty) NullVisualProperty(org.cytoscape.view.presentation.property.NullVisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) HashSet(java.util.HashSet) AbstractVisualStyleFactoryTest(org.cytoscape.view.vizmap.AbstractVisualStyleFactoryTest) Test(org.junit.Test)

Aggregations

DiscreteMappingImpl (org.cytoscape.view.vizmap.internal.mappings.DiscreteMappingImpl)2 Paint (java.awt.Paint)1 HashSet (java.util.HashSet)1 CyEventHelper (org.cytoscape.event.CyEventHelper)1 VisualProperty (org.cytoscape.view.model.VisualProperty)1 NullVisualProperty (org.cytoscape.view.presentation.property.NullVisualProperty)1 AbstractVisualStyleFactoryTest (org.cytoscape.view.vizmap.AbstractVisualStyleFactoryTest)1 VisualPropertyDependency (org.cytoscape.view.vizmap.VisualPropertyDependency)1 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)1 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)1 Test (org.junit.Test)1