use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class UnHideAllNodesTaskFactoryTest method testRun.
@Test
public void testRun() throws Exception {
UndoSupport undoSupport = mock(UndoSupport.class);
CyEventHelper eventHelper = mock(CyEventHelper.class);
VisualMappingManager vmMgr = mock(VisualMappingManager.class);
CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
when(serviceRegistrar.getService(UndoSupport.class)).thenReturn(undoSupport);
when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
when(serviceRegistrar.getService(VisualMappingManager.class)).thenReturn(vmMgr);
UnHideAllNodesTaskFactoryImpl factory = new UnHideAllNodesTaskFactoryImpl(serviceRegistrar);
CyNetworkView view = mock(CyNetworkView.class);
TaskIterator ti = factory.createTaskIterator(view);
assertNotNull(ti);
assertTrue(ti.hasNext());
Task t = ti.next();
assertNotNull(t);
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class HideSelectedEdgesTaskFactoryTest method testRun.
@Test
public void testRun() throws Exception {
UndoSupport undoSupport = mock(UndoSupport.class);
CyEventHelper eventHelper = mock(CyEventHelper.class);
VisualMappingManager vmMgr = mock(VisualMappingManager.class);
CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
when(serviceRegistrar.getService(UndoSupport.class)).thenReturn(undoSupport);
when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
when(serviceRegistrar.getService(VisualMappingManager.class)).thenReturn(vmMgr);
HideSelectedEdgesTaskFactoryImpl factory = new HideSelectedEdgesTaskFactoryImpl(serviceRegistrar);
CyNetworkView view = mock(CyNetworkView.class);
TaskIterator ti = factory.createTaskIterator(view);
assertNotNull(ti);
assertTrue(ti.hasNext());
Task t = ti.next();
assertNotNull(t);
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class HideSelectedTaskFactoryTest method testRun.
@Test
public void testRun() throws Exception {
UndoSupport undoSupport = mock(UndoSupport.class);
CyEventHelper eventHelper = mock(CyEventHelper.class);
VisualMappingManager vmMgr = mock(VisualMappingManager.class);
CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
when(serviceRegistrar.getService(UndoSupport.class)).thenReturn(undoSupport);
when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
when(serviceRegistrar.getService(VisualMappingManager.class)).thenReturn(vmMgr);
HideSelectedTaskFactoryImpl factory = new HideSelectedTaskFactoryImpl(serviceRegistrar);
CyNetworkView view = mock(CyNetworkView.class);
TaskIterator ti = factory.createTaskIterator(view);
assertNotNull(ti);
assertTrue(ti.hasNext());
Task t = ti.next();
assertNotNull(t);
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class UnHideAllTaskFactoryTest method testRun.
@Test
public void testRun() throws Exception {
UndoSupport undoSupport = mock(UndoSupport.class);
CyEventHelper eventHelper = mock(CyEventHelper.class);
VisualMappingManager vmMgr = mock(VisualMappingManager.class);
CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
when(serviceRegistrar.getService(UndoSupport.class)).thenReturn(undoSupport);
when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
when(serviceRegistrar.getService(VisualMappingManager.class)).thenReturn(vmMgr);
UnHideAllTaskFactoryImpl factory = new UnHideAllTaskFactoryImpl(serviceRegistrar);
CyNetworkView view = mock(CyNetworkView.class);
TaskIterator ti = factory.createTaskIterator(view);
assertNotNull(ti);
assertTrue(ti.hasNext());
Task t = ti.next();
assertNotNull(t);
}
use of org.cytoscape.event.CyEventHelper in project cytoscape-impl by cytoscape.
the class ClipboardImpl method paste.
public List<CyIdentifiable> paste(CyNetworkView targetView, double x, double y) {
final List<CyIdentifiable> pastedObjects = new ArrayList<>();
final Map<CyRow, CyRow> rowMap = new HashMap<>();
// We need to do this in 4 passes.
// In pass 1, we'll add all of the nodes and store their (possibly new) SUID.
// In pass 2, we'll add the edges.
// In pass 3, we'll reposition the nodes and paste any locked visual properties node views.
// In pass 4, we'll paste any locked visual properties to edge views
// Note that if we add any nodes, we'll only add edges to nodes that exist.
// Pass 1: add the nodes
final Map<CyNode, CyNode> newNodeMap = new HashMap<>();
for (CyNode node : nodes) {
CyNode newNode = pasteNode(sourceView, targetView, node, rowMap);
newNodeMap.put(node, newNode);
pastedObjects.add(newNode);
}
// Pass 2: add the edges
final Map<CyEdge, CyEdge> newEdgeMap = new HashMap<>();
for (CyEdge edge : edges) {
CyEdge newEdge = pasteEdge(sourceView, targetView, edge, rowMap, newNodeMap, pastedObjects);
if (newEdge != null) {
newEdgeMap.put(edge, newEdge);
pastedObjects.add(newEdge);
}
}
copyRows(rowMap);
final CyEventHelper eventHelper = serviceRegistrar.getService(CyEventHelper.class);
// Make sure node/edge views were created
eventHelper.flushPayloadEvents();
targetView.updateView();
// Pass 3: paste locked visual properties and reposition the new node views
double xOffset = xCenter - x;
double yOffset = yCenter - y;
for (CyNode node : nodePositions.keySet()) {
final CyNode newNode = newNodeMap.get(node);
if (newNode == null || !pastedObjects.contains(newNode))
continue;
final double[] position = nodePositions.get(node);
double nodeX = (position == null ? 0 : position[0]) - xOffset;
double nodeY = (position == null ? 0 : position[1]) - yOffset;
// Now, get the new node view
View<CyNode> newNodeView = targetView.getNodeView(newNode);
if (newNodeView != null) {
newNodeView.setVisualProperty(BasicVisualLexicon.NODE_X_LOCATION, nodeX);
newNodeView.setVisualProperty(BasicVisualLexicon.NODE_Y_LOCATION, nodeY);
setLockedValues(newNodeView, node, nodeBypass);
}
}
// Pass 4: paste locked visual properties to new edge views
if (!edgeBypassMap.isEmpty()) {
for (CyEdge edge : edgeBypassMap.keySet()) {
// Now, get the new edge view
CyEdge newEdge = newEdgeMap.get(edge);
View<CyEdge> newEdgeView = newEdge != null ? targetView.getEdgeView(newEdge) : null;
if (newEdgeView != null)
setLockedValues(newEdgeView, edge, edgeBypassMap);
}
}
// the nodes and edges don't show as selected. We need to fix that now
for (CyIdentifiable object : pastedObjects) {
// Special-case selected!!!
if (isSelected(targetView, object))
reselect(targetView, object);
}
return pastedObjects;
}
Aggregations