Search in sources :

Example 1 with GenericIndex

use of org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex in project cytoscape-impl by cytoscape.

the class RangeSelectionListener method onUserSelection.

/**
 * Indicates that the user has selected a text item within the QuickFind
 * Search Box.
 *
 * @param network the current CyNetwork.
 * @param hit     hit value chosen by the user.
 */
public void onUserSelection(final CyNetwork network, Hit hit) {
    SelectUtil.unselectAllNodes(network);
    SelectUtil.unselectAllEdges(network);
    // Assemble Hit Objects
    final Object[] graphObjects = hit.getAssociatedObjects();
    final List list = new ArrayList();
    for (int i = 0; i < graphObjects.length; i++) {
        list.add(graphObjects[i]);
    }
    // Fit Selected Content
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            final CyNetwork cyNetwork = applicationManager.getCurrentNetwork();
            CyNetworkView networkView = applicationManager.getCurrentNetworkView();
            GenericIndex index = quickFind.getIndex(cyNetwork);
            if (index.getIndexType() == QuickFind.INDEX_NODES) {
                SelectUtil.setSelectedNodeState(network, list, true);
                final CyNetworkView currentView = applicationManager.getCurrentNetworkView();
                if (currentView != null)
                    currentView.fitSelected();
            } else {
                SelectUtil.setSelectedEdgeState(network, list, true);
                List<CyNode> nodeList = new ArrayList<CyNode>();
                for (int i = 0; i < list.size(); i++) {
                    CyEdge edge = (CyEdge) list.get(i);
                    CyNode sourceNode = edge.getSource();
                    CyNode targetNode = edge.getTarget();
                    nodeList.add(sourceNode);
                    nodeList.add(targetNode);
                }
                SelectUtil.setSelectedNodeState(network, nodeList, true);
                networkView.fitSelected();
            }
            // so that node does not take up whole screen.
            if (graphObjects.length == 1) {
                if (graphObjects[0] instanceof CyNode) {
                    CyNode node = (CyNode) graphObjects[0];
                    // Obtain dimensions of current InnerCanvas
                    RenderingEngine<CyNetwork> engine = applicationManager.getCurrentRenderingEngine();
                    VisualLexicon lexicon = engine.getVisualLexicon();
                    Double networkWidth = VisualPropertyUtil.get(lexicon, networkView, "NETWORK_WIDTH", BasicVisualLexicon.NETWORK, Double.class);
                    Double networkHeight = VisualPropertyUtil.get(lexicon, networkView, "NETWORK_HEIGHT", BasicVisualLexicon.NETWORK, Double.class);
                    View<CyNode> nodeView = networkView.getNodeView(node);
                    Double nodeWidth = VisualPropertyUtil.get(lexicon, nodeView, "NODE_WIDTH", BasicVisualLexicon.NODE, Double.class);
                    Double nodeHeight = VisualPropertyUtil.get(lexicon, nodeView, "NODE_HEIGHT", BasicVisualLexicon.NODE, Double.class);
                    double width = nodeWidth * NODE_SIZE_MULTIPLER;
                    double height = nodeHeight * NODE_SIZE_MULTIPLER;
                    double scaleFactor = Math.min(networkWidth / width, (networkHeight / height));
                // TODO: How do we set the zoom in the new API?
                // networkView.setZoom(scaleFactor);
                }
            }
            networkView.updateView();
        }
    });
}
Also used : BasicVisualLexicon(org.cytoscape.view.presentation.property.BasicVisualLexicon) VisualLexicon(org.cytoscape.view.model.VisualLexicon) ArrayList(java.util.ArrayList) CyNetwork(org.cytoscape.model.CyNetwork) CyEdge(org.cytoscape.model.CyEdge) View(org.cytoscape.view.model.View) CyNetworkView(org.cytoscape.view.model.CyNetworkView) GenericIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex) RenderingEngine(org.cytoscape.view.presentation.RenderingEngine) ArrayList(java.util.ArrayList) List(java.util.List) CyNode(org.cytoscape.model.CyNode) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 2 with GenericIndex

use of org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex in project cytoscape-impl by cytoscape.

the class RangeSelectionListener method onUserRangeSelection.

/**
 * Indicates that the user has selected a number range within the QuickFind
 * Range selector.
 *
 * @param network   the current CyNetwork.
 * @param lowValue  the low value of the range.
 * @param highValue the high value of the range.
 */
public void onUserRangeSelection(CyNetwork network, Number lowValue, Number highValue) {
    try {
        GenericIndex index = quickFind.getIndex(network);
        NumberIndex numberIndex = (NumberIndex) index;
        final List rangeList = numberIndex.getRange(lowValue, highValue);
        if (index.getIndexType() == QuickFind.INDEX_NODES) {
            selectNodes(network, rangeList);
        } else {
            selectEdges(network, rangeList);
        }
    } catch (IllegalArgumentException exc) {
    }
}
Also used : GenericIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex) NumberIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.NumberIndex) ArrayList(java.util.ArrayList) List(java.util.List)

Example 3 with GenericIndex

use of org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex in project cytoscape-impl by cytoscape.

the class RangeSelectionListener method handleNetworkModified.

private void handleNetworkModified(final CyNetwork cyNetwork) {
    if (!networkManager.networkExists(cyNetwork.getSUID()))
        return;
    if (cyNetwork.getNodeCount() > 0) {
        // this can happen if an empty network was added
        if (quickFind.getIndex(cyNetwork) == null) {
            // Run Indexer in separate background daemon thread.
            Thread thread = new Thread() {

                public void run() {
                    quickFind.addNetwork(cyNetwork, new TaskMonitorBase());
                }
            };
            thread.start();
        } else // very large networks.
        if (cyNetwork.getNodeCount() < QuickFindApp.REINDEX_THRESHOLD) {
            // Run Indexer in separate background daemon thread.
            Thread thread = new Thread() {

                public void run() {
                    GenericIndex index = quickFind.getIndex(cyNetwork);
                    quickFind.reindexNetwork(cyNetwork, index.getIndexType(), index.getControllingAttribute(), new TaskMonitorBase());
                }
            };
            thread.start();
        }
    }
}
Also used : GenericIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex) TaskMonitorBase(org.cytoscape.filter.internal.quickfind.util.TaskMonitorBase)

Example 4 with GenericIndex

use of org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex in project cytoscape-impl by cytoscape.

the class FilterSettingPanel method createNumberIndex.

private NumberIndex createNumberIndex(NumericFilter pNumericFilter) {
    CyNetwork currentNetwork = applicationManager.getCurrentNetwork();
    if (currentNetwork == null)
        return null;
    int indexType = pNumericFilter.getIndexType();
    quickFind.reindexNetwork(currentNetwork, indexType, pNumericFilter.getControllingAttribute(), new TaskMonitorBase());
    GenericIndex currentIndex = quickFind.getIndex(currentNetwork);
    if (currentIndex == null || !(currentIndex instanceof NumberIndex)) {
        return null;
    }
    return (NumberIndex) currentIndex;
}
Also used : GenericIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex) NumberIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.NumberIndex) CyNetwork(org.cytoscape.model.CyNetwork) TaskMonitorBase(org.cytoscape.filter.internal.quickfind.util.TaskMonitorBase)

Example 5 with GenericIndex

use of org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex in project cytoscape-impl by cytoscape.

the class RangeSelectionListener method stateChanged.

/**
 * State Change Event.
 *
 * @param e ChangeEvent Object.
 */
public void stateChanged(ChangeEvent e) {
    final CyNetwork cyNetwork = applicationManager.getCurrentNetwork();
    GenericIndex index = quickFind.getIndex(cyNetwork);
    NumberRangeModel model = (NumberRangeModel) slider.getModel();
    if (slider.isVisible()) {
        if (index instanceof NumberIndex) {
            Number lowValue = (Number) model.getLowValue();
            Number highValue = (Number) model.getHighValue();
            quickFind.selectRange(cyNetwork, lowValue, highValue);
        }
    }
}
Also used : GenericIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex) NumberIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.NumberIndex) NumberRangeModel(org.cytoscape.filter.internal.prefuse.data.query.NumberRangeModel) CyNetwork(org.cytoscape.model.CyNetwork)

Aggregations

GenericIndex (org.cytoscape.filter.internal.widgets.autocomplete.index.GenericIndex)8 NumberIndex (org.cytoscape.filter.internal.widgets.autocomplete.index.NumberIndex)3 CyNetwork (org.cytoscape.model.CyNetwork)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 TaskMonitorBase (org.cytoscape.filter.internal.quickfind.util.TaskMonitorBase)2 CyColumn (org.cytoscape.model.CyColumn)2 CyTable (org.cytoscape.model.CyTable)2 Date (java.util.Date)1 NumberRangeModel (org.cytoscape.filter.internal.prefuse.data.query.NumberRangeModel)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNode (org.cytoscape.model.CyNode)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1 View (org.cytoscape.view.model.View)1 VisualLexicon (org.cytoscape.view.model.VisualLexicon)1 RenderingEngine (org.cytoscape.view.presentation.RenderingEngine)1 BasicVisualLexicon (org.cytoscape.view.presentation.property.BasicVisualLexicon)1