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;
}
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);
}
}
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;
}
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);
}
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);
}
Aggregations