Search in sources :

Example 11 with VisualStyle

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

the class CySessionManagerImpl method getCurrentSession.

@Override
public CySession getCurrentSession() {
    // Apps who want to save anything to a session will have to listen for this event
    // and will then be responsible for adding files through SessionAboutToBeSavedEvent.addAppFiles(..)
    final SessionAboutToBeSavedEvent savingEvent = new SessionAboutToBeSavedEvent(this);
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    eventHelper.fireEvent(savingEvent);
    final Set<CyNetwork> networks = getSerializableNetworks();
    final CyNetworkViewManager nvMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
    final Set<CyNetworkView> netViews = nvMgr.getNetworkViewSet();
    // Visual Styles Map
    final Map<CyNetworkView, String> stylesMap = new HashMap<>();
    final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
    if (netViews != null) {
        for (final CyNetworkView nv : netViews) {
            final VisualStyle style = vmMgr.getVisualStyle(nv);
            if (style != null)
                stylesMap.put(nv, style.getTitle());
        }
    }
    final Map<String, List<File>> appMap = savingEvent.getAppFileListMap();
    final Set<CyTableMetadata> metadata = createTablesMetadata(networks);
    final Set<VisualStyle> styles = vmMgr.getAllVisualStyles();
    final Set<CyProperty<?>> props = getAllProperties();
    // Build the session
    final CySession sess = new CySession.Builder().properties(props).appFileListMap(appMap).tables(metadata).networks(networks).networkViews(netViews).visualStyles(styles).viewVisualStyleMap(stylesMap).build();
    return sess;
}
Also used : CySession(org.cytoscape.session.CySession) CyEventHelper(org.cytoscape.event.CyEventHelper) CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) HashMap(java.util.HashMap) CyNetwork(org.cytoscape.model.CyNetwork) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty) CyProperty(org.cytoscape.property.CyProperty) SessionAboutToBeSavedEvent(org.cytoscape.session.events.SessionAboutToBeSavedEvent) CyTableMetadata(org.cytoscape.model.CyTableMetadata) ArrayList(java.util.ArrayList) List(java.util.List) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 12 with VisualStyle

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

the class CySessionManagerImpl method restoreCurrentVisualStyle.

private void restoreCurrentVisualStyle() {
    // Make sure the current visual style is the one applied to the current network view
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    eventHelper.flushPayloadEvents();
    final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
    final CyNetworkView cv = appMgr.getCurrentNetworkView();
    if (cv != null) {
        final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
        final VisualStyle style = vmMgr.getVisualStyle(cv);
        if (style != null && !style.equals(vmMgr.getCurrentVisualStyle()))
            vmMgr.setCurrentVisualStyle(style);
    }
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyEventHelper(org.cytoscape.event.CyEventHelper) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 13 with VisualStyle

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

the class CySessionManagerImpl method disposeCurrentSession.

@Override
public void disposeCurrentSession() {
    logger.debug("Disposing current session...");
    // Destroy network views
    final CyNetworkViewManager nvMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
    final Set<CyNetworkView> netViews = nvMgr.getNetworkViewSet();
    for (final CyNetworkView nv : netViews) nvMgr.destroyNetworkView(nv);
    nvMgr.reset();
    // Destroy networks
    final CyNetworkManager netMgr = serviceRegistrar.getService(CyNetworkManager.class);
    final Set<CyNetwork> networks = netMgr.getNetworkSet();
    for (final CyNetwork n : networks) netMgr.destroyNetwork(n);
    netMgr.reset();
    // Destroy styles
    logger.debug("Removing current visual styles...");
    final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
    final VisualStyle defaultStyle = vmMgr.getDefaultVisualStyle();
    final List<VisualStyle> allStyles = new ArrayList<>(vmMgr.getAllVisualStyles());
    for (final VisualStyle vs : allStyles) {
        if (!vs.equals(defaultStyle))
            vmMgr.removeVisualStyle(vs);
    }
    // Destroy tables
    final CyTableManager tblMgr = serviceRegistrar.getService(CyTableManager.class);
    tblMgr.reset();
    // Reset groups
    serviceRegistrar.getService(CyGroupManager.class).reset();
    // Unregister session properties
    final Set<CyProperty<?>> cyPropsClone = getAllProperties();
    for (CyProperty<?> cyProps : cyPropsClone) {
        if (cyProps.getSavePolicy().equals(CyProperty.SavePolicy.SESSION_FILE)) {
            serviceRegistrar.unregisterAllServices(cyProps);
            sessionProperties.remove(cyProps.getName());
        }
    }
    // Clear undo stack
    serviceRegistrar.getService(UndoSupport.class).reset();
    // Reset current table and rendering engine
    final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
    appMgr.reset();
    currentFileName = null;
    disposed = true;
}
Also used : CyNetworkViewManager(org.cytoscape.view.model.CyNetworkViewManager) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyApplicationManager(org.cytoscape.application.CyApplicationManager) SimpleCyProperty(org.cytoscape.property.SimpleCyProperty) CyProperty(org.cytoscape.property.CyProperty) CyNetworkManager(org.cytoscape.model.CyNetworkManager) CyTableManager(org.cytoscape.model.CyTableManager) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyGroupManager(org.cytoscape.group.CyGroupManager)

Example 14 with VisualStyle

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

the class NewEmptyNetworkTask method run.

@Override
public void run(final TaskMonitor tm) {
    tm.setProgress(0.0);
    final String networkCollectionName = rootNetworkList.getSelectedValue();
    if (networkCollectionName == null || networkCollectionName.equalsIgnoreCase(CRERATE_NEW_COLLECTION_STRING)) {
        // This is a new network collection, create a root network and a subnetwork, which is a base subnetwork
        subNetwork = (CySubNetwork) netFactory.createNetwork();
    } else {
        // Add a new subNetwork to the given collection
        subNetwork = this.name2RootMap.get(networkCollectionName).addSubNetwork();
    }
    tm.setProgress(0.2);
    final String networkName = namingUtil.getSuggestedNetworkTitle(name);
    subNetwork.getRow(subNetwork).set(CyNetwork.NAME, networkName);
    if (networkCollectionName == null || networkCollectionName.equalsIgnoreCase(CRERATE_NEW_COLLECTION_STRING)) {
        // Set the name of new root network
        final CyNetwork rootNetwork = subNetwork.getRootNetwork();
        rootNetwork.getRow(rootNetwork).set(CyNetwork.NAME, networkName);
    }
    NetworkViewRenderer nvRenderer = null;
    try {
        nvRenderer = renderers.getSelectedValue();
    } catch (ClassCastException cce) {
        tm.showMessage(TaskMonitor.Level.WARN, "Unknown renderer: " + renderers.getSelectedValue() + " using default renderer.");
    }
    if (nvRenderer == null)
        nvRenderer = appMgr.getDefaultNetworkViewRenderer();
    final CyNetworkViewFactory netViewFactory = nvRenderer.getNetworkViewFactory();
    tm.setProgress(0.4);
    view = netViewFactory.createNetworkView(subNetwork);
    tm.setProgress(0.6);
    netMgr.addNetwork(subNetwork, false);
    appMgr.setCurrentNetwork(subNetwork);
    tm.setProgress(0.8);
    // get the current style before registering the view!
    final VisualStyle style = vmMgr.getCurrentVisualStyle();
    netViewMgr.addNetworkView(view);
    tm.setProgress(0.9);
    applyVisualStyle(style);
    tm.setProgress(1.0);
}
Also used : CyNetworkViewFactory(org.cytoscape.view.model.CyNetworkViewFactory) CyNetwork(org.cytoscape.model.CyNetwork) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer)

Example 15 with VisualStyle

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

the class HideFromSelectionTask method run.

@Override
public void run(final TaskMonitor tm) {
    tm.setProgress(0.0);
    final CyNetwork network = view.getModel();
    final List<CyIdentifiable> elements = new ArrayList<>();
    List<CyNode> nodes = null;
    List<CyEdge> edges = null;
    if (hideNodes) {
        nodes = CyTableUtil.getNodesInState(network, CyNetwork.SELECTED, selectionValue);
        elements.addAll(nodes);
    }
    tm.setProgress(0.1);
    if (hideEdges) {
        edges = CyTableUtil.getEdgesInState(network, CyNetwork.SELECTED, selectionValue);
        elements.addAll(edges);
    }
    final UndoSupport undoSupport = serviceRegistrar.getService(UndoSupport.class);
    final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
    final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
    undoSupport.postEdit(new HideEdit(description, view, elements, false, eventHelper, vmMgr));
    tm.setProgress(0.4);
    if (nodes != null)
        HideUtils.setVisibleNodes(nodes, false, view);
    tm.setProgress(0.6);
    if (edges != null)
        HideUtils.setVisibleEdges(edges, false, view);
    tm.setProgress(0.8);
    VisualStyle style = vmMgr.getVisualStyle(view);
    for (CyIdentifiable e : elements) {
        View<? extends CyIdentifiable> ev = null;
        if (e instanceof CyNode)
            ev = view.getNodeView((CyNode) e);
        else if (e instanceof CyEdge)
            ev = view.getEdgeView((CyEdge) e);
        if (ev != null)
            style.apply(network.getRow(e), ev);
    }
    view.updateView();
    tm.setProgress(1.0);
}
Also used : CyEventHelper(org.cytoscape.event.CyEventHelper) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) UndoSupport(org.cytoscape.work.undo.UndoSupport) CyNode(org.cytoscape.model.CyNode) VisualMappingManager(org.cytoscape.view.vizmap.VisualMappingManager) VisualStyle(org.cytoscape.view.vizmap.VisualStyle) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

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