Search in sources :

Example 1 with Visualizable

use of org.cytoscape.view.model.Visualizable in project cytoscape-api by cytoscape.

the class VisualPropertyTest method testVisualProperties.

@Test
public void testVisualProperties() {
    final VisualProperty<Paint> colorProp = BasicVisualLexicon.NODE_FILL_COLOR;
    assertEquals(Paint.class, colorProp.getRange().getType());
    final VisualProperty<Boolean> booleanProp = BasicVisualLexicon.NODE_VISIBLE;
    assertEquals(Boolean.class, booleanProp.getRange().getType());
    assertEquals("false", booleanProp.toSerializableString(Boolean.FALSE));
    assertEquals(false, booleanProp.parseSerializableString("false"));
    assertEquals(false, booleanProp.parseSerializableString("False"));
    assertEquals(false, booleanProp.parseSerializableString("FALSE"));
    assertEquals(CyNode.class, booleanProp.getTargetDataType());
    final VisualProperty<Double> doubleProp = BasicVisualLexicon.NODE_SIZE;
    assertEquals(Double.class, doubleProp.getRange().getType());
    assertEquals("20.0", doubleProp.toSerializableString(Double.valueOf(20)));
    assertEquals(Double.valueOf(100.12), doubleProp.parseSerializableString("100.12"));
    final VisualProperty<Paint> paintProp = BasicVisualLexicon.NODE_FILL_COLOR;
    assertEquals(Paint.class, paintProp.getRange().getType());
    assertEquals(CyNode.class, paintProp.getTargetDataType());
    final Color testColor = new Color(10, 20, 30);
    assertEquals("#0A141E", paintProp.toSerializableString(testColor).toUpperCase());
    assertEquals(testColor, paintProp.parseSerializableString("#0A141E"));
    assertEquals(testColor, paintProp.parseSerializableString("#0a141e"));
    assertEquals(testColor, paintProp.parseSerializableString("10,20,30"));
    assertEquals(testColor, paintProp.parseSerializableString("rgb(10,20,30)"));
    assertEquals(testColor, paintProp.parseSerializableString("RGB ( 10 , 20 , 30 )"));
    try {
        paintProp.parseSerializableString(null);
    } catch (Exception e) {
        assertTrue(e instanceof IllegalArgumentException);
    }
    try {
        paintProp.parseSerializableString("#2JK20A141E");
    } catch (Exception e) {
        assertTrue(e instanceof IllegalArgumentException);
    }
    try {
        paintProp.parseSerializableString("10, 20");
    } catch (Exception e) {
        assertTrue(e instanceof IllegalArgumentException);
    }
    try {
        paintProp.parseSerializableString("10, 20, IJK");
    } catch (Exception e) {
        assertTrue(e instanceof IllegalArgumentException);
    }
    final VisualProperty<Visualizable> visualizableProp = BasicVisualLexicon.NODE;
    assertEquals(Visualizable.class, visualizableProp.getRange().getType());
    assertTrue(visualizableProp.parseSerializableString("test string") instanceof Visualizable);
    final VisualProperty<String> stringProp = BasicVisualLexicon.NODE_LABEL;
    assertEquals(String.class, stringProp.getRange().getType());
    assertEquals("test string", stringProp.toSerializableString("test string"));
    assertEquals("test string 2", stringProp.parseSerializableString("test string 2"));
    final VisualProperty<NullDataType> nullProp = new NullVisualProperty("ROOT", "Root Visual Property");
    assertEquals(NullDataType.class, nullProp.getRange().getType());
    assertTrue(nullProp.parseSerializableString("test string") instanceof NullDataType);
}
Also used : NullVisualProperty(org.cytoscape.view.presentation.property.NullVisualProperty) Color(java.awt.Color) Paint(java.awt.Paint) Visualizable(org.cytoscape.view.model.Visualizable) NullDataType(org.cytoscape.view.model.NullDataType) Test(org.junit.Test)

Aggregations

Color (java.awt.Color)1 Paint (java.awt.Paint)1 NullDataType (org.cytoscape.view.model.NullDataType)1 Visualizable (org.cytoscape.view.model.Visualizable)1 NullVisualProperty (org.cytoscape.view.presentation.property.NullVisualProperty)1 Test (org.junit.Test)1