use of org.cytoscape.view.model.View 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.model.View in project cytoscape-impl by cytoscape.
the class SIFInterpreterTask method run.
@Override
public void run(TaskMonitor tm) {
if (sifString == null)
throw new NullPointerException("SIF input string is null");
String[] terms = sifString.split("\\s");
if (terms != null) {
if (terms.length > 0) {
String name1 = terms[0].trim();
if (!name1.equals(null)) {
CyNode node1 = findNode(terms[0]);
if (node1 == null) {
node1 = network.addNode();
network.getRow(node1).set("name", terms[0]);
// nv1 = view.getNodeView(node1);
// double[] nextLocn = new double[2];
// nextLocn[0] = p.getX();
// nextLocn[1] = p.getY();
// view.xformComponentToNodeCoords(nextLocn);
// nv1.setOffset(nextLocn[0], nextLocn[1]);
} else {
// nv1 = view.getNodeView(node1);
}
if (terms.length == 3) {
// simple case of 'A interaction B'
CyNode node2 = findNode(terms[2]);
if (node2 == null) {
node2 = network.addNode();
network.getRow(node2).set("name", terms[2]);
// nv2 = view.getNodeView(node2);
// nv2.setOffset(nv1.getXPosition() + spacing, nv1.getYPosition());
}
CyEdge edge = network.addEdge(node1, node2, true);
network.getRow(edge).set("name", terms[1]);
} else if (terms.length > 3) {
// process multiple targets and one source
List<View<CyNode>> nodeViews = new ArrayList<View<CyNode>>();
String interactionType = terms[1];
for (int i = 2; i < terms.length; i++) {
CyNode node2 = findNode(terms[i]);
if (node2 == null) {
node2 = network.addNode();
network.getRow(node2).set("name", terms[i]);
// nv2 = view.getNodeView(node2);
// nv2.setOffset(nv1.getXPosition() + spacing, nv1
// .getYPosition());
}
CyEdge edge = network.addEdge(node1, node2, true);
network.getRow(edge).set("name", terms[1]);
// doCircleLayout(nodeViews, nv1);
}
}
}
// Apply visual style
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
// To make sure the edge view is created before applying the style
eventHelper.flushPayloadEvents();
final VisualMappingManager vmMgr = serviceRegistrar.getService(VisualMappingManager.class);
VisualStyle vs = vmMgr.getVisualStyle(view);
vs.apply(view);
view.updateView();
}
}
}
use of org.cytoscape.view.model.View in project cytoscape-impl by cytoscape.
the class NetworkViewMediator method updateView.
private void updateView(final CyNetworkView view, final VisualStyle style) {
if (view == null)
return;
if (getNetworkViewMainPanel().isGridVisible() || view.equals(getNetworkViewMainPanel().getCurrentNetworkView())) {
Timer timer = null;
synchronized (lock) {
timer = viewUpdateTimers.get(view);
}
if (timer == null) {
timer = new Timer(0, evt -> {
VisualStyle vs = style != null ? style : serviceRegistrar.getService(VisualMappingManager.class).getVisualStyle(view);
vs.apply(view);
view.updateView();
});
timer.setRepeats(false);
timer.setCoalesce(true);
synchronized (lock) {
viewUpdateTimers.put(view, timer);
}
} else {
timer.stop();
}
timer.setInitialDelay(120);
timer.start();
} else {
viewUpdateRequired.add(view);
}
}
use of org.cytoscape.view.model.View in project cytoscape-impl by cytoscape.
the class SelectFirstNeighborsNodeViewTaskTest method testRun.
@Test
public void testRun() throws Exception {
// more setup
List<CyNode> nl = new ArrayList<CyNode>();
nl.add(e4);
when(net.getNeighborList(e3, CyEdge.Type.ANY)).thenReturn(nl);
View<CyNode> nv = (View<CyNode>) mock(View.class);
when(nv.getModel()).thenReturn(e3);
CyNetworkView netView = mock(CyNetworkView.class);
when(netView.getModel()).thenReturn(net);
// run the task
Task t = new SelectFirstNeighborsNodeViewTask(nv, netView, CyEdge.Type.ANY, eventHelper);
t.run(tm);
// check that the expected rows were set
verify(r4, times(1)).set("selected", true);
}
use of org.cytoscape.view.model.View in project cytoscape-impl by cytoscape.
the class AbstractPropertyTask method getPropertyValue.
public Object getPropertyValue(CyNetwork network, CyIdentifiable target, VisualProperty vp) {
CyNetworkView networkView = getViewForNetwork(network);
Class<? extends CyIdentifiable> vpTargetType = vp.getTargetDataType();
if (target instanceof CyNetwork) {
if (vpTargetType != CyNetwork.class)
throw new RuntimeException("Property '" + vp.getDisplayName() + "' not available for networks");
return networkView.getVisualProperty(vp);
} else if (target instanceof CyNode) {
if (vpTargetType != CyNode.class)
throw new RuntimeException("Property '" + vp.getDisplayName() + "' not available for nodes");
View<CyNode> nodeView = networkView.getNodeView((CyNode) target);
return nodeView.getVisualProperty(vp);
} else if (target instanceof CyEdge) {
if (vpTargetType != CyEdge.class)
throw new RuntimeException("Property '" + vp.getDisplayName() + "' not available for edges");
View<CyEdge> edgeView = networkView.getEdgeView((CyEdge) target);
return edgeView.getVisualProperty(vp);
}
return null;
}
Aggregations