Search in sources :

Example 1 with NullDataType

use of org.cytoscape.view.model.NullDataType in project cytoscape-impl by cytoscape.

the class VisualStyleTest method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
    NetworkViewTestSupport nvts = new NetworkViewTestSupport();
    network = nvts.getNetworkFactory().createNetwork();
    node1 = network.addNode();
    node2 = network.addNode();
    node3 = network.addNode();
    edge = network.addEdge(node1, node2, true);
    CyTable nodeTable = network.getDefaultNodeTable();
    nodeTable.createColumn(attrName, String.class, true);
    nodeTable.getRow(node1.getSUID()).set(attrName, "red");
    nodeTable.getRow(node2.getSUID()).set(attrName, "green");
    nodeTable.getRow(node3.getSUID()).set(attrName, "foo");
    networkView = nvts.getNetworkViewFactory().createNetworkView(network);
    // Create root node.
    final NullVisualProperty minimalRoot = new NullVisualProperty("MINIMAL_ROOT", "Minimal Root Visual Property");
    final BasicVisualLexicon minimalLex = new BasicVisualLexicon(minimalRoot);
    final Set<VisualLexicon> lexSet = new HashSet<VisualLexicon>();
    lexSet.add(minimalLex);
    final VisualMappingFunctionFactory ptFactory = mock(VisualMappingFunctionFactory.class);
    eventHelper = mock(CyEventHelper.class);
    final RenderingEngineFactory<CyNetwork> reFatory = mock(RenderingEngineFactory.class);
    when(reFatory.getVisualLexicon()).thenReturn(minimalLex);
    final NetworkViewRenderer nvRenderer = mock(NetworkViewRenderer.class);
    when(nvRenderer.getRenderingEngineFactory(NetworkViewRenderer.DEFAULT_CONTEXT)).thenReturn(reFatory);
    final CyApplicationManager appManager = mock(CyApplicationManager.class);
    when(appManager.getCurrentNetworkViewRenderer()).thenReturn(nvRenderer);
    final CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
    when(serviceRegistrar.getService(CyApplicationManager.class)).thenReturn(appManager);
    VisualProperty<NullDataType> rootVisualProperty = mock(VisualProperty.class);
    BasicVisualLexicon lexicon = new BasicVisualLexicon(rootVisualProperty);
    vpSet = new HashSet<VisualProperty<Paint>>();
    vpSet.add(BasicVisualLexicon.NODE_BORDER_PAINT);
    vpSet.add(BasicVisualLexicon.NODE_FILL_COLOR);
    dependency = new VisualPropertyDependency<Paint>("dep1", "Dep 1", vpSet, lexicon);
    final VisualStyleFactoryImpl visualStyleFactory = new VisualStyleFactoryImpl(serviceRegistrar, ptFactory);
    originalTitle = "Style 1";
    newTitle = "Style 2";
    style = visualStyleFactory.createVisualStyle(originalTitle);
    style.setDefaultValue(NODE_SIZE, DEF_NODE_SIZE);
    style.setDefaultValue(NODE_FILL_COLOR, DEF_NODE_COLOR);
    reset(eventHelper);
}
Also used : NullVisualProperty(org.cytoscape.view.presentation.property.NullVisualProperty) CyEventHelper(org.cytoscape.event.CyEventHelper) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualLexicon(org.cytoscape.view.model.VisualLexicon) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) CyNetwork(org.cytoscape.model.CyNetwork) Paint(java.awt.Paint) NetworkViewTestSupport(org.cytoscape.ding.NetworkViewTestSupport) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) NullDataType(org.cytoscape.view.model.NullDataType) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualProperty(org.cytoscape.view.model.VisualProperty) NullVisualProperty(org.cytoscape.view.presentation.property.NullVisualProperty) HashSet(java.util.HashSet) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer) Before(org.junit.Before)

Example 2 with NullDataType

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

the class AbstractVisualLexiconTest method testTree.

protected void testTree(VisualLexicon lexicon) throws Exception {
    final VisualProperty<NullDataType> root = lexicon.getRootVisualProperty();
    assertNotNull(root);
    assertEquals(lexicon.getRootVisualProperty(), root);
    // test common methods
    try {
        Collection<VisualProperty<?>> result = lexicon.getAllDescendants(null);
    } catch (Exception e) {
        assertTrue(e instanceof NullPointerException);
    }
    try {
        Collection<VisualProperty<?>> result = lexicon.getAllDescendants(new DefaultVisualizableVisualProperty("test", "Test Visual Property", CyNode.class));
    } catch (Exception e) {
        assertTrue(e instanceof IllegalArgumentException);
    }
    final VisualLexiconNode rootNode = lexicon.getVisualLexiconNode(root);
    assertNotNull(rootNode);
    assertEquals(root, rootNode.getVisualProperty());
    final Collection<VisualLexiconNode> children = rootNode.getChildren();
    assertFalse(0 == children.size());
    traverse(children, lexicon);
    // Test adding
    final DoubleVisualProperty dummyVP = new DoubleVisualProperty(new Double(10), BasicVisualLexicon.ARBITRARY_DOUBLE_RANGE, "DUMMY", "Dummy VP", CyNode.class);
    try {
        ((BasicVisualLexicon) lexicon).addVisualProperty(BasicVisualLexicon.NODE_FILL_COLOR, root);
    } catch (Exception e) {
        assertTrue(e instanceof IllegalStateException);
    }
    try {
        ((BasicVisualLexicon) lexicon).addVisualProperty(dummyVP, null);
    } catch (Exception e) {
        assertTrue(e instanceof NullPointerException);
    }
    try {
        ((BasicVisualLexicon) lexicon).addVisualProperty(dummyVP, dummyVP);
    } catch (Exception e) {
        assertTrue(e instanceof IllegalArgumentException);
    }
    ((BasicVisualLexicon) lexicon).addVisualProperty(dummyVP, root);
}
Also used : VisualLexiconNode(org.cytoscape.view.model.VisualLexiconNode) NullDataType(org.cytoscape.view.model.NullDataType) VisualProperty(org.cytoscape.view.model.VisualProperty) CyNode(org.cytoscape.model.CyNode)

Example 3 with NullDataType

use of org.cytoscape.view.model.NullDataType 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

NullDataType (org.cytoscape.view.model.NullDataType)3 Paint (java.awt.Paint)2 VisualProperty (org.cytoscape.view.model.VisualProperty)2 NullVisualProperty (org.cytoscape.view.presentation.property.NullVisualProperty)2 Color (java.awt.Color)1 HashSet (java.util.HashSet)1 CyApplicationManager (org.cytoscape.application.CyApplicationManager)1 NetworkViewRenderer (org.cytoscape.application.NetworkViewRenderer)1 NetworkViewTestSupport (org.cytoscape.ding.NetworkViewTestSupport)1 CyEventHelper (org.cytoscape.event.CyEventHelper)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyNode (org.cytoscape.model.CyNode)1 CyTable (org.cytoscape.model.CyTable)1 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)1 VisualLexicon (org.cytoscape.view.model.VisualLexicon)1 VisualLexiconNode (org.cytoscape.view.model.VisualLexiconNode)1 Visualizable (org.cytoscape.view.model.Visualizable)1 BasicVisualLexicon (org.cytoscape.view.presentation.property.BasicVisualLexicon)1 VisualMappingFunctionFactory (org.cytoscape.view.vizmap.VisualMappingFunctionFactory)1 Before (org.junit.Before)1