use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class RowsSetViewUpdater method updateView.
private final void updateView(final RowsSetEvent e) {
boolean refreshView = false;
boolean refreshOtherViews = false;
// Acquire services once to avoid performance overhead of repeated lookup
final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
final CyColumnIdentifierFactory columnIdentifierFactory = serviceRegistrar.getService(CyColumnIdentifierFactory.class);
final CyNetworkViewManager networkViewManager = serviceRegistrar.getService(CyNetworkViewManager.class);
final VisualMappingManager visualMappingManager = serviceRegistrar.getService(VisualMappingManager.class);
final RenderingEngine<CyNetwork> renderer = applicationManager.getCurrentRenderingEngine();
final CyNetwork network = applicationManager.getCurrentNetwork();
if (network == null)
return;
// 1: Update current network view
final Collection<CyNetworkView> views = networkViewManager.getNetworkViews(network);
CyNetworkView networkView = null;
if (views.isEmpty())
return;
else
networkView = views.iterator().next();
final VisualStyle vs = visualMappingManager.getVisualStyle(networkView);
Map<CyRow, View<? extends CyIdentifiable>> rowViewMap = tracker.getRowViewMap(networkView);
for (final RowSetRecord record : e.getPayloadCollection()) {
final CyRow row = record.getRow();
final String columnName = record.getColumn();
final CyColumn column = row.getTable().getColumn(columnName);
if (column == null)
continue;
final VirtualColumnInfo virtualColInfo = column.getVirtualColumnInfo();
final boolean virtual = virtualColInfo.isVirtual();
final View<? extends CyIdentifiable> v = rowViewMap.get(row);
if (v == null)
continue;
if (v.getModel() instanceof CyNode) {
final CyNode node = (CyNode) v.getModel();
if (network.containsNode(node) && isStyleAffected(vs, columnName, renderer, columnIdentifierFactory)) {
vs.apply(row, v);
refreshView = false;
}
} else if (v.getModel() instanceof CyEdge) {
final CyEdge edge = (CyEdge) v.getModel();
if (network.containsEdge(edge) && isStyleAffected(vs, columnName, renderer, columnIdentifierFactory)) {
vs.apply(row, v);
refreshView = false;
}
}
// If virtual, it may be used in other networks.
if (refreshView && virtual)
refreshOtherViews = true;
// if (refreshView)
// vs.apply(record.getRow(), (View<? extends CyIdentifiable>) v);
}
if (refreshView) {
vs.apply(networkView);
networkView.updateView();
if (refreshOtherViews) {
// Check other views. If update is required, set the flag.
for (final CyNetworkView view : networkViewManager.getNetworkViewSet()) {
if (view == networkView)
continue;
final VisualStyle style = visualMappingManager.getVisualStyle(view);
if (style == vs) {
// Same style is in use. Need to apply.
netViewMediator.setUpdateFlag(view);
}
}
}
}
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class ApplyVisualStyleTaskTest method testRun.
@Test
public void testRun() throws Exception {
NetworkViewTestSupport nvts = new NetworkViewTestSupport();
TaskMonitor tm = mock(TaskMonitor.class);
final CyNetworkView view = nvts.getNetworkView();
final Set<CyNetworkView> views = new HashSet<CyNetworkView>();
views.add(view);
ApplyVisualStyleTask task = new ApplyVisualStyleTask(views, serviceRegistrar);
final List<VisualStyle> vsList = new ArrayList<VisualStyle>();
VisualStyle style1 = mock(VisualStyle.class);
vsList.add(style1);
task.styles = new ListSingleSelection<VisualStyle>(vsList);
task.styles.setSelectedValue(style1);
task.run(tm);
verify(style1, times(1)).apply(view);
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class ViewUtils method applyStyle.
public static void applyStyle(final Collection<? extends CyIdentifiable> elements, final Collection<CyNetworkView> networkViews, final VisualMappingManager cyStyleManager) {
if (elements == null || networkViews == null)
return;
for (CyNetworkView netView : networkViews) {
final CyNetwork net = netView.getModel();
final VisualStyle style = cyStyleManager.getVisualStyle(netView);
for (CyIdentifiable entry : elements) {
View<? extends CyIdentifiable> view = null;
if (entry instanceof CyNode)
view = netView.getNodeView((CyNode) entry);
else if (entry instanceof CyEdge)
view = netView.getEdgeView((CyEdge) entry);
if (view != null)
style.apply(net.getRow(entry), view);
}
}
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class NetworkAddedSetCurrent method handleEvent.
@Override
public void handleEvent(NetworkViewAddedEvent e) {
e.getNetworkView().setVisualProperty(BasicVisualLexicon.NETWORK_WIDTH, 300.0);
e.getNetworkView().setVisualProperty(BasicVisualLexicon.NETWORK_HEIGHT, 300.0);
JPanel temp = new JPanel();
VisualStyle vs = vman.getVisualStyle(e.getNetworkView());
vs.apply(e.getNetworkView());
final RenderingEngine<CyNetwork> renderingEngine = rfactory.createRenderingEngine(temp, e.getNetworkView());
rman.addRenderingEngine(renderingEngine);
appManager.setCurrentRenderingEngine(renderingEngine);
}
use of org.cytoscape.view.vizmap.VisualStyle in project cytoscape-impl by cytoscape.
the class VisualMappingManagerImpl method getVisualStyle.
/**
* Returns an associated Visual Style for the View Model.
*/
@Override
public VisualStyle getVisualStyle(CyNetworkView nv) {
if (nv == null) {
logger.warn("Attempting to get the visual style for a null network view; " + "returning the default visual style.");
return getDefaultVisualStyle();
}
synchronized (lock) {
VisualStyle style = network2VisualStyleMap.get(nv);
// Not registered yet. Provide default style.
if (style == null) {
style = getDefaultVisualStyle();
network2VisualStyleMap.put(nv, style);
}
return style;
}
}
Aggregations