Search in sources :

Example 1 with NodeShape

use of org.cytoscape.view.presentation.property.values.NodeShape in project EnrichmentMapApp by BaderLab.

the class EMStyleBuilder method setNodeShapes.

@SuppressWarnings({ "unchecked", "rawtypes" })
private void setNodeShapes(VisualStyle vs, EMStyleOptions options, ChartType chartType) {
    String prefix = options.getAttributePrefix();
    String columnName = Columns.NODE_GS_TYPE.with(prefix, null);
    NodeShape enrShape = getDefaultNodeShape(chartType);
    VisualMappingFunction<?, NodeShape> oldMapping = vs.getVisualMappingFunction(NODE_SHAPE);
    // This is done for performance optimization only!
    boolean update = oldMapping instanceof DiscreteMapping == false;
    if (!update) {
        // Also test the mapped column name
        update = !columnName.equals(oldMapping.getMappingColumnName());
        if (!update) {
            // Finally test the mapping values
            Object enrVal = ((DiscreteMapping) oldMapping).getMapValue(Columns.NODE_GS_TYPE_ENRICHMENT);
            Object sigVal = ((DiscreteMapping) oldMapping).getMapValue(Columns.NODE_GS_TYPE_SIGNATURE);
            update = !enrShape.equals(enrVal) || !SIGNATURE_NODE_SHAPE.equals(sigVal);
        }
    }
    if (update) {
        // Add mapping function for node shape
        DiscreteMapping<String, NodeShape> dm = (DiscreteMapping<String, NodeShape>) dmFactory.createVisualMappingFunction(columnName, String.class, NODE_SHAPE);
        // Silence events fired by this mapping to prevent unnecessary style and view updates
        eventHelper.silenceEventSource(dm);
        try {
            dm.putMapValue(Columns.NODE_GS_TYPE_ENRICHMENT, enrShape);
            dm.putMapValue(Columns.NODE_GS_TYPE_SIGNATURE, SIGNATURE_NODE_SHAPE);
        } finally {
            eventHelper.unsilenceEventSource(dm);
        }
        vs.addVisualMappingFunction(dm);
    }
}
Also used : NodeShape(org.cytoscape.view.presentation.property.values.NodeShape) DiscreteMapping(org.cytoscape.view.vizmap.mappings.DiscreteMapping)

Example 2 with NodeShape

use of org.cytoscape.view.presentation.property.values.NodeShape in project EnrichmentMapApp by BaderLab.

the class LegendPanel method updateNodeShapePanel.

private void updateNodeShapePanel(EnrichmentMap map) {
    JPanel p = getNodeShapePanel();
    p.removeAll();
    CyNetworkView netView = options.getNetworkView();
    VisualStyle style = netView != null ? visualMappingManager.getVisualStyle(netView) : null;
    nodeShapeIcon1.setVisible(style != null);
    nodeShapeDesc1.setVisible(style != null);
    nodeShapeIcon2.setVisible(style != null && map.hasSignatureDataSets());
    nodeShapeDesc2.setVisible(style != null && map.hasSignatureDataSets());
    if (style != null) {
        NodeShape shape = EMStyleBuilder.getGeneSetNodeShape(style);
        nodeShapeIcon1.setIcon(getIcon(BasicVisualLexicon.NODE_SHAPE, shape, netView));
        if (map.hasSignatureDataSets()) {
            shape = EMStyleBuilder.getSignatureNodeShape(style);
            nodeShapeIcon2.setIcon(getIcon(BasicVisualLexicon.NODE_SHAPE, shape, netView));
        }
    }
    p.revalidate();
}
Also used : JPanel(javax.swing.JPanel) NodeShape(org.cytoscape.view.presentation.property.values.NodeShape) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Aggregations

NodeShape (org.cytoscape.view.presentation.property.values.NodeShape)2 JPanel (javax.swing.JPanel)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)1 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)1