use of org.cytoscape.view.vizmap.VisualStyle 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.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class NetworkViewMediator method handleEvent.
@Override
public void handleEvent(final SetCurrentVisualStyleEvent e) {
if (loadingSession)
return;
final VisualStyle style = e.getVisualStyle();
if (style != null) {
final CyNetworkView curView = serviceRegistrar.getService(CyApplicationManager.class).getCurrentNetworkView();
if (curView != null) {
final VisualMappingManager vmm = serviceRegistrar.getService(VisualMappingManager.class);
vmm.setVisualStyle(style, curView);
}
}
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class NetworkViewMediator method onColumnChanged.
private void onColumnChanged(final CyTable tbl, final String columnName) {
if (loadingSession || getNetworkViewMainPanel().isEmpty())
return;
final CyNetworkTableManager netTblMgr = serviceRegistrar.getService(CyNetworkTableManager.class);
final CyNetwork net = netTblMgr.getNetworkForTable(tbl);
final CyNetworkViewManager netViewMgr = serviceRegistrar.getService(CyNetworkViewManager.class);
// And if there is no related view, nothing needs to be done
if (net != null && netViewMgr.viewExists(net) && (tbl.equals(net.getDefaultNodeTable()) || tbl.equals(net.getDefaultEdgeTable()))) {
// Reapply locked values that map to changed columns
final Collection<CyNetworkView> networkViews = netViewMgr.getNetworkViews(net);
final boolean lockedValuesApplyed = reapplyLockedValues(columnName, networkViews);
// Find views that had their styles affected by the RowsSetEvent
final Set<VisualStyle> styles = findStylesWithMappedColumn(columnName);
final Set<CyNetworkView> viewsToUpdate = findNetworkViewsWithStyles(styles);
if (lockedValuesApplyed)
viewsToUpdate.addAll(networkViews);
// Update views
for (final CyNetworkView view : viewsToUpdate) updateView(view, null);
}
}
use of org.cytoscape.view.vizmap.VisualStyle 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.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class CreateNetworkViewTask method run.
@Override
public void run(TaskMonitor tm) throws Exception {
tm.setProgress(0.0);
final Collection<CyNetwork> netList = network != null ? Collections.singletonList(network) : networks;
final int total = netList.size();
tm.setTitle("Creating Network View" + (total == 1 ? "" : "s"));
tm.setStatusMessage("Creating " + total + " network view" + (total == 1 ? "" : "s") + "...");
if (viewFactory == null && viewRenderers.size() > 1) {
// Let the user choose the network view renderer first
final ChooseViewRendererTask chooseRendererTask = new ChooseViewRendererTask(netList);
insertTasksAfterCurrentTask(chooseRendererTask);
} else {
final CyNetwork curNet = appMgr.getCurrentNetwork();
CyNetworkView curView = appMgr.getCurrentNetworkView();
final VisualStyle style = vmMgr.getCurrentVisualStyle();
int i = 0;
int viewCount = netList.size();
for (final CyNetwork n : netList) {
// TODO Remove this check when multiple views per network is supported
if (netViewMgr.viewExists(n))
continue;
final CyNetworkView view = createView(n, style, tm);
networkViews.add(view);
if (curView == null && n.equals(curNet))
curView = view;
tm.setStatusMessage("Network view successfully created for: " + n.getRow(n).get(CyNetwork.NAME, String.class));
i++;
tm.setProgress((i / (double) viewCount));
}
final List<CyNetwork> selectedNetworks = appMgr.getSelectedNetworks();
final List<CyNetworkView> selectedViews = new ArrayList<>(appMgr.getSelectedNetworkViews());
boolean setSelectedViews = false;
if (layoutMgr == null) {
// Create network from selection?
insertTasksAfterCurrentTask(new RegisterNetworkTask(networkViews.get(0), style, netMgr, vmMgr, appMgr, netViewMgr));
} else {
insertTasksAfterCurrentTask(new RegisterNetworkTask(networkViews, style, netMgr, vmMgr, appMgr, netViewMgr));
}
}
tm.setProgress(1.0);
}
Aggregations