use of org.cytoscape.view.vizmap.VisualStyle in project EnrichmentMapApp by BaderLab.
the class EMStyleBuilder method setEdgeLineType.
private void setEdgeLineType(VisualStyle vs, EMStyleOptions options) {
String col = CyEdge.INTERACTION;
DiscreteMapping<String, LineType> dm = (DiscreteMapping<String, LineType>) dmFactory.createVisualMappingFunction(col, String.class, EDGE_LINE_TYPE);
// Silence events fired by this mapping to prevent unnecessary style and view updates
eventHelper.silenceEventSource(dm);
try {
LineType sigLineType = LineTypeVisualProperty.DOT;
if (EDGE_LINE_TYPE.getRange().isDiscrete()) {
DiscreteRange<LineType> range = (DiscreteRange<LineType>) EDGE_LINE_TYPE.getRange();
Optional<LineType> first = range.values().stream().filter(v -> "MARQUEE_EQUAL".equalsIgnoreCase(v.getSerializableString())).findFirst();
if (first.isPresent())
sigLineType = first.get();
}
dm.putMapValue(Columns.EDGE_DATASET_VALUE_COMPOUND, LineTypeVisualProperty.SOLID);
dm.putMapValue(Columns.EDGE_INTERACTION_VALUE_SIG, sigLineType);
} finally {
eventHelper.unsilenceEventSource(dm);
}
vs.addVisualMappingFunction(dm);
}
use of org.cytoscape.view.vizmap.VisualStyle in project EnrichmentMapApp by BaderLab.
the class ControlPanelMediator method setCurrentView.
private void setCurrentView(CyNetworkView netView) {
ForkJoinPool.commonPool().submit(() -> {
// Work around a bug in Cytoscape.
// When the current network view is changed it can lose its style, so set it back.
CyNetworkView prevNetView = applicationManager.getCurrentNetworkView();
VisualStyle visualStyle = visualMappingManager.getVisualStyle(prevNetView);
applicationManager.setCurrentNetworkView(netView);
visualMappingManager.setVisualStyle(visualStyle, prevNetView);
});
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class AddEdgeTask method run.
@Override
public void run(final TaskMonitor taskMonitor) {
if (network == null) {
network = serviceRegistrar.getService(CyApplicationManager.class).getCurrentNetwork();
if (network == null) {
taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Network must be specified for add command");
return;
}
}
if (sourceName == null) {
taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Source node name must be specified for add command");
return;
}
if (targetName == null) {
taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Target node name must be specified for add command");
return;
}
// Find the source and target nodes
CyNode source = null;
CyNode target = null;
for (CyNode node : network.getNodeList()) {
String nodeName = network.getRow(node).get(CyNetwork.NAME, String.class);
if (sourceName.equals(nodeName))
source = node;
else if (targetName.equals(nodeName))
target = node;
if (source != null && target != null)
break;
}
if (source == null) {
taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Can't find source node named '" + sourceName + "'");
return;
}
if (target == null) {
taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Can't find target node named '" + targetName + "'");
return;
}
newEdge = network.addEdge(source, target, isDirected);
if (name != null) {
network.getRow(newEdge).set(CyNetwork.NAME, name);
network.getRow(newEdge).set(CyRootNetwork.SHARED_NAME, name);
}
cyEventHelper.flushPayloadEvents();
if (networkViewManager.viewExists(network)) {
for (CyNetworkView view : networkViewManager.getNetworkViews(network)) {
View<CyEdge> edgeView = view.getEdgeView(newEdge);
VisualStyle style = visualMappingManager.getVisualStyle(view);
if (style != null) {
style.apply(network.getRow(newEdge), edgeView);
}
// Not sure why we need to refresh the view for edges and not nodes, but apparently we do
view.updateView();
}
}
cyEventHelper.flushPayloadEvents();
taskMonitor.showMessage(TaskMonitor.Level.INFO, "Added edge " + newEdge.toString() + " to network");
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class AddNodeTask method run.
@Override
public void run(final TaskMonitor taskMonitor) {
if (network == null) {
network = serviceRegistrar.getService(CyApplicationManager.class).getCurrentNetwork();
if (network == null) {
taskMonitor.showMessage(TaskMonitor.Level.ERROR, "Network must be specified for add command");
return;
}
}
newNode = network.addNode();
if (name != null) {
network.getRow(newNode).set(CyNetwork.NAME, name);
network.getRow(newNode).set(CyRootNetwork.SHARED_NAME, name);
}
cyEventHelper.flushPayloadEvents();
if (networkViewManager.viewExists(network)) {
for (CyNetworkView view : networkViewManager.getNetworkViews(network)) {
View<CyNode> nodeView = view.getNodeView(newNode);
VisualStyle style = visualMappingManager.getVisualStyle(view);
if (style != null) {
style.apply(network.getRow(newNode), nodeView);
}
}
}
cyEventHelper.flushPayloadEvents();
taskMonitor.showMessage(TaskMonitor.Level.INFO, "Added node " + newNode.toString() + " to network");
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class PasteEdit method redo.
@Override
public void redo() {
List<CyIdentifiable> pastedObjects = null;
if (this.xformPt == null)
pastedObjects = clipboard.paste(view, 0.0, 0.0);
else
pastedObjects = clipboard.paste(view, xformPt.getX(), xformPt.getY());
// 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();
}
Aggregations