Search in sources :

Example 1 with TunablePropertySerializer

use of org.cytoscape.work.properties.TunablePropertySerializer in project cytoscape-impl by cytoscape.

the class LayoutSettingsManager method saveLayoutContext.

public void saveLayoutContext(PanelTaskManager taskMgr, CyLayoutAlgorithm layout) {
    try {
        Object layoutContext = layout.getDefaultLayoutContext();
        taskMgr.validateAndApplyTunables(layoutContext);
        final TunablePropertySerializerFactory serializerFactory = serviceRegistrar.getService(TunablePropertySerializerFactory.class);
        final TunablePropertySerializer serializer = serializerFactory.createSerializer();
        final Properties layoutProps = serializer.toProperties(layoutContext);
        // No need to save empty props
        if (!layoutProps.isEmpty()) {
            CyProperty<Properties> cyProperty = getPropertyService(layout);
            cyProperty.getProperties().clear();
            cyProperty.getProperties().putAll(layoutProps);
        }
    } catch (Exception e) {
        logger.error("Error saving layout settings for '" + layout.getName() + "'", e);
    }
}
Also used : TunablePropertySerializer(org.cytoscape.work.properties.TunablePropertySerializer) TunablePropertySerializerFactory(org.cytoscape.work.properties.TunablePropertySerializerFactory) Properties(java.util.Properties)

Example 2 with TunablePropertySerializer

use of org.cytoscape.work.properties.TunablePropertySerializer in project cytoscape-impl by cytoscape.

the class TunablePropertySerializerTest method testSetTunablesFromProperties.

@Test
public void testSetTunablesFromProperties() {
    Properties props = new Properties();
    props.setProperty("line.startPoint.x", "5");
    props.setProperty("line.startPoint.y", "10");
    props.setProperty("line.endPoint.x", "15");
    props.setProperty("line.endPoint.y", "20");
    props.setProperty("why", "false");
    props.setProperty("str", "This is now a string that has a different value");
    props.setProperty("yesNoMaybe", "MAYBE");
    props.setProperty("integer", "44");
    props.setProperty("primitiveInt", "55");
    props.setProperty("listSingleNumbers", "3");
    props.setProperty("listMultipleNames", "Max,Fred");
    props.setProperty("listSingleEnum", "MAYBE");
    props.setProperty("intRange", "1");
    props.setProperty("doubleRange", "0.1");
    LotsOfTunables tunables = new LotsOfTunables();
    TunablePropertySerializer serializer = getSerializer();
    serializer.setTunables(tunables, props);
    assertEquals(tunables.line.startPoint.x, 5);
    assertEquals(tunables.line.startPoint.y, 10);
    assertEquals(tunables.line.endPoint.x, 15);
    assertEquals(tunables.line.endPoint.y, 20);
    assertEquals(tunables.why, false);
    assertEquals(tunables.str, "This is now a string that has a different value");
    assertEquals(tunables.yesNoMaybe, YesNoMaybe.MAYBE);
    assertEquals(tunables.integer, Integer.valueOf(44));
    assertEquals(tunables.primitiveInt, 55);
    assertEquals(tunables.listSingleNumbers.getSelectedValue(), Integer.valueOf(3));
    assertEquals(tunables.listMultipleNames.getSelectedValues(), Arrays.asList("Max", "Fred"));
    assertEquals(tunables.listSingleEnum.getSelectedValue(), YesNoMaybe.MAYBE);
    assertEquals(tunables.intRange.getValue(), Integer.valueOf(1));
    assertEquals(tunables.doubleRange.getValue(), Double.valueOf(0.1));
    assertEquals(tunables.missingValue, 0);
}
Also used : TunablePropertySerializer(org.cytoscape.work.properties.TunablePropertySerializer) Properties(java.util.Properties) Test(org.junit.Test)

Example 3 with TunablePropertySerializer

use of org.cytoscape.work.properties.TunablePropertySerializer in project cytoscape-impl by cytoscape.

the class LayoutSettingsManager method restoreLayoutContext.

private void restoreLayoutContext(CyLayoutAlgorithm layout) {
    try {
        Object layoutContext = layout.getDefaultLayoutContext();
        CyProperty<Properties> cyProperty = getPropertyService(layout);
        Properties propsBefore = cyProperty.getProperties();
        if (!propsBefore.isEmpty()) {
            // use the Properties to restore the values of the Tunable fields
            final TunablePropertySerializerFactory serializerFactory = serviceRegistrar.getService(TunablePropertySerializerFactory.class);
            final TunablePropertySerializer serializer = serializerFactory.createSerializer();
            serializer.setTunables(layoutContext, propsBefore);
        }
    } catch (Exception e) {
        logger.error("Error restoring layout settings for '" + layout.getName() + "'", e);
    }
}
Also used : TunablePropertySerializer(org.cytoscape.work.properties.TunablePropertySerializer) TunablePropertySerializerFactory(org.cytoscape.work.properties.TunablePropertySerializerFactory) Properties(java.util.Properties)

Aggregations

Properties (java.util.Properties)3 TunablePropertySerializer (org.cytoscape.work.properties.TunablePropertySerializer)3 TunablePropertySerializerFactory (org.cytoscape.work.properties.TunablePropertySerializerFactory)2 Test (org.junit.Test)1