Search in sources :

Example 1 with DefaultVisualizableVisualProperty

use of org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty in project cytoscape-impl by cytoscape.

the class VizMapperMediator method createVisualPropertySheetItems.

@SuppressWarnings("rawtypes")
private Set<VisualPropertySheetItem<?>> createVisualPropertySheetItems(final Class<? extends CyIdentifiable> type, final VisualLexicon lexicon, final VisualStyle style) {
    final Set<VisualPropertySheetItem<?>> items = new HashSet<>();
    if (lexicon == null || style == null)
        return items;
    final Collection<VisualProperty<?>> vpList = lexicon.getAllDescendants(BasicVisualLexicon.NETWORK);
    final CyNetworkView curNetView = vmProxy.getCurrentNetworkView();
    final Set<View<CyNode>> selectedNodeViews = vmProxy.getSelectedNodeViews(curNetView);
    final Set<View<CyEdge>> selectedEdgeViews = vmProxy.getSelectedEdgeViews(curNetView);
    final Set<View<CyNetwork>> selectedNetViews = curNetView != null ? Collections.singleton((View<CyNetwork>) curNetView) : Collections.EMPTY_SET;
    final RenderingEngine<CyNetwork> engine = vizMapperMainPanel.getRenderingEngine();
    for (final VisualProperty<?> vp : vpList) {
        if (vp.getTargetDataType() != type || vp instanceof DefaultVisualizableVisualProperty)
            continue;
        if (!vmProxy.isSupported(vp))
            continue;
        // Create model
        final VisualPropertySheetItemModel<?> model = new VisualPropertySheetItemModel(vp, style, engine, lexicon);
        final Set values;
        if (vp.getTargetDataType() == CyNode.class) {
            values = getDistinctLockedValues(vp, selectedNodeViews);
            updateVpInfoLockedState(model, values, selectedNodeViews);
        } else if (vp.getTargetDataType() == CyEdge.class) {
            values = getDistinctLockedValues(vp, selectedEdgeViews);
            updateVpInfoLockedState(model, values, selectedEdgeViews);
        } else {
            values = getDistinctLockedValues(vp, selectedNetViews);
            updateVpInfoLockedState(model, values, selectedNetViews);
        }
        // Create View
        final VisualPropertySheetItem<?> sheetItem = new VisualPropertySheetItem(model, vizMapPropertyBuilder, servicesUtil);
        items.add(sheetItem);
        // Add listeners to item and model:
        if (model.isVisualMappingAllowed()) {
            sheetItem.getPropSheetPnl().addPropertySheetChangeListener(evt -> {
                if (evt.getPropertyName().equals("value") && evt.getSource() instanceof VizMapperProperty)
                    updateMappingStatus(sheetItem);
            });
        }
        // Set the updated values to the visual style
        model.addPropertyChangeListener("defaultValue", evt -> {
            final VisualStyle vs = model.getVisualStyle();
            vs.setDefaultValue((VisualProperty) vp, evt.getNewValue());
        });
        model.addPropertyChangeListener("visualMappingFunction", evt -> {
            final VisualStyle vs = model.getVisualStyle();
            if (evt.getNewValue() == null && vs.getVisualMappingFunction(vp) != null)
                vs.removeVisualMappingFunction(vp);
            else if (evt.getNewValue() != null && !evt.getNewValue().equals(vs.getVisualMappingFunction(vp)))
                vs.addVisualMappingFunction((VisualMappingFunction<?, ?>) evt.getNewValue());
            updateMappingStatus(sheetItem);
        });
    }
    // Add dependencies
    final Set<VisualPropertyDependency<?>> dependencies = style.getAllVisualPropertyDependencies();
    for (final VisualPropertyDependency<?> dep : dependencies) {
        if (dep.getParentVisualProperty().getTargetDataType() != type)
            continue;
        if (!vmProxy.isSupported(dep))
            continue;
        final VisualPropertySheetItemModel<?> model = new VisualPropertySheetItemModel(dep, style, engine, lexicon);
        final VisualPropertySheetItem<?> sheetItem = new VisualPropertySheetItem(model, vizMapPropertyBuilder, servicesUtil);
        items.add(sheetItem);
    }
    return items;
}
Also used : Set(java.util.Set) SortedSet(java.util.SortedSet) HashSet(java.util.HashSet) CyNetwork(org.cytoscape.model.CyNetwork) CyNetworkView(org.cytoscape.view.model.CyNetworkView) View(org.cytoscape.view.model.View) CyEdge(org.cytoscape.model.CyEdge) VizMapperProperty(org.cytoscape.view.vizmap.gui.internal.VizMapperProperty) VisualPropertyDependency(org.cytoscape.view.vizmap.VisualPropertyDependency) DefaultVisualizableVisualProperty(org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty) VisualProperty(org.cytoscape.view.model.VisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView) HashSet(java.util.HashSet) DefaultVisualizableVisualProperty(org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty)

Aggregations

HashSet (java.util.HashSet)1 Set (java.util.Set)1 SortedSet (java.util.SortedSet)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1 View (org.cytoscape.view.model.View)1 VisualProperty (org.cytoscape.view.model.VisualProperty)1 DefaultVisualizableVisualProperty (org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty)1 VisualPropertyDependency (org.cytoscape.view.vizmap.VisualPropertyDependency)1 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)1 VizMapperProperty (org.cytoscape.view.vizmap.gui.internal.VizMapperProperty)1