Search in sources :

Example 11 with PassthroughMapping

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

the class LegendDialog method createMappingLegends.

@SuppressWarnings("rawtypes")
private void createMappingLegends(final Collection<VisualMappingFunction<?, ?>> mappings, final JPanel legend) {
    for (VisualMappingFunction<?, ?> map : mappings) {
        final CyApplicationManager appMgr = servicesUtil.get(CyApplicationManager.class);
        final JPanel mappingLegend;
        if (map instanceof ContinuousMapping) {
            mappingLegend = new ContinuousLegendPanel(visualStyle, (ContinuousMapping) map, appMgr.getCurrentNetwork().getDefaultNodeTable(), servicesUtil);
        } else if (map instanceof DiscreteMapping) {
            mappingLegend = new DiscreteLegendPanel((DiscreteMapping<?, ?>) map, servicesUtil);
        } else if (map instanceof DiscreteMapping) {
            mappingLegend = new PassthroughLegendPanel((PassthroughMapping<?, ?>) map, servicesUtil);
        } else {
            continue;
        }
        // display anything besides the title.
        if (map instanceof PassthroughMapping)
            legend.add(mappingLegend, 0);
        else
            legend.add(mappingLegend);
        // Set padding
        mappingLegend.setBorder(new EmptyBorder(15, 30, 15, 30));
    }
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) JPanel(javax.swing.JPanel) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) EmptyBorder(javax.swing.border.EmptyBorder)

Example 12 with PassthroughMapping

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

the class VisualStyleSerializer method createVizmapProperties.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void createVizmapProperties(final VisualStyle vs, final VisualProperty<Visualizable> root, final List<org.cytoscape.io.internal.util.vizmap.model.VisualProperty> vpModelList) {
    final Collection<VisualProperty<?>> vpList = lexicon.getAllDescendants(root);
    final Iterator<VisualProperty<?>> iter = vpList.iterator();
    while (iter.hasNext()) {
        final VisualProperty vp = iter.next();
        try {
            // NETWORK root includes NODES and EDGES, but we want to separate the CyNetwork properties!
            if (root == BasicVisualLexicon.NETWORK && vp.getTargetDataType() != CyNetwork.class)
                continue;
            Object defValue = vs.getDefaultValue(vp);
            final VisualMappingFunction<?, ?> mapping = vs.getVisualMappingFunction(vp);
            if (defValue != null || mapping != null) {
                org.cytoscape.io.internal.util.vizmap.model.VisualProperty vpModel = new org.cytoscape.io.internal.util.vizmap.model.VisualProperty();
                vpModel.setName(vp.getIdString());
                vpModelList.add(vpModel);
                try {
                    if (defValue != null) {
                        String sValue = vp.toSerializableString(defValue);
                        if (sValue != null)
                            vpModel.setDefault(sValue);
                    }
                } catch (final Exception e) {
                    System.out.println("CCE in VisualStyleSerielizer");
                }
                if (mapping instanceof PassthroughMapping<?, ?>) {
                    PassthroughMapping<?, ?> pm = (PassthroughMapping<?, ?>) mapping;
                    AttributeType attrType = toAttributeType(pm.getMappingColumnType());
                    org.cytoscape.io.internal.util.vizmap.model.PassthroughMapping pmModel = new org.cytoscape.io.internal.util.vizmap.model.PassthroughMapping();
                    pmModel.setAttributeName(pm.getMappingColumnName());
                    pmModel.setAttributeType(attrType);
                    vpModel.setPassthroughMapping(pmModel);
                } else if (mapping instanceof DiscreteMapping<?, ?>) {
                    DiscreteMapping<?, ?> dm = (DiscreteMapping<?, ?>) mapping;
                    AttributeType attrType = toAttributeType(dm.getMappingColumnType());
                    org.cytoscape.io.internal.util.vizmap.model.DiscreteMapping dmModel = new org.cytoscape.io.internal.util.vizmap.model.DiscreteMapping();
                    dmModel.setAttributeName(dm.getMappingColumnName());
                    dmModel.setAttributeType(attrType);
                    Map<?, ?> map = dm.getAll();
                    for (Map.Entry<?, ?> entry : map.entrySet()) {
                        final Object value = entry.getValue();
                        if (value == null)
                            continue;
                        try {
                            DiscreteMappingEntry entryModel = new DiscreteMappingEntry();
                            entryModel.setAttributeValue(entry.getKey().toString());
                            // System.out.println("DiscreteMapEntry: " + entry.getKey().toString() + " = " + value);
                            entryModel.setValue(vp.toSerializableString(value));
                            dmModel.getDiscreteMappingEntry().add(entryModel);
                        } catch (Exception e) {
                            logger.warn("Could not add Discrete Mapping entry: " + value, e);
                        }
                    }
                    vpModel.setDiscreteMapping(dmModel);
                } else if (mapping instanceof ContinuousMapping<?, ?>) {
                    final ContinuousMapping<?, ?> cm = (ContinuousMapping<?, ?>) mapping;
                    AttributeType attrType = toAttributeType(cm.getMappingColumnType());
                    org.cytoscape.io.internal.util.vizmap.model.ContinuousMapping cmModel = new org.cytoscape.io.internal.util.vizmap.model.ContinuousMapping();
                    cmModel.setAttributeName(cm.getMappingColumnName());
                    cmModel.setAttributeType(attrType);
                    List<?> points = cm.getAllPoints();
                    for (Object point : points) {
                        ContinuousMappingPoint<?, ?> continuousPoint = (ContinuousMappingPoint<?, ?>) point;
                        org.cytoscape.io.internal.util.vizmap.model.ContinuousMappingPoint pModel = new org.cytoscape.io.internal.util.vizmap.model.ContinuousMappingPoint();
                        Object originalValue = continuousPoint.getValue();
                        final String sValue = originalValue.toString();
                        final BigDecimal value = new BigDecimal(sValue);
                        pModel.setAttrValue(value);
                        Object lesser = continuousPoint.getRange().lesserValue;
                        Object equal = continuousPoint.getRange().equalValue;
                        Object greater = continuousPoint.getRange().greaterValue;
                        pModel.setLesserValue(vp.toSerializableString(lesser));
                        pModel.setEqualValue(vp.toSerializableString(equal));
                        pModel.setGreaterValue(vp.toSerializableString(greater));
                        cmModel.getContinuousMappingPoint().add(pModel);
                    }
                    vpModel.setContinuousMapping(cmModel);
                }
            }
        } catch (final Exception e) {
            logger.error("Cannot save visual property: " + (vp != null ? vp.getDisplayName() : ""), e);
        }
    }
}
Also used : CyNetwork(org.cytoscape.model.CyNetwork) ContinuousMappingPoint(org.cytoscape.view.vizmap.mappings.ContinuousMappingPoint) DiscreteMappingEntry(org.cytoscape.io.internal.util.vizmap.model.DiscreteMappingEntry) Entry(java.util.Map.Entry) AttributeType(org.cytoscape.io.internal.util.vizmap.model.AttributeType) ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping) BigDecimal(java.math.BigDecimal) VisualProperty(org.cytoscape.view.model.VisualProperty) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) HashMap(java.util.HashMap) Map(java.util.Map) DiscreteMappingEntry(org.cytoscape.io.internal.util.vizmap.model.DiscreteMappingEntry)

Example 13 with PassthroughMapping

use of org.cytoscape.view.vizmap.mappings.PassthroughMapping in project PhenomeScape by soulj.

the class VizStyle method createVizStyle.

public VisualStyle createVizStyle(CyServiceRegistrar cyServiceRegistrar, String geneName, String foldchangeName, double maxFC, double minFC) {
    // To get references to services in CyActivator class
    VisualMappingManager vmmServiceRef = cyServiceRegistrar.getService(VisualMappingManager.class);
    VisualStyleFactory visualStyleFactoryServiceRef = cyServiceRegistrar.getService(VisualStyleFactory.class);
    VisualMappingFunctionFactory vmfFactoryC = cyServiceRegistrar.getService(VisualMappingFunctionFactory.class, "(mapping.type=continuous)");
    VisualMappingFunctionFactory vmfFactoryD = cyServiceRegistrar.getService(VisualMappingFunctionFactory.class, "(mapping.type=discrete)");
    VisualMappingFunctionFactory vmfFactoryP = cyServiceRegistrar.getService(VisualMappingFunctionFactory.class, "(mapping.type=passthrough)");
    // To create a new VisualStyle object and set the mapping function
    VisualStyle vs = visualStyleFactoryServiceRef.createVisualStyle("PhenomeScape");
    // Use pass-through mapping to create the node label
    PassthroughMapping nameMapping = (PassthroughMapping) vmfFactoryP.createVisualMappingFunction(geneName, String.class, BasicVisualLexicon.NODE_LABEL);
    vs.addVisualMappingFunction(nameMapping);
    vs.setDefaultValue(BasicVisualLexicon.NODE_SIZE, 15.0);
    // RenderingEngineManager renderingEngineManager = cyServiceRegistrar.getService(RenderingEngineManager.class);
    // CyNetworkViewManager viewManager = cyServiceRegistrar.getService(CyNetworkViewManager.class);
    // CyNetworkViewFactory networkViewFactory = cyServiceRegistrar.getService(CyNetworkViewFactory.class);
    // Set<CyNetworkView> views = viewManager.getNetworkViewSet();
    // CyNetworkView networkView = views.iterator().next();
    // Collection<RenderingEngine<?>> engines = renderingEngineManager.getAllRenderingEngines();
    // VisualLexicon lex = engines.iterator().next().getVisualLexicon();
    // VisualProperty prop = lex.lookup(CyNode.class, "NODE_LABEL_POSITION");
    // Object value = prop.parseSerializableString("S,N,c,0.0,5.0"); // Put the north of the label on the southeast corner of the node
    // vs.setDefaultValue(prop, value);
    // Set the node size to smaller than the default
    // Set node color map to attribute "FoldChange"
    ContinuousMapping mapping = (ContinuousMapping) vmfFactoryC.createVisualMappingFunction(foldchangeName, Double.class, BasicVisualLexicon.NODE_FILL_COLOR);
    // Define the points
    BoundaryRangeValues<Paint> brv1 = new BoundaryRangeValues<Paint>(Color.GREEN, Color.GREEN, Color.WHITE);
    BoundaryRangeValues<Paint> brv2 = new BoundaryRangeValues<Paint>(Color.GREEN, Color.WHITE, Color.RED);
    BoundaryRangeValues<Paint> brv3 = new BoundaryRangeValues<Paint>(Color.RED, Color.RED, Color.RED);
    // Set the points
    // TODO add the point size and text postition
    mapping.addPoint(minFC, brv1);
    mapping.addPoint(0.0, brv2);
    mapping.addPoint(maxFC, brv3);
    // add the mapping to visual style
    vs.addVisualMappingFunction(mapping);
    // Add the new style to the VisualMappingManager
    vmmServiceRef.addVisualStyle(vs);
    return (vs);
}
Also used : ContinuousMapping(org.cytoscape.view.vizmap.mappings.ContinuousMapping) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) BoundaryRangeValues(org.cytoscape.view.vizmap.mappings.BoundaryRangeValues) PassthroughMapping(org.cytoscape.view.vizmap.mappings.PassthroughMapping) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) Paint(java.awt.Paint) VisualStyleFactory(org.cytoscape.view.vizmap.VisualStyleFactory)

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