use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.
the class SelectModeAction method menuSelected.
@Override
public void menuSelected(MenuEvent e) {
final JCheckBoxMenuItem item = getThisItem();
if (item != null) {
final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
final CyNetworkView view = applicationManager.getCurrentNetworkView();
if (view == null)
item.setSelected(false);
else if (view.getVisualProperty(NETWORK_NODE_SELECTION) && view.getVisualProperty(NETWORK_EDGE_SELECTION))
item.setSelected(name.equalsIgnoreCase(ALL));
else if (view.getVisualProperty(NETWORK_NODE_SELECTION))
item.setSelected(name.equalsIgnoreCase(NODES));
else if (view.getVisualProperty(NETWORK_EDGE_SELECTION))
item.setSelected(name.equalsIgnoreCase(EDGES));
else
item.setSelected(false);
}
updateEnableState();
}
use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.
the class TransformerWorker method doWork.
@Override
public void doWork(ProgressMonitor monitor) {
if (controller == null) {
return;
}
final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
CyNetworkView networkView = applicationManager.getCurrentNetworkView();
CyNetwork network;
if (networkView != null) {
network = networkView.getModel();
} else {
network = applicationManager.getCurrentNetwork();
}
if (network == null) {
return;
}
ProgressMonitor filterMonitor = new SubProgressMonitor(monitor, 0.0, 0.4);
ProgressMonitor chainMonitor = new SubProgressMonitor(monitor, 0.4, 0.98);
monitor.setProgress(0.0);
monitor.setStatusMessage(null);
Sink sink = new Sink(network);
long startTime = System.currentTimeMillis();
try {
List<Transformer<CyNetwork, CyIdentifiable>> transformers = controller.getTransformers(view);
FilterElement selected = (FilterElement) controller.getStartWithComboBoxModel().getSelectedItem();
TransformerSource<CyNetwork, CyIdentifiable> source = createSource(network, selected, filterMonitor);
for (Transformer<?, ?> transformer : transformers) {
if (transformer instanceof MemoizableTransformer) {
((MemoizableTransformer) transformer).startCaching();
}
}
try {
transformerManager.execute(network, source, transformers, sink, chainMonitor);
} finally {
for (Transformer<?, ?> transformer : transformers) {
if (transformer instanceof MemoizableTransformer) {
((MemoizableTransformer) transformer).clearCache();
}
}
}
if (networkView != null) {
networkView.updateView();
}
} finally {
long duration = System.currentTimeMillis() - startTime;
monitor.setProgress(1.0);
monitor.setStatusMessage(String.format("Selected %d %s and %d %s in %dms", sink.nodeCount, sink.nodeCount == 1 ? "node" : "nodes", sink.edgeCount, sink.edgeCount == 1 ? "edge" : "edges", duration));
}
}
use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.
the class FilterWorker method doWork.
@Override
public void doWork(ProgressMonitor monitor) {
if (controller == null) {
return;
}
final CyApplicationManager applicationManager = serviceRegistrar.getService(CyApplicationManager.class);
CyNetworkView networkView = applicationManager.getCurrentNetworkView();
CyNetwork network;
if (networkView != null) {
network = networkView.getModel();
} else {
network = applicationManager.getCurrentNetwork();
}
if (network == null) {
return;
}
monitor.setProgress(0);
monitor.setStatusMessage(null);
int nodeCount = 0;
int edgeCount = 0;
int counter = 0;
long startTime = System.currentTimeMillis();
try {
Filter<CyNetwork, CyIdentifiable> filter = controller.getFilter();
if (filter instanceof CompositeFilter) {
// If we have an empty CompositeFilter, bail out.
CompositeFilter<CyNetwork, CyIdentifiable> composite = (CompositeFilter<CyNetwork, CyIdentifiable>) filter;
if (composite.getLength() == 0) {
return;
}
}
if (filter instanceof MemoizableTransformer) {
((MemoizableTransformer) filter).startCaching();
}
try {
List<CyNode> nodeList = network.getNodeList();
List<CyEdge> edgeList = network.getEdgeList();
double total = nodeList.size() + edgeList.size();
List<CyIdentifiable> selected = new ArrayList<>();
List<CyIdentifiable> unselected = new ArrayList<>();
for (CyNode node : nodeList) {
if (monitor.isCancelled()) {
return;
}
boolean accepted = filter.accepts(network, node);
if (accepted) {
selected.add(node);
nodeCount++;
} else {
unselected.add(node);
}
monitor.setProgress(++counter / total);
}
for (CyEdge edge : edgeList) {
if (monitor.isCancelled()) {
return;
}
boolean accepted = filter.accepts(network, edge);
if (accepted) {
selected.add(edge);
edgeCount++;
} else {
unselected.add(edge);
}
monitor.setProgress(++counter / total);
}
// now do the selection
for (CyIdentifiable element : unselected) {
CyRow row = network.getRow(element);
if (row.get(CyNetwork.SELECTED, Boolean.class)) {
row.set(CyNetwork.SELECTED, Boolean.FALSE);
}
}
for (CyIdentifiable element : selected) {
CyRow row = network.getRow(element);
if (!row.get(CyNetwork.SELECTED, Boolean.class)) {
row.set(CyNetwork.SELECTED, Boolean.TRUE);
}
}
} finally {
if (filter instanceof MemoizableTransformer) {
((MemoizableTransformer) filter).clearCache();
}
}
if (networkView != null) {
networkView.updateView();
}
} finally {
long duration = System.currentTimeMillis() - startTime;
monitor.setProgress(1.0);
monitor.setStatusMessage(String.format("Selected %d %s and %d %s in %dms", nodeCount, nodeCount == 1 ? "node" : "nodes", edgeCount, edgeCount == 1 ? "edge" : "edges", duration));
}
}
use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.
the class VisualStyleTest method setUp.
@Before
@SuppressWarnings("unchecked")
public void setUp() throws Exception {
NetworkViewTestSupport nvts = new NetworkViewTestSupport();
network = nvts.getNetworkFactory().createNetwork();
node1 = network.addNode();
node2 = network.addNode();
node3 = network.addNode();
edge = network.addEdge(node1, node2, true);
CyTable nodeTable = network.getDefaultNodeTable();
nodeTable.createColumn(attrName, String.class, true);
nodeTable.getRow(node1.getSUID()).set(attrName, "red");
nodeTable.getRow(node2.getSUID()).set(attrName, "green");
nodeTable.getRow(node3.getSUID()).set(attrName, "foo");
networkView = nvts.getNetworkViewFactory().createNetworkView(network);
// Create root node.
final NullVisualProperty minimalRoot = new NullVisualProperty("MINIMAL_ROOT", "Minimal Root Visual Property");
final BasicVisualLexicon minimalLex = new BasicVisualLexicon(minimalRoot);
final Set<VisualLexicon> lexSet = new HashSet<VisualLexicon>();
lexSet.add(minimalLex);
final VisualMappingFunctionFactory ptFactory = mock(VisualMappingFunctionFactory.class);
eventHelper = mock(CyEventHelper.class);
final RenderingEngineFactory<CyNetwork> reFatory = mock(RenderingEngineFactory.class);
when(reFatory.getVisualLexicon()).thenReturn(minimalLex);
final NetworkViewRenderer nvRenderer = mock(NetworkViewRenderer.class);
when(nvRenderer.getRenderingEngineFactory(NetworkViewRenderer.DEFAULT_CONTEXT)).thenReturn(reFatory);
final CyApplicationManager appManager = mock(CyApplicationManager.class);
when(appManager.getCurrentNetworkViewRenderer()).thenReturn(nvRenderer);
final CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
when(serviceRegistrar.getService(CyApplicationManager.class)).thenReturn(appManager);
VisualProperty<NullDataType> rootVisualProperty = mock(VisualProperty.class);
BasicVisualLexicon lexicon = new BasicVisualLexicon(rootVisualProperty);
vpSet = new HashSet<VisualProperty<Paint>>();
vpSet.add(BasicVisualLexicon.NODE_BORDER_PAINT);
vpSet.add(BasicVisualLexicon.NODE_FILL_COLOR);
dependency = new VisualPropertyDependency<Paint>("dep1", "Dep 1", vpSet, lexicon);
final VisualStyleFactoryImpl visualStyleFactory = new VisualStyleFactoryImpl(serviceRegistrar, ptFactory);
originalTitle = "Style 1";
newTitle = "Style 2";
style = visualStyleFactory.createVisualStyle(originalTitle);
style.setDefaultValue(NODE_SIZE, DEF_NODE_SIZE);
style.setDefaultValue(NODE_FILL_COLOR, DEF_NODE_COLOR);
reset(eventHelper);
}
use of org.cytoscape.application.CyApplicationManager in project cytoscape-impl by cytoscape.
the class AbstractApplyHandler method apply.
@Override
public void apply(final CyRow row, final View<T> view) {
if (updateDependencyMaps)
updateDependencyMaps();
// Clear visual properties first
view.clearVisualProperties();
// Get current Visual Lexicon
final CyApplicationManager appMgr = serviceRegistrar.getService(CyApplicationManager.class);
final VisualLexicon lexicon = appMgr.getCurrentNetworkViewRenderer().getRenderingEngineFactory(NetworkViewRenderer.DEFAULT_CONTEXT).getVisualLexicon();
final LinkedList<VisualLexiconNode> descendants = new LinkedList<VisualLexiconNode>();
descendants.addAll(lexicon.getVisualLexiconNode(rootVisualProperty).getChildren());
while (!descendants.isEmpty()) {
final VisualLexiconNode node = descendants.pop();
final VisualProperty<?> vp = node.getVisualProperty();
if (vp.getTargetDataType() != targetDataType)
// Because NETWORK has node/edge properties as descendants as well
continue;
final VisualMappingFunction<?, ?> mapping = style.getVisualMappingFunction(vp);
final Object value = mapping != null ? mapping.getMappedValue(row) : null;
if (value == null) {
// Apply the default value...
applyDefaultValue(view, vp, lexicon);
} else {
// Apply the mapped value...
applyMappedValue(view, vp, value);
}
descendants.addAll(node.getChildren());
}
}
Aggregations