Search in sources :

Example 61 with VisualStyle

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

the class VizMapperMediator method updateItemsStatus.

private void updateItemsStatus() {
    // Children of enabled dependencies must be disabled
    final Set<VisualProperty<?>> disabled = new HashSet<>();
    final Map<VisualProperty<?>, String> messages = new HashMap<>();
    final VisualStyle style = vmProxy.getCurrentVisualStyle();
    final String infoMsgTemplate = "<html>To enable this visual property,<br><b>%s</b> the dependency <i><b>%s</b></i></html>";
    for (final VisualPropertyDependency<?> dep : style.getAllVisualPropertyDependencies()) {
        final VisualProperty<?> parent = dep.getParentVisualProperty();
        final Set<VisualProperty<?>> properties = dep.getVisualProperties();
        if (dep.isDependencyEnabled()) {
            disabled.addAll(properties);
            for (final VisualProperty<?> vp : properties) messages.put(vp, String.format(infoMsgTemplate, "uncheck", dep.getDisplayName()));
        } else {
            disabled.add(parent);
            messages.put(parent, String.format(infoMsgTemplate, "check", dep.getDisplayName()));
        }
    }
    for (final VisualPropertySheet vpSheet : vizMapperMainPanel.getVisualPropertySheets()) {
        final Set<VisualPropertySheetItem<?>> vpSheetItems = vpSheet.getItems();
        for (final VisualPropertySheetItem<?> item : vpSheetItems) {
            // First check if this property item must be disabled and show an INFO message
            String msg = null;
            MessageType msgType = null;
            if (msgType == null && item.getModel().getVisualPropertyDependency() == null) {
                item.setEnabled(!disabled.contains(item.getModel().getVisualProperty()));
                msg = messages.get(item.getModel().getVisualProperty());
                msgType = item.isEnabled() ? null : MessageType.INFO;
            }
            item.setMessage(msg, msgType);
            // If item is enabled, check whether or not the mapping is valid for the current network
            updateMappingStatus(item);
        }
    }
}
Also used : HashMap(java.util.HashMap) DefaultVisualizableVisualProperty(org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty) VisualProperty(org.cytoscape.view.model.VisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) MessageType(org.cytoscape.view.vizmap.gui.internal.view.VisualPropertySheetItem.MessageType) HashSet(java.util.HashSet)

Example 62 with VisualStyle

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

the class VizMapperMediator method handleNotification.

@Override
public void handleNotification(final INotification notification) {
    final String id = notification.getName();
    final Object body = notification.getBody();
    if (id.equals(VISUAL_STYLE_SET_CHANGED)) {
        updateVisualStyleList((SortedSet<VisualStyle>) body, true);
    } else if (id.equals(VISUAL_STYLE_ADDED) || id.equals(VISUAL_STYLE_REMOVED)) {
        updateVisualStyleList(vmProxy.getVisualStyles(), false);
    } else if (id.equals(CURRENT_VISUAL_STYLE_CHANGED)) {
        invokeOnEDTAndWait(() -> {
            ignoreVisualStyleSelectedEvents = true;
            try {
                selectCurrentVisualStyle((VisualStyle) body);
            } finally {
                ignoreVisualStyleSelectedEvents = false;
            }
        });
        invokeOnEDT(() -> {
            updateVisualPropertySheets((VisualStyle) body, false);
        });
    } else if (id.equals(VISUAL_STYLE_UPDATED) && body != null && body.equals(vmProxy.getCurrentVisualStyle())) {
        updateVisualPropertySheets((VisualStyle) body, false);
    } else if (id.equals(CURRENT_NETWORK_VIEW_CHANGED)) {
        final CyNetworkView view = (CyNetworkView) body;
        final String newRendererId = view != null ? view.getRendererId() : null;
        if (view != null && newRendererId != null && !newRendererId.equals(curRendererId)) {
            updateVisualPropertySheets(vmProxy.getVisualStyle(view), false);
            curRendererId = newRendererId;
        } else if (view == null || vmProxy.getVisualStyle(view).equals(vizMapperMainPanel.getSelectedVisualStyle())) {
            // Ignore it, if the selected style is not the current one,
            // because it should change the selection style first and then recreate all the items, anyway.
            updateLockedValues((CyNetworkView) body);
            if (body instanceof CyNetworkView) {
                updateMappings(CyNode.class, view.getModel().getDefaultNodeTable());
                updateMappings(CyEdge.class, view.getModel().getDefaultEdgeTable());
            }
            updateItemsStatus();
        }
    } else if (id.equals(VISUAL_STYLE_NAME_CHANGED)) {
        vizMapperMainPanel.getStylesBtn().repaint();
    }
}
Also used : CyNode(org.cytoscape.model.CyNode) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyEdge(org.cytoscape.model.CyEdge)

Example 63 with VisualStyle

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

the class VizMapperMediator method openDefaultValueEditor.

@SuppressWarnings("rawtypes")
private void openDefaultValueEditor(final ActionEvent evt, final VisualPropertySheetItem vpSheetItem) {
    final VisualPropertySheetItemModel model = vpSheetItem.getModel();
    final VisualProperty vp = model.getVisualProperty();
    final VisualStyle style = vmProxy.getCurrentVisualStyle();
    final Object oldValue = style.getDefaultValue(vp);
    Object val = null;
    try {
        final EditorManager editorMgr = servicesUtil.get(EditorManager.class);
        val = editorMgr.showVisualPropertyValueEditor(vizMapperMainPanel, vp, oldValue);
    } catch (final Exception ex) {
        logger.error("Error opening Visual Property values editor for: " + vp, ex);
    }
    final Object newValue = val;
    if (newValue != null && !newValue.equals(oldValue)) {
        style.setDefaultValue(vp, newValue);
        // Undo support
        final UndoSupport undo = servicesUtil.get(UndoSupport.class);
        undo.postEdit(new AbstractCyEdit("Set Default Value") {

            @Override
            public void undo() {
                style.setDefaultValue(vp, oldValue);
            }

            @Override
            public void redo() {
                style.setDefaultValue(vp, newValue);
            }
        });
    }
}
Also used : DefaultVisualizableVisualProperty(org.cytoscape.view.presentation.property.DefaultVisualizableVisualProperty) VisualProperty(org.cytoscape.view.model.VisualProperty) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) EditorManager(org.cytoscape.view.vizmap.gui.editor.EditorManager) UndoSupport(org.cytoscape.work.undo.UndoSupport) AbstractCyEdit(org.cytoscape.work.undo.AbstractCyEdit)

Example 64 with VisualStyle

use of org.cytoscape.view.vizmap.VisualStyle 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)

Example 65 with VisualStyle

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

the class VisualMappingManagerImpl method handleEvent.

@Override
public void handleEvent(SetCurrentNetworkViewEvent e) {
    final CyNetworkView view = e.getNetworkView();
    if (view == null)
        return;
    final VisualStyle newStyle = this.getVisualStyle(view);
    if (newStyle != null)
        setCurrentVisualStyle(newStyle);
}
Also used : VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Aggregations

VisualStyle (org.cytoscape.view.vizmap.VisualStyle)100 CyNetworkView (org.cytoscape.view.model.CyNetworkView)42 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)37 CyNetwork (org.cytoscape.model.CyNetwork)35 CyNode (org.cytoscape.model.CyNode)30 CyEdge (org.cytoscape.model.CyEdge)24 CyEventHelper (org.cytoscape.event.CyEventHelper)14 HashSet (java.util.HashSet)13 VisualProperty (org.cytoscape.view.model.VisualProperty)12 DiscreteMapping (org.cytoscape.view.vizmap.mappings.DiscreteMapping)12 Paint (java.awt.Paint)11 HashMap (java.util.HashMap)11 CyApplicationManager (org.cytoscape.application.CyApplicationManager)11 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)11 Color (java.awt.Color)10 ArrayList (java.util.ArrayList)10 RenderingEngineManager (org.cytoscape.view.presentation.RenderingEngineManager)9 BasicVisualLexicon (org.cytoscape.view.presentation.property.BasicVisualLexicon)9 ContinuousMapping (org.cytoscape.view.vizmap.mappings.ContinuousMapping)9 View (org.cytoscape.view.model.View)8