use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class EdgeBundlerTask method render.
private final void render(final Collection<View<CyEdge>> edges, final HandleFactory hf, final BendFactory bf, final VisualMappingManager vmm, final VisualMappingFunctionFactory discreteFactory) {
final VisualStyle style = vmm.getVisualStyle(view);
// Check existing mapping
VisualMappingFunction<?, Bend> bendMapping = style.getVisualMappingFunction(EDGE_BEND);
final Map<Long, Bend> mappingValues;
Map<Long, Bend> existingMap = null;
if (bendMapping != null && bendMapping instanceof DiscreteMapping) {
final String columnName = bendMapping.getMappingColumnName();
if (columnName.equals(BEND_MAP_COLUMN)) {
existingMap = ((DiscreteMapping<Long, Bend>) bendMapping).getAll();
} else {
bendMapping = (DiscreteMapping<Long, Bend>) discreteFactory.createVisualMappingFunction(BEND_MAP_COLUMN, Long.class, EDGE_BEND);
}
}
mappingValues = new HashMap<>();
final CyNetwork network = view.getModel();
final CyTable edgeTable = network.getTable(CyEdge.class, CyNetwork.LOCAL_ATTRS);
final CyColumn bendMapColumn = edgeTable.getColumn(BEND_MAP_COLUMN);
if (bendMapColumn == null) {
edgeTable.createColumn(BEND_MAP_COLUMN, Long.class, false);
}
int ei = 0;
for (final View<CyEdge> edge : edges) {
final Long edgeId = edge.getModel().getSUID();
final View<CyNode> eSource = view.getNodeView(edge.getModel().getSource());
final View<CyNode> eTarget = view.getNodeView(edge.getModel().getTarget());
network.getRow(edge.getModel()).set(BEND_MAP_COLUMN, edgeId);
// Ignore self-edge
if (eSource.getSUID().equals(eTarget.getSUID()))
continue;
final Bend bend = bf.createBend();
final List<Handle> hlist = bend.getAllHandles();
for (int ni = 0; ni < numNubs; ni++) {
final double x = nubs[ni][0][ei];
final double y = nubs[ni][1][ei];
final Handle h = hf.createHandle(view, edge, x, y);
hlist.add(h);
}
mappingValues.put(edgeId, bend);
ei++;
}
if (bendMapping == null) {
// Create new discrete mapping for edge SUID to Edge Bend
final DiscreteMapping<Long, Bend> function = (DiscreteMapping<Long, Bend>) discreteFactory.createVisualMappingFunction(BEND_MAP_COLUMN, Long.class, EDGE_BEND);
style.addVisualMappingFunction(function);
function.putAll(mappingValues);
} else {
if (existingMap != null) {
mappingValues.putAll(existingMap);
}
((DiscreteMapping<Long, Bend>) bendMapping).putAll(mappingValues);
}
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class DeleteNestedNetworkTask method run.
@Override
public void run(TaskMonitor tm) throws Exception {
final CyNode node = nodeView.getModel();
setNestedNetwork(node, null);
final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
final VisualStyle style = vmMgr.getVisualStyle(netView);
style.apply(netView.getModel().getRow(node), nodeView);
netView.updateView();
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class PasteTask method run.
@Override
public void run(TaskMonitor tm) throws Exception {
tm.setTitle("Paste Task");
final List<CyIdentifiable> pastedObjects;
if (xformPt == null)
pastedObjects = clipMgr.paste(view, 0.0, 0.0);
else
pastedObjects = clipMgr.paste(view, xformPt.getX(), xformPt.getY());
if (pastedObjects == null) {
tm.showMessage(TaskMonitor.Level.WARN, "Nothing to past");
return;
}
final UndoSupport undoSupport = serviceRegistrar.getService(UndoSupport.class);
undoSupport.postEdit(new PasteEdit(view, xformPt, clipMgr, pastedObjects, serviceRegistrar));
// Apply visual style
final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
VisualStyle vs = vmMgr.getVisualStyle(view);
for (CyIdentifiable element : pastedObjects) {
View<? extends CyIdentifiable> elementView = null;
if (element instanceof CyNode)
elementView = view.getNodeView((CyNode) element);
else if (element instanceof CyEdge)
elementView = view.getEdgeView((CyEdge) element);
else
continue;
vs.apply(view.getModel().getRow(element), elementView);
}
view.updateView();
tm.setStatusMessage("Pasted " + pastedObjects.size() + " nodes and/or edges");
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class GroupViewCollapseHandler method handleEvent.
@Override
public void handleEvent(GroupCollapsedEvent e) {
getServices();
CyNetwork network = e.getNetwork();
CyGroup group = e.getSource();
final Collection<CyNetworkView> views = cyNetworkViewManager.getNetworkViews(network);
CyNetworkView view = null;
if (views.size() == 0) {
return;
}
for (CyNetworkView v : views) {
if (v.getRendererId().equals("org.cytoscape.ding")) {
view = v;
}
}
if (view == null)
return;
CyRootNetwork rootNetwork = group.getRootNetwork();
GroupViewType groupViewType = cyGroupSettings.getGroupViewType(group);
if (e.collapsed()) {
// System.out.println("Got collapse event for "+group);
// Get the location to move the group node to
Dimension d = ViewUtils.getLocation(network, group);
if (d != null) {
// Move it.
ViewUtils.moveNode(view, group.getGroupNode(), d);
}
View<CyNode> nView = view.getNodeView(group.getGroupNode());
if (cyGroupSettings.getUseNestedNetworks(group)) {
// Now, if we're displaying the nested network, create it....
CyNetwork nn = group.getGroupNetwork();
CyNetworkView nnView = null;
// If we've already registered the network, don't do it again
if (!cyNetworkManager.networkExists(nn.getSUID())) {
cyNetworkManager.addNetwork(nn, false);
nnView = cyNetworkViewFactory.createNetworkView(nn);
cyNetworkViewManager.addNetworkView(nnView, false);
// Apply our current style to the nested network
VisualStyle style = cyStyleManager.getVisualStyle(view);
cyStyleManager.setVisualStyle(style, nnView);
style.apply(nnView);
} else if (cyNetworkViewManager.viewExists(nn)) {
nnView = cyNetworkViewManager.getNetworkViews(nn).iterator().next();
}
if (nnView != null) {
ViewUtils.moveNodes(group, nnView, d);
nnView.updateView();
// Allow the nested network image to be displayed
nView.clearValueLock(BasicVisualLexicon.NODE_NESTED_NETWORK_IMAGE_VISIBLE);
}
} else {
// Make sure the nested network image is not displayed
nView.setLockedValue(BasicVisualLexicon.NODE_NESTED_NETWORK_IMAGE_VISIBLE, Boolean.FALSE);
}
// If we were showing this as a compound node, we need to restyle
if (groupViewType.equals(GroupViewType.COMPOUND)) {
deActivateCompoundNode(group, view);
}
styleGroupNode(group, view, views);
} else {
// System.out.println("Got expand event for "+group);
CyNode groupNode = group.getGroupNode();
// Get the location of the group node before it went away
Dimension center = ViewUtils.getLocation(network, group);
if (center != null)
ViewUtils.moveNodes(group, view, center);
// If we're asked to, show the group node
if (!groupViewType.equals(GroupViewType.NONE)) {
CySubNetwork subnet = (CySubNetwork) network;
// Add the node back
subnet.addNode(group.getGroupNode());
// Add the group nodes's edges back
List<CyEdge> groupNodeEdges = rootNetwork.getAdjacentEdgeList(groupNode, CyEdge.Type.ANY);
for (CyEdge edge : groupNodeEdges) {
CyRow row = rootNetwork.getRow(edge, CyNetwork.HIDDEN_ATTRS);
// Only add non-meta edges
if (row != null && (!row.isSet(CyGroupImpl.ISMETA_EDGE_ATTR) || !row.get(CyGroupImpl.ISMETA_EDGE_ATTR, Boolean.class))) {
subnet.addEdge(edge);
} else if (subnet.containsEdge(edge) && row != null && row.isSet(CyGroupImpl.ISMETA_EDGE_ATTR) && row.get(CyGroupImpl.ISMETA_EDGE_ATTR, Boolean.class)) {
// Edge is a meta edge, but is still in the network. Remove it
subnet.removeEdges(Collections.singletonList(edge));
}
}
if (groupViewType.equals(GroupViewType.SHOWGROUPNODE)) {
// If this is the first time, we need to add our member
// edges in.
addMemberEdges(group, network);
// Style our member edges
styleGroupNode(group, view, views);
}
// Flush events so that the view hears about it
final CyEventHelper cyEventHelper = cyGroupManager.getService(CyEventHelper.class);
cyEventHelper.flushPayloadEvents();
// Now, call ourselves as if we had been collapsed
handleEvent(new GroupCollapsedEvent(group, network, true));
if (groupViewType.equals(GroupViewType.COMPOUND) || groupViewType.equals(GroupViewType.SINGLENODE)) {
// May be redundant, but just to make sure
((CyGroupImpl) group).setGroupNodeShown(network, true);
activateCompoundNode(group, view);
}
cyEventHelper.flushPayloadEvents();
view.updateView();
return;
}
final List<CyNode> nodeList = group.getNodeList();
// TODO: turn off stupid nested network thing
for (CyNode node : nodeList) {
if (!network.containsNode(node))
continue;
View<CyNode> nView = view.getNodeView(node);
if (node.getNetworkPointer() != null && cyGroupManager.isGroup(node, network)) {
if (!cyGroupSettings.getUseNestedNetworks(cyGroupManager.getGroup(node, network))) {
nView.setLockedValue(BasicVisualLexicon.NODE_NESTED_NETWORK_IMAGE_VISIBLE, Boolean.FALSE);
}
}
}
// Apply visual property to added graph elements
ViewUtils.applyStyle(nodeList, views, cyStyleManager);
ViewUtils.applyStyle(group.getInternalEdgeList(), views, cyStyleManager);
ViewUtils.applyStyle(group.getExternalEdgeList(), views, cyStyleManager);
}
view.updateView();
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class SessionWriterImpl method zipVizmap.
/**
* Writes the vizmap.props file to the session zip.
*/
private void zipVizmap() throws Exception {
Set<VisualStyle> styles = session.getVisualStyles();
zos.putNextEntry(new ZipEntry(sessionDir + VIZMAP_FILE));
CyWriter vizmapWriter = vizmapWriterMgr.getWriter(styles, vizmapFilter, zos);
vizmapWriter.run(taskMonitor);
zos.closeEntry();
vizmapWriter = null;
}
Aggregations