Search in sources :

Example 56 with VisualStyle

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

the class CySessionManagerImpl method restoreVisualStyles.

private void restoreVisualStyles(final CySession sess) {
    logger.debug("Restoring visual styles...");
    // Register visual styles
    final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
    final VisualStyle defStyle = vmMgr.getDefaultVisualStyle();
    final String DEFAULT_STYLE_NAME = defStyle.getTitle();
    final Set<VisualStyle> styles = sess.getVisualStyles();
    final Map<String, VisualStyle> stylesMap = new HashMap<>();
    final RenderingEngineManager engineManager = serviceRegistrar.getService(RenderingEngineManager.class);
    if (styles != null) {
        for (VisualStyle vs : styles) {
            if (vs.getTitle().equals(DEFAULT_STYLE_NAME)) {
                // Update the current default style, because it can't be replaced or removed
                updateVisualStyle(vs, defStyle, engineManager);
                vs = defStyle;
            }
            stylesMap.put(vs.getTitle(), vs);
            if (!vs.equals(defStyle))
                vmMgr.addVisualStyle(vs);
        }
    }
    // Set visual styles to network views
    final Map<CyNetworkView, String> viewStyleMap = sess.getViewVisualStyleMap();
    if (viewStyleMap != null) {
        for (Entry<CyNetworkView, String> entry : viewStyleMap.entrySet()) {
            final CyNetworkView netView = entry.getKey();
            final String stName = entry.getValue();
            VisualStyle vs = stylesMap.get(stName);
            if (vs == null)
                vs = defStyle;
            if (vs != null) {
                vmMgr.setVisualStyle(vs, netView);
                vs.apply(netView);
            }
        }
    }
}
Also used : HashMap(java.util.HashMap) RenderingEngineManager(org.cytoscape.view.presentation.RenderingEngineManager) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 57 with VisualStyle

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

the class SetLockedValuesTask method updateView.

private void updateView() {
    final VisualStyle style = servicesUtil.get(VisualMappingManager.class).getVisualStyle(netView);
    style.apply(netView);
    netView.updateView();
}
Also used : VisualStyle(org.cytoscape.view.vizmap.VisualStyle) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager)

Example 58 with VisualStyle

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

the class VizMapperMediator method handleEvent.

@Override
public void handleEvent(final VisualMappingFunctionChangedEvent e) {
    final VisualMappingFunction<?, ?> vm = e.getSource();
    final VisualProperty<?> vp = vm.getVisualProperty();
    final VisualStyle curStyle = vmProxy.getCurrentVisualStyle();
    // If the source mapping belongs to the current visual style, update the correspondent property sheet item
    if (vm.equals(curStyle.getVisualMappingFunction(vp))) {
        final VisualPropertySheet vpSheet = vizMapperMainPanel.getVisualPropertySheet(vp.getTargetDataType());
        if (vpSheet != null) {
            final VisualPropertySheetItem<?> vpSheetItem = vpSheet.getItem(vp);
            if (vpSheetItem != null)
                invokeOnEDT(() -> vpSheetItem.updateMapping());
        }
    }
}
Also used : VisualStyle(org.cytoscape.view.vizmap.VisualStyle)

Example 59 with VisualStyle

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

the class VizMapperMediator method handleEvent.

@Override
public void handleEvent(final LexiconStateChangedEvent e) {
    // Update Network Views
    final VisualStyle curStyle = vmProxy.getCurrentVisualStyle();
    final Set<CyNetworkView> views = vmProxy.getNetworkViewsWithStyle(curStyle);
    for (final CyNetworkView view : views) {
        // TODO This should be done by NetworkViewMediator only, if possible
        curStyle.apply(view);
        view.updateView();
    }
    // Update VP Sheet Items
    invokeOnEDT(() -> updateItemsStatus());
}
Also used : VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 60 with VisualStyle

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

the class VizMapperMediator method onSelectedVisualStyleChanged.

private void onSelectedVisualStyleChanged(final PropertyChangeEvent e) {
    final VisualStyle newStyle = (VisualStyle) e.getNewValue();
    final VisualStyle oldStyle = vmProxy.getCurrentVisualStyle();
    if (!ignoreVisualStyleSelectedEvents && newStyle != null && !newStyle.equals(oldStyle)) {
        // Update proxy
        vmProxy.setCurrentVisualStyle(newStyle);
        // Undo support
        final UndoSupport undo = servicesUtil.get(UndoSupport.class);
        undo.postEdit(new AbstractCyEdit("Set Current Style") {

            @Override
            public void undo() {
                vmProxy.setCurrentVisualStyle(oldStyle);
            }

            @Override
            public void redo() {
                vmProxy.setCurrentVisualStyle(newStyle);
            }
        });
    }
}
Also used : VisualStyle(org.cytoscape.view.vizmap.VisualStyle) UndoSupport(org.cytoscape.work.undo.UndoSupport) AbstractCyEdit(org.cytoscape.work.undo.AbstractCyEdit)

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