Search in sources :

Example 26 with CyApplicationManager

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();
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNetworkView(org.cytoscape.view.model.CyNetworkView) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem)

Example 27 with CyApplicationManager

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));
    }
}
Also used : Transformer(org.cytoscape.filter.model.Transformer) MemoizableTransformer(org.cytoscape.filter.internal.MemoizableTransformer) CyNetwork(org.cytoscape.model.CyNetwork) MemoizableTransformer(org.cytoscape.filter.internal.MemoizableTransformer) CyApplicationManager(org.cytoscape.application.CyApplicationManager) FilterElement(org.cytoscape.filter.internal.view.FilterElement) TransformerSink(org.cytoscape.filter.model.TransformerSink) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 28 with CyApplicationManager

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));
    }
}
Also used : CompositeFilter(org.cytoscape.filter.model.CompositeFilter) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyRow(org.cytoscape.model.CyRow) CyEdge(org.cytoscape.model.CyEdge) MemoizableTransformer(org.cytoscape.filter.internal.MemoizableTransformer) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView) CyIdentifiable(org.cytoscape.model.CyIdentifiable)

Example 29 with CyApplicationManager

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);
}
Also used : NullVisualProperty(org.cytoscape.view.presentation.property.NullVisualProperty) CyEventHelper(org.cytoscape.event.CyEventHelper) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualLexicon(org.cytoscape.view.model.VisualLexicon) VisualMappingFunctionFactory(org.cytoscape.view.vizmap.VisualMappingFunctionFactory) CyNetwork(org.cytoscape.model.CyNetwork) Paint(java.awt.Paint) NetworkViewTestSupport(org.cytoscape.ding.NetworkViewTestSupport) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar) CyApplicationManager(org.cytoscape.application.CyApplicationManager) CyTable(org.cytoscape.model.CyTable) NullDataType(org.cytoscape.view.model.NullDataType) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualProperty(org.cytoscape.view.model.VisualProperty) NullVisualProperty(org.cytoscape.view.presentation.property.NullVisualProperty) HashSet(java.util.HashSet) NetworkViewRenderer(org.cytoscape.application.NetworkViewRenderer) Before(org.junit.Before)

Example 30 with CyApplicationManager

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());
    }
}
Also used : CyApplicationManager(org.cytoscape.application.CyApplicationManager) BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualLexicon(org.cytoscape.view.model.VisualLexicon) VisualLexiconNode(org.cytoscape.view.model.VisualLexiconNode) LinkedList(java.util.LinkedList)

Aggregations

CyApplicationManager (org.cytoscape.application.CyApplicationManager)80 CyNetwork (org.cytoscape.model.CyNetwork)40 CyNetworkView (org.cytoscape.view.model.CyNetworkView)30 CyNetworkViewManager (org.cytoscape.view.model.CyNetworkViewManager)18 VisualMappingManager (org.cytoscape.view.vizmap.VisualMappingManager)16 CyNetworkManager (org.cytoscape.model.CyNetworkManager)14 CyEventHelper (org.cytoscape.event.CyEventHelper)12 CyTable (org.cytoscape.model.CyTable)12 ArrayList (java.util.ArrayList)11 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)10 CyNode (org.cytoscape.model.CyNode)9 VisualStyle (org.cytoscape.view.vizmap.VisualStyle)9 Test (org.junit.Test)9 HashSet (java.util.HashSet)8 CyNetworkTableManager (org.cytoscape.model.CyNetworkTableManager)8 CyRootNetworkManager (org.cytoscape.model.subnetwork.CyRootNetworkManager)8 TaskIterator (org.cytoscape.work.TaskIterator)8 HashMap (java.util.HashMap)7 CyGroupManager (org.cytoscape.group.CyGroupManager)7 CyTableManager (org.cytoscape.model.CyTableManager)7