Search in sources :

Example 1 with PassthroughMapping

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

the class VizMapPropertyBuilder method createMappingProperties.

public <K, V> void createMappingProperties(final VisualMappingFunction<K, V> visualMapping, final PropertySheetPanel propertySheetPanel, final VisualMappingFunctionFactory factory) {
    final String attrName = visualMapping.getMappingColumnName();
    if (attrName == null)
        return;
    removeMappingProperties(propertySheetPanel);
    final VisualProperty<V> vp = visualMapping.getVisualProperty();
    final VisualPropertyEditor<V> vpEditor = editorManager.getVisualPropertyEditor(vp);
    if (visualMapping instanceof DiscreteMapping) {
        // Discrete Mapping
        // This set should not contain null!
        final SortedSet<Object> attrSet = new TreeSet<Object>();
        final CyApplicationManager appMgr = servicesUtil.get(CyApplicationManager.class);
        final CyNetwork network = appMgr.getCurrentNetwork();
        if (network != null) {
            final Set<CyIdentifiable> graphObjects = new HashSet<CyIdentifiable>();
            if (network != null) {
                if (vp.getTargetDataType().equals(CyNode.class)) {
                    graphObjects.addAll(network.getNodeList());
                } else if (vp.getTargetDataType().equals(CyEdge.class)) {
                    graphObjects.addAll(network.getEdgeList());
                } else if (vp.getTargetDataType().equals(CyNetwork.class)) {
                    graphObjects.add(network);
                } else {
                    throw new IllegalArgumentException("Data type not supported: " + vp.getTargetDataType());
                }
            }
            if (vp.getTargetDataType() == CyNetwork.class) {
                final CyRow row = network.getRow(network);
                final CyColumn column = row.getTable().getColumn(attrName);
                if (column != null)
                    processDiscretValues(row, attrName, column, column.getType(), attrSet);
            } else {
                // Make sure all data sets have the same data type.
                if (!graphObjects.isEmpty()) {
                    final CyIdentifiable firstEntry = graphObjects.iterator().next();
                    final CyRow firstRow = network.getRow(firstEntry);
                    final CyColumn column = firstRow.getTable().getColumn(attrName);
                    if (column != null) {
                        final Class<?> type = column.getType();
                        for (final CyIdentifiable go : graphObjects) {
                            final CyRow row = network.getRow(go);
                            processDiscretValues(row, attrName, column, type, attrSet);
                        }
                    }
                }
            }
        }
        // Also keep current mapping entries that have non-null values
        for (final Map.Entry<K, V> entry : ((DiscreteMapping<K, V>) visualMapping).getAll().entrySet()) {
            if (entry.getValue() != null)
                attrSet.add(entry.getKey());
        }
        setDiscreteProps(vp, visualMapping, attrSet, vpEditor, propertySheetPanel);
    } else if (visualMapping instanceof ContinuousMapping) {
        // TODO: How do we decide when to reset the range tracer for this mapping?
        final VizMapperProperty<String, VisualMappingFunction, VisualMappingFunction<K, V>> graphicalView = new VizMapperProperty<String, VisualMappingFunction, VisualMappingFunction<K, V>>(CellType.CONTINUOUS, visualMapping.getVisualProperty().getDisplayName() + "_" + GRAPHICAL_MAP_VIEW, visualMapping.getClass());
        graphicalView.setShortDescription("Continuous Mapping from " + visualMapping.getMappingColumnName() + " to " + visualMapping.getVisualProperty().getDisplayName());
        graphicalView.setValue(visualMapping);
        graphicalView.setDisplayName("Current Mapping");
        propertySheetPanel.addProperty(2, graphicalView);
        final PropertySheetTable table = propertySheetPanel.getTable();
        final PropertyRendererRegistry rendReg = (PropertyRendererRegistry) table.getRendererFactory();
        final PropertyEditorRegistry cellEditorFactory = (PropertyEditorRegistry) table.getEditorFactory();
        final PropertyEditor continuousCellEditor = editorManager.getContinuousEditor(vp);
        if (continuousCellEditor == null) {
            throw new NullPointerException("Continuous Mapping cell editor is null.");
        } else {
            // Renderer for Continuous mapping icon cell
            final TableCellRenderer continuousRenderer = vpEditor.getContinuousTableCellRenderer((ContinuousMappingEditor<? extends Number, V>) continuousCellEditor);
            rendReg.registerRenderer(graphicalView, continuousRenderer);
            continuousCellEditor.setValue(visualMapping);
            cellEditorFactory.registerEditor(graphicalView, continuousCellEditor);
        }
    } else if (visualMapping instanceof PassthroughMapping && (attrName != null)) {
    // Doesn't need to display the mapped values!
    } else {
        throw new IllegalArgumentException("Unsupported mapping type: " + visualMapping);
    }
    propertySheetPanel.getTable().repaint();
    propertySheetPanel.repaint();
}
Also used : PropertyRendererRegistry(com.l2fprod.common.propertysheet.PropertyRendererRegistry) ContinuousMappingEditor(org.cytoscape.view.vizmap.gui.editor.ContinuousMappingEditor) VisualMappingFunction(org.cytoscape.view.vizmap.VisualMappingFunction) PropertyEditorRegistry(com.l2fprod.common.propertysheet.PropertyEditorRegistry) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) TreeSet(java.util.TreeSet) CyIdentifiable(org.cytoscape.model.CyIdentifiable) HashSet(java.util.HashSet) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) CyColumn(org.cytoscape.model.CyColumn) CyEdge(org.cytoscape.model.CyEdge) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) CyApplicationManager(org.cytoscape.application.CyApplicationManager) PropertySheetTable(com.l2fprod.common.propertysheet.PropertySheetTable) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) VisualPropertyEditor(org.cytoscape.view.vizmap.gui.editor.VisualPropertyEditor) PropertyEditor(java.beans.PropertyEditor) Map(java.util.Map)

Example 2 with PassthroughMapping

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

the class VisualStyleTest method testAddMappingFiresEvent.

@Test
@SuppressWarnings("rawtypes")
public void testAddMappingFiresEvent() {
    DiscreteMapping dm = mock(DiscreteMapping.class);
    when(dm.getVisualProperty()).thenReturn(NODE_BORDER_WIDTH);
    PassthroughMapping pm = mock(PassthroughMapping.class);
    when(pm.getVisualProperty()).thenReturn(NODE_BORDER_WIDTH);
    style.addVisualMappingFunction(dm);
    style.addVisualMappingFunction(pm);
    verify(eventHelper, times(2)).addEventPayload(eq(style), any(VisualStyleChangeRecord.class), eq(VisualStyleChangedEvent.class));
}
Also used : VisualStyleChangedEvent(org.cytoscape.view.vizmap.events.VisualStyleChangedEvent) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) VisualStyleChangeRecord(org.cytoscape.view.vizmap.events.VisualStyleChangeRecord) Test(org.junit.Test) AbstractVisualStyleTest(org.cytoscape.view.vizmap.AbstractVisualStyleTest)

Example 3 with PassthroughMapping

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

the class VisualStyleSerializerTest method testCy240Vizmap.

@Test
@SuppressWarnings("unchecked")
public void testCy240Vizmap() throws Exception {
    Properties props = loadVizmapProps("v240_vizmap.props");
    Set<VisualStyle> styles = serializer.createVisualStyles(props);
    assertEquals(4, styles.size());
    assertVisualStylesNotNull(styles, new String[] { "default", "Sample1", "Sample2", "SimpleBioMoleculeEditor" });
    // Test visual styles (defaults, mappings and dependencies)
    // -----
    VisualStyle def = getVisualStyleByTitle(styles, DEFAULT_STYLE_NAME);
    assertEquals(new Color(204, 204, 254), def.getDefaultValue(NETWORK_BACKGROUND_PAINT));
    assertEquals(new Color(0, 0, 255), def.getDefaultValue(EDGE_UNSELECTED_PAINT));
    assertEquals(new Color(0, 0, 255), def.getDefaultValue(EDGE_STROKE_UNSELECTED_PAINT));
    assertEquals(new Color(254, 0, 0), def.getDefaultValue(EDGE_STROKE_SELECTED_PAINT));
    assertEquals(new Color(255, 153, 153), def.getDefaultValue(NODE_FILL_COLOR));
    assertEquals(new Color(254, 254, 0), def.getDefaultValue(NODE_SELECTED_PAINT));
    PassthroughMapping<String, String> nLabelMp = (PassthroughMapping<String, String>) def.getVisualMappingFunction(NODE_LABEL);
    assertEquals(NAME, nLabelMp.getMappingColumnName());
    assertEquals(String.class, nLabelMp.getMappingColumnType());
    ContinuousMapping<Double, Paint> nColorMp = (ContinuousMapping<Double, Paint>) def.getVisualMappingFunction(NODE_FILL_COLOR);
    assertEquals("gal1RGexp", nColorMp.getMappingColumnName());
    assertEquals(Number.class, nColorMp.getMappingColumnType());
    assertEquals(3, nColorMp.getPointCount());
    assertEquals(-2.5, nColorMp.getPoint(0).getValue(), 0.0001);
    assertEquals(new Color(255, 0, 0), nColorMp.getPoint(0).getRange().equalValue);
    assertEquals(new Color(255, 0, 0), nColorMp.getPoint(0).getRange().greaterValue);
    assertEquals(new Color(0, 0, 255), nColorMp.getPoint(0).getRange().lesserValue);
    assertEquals(0.0, nColorMp.getPoint(1).getValue(), 0.0);
    assertEquals(new Color(255, 255, 255), nColorMp.getPoint(1).getRange().equalValue);
    assertEquals(new Color(255, 255, 255), nColorMp.getPoint(1).getRange().greaterValue);
    assertEquals(new Color(255, 255, 255), nColorMp.getPoint(1).getRange().lesserValue);
    assertEquals(2.1, nColorMp.getPoint(2).getValue(), 0.0001);
    assertEquals(new Color(0, 255, 102), nColorMp.getPoint(2).getRange().equalValue);
    assertEquals(new Color(0, 0, 0), nColorMp.getPoint(2).getRange().greaterValue);
    assertEquals(new Color(0, 255, 102), nColorMp.getPoint(2).getRange().lesserValue);
    ContinuousMapping<Double, NodeShape> nShapeMp = (ContinuousMapping<Double, NodeShape>) def.getVisualMappingFunction(NODE_SHAPE);
    assertEquals("gal1RGexp", nShapeMp.getMappingColumnName());
    assertEquals(Number.class, nShapeMp.getMappingColumnType());
    assertEquals(3, nShapeMp.getPointCount());
    assertEquals(-1.0, nShapeMp.getPoint(0).getValue(), 0.0);
    assertEquals(NodeShapeVisualProperty.ELLIPSE, nShapeMp.getPoint(0).getRange().equalValue);
    assertEquals(NodeShapeVisualProperty.ELLIPSE, nShapeMp.getPoint(0).getRange().greaterValue);
    assertEquals(NodeShapeVisualProperty.PARALLELOGRAM, nShapeMp.getPoint(0).getRange().lesserValue);
    assertEquals(0.0, nShapeMp.getPoint(1).getValue(), 0.0);
    assertEquals(NodeShapeVisualProperty.DIAMOND, nShapeMp.getPoint(1).getRange().equalValue);
    assertEquals(NodeShapeVisualProperty.RECTANGLE, nShapeMp.getPoint(1).getRange().greaterValue);
    assertEquals(NodeShapeVisualProperty.ELLIPSE, nShapeMp.getPoint(1).getRange().lesserValue);
    assertEquals(1.0, nShapeMp.getPoint(2).getValue(), 0.0);
    assertEquals(NodeShapeVisualProperty.RECTANGLE, nShapeMp.getPoint(2).getRange().equalValue);
    assertEquals(NodeShapeVisualProperty.HEXAGON, nShapeMp.getPoint(2).getRange().greaterValue);
    assertEquals(NodeShapeVisualProperty.RECTANGLE, nShapeMp.getPoint(2).getRange().lesserValue);
    ContinuousMapping<Double, Double> nSizeMp = (ContinuousMapping<Double, Double>) def.getVisualMappingFunction(NODE_SIZE);
    assertEquals("gal1RGexp", nSizeMp.getMappingColumnName());
    assertEquals(Number.class, nSizeMp.getMappingColumnType());
    assertEquals(2, nSizeMp.getPointCount());
    assertEquals(0.0, nSizeMp.getPoint(0).getValue(), 0.0);
    assertEquals(50, nSizeMp.getPoint(0).getRange().equalValue.intValue());
    assertEquals(50, nSizeMp.getPoint(0).getRange().greaterValue.intValue());
    assertEquals(20, nSizeMp.getPoint(0).getRange().lesserValue.intValue());
    assertEquals(1.0, nSizeMp.getPoint(1).getValue(), 0.0);
    assertEquals(100, nSizeMp.getPoint(1).getRange().equalValue.intValue());
    assertEquals(100, nSizeMp.getPoint(1).getRange().greaterValue.intValue());
    assertEquals(100, nSizeMp.getPoint(1).getRange().lesserValue.intValue());
    // -----
    VisualStyle bio = getVisualStyleByTitle(styles, "SimpleBioMoleculeEditor");
    assertEquals(new Color(204, 204, 255), bio.getDefaultValue(NETWORK_BACKGROUND_PAINT));
    assertEquals(new Color(0, 0, 0), bio.getDefaultValue(EDGE_STROKE_UNSELECTED_PAINT));
    assertEquals(new Color(255, 0, 0), bio.getDefaultValue(EDGE_STROKE_SELECTED_PAINT));
    assertEquals(Font.decode("Monospaced-PLAIN-12"), bio.getDefaultValue(EDGE_LABEL_FONT_FACE));
    // defaultEdgeLineType=DASHED_2 (split "DASHED" + "2")
    assertEquals(LineTypeVisualProperty.EQUAL_DASH, bio.getDefaultValue(EDGE_LINE_TYPE));
    assertEquals(2, bio.getDefaultValue(EDGE_WIDTH).intValue());
    // defaultEdgeSourceArrow=WHITE_T (can't test EDGE_SOURCE_ARROW_UNSELECTED_PAINT; it's Ding Lexicon's property)
    assertEquals(ArrowShapeVisualProperty.T, bio.getDefaultValue(EDGE_SOURCE_ARROW_SHAPE));
    // defaultEdgeTargetArrow=BLACK_ARROW
    assertEquals(ArrowShapeVisualProperty.ARROW, bio.getDefaultValue(EDGE_TARGET_ARROW_SHAPE));
    assertEquals(new Color(255, 255, 255), bio.getDefaultValue(NODE_FILL_COLOR));
    assertEquals(new Color(255, 255, 0), bio.getDefaultValue(NODE_SELECTED_PAINT));
    assertEquals(35, bio.getDefaultValue(NODE_HEIGHT).intValue());
    assertEquals(28, bio.getDefaultValue(NODE_WIDTH).intValue());
    assertEquals(42, bio.getDefaultValue(NODE_SIZE).intValue());
    // defaultNodeLineType=LINE_1
    assertEquals(LineTypeVisualProperty.SOLID, bio.getDefaultValue(NODE_BORDER_LINE_TYPE));
    assertEquals(1, bio.getDefaultValue(NODE_BORDER_WIDTH).intValue());
    assertEquals(NodeShapeVisualProperty.RECTANGLE, bio.getDefaultValue(NODE_SHAPE));
    nLabelMp = (PassthroughMapping<String, String>) bio.getVisualMappingFunction(NODE_LABEL);
    assertEquals("canonicalName", nLabelMp.getMappingColumnName());
    assertEquals(String.class, nLabelMp.getMappingColumnType());
    DiscreteMapping<String, NodeShape> nShape = (DiscreteMapping<String, NodeShape>) bio.getVisualMappingFunction(NODE_SHAPE);
    assertEquals("NODE_TYPE", nShape.getMappingColumnName());
    assertEquals(String.class, nShape.getMappingColumnType());
    assertEquals(NodeShapeVisualProperty.ELLIPSE, nShape.getMapValue("biochemicalReaction"));
    assertEquals(NodeShapeVisualProperty.ROUND_RECTANGLE, nShape.getMapValue("catalyst"));
    assertEquals(NodeShapeVisualProperty.RECTANGLE, nShape.getMapValue("protein"));
    assertEquals(NodeShapeVisualProperty.DIAMOND, nShape.getMapValue("smallMolecule"));
}
Also used : ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) Color(java.awt.Color) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) Matchers.anyString(org.mockito.Matchers.anyString) Paint(java.awt.Paint) Properties(java.util.Properties) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) NodeShape(org.cytoscape.view.presentation.property.values.NodeShape) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) Test(org.junit.Test)

Example 4 with PassthroughMapping

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

the class VisualStyleSerializerTest method testCy283Vizmap.

@Test
@SuppressWarnings("unchecked")
public void testCy283Vizmap() throws Exception {
    Properties props = loadVizmapProps("v283_vizmap.props");
    Set<VisualStyle> styles = serializer.createVisualStyles(props);
    assertEquals(6, styles.size());
    assertVisualStylesNotNull(styles, new String[] { "default", "Sample1", "Solid", "Universe", "{Gal_Filt}: -(1:2),&[A*|B?]+%$#@!\\/;", /*Testing special chars*/
    "Nested Network Style" });
    // Test visual styles (defaults, mappings and dependencies)
    // -----
    VisualStyle sample1 = getVisualStyleByTitle(styles, "Sample1");
    assertEquals(new Color(255, 255, 204), sample1.getDefaultValue(NETWORK_BACKGROUND_PAINT));
    assertEquals(Color.BLACK, sample1.getDefaultValue(EDGE_UNSELECTED_PAINT));
    assertEquals(Color.BLACK, sample1.getDefaultValue(EDGE_STROKE_UNSELECTED_PAINT));
    assertEquals(new Color(255, 0, 1), sample1.getDefaultValue(EDGE_STROKE_SELECTED_PAINT));
    assertEquals(Font.decode("Default-PLAIN-10"), sample1.getDefaultValue(EDGE_LABEL_FONT_FACE));
    assertEquals(10, sample1.getDefaultValue(EDGE_LABEL_FONT_SIZE).intValue());
    assertEquals(new Color(0, 10, 0), sample1.getDefaultValue(EDGE_LABEL_COLOR));
    assertEquals(120, sample1.getDefaultValue(EDGE_LABEL_TRANSPARENCY).intValue());
    assertEquals("", sample1.getDefaultValue(EDGE_LABEL));
    assertEquals(LineTypeVisualProperty.SOLID, sample1.getDefaultValue(EDGE_LINE_TYPE));
    assertEquals(1, sample1.getDefaultValue(EDGE_WIDTH).intValue());
    assertEquals(180, sample1.getDefaultValue(EDGE_TRANSPARENCY).intValue());
    assertEquals(ArrowShapeVisualProperty.NONE, sample1.getDefaultValue(EDGE_SOURCE_ARROW_SHAPE));
    assertEquals(ArrowShapeVisualProperty.CIRCLE, sample1.getDefaultValue(EDGE_TARGET_ARROW_SHAPE));
    assertEquals("", sample1.getDefaultValue(EDGE_TOOLTIP));
    assertEquals(new Color(10, 20, 0), sample1.getDefaultValue(NODE_BORDER_PAINT));
    assertEquals(242, sample1.getDefaultValue(NODE_BORDER_TRANSPARENCY).intValue());
    assertEquals(new Color(204, 204, 255), sample1.getDefaultValue(NODE_FILL_COLOR));
    assertEquals(new Color(255, 255, 1), sample1.getDefaultValue(NODE_SELECTED_PAINT));
    assertEquals(Font.decode("Dialog-BOLD-12"), sample1.getDefaultValue(NODE_LABEL_FONT_FACE));
    assertEquals(12, sample1.getDefaultValue(NODE_LABEL_FONT_SIZE).intValue());
    assertEquals("node", sample1.getDefaultValue(NODE_LABEL));
    assertEquals(new Color(0, 0, 255), sample1.getDefaultValue(NODE_LABEL_COLOR));
    assertEquals(220, sample1.getDefaultValue(NODE_LABEL_TRANSPARENCY).intValue());
    assertEquals(30, sample1.getDefaultValue(NODE_HEIGHT).intValue());
    assertEquals(70, sample1.getDefaultValue(NODE_WIDTH).intValue());
    assertEquals(40, sample1.getDefaultValue(NODE_SIZE).intValue());
    assertEquals(LineTypeVisualProperty.LONG_DASH, sample1.getDefaultValue(NODE_BORDER_LINE_TYPE));
    assertEquals(0, sample1.getDefaultValue(NODE_BORDER_WIDTH).intValue());
    assertEquals(250, sample1.getDefaultValue(NODE_TRANSPARENCY).intValue());
    assertEquals(NodeShapeVisualProperty.ELLIPSE, sample1.getDefaultValue(NODE_SHAPE));
    assertEquals(true, sample1.getDefaultValue(NODE_NESTED_NETWORK_IMAGE_VISIBLE));
    assertEquals("My test...", sample1.getDefaultValue(NODE_TOOLTIP));
    PassthroughMapping<String, String> nLabelMp = (PassthroughMapping<String, String>) sample1.getVisualMappingFunction(NODE_LABEL);
    assertEquals(NAME, nLabelMp.getMappingColumnName());
    assertEquals(String.class, nLabelMp.getMappingColumnType());
    PassthroughMapping<String, String> eLabelMp = (PassthroughMapping<String, String>) sample1.getVisualMappingFunction(EDGE_LABEL);
    assertEquals(INTERACTION, eLabelMp.getMappingColumnName());
    DiscreteMapping<String, Paint> eColorMp1 = (DiscreteMapping<String, Paint>) sample1.getVisualMappingFunction(EDGE_UNSELECTED_PAINT);
    assertEquals(INTERACTION, eColorMp1.getMappingColumnName());
    assertEquals(String.class, eColorMp1.getMappingColumnType());
    assertEquals(new Color(255, 0, 51), eColorMp1.getMapValue("pd"));
    assertEquals(new Color(0, 204, 0), eColorMp1.getMapValue("pp"));
    DiscreteMapping<String, Paint> eColorMp2 = (DiscreteMapping<String, Paint>) sample1.getVisualMappingFunction(EDGE_STROKE_UNSELECTED_PAINT);
    assertEquals(INTERACTION, eColorMp2.getMappingColumnName());
    assertEquals(String.class, eColorMp2.getMappingColumnType());
    assertEquals(new Color(255, 0, 51), eColorMp2.getMapValue("pd"));
    assertEquals(new Color(0, 204, 0), eColorMp2.getMapValue("pp"));
    DiscreteMapping<String, LineType> eTypeMp = (DiscreteMapping<String, LineType>) sample1.getVisualMappingFunction(EDGE_LINE_TYPE);
    assertEquals(INTERACTION, eTypeMp.getMappingColumnName());
    assertEquals(LineTypeVisualProperty.LONG_DASH, eTypeMp.getMapValue("pd"));
    assertEquals(LineTypeVisualProperty.SOLID, eTypeMp.getMapValue("pp"));
    VisualPropertyDependency<?> dep1 = getDependency(sample1, NODE_SIZE_LOCKED_DEPENDENCY);
    assertFalse(dep1.isDependencyEnabled());
    // -----
    VisualStyle galFiltered = getVisualStyleByTitle(styles, "{Gal_Filt}: -(1:2),&[A*|B?]+%$#@!\\/;");
    ContinuousMapping<Double, Paint> nColorMp = (ContinuousMapping<Double, Paint>) galFiltered.getVisualMappingFunction(NODE_FILL_COLOR);
    assertEquals("gal4RGexp", nColorMp.getMappingColumnName());
    assertEquals(Number.class, nColorMp.getMappingColumnType());
    assertEquals(3, nColorMp.getPointCount());
    assertEquals(-2.0249776914715767, nColorMp.getPoint(0).getValue(), 0.0001);
    assertEquals(new Color(255, 0, 0), nColorMp.getPoint(0).getRange().equalValue);
    assertEquals(new Color(255, 0, 0), nColorMp.getPoint(0).getRange().greaterValue);
    assertEquals(Color.BLACK, nColorMp.getPoint(0).getRange().lesserValue);
    assertEquals(0.20517408847808838, nColorMp.getPoint(1).getValue(), 0.0001);
    assertEquals(Color.WHITE, nColorMp.getPoint(1).getRange().equalValue);
    assertEquals(Color.WHITE, nColorMp.getPoint(1).getRange().greaterValue);
    assertEquals(Color.WHITE, nColorMp.getPoint(1).getRange().lesserValue);
    assertEquals(2.5, nColorMp.getPoint(2).getValue(), 0.0001);
    assertEquals(new Color(0, 153, 0), nColorMp.getPoint(2).getRange().equalValue);
    assertEquals(new Color(0, 0, 204), nColorMp.getPoint(2).getRange().greaterValue);
    assertEquals(new Color(0, 153, 0), nColorMp.getPoint(2).getRange().lesserValue);
    VisualPropertyDependency<?> dep2 = getDependency(galFiltered, NODE_SIZE_LOCKED_DEPENDENCY);
    assertTrue(dep2.isDependencyEnabled());
    // -----
    VisualStyle nested = getVisualStyleByTitle(styles, "Nested Network Style");
    DiscreteMapping<Boolean, Paint> nLabelColorMp = (DiscreteMapping<Boolean, Paint>) nested.getVisualMappingFunction(NODE_LABEL_COLOR);
    assertEquals("has_nested_network", nLabelColorMp.getMappingColumnName());
    assertEquals(Boolean.class, nLabelColorMp.getMappingColumnType());
    assertEquals(new Color(0, 102, 204), nLabelColorMp.getMapValue(true));
}
Also used : ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) Color(java.awt.Color) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) Matchers.anyString(org.mockito.Matchers.anyString) Paint(java.awt.Paint) Properties(java.util.Properties) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) LineType(org.cytoscape.view.presentation.property.values.LineType) Test(org.junit.Test)

Example 5 with PassthroughMapping

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

the class VisualStyleSerializer method createVisualProperties.

@SuppressWarnings("unchecked")
private <K, V> void createVisualProperties(VisualStyle vs, Class<? extends CyIdentifiable> targetType, List<org.cytoscape.io.internal.util.vizmap.model.VisualProperty> vpModelList) {
    for (org.cytoscape.io.internal.util.vizmap.model.VisualProperty vpModel : vpModelList) {
        String vpId = vpModel.getName();
        String defValue = vpModel.getDefault();
        VisualProperty<V> vp = (VisualProperty<V>) lexicon.lookup(targetType, vpId);
        if (vp != null) {
            // Default Value
            if (defValue != null) {
                V value = parseValue(defValue, vp);
                vs.setDefaultValue(vp, value);
            }
            // Any mapping?
            if (vpModel.getPassthroughMapping() != null) {
                org.cytoscape.io.internal.util.vizmap.model.PassthroughMapping pmModel = vpModel.getPassthroughMapping();
                final String attrName = pmModel.getAttributeName();
                final AttributeType attrType = pmModel.getAttributeType();
                final Class<?> columnDataType;
                if (attrType == AttributeType.BOOLEAN)
                    columnDataType = Boolean.class;
                else if (attrType == AttributeType.FLOAT)
                    columnDataType = Double.class;
                else if (attrType == AttributeType.INTEGER)
                    columnDataType = Integer.class;
                else if (attrType == AttributeType.LONG)
                    columnDataType = Long.class;
                else if (attrType == AttributeType.LIST)
                    columnDataType = List.class;
                else
                    columnDataType = String.class;
                try {
                    VisualMappingFunctionFactory pmFactory = serviceRegistrar.getService(VisualMappingFunctionFactory.class, "(mapping.type=passthrough)");
                    PassthroughMapping<K, V> pm = (PassthroughMapping<K, V>) pmFactory.createVisualMappingFunction(attrName, columnDataType, vp);
                    vs.addVisualMappingFunction(pm);
                } catch (Throwable e) {
                    logger.error("Cannot create PassthroughMapping (style=" + vs.getTitle() + ", property=" + vp.getIdString() + ")", e);
                }
            } else if (vpModel.getDiscreteMapping() != null) {
                org.cytoscape.io.internal.util.vizmap.model.DiscreteMapping dmModel = vpModel.getDiscreteMapping();
                String attrName = dmModel.getAttributeName();
                AttributeType attrType = dmModel.getAttributeType();
                try {
                    Class<?> attrClass = null;
                    // TODO refactor attr type assignment
                    switch(attrType) {
                        case BOOLEAN:
                            attrClass = Boolean.class;
                            break;
                        case FLOAT:
                            attrClass = Double.class;
                            break;
                        case INTEGER:
                            attrClass = Integer.class;
                            break;
                        case LONG:
                            attrClass = Long.class;
                            break;
                        default:
                            attrClass = String.class;
                            break;
                    }
                    VisualMappingFunctionFactory dmFactory = serviceRegistrar.getService(VisualMappingFunctionFactory.class, "(mapping.type=discrete)");
                    DiscreteMapping<K, V> dm = (DiscreteMapping<K, V>) dmFactory.createVisualMappingFunction(attrName, attrClass, vp);
                    for (DiscreteMappingEntry entryModel : dmModel.getDiscreteMappingEntry()) {
                        String sAttrValue = entryModel.getAttributeValue();
                        String sValue = entryModel.getValue();
                        if (sAttrValue != null && sValue != null) {
                            Object attrValue = null;
                            switch(attrType) {
                                case BOOLEAN:
                                    attrValue = Boolean.parseBoolean(sAttrValue);
                                    break;
                                case FLOAT:
                                    attrValue = Double.parseDouble(sAttrValue);
                                    break;
                                case INTEGER:
                                    attrValue = Integer.parseInt(sAttrValue);
                                    break;
                                case LONG:
                                    attrValue = Long.parseLong(sAttrValue);
                                    break;
                                default:
                                    // Note: Always handle List type as String!
                                    attrValue = sAttrValue;
                                    break;
                            }
                            V vpValue = parseValue(sValue, vp);
                            if (vpValue != null)
                                dm.putMapValue((K) attrValue, vpValue);
                        }
                    }
                    vs.addVisualMappingFunction(dm);
                } catch (Throwable e) {
                    logger.error("Cannot create DiscreteMapping (style=" + vs.getTitle() + ", property=" + vp.getIdString() + ")", e);
                }
            } else if (vpModel.getContinuousMapping() != null) {
                org.cytoscape.io.internal.util.vizmap.model.ContinuousMapping cmModel = vpModel.getContinuousMapping();
                String attrName = cmModel.getAttributeName();
                try {
                    VisualMappingFunctionFactory cmFactory = serviceRegistrar.getService(VisualMappingFunctionFactory.class, "(mapping.type=continuous)");
                    ContinuousMapping<K, V> cm = (ContinuousMapping<K, V>) cmFactory.createVisualMappingFunction(attrName, Number.class, vp);
                    for (org.cytoscape.io.internal.util.vizmap.model.ContinuousMappingPoint pModel : cmModel.getContinuousMappingPoint()) {
                        // Should be numbers or colors
                        V lesser = parseValue(pModel.getLesserValue(), vp);
                        V equal = parseValue(pModel.getEqualValue(), vp);
                        V greater = parseValue(pModel.getGreaterValue(), vp);
                        BoundaryRangeValues<V> brv = new BoundaryRangeValues<V>(lesser, equal, greater);
                        Double attrValue = pModel.getAttrValue().doubleValue();
                        cm.addPoint((K) attrValue, brv);
                    }
                    vs.addVisualMappingFunction(cm);
                } catch (Throwable e) {
                    logger.error("Cannot create ContinuousMapping (style=" + vs.getTitle() + ", property=" + vp.getIdString() + ")", e);
                }
            }
        }
    }
}
Also used : VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) AttributeType(org.cytoscape.io.internal.util.vizmap.model.AttributeType) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues) List(java.util.List) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) VisualProperty(org.cytoscape.view.model.VisualProperty) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) DiscreteMappingEntry(org.cytoscape.io.internal.util.vizmap.model.DiscreteMappingEntry)

Aggregations

PassthroughMapping (org.cytoscape.view.vizmap.mappings.PassthroughMapping)13 ContinuousMapping (org.cytoscape.view.vizmap.mappings.ContinuousMapping)10 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)10 Paint (java.awt.Paint)6 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)6 Test (org.junit.Test)5 Color (java.awt.Color)4 Properties (java.util.Properties)4 Matchers.anyString (org.mockito.Matchers.anyString)4 CyNetwork (org.cytoscape.model.CyNetwork)3 VisualProperty (org.cytoscape.view.model.VisualProperty)3 VisualMappingFunctionFactory (org.cytoscape.view.vizmap.VisualMappingFunctionFactory)3 Map (java.util.Map)2 CyApplicationManager (org.cytoscape.application.CyApplicationManager)2 AttributeType (org.cytoscape.io.internal.util.vizmap.model.AttributeType)2 DiscreteMappingEntry (org.cytoscape.io.internal.util.vizmap.model.DiscreteMappingEntry)2 LineType (org.cytoscape.view.presentation.property.values.LineType)2 BoundaryRangeValues (org.cytoscape.view.vizmap.mappings.BoundaryRangeValues)2 PropertyEditorRegistry (com.l2fprod.common.propertysheet.PropertyEditorRegistry)1 PropertyRendererRegistry (com.l2fprod.common.propertysheet.PropertyRendererRegistry)1