Search in sources :

Example 1 with TextIndex

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

the class StringFilter method apply.

/**
 * Caculate the bitSet based on the existing TextIndex and search string.
 * The size of the bitSet is the number of nodes/edges in the given network,
 * All bits are initially set to false, those with hits are set to true.
 * @param none.
 * @return none.
 */
public void apply() {
    List<CyNode> nodes_list = null;
    List<CyEdge> edges_list = null;
    // Initialize the bitset
    int objectCount = -1;
    if (index_type == QuickFind.INDEX_NODES) {
        nodes_list = network.getNodeList();
        objectCount = nodes_list.size();
        // all the bits are false at very beginning
        node_bits = new BitSet(objectCount);
    } else if (index_type == QuickFind.INDEX_EDGES) {
        edges_list = network.getEdgeList();
        objectCount = edges_list.size();
        // all the bits are false at very beginning
        edge_bits = new BitSet(objectCount);
    } else {
        LoggerFactory.getLogger("org.cytoscape.application.userlog").error("StringFilter: Index_type is undefined.");
        return;
    }
    if (searchStr == null || network == null || !FilterUtil.hasSuchAttribute(network, controllingAttribute, index_type)) {
        return;
    }
    // If quickFind_index does not exist, build the Index
    // if (quickFind_index == null) {
    quickFind_index = FilterUtil.getQuickFindIndex(quickFind, controllingAttribute, network, index_type);
    // }
    TextIndex theIndex = (TextIndex) quickFind_index;
    Hit[] hits = theIndex.getHits(searchStr, Integer.MAX_VALUE);
    if (hits.length == 0) {
        return;
    }
    Hit hit0 = hits[0];
    Object[] hit_objs = hit0.getAssociatedObjects();
    int index = -1;
    if (index_type == QuickFind.INDEX_NODES) {
        for (Object obj : hit_objs) {
            index = nodes_list.indexOf(obj);
            node_bits.set(index, true);
        }
    } else if (index_type == QuickFind.INDEX_EDGES) {
        for (Object obj : hit_objs) {
            index = edges_list.indexOf(obj);
            edge_bits.set(index, true);
        }
    }
    if (negation) {
        if (index_type == QuickFind.INDEX_NODES) {
            node_bits.flip(0, objectCount);
        }
        if (index_type == QuickFind.INDEX_EDGES) {
            edge_bits.flip(0, objectCount);
        }
    }
}
Also used : Hit(org.cytoscape.filter.internal.widgets.autocomplete.index.Hit) TextIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.TextIndex) BitSet(java.util.BitSet) CyNode(org.cytoscape.model.CyNode) CyEdge(org.cytoscape.model.CyEdge)

Example 2 with TextIndex

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

the class FilterSettingPanel method getTextIndexComboBox.

private JComboBox getTextIndexComboBox(StringFilter pFilter) {
    TextIndexComboBox comboBox = null;
    try {
        // If index doesnot exist, check if there is such attribute or
        if (!FilterUtil.hasSuchAttribute(pFilter.getNetwork(), pFilter.getControllingAttribute(), pFilter.getIndexType())) {
            // no such attribute
            JComboBox tmpCombo;
            if (pFilter.getSearchStr() != null) {
                Object[] objList = { pFilter.getSearchStr() };
                tmpCombo = new JComboBox(objList);
            } else {
                tmpCombo = new JComboBox();
            }
            tmpCombo.setEnabled(false);
            return tmpCombo;
        }
        // The attribute exists, create an index
        // final QuickFind quickFind = QuickFindFactory.getGlobalQuickFindInstance();
        // quickFind.reindexNetwork(Cytoscape.getCurrentNetwork(), pFilter.getIndexType(),
        // pFilter.getControllingAttribute(), new TaskMonitorBase());
        // TextIndex index_by_thisAttr = (TextIndex) quickFind.getIndex(Cytoscape.getCurrentNetwork());
        pFilter.setIndex(createTextIndex(pFilter));
        comboBox = ComboBoxFactory.createTextIndexComboBox((TextIndex) pFilter.getIndex(), 2.0);
        // Set Size of ComboBox Display, based on # of specific chars
        comboBox.setPrototypeDisplayValue("01234567");
        // Set Max Size of ComboBox to match preferred size
        comboBox.setMaximumSize(comboBox.getPreferredSize());
        comboBox.setName(pFilter.getControllingAttribute());
        if (pFilter.getSearchStr() != null) {
            comboBox.setSelectedItem(pFilter.getSearchStr());
        }
        ActionListener listener = new UserSelectionListener(comboBox);
        comboBox.addFinalSelectionListener(listener);
        final JTextComponent editor = (JTextComponent) comboBox.getEditor().getEditorComponent();
        ComboBoxFocusListener focuslistener = new ComboBoxFocusListener(comboBox);
        editor.addFocusListener(focuslistener);
    } catch (Exception e) {
        logger.error("Exception in FilterSettingpanel.getTextIndexComboBox()", e);
    }
    return comboBox;
}
Also used : TextIndexComboBox(org.cytoscape.filter.internal.widgets.autocomplete.view.TextIndexComboBox) JComboBox(javax.swing.JComboBox) TextIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.TextIndex) ActionListener(java.awt.event.ActionListener) JTextComponent(javax.swing.text.JTextComponent)

Example 3 with TextIndex

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

the class FilterSettingPanel method refreshIndicesForWidgets.

// Refresh indices for widget after network switch or Cytoscape.ATTRIBUTES_CHANGED event is received
// The method may be triggered by event of NETWORK_VIEW_FOCUSED
public void refreshIndicesForWidgets() {
    // Check if each widget has associatd index, if not, try to create one
    // System.out.println("FilterSettingpanel:refreshIndicesForWidgets()...\n");
    List<CyFilter> children = theFilter.getChildren();
    if ((children == null) || (children.size() == 0)) {
        return;
    }
    CyNetwork network = applicationManager.getCurrentNetwork();
    for (int i = 0; i < children.size(); i++) {
        CyFilter child = children.get(i);
        if (child instanceof StringFilter) {
            if (pnlCustomSettings.getComponent(i * 5 + 3) instanceof TextIndexComboBox) {
                TextIndexComboBox theBox = (TextIndexComboBox) pnlCustomSettings.getComponent(i * 5 + 3);
                if (network != null) {
                    CyNetworkView networkView = applicationManager.getCurrentNetworkView();
                    if (networkView != null) {
                        TextIndex textIndex = createTextIndex((StringFilter) child);
                        ;
                        if (textIndex != null) {
                            theBox.setTextIndex(textIndex);
                            StringFilter aFilter = (StringFilter) child;
                            aFilter.setIndex(textIndex);
                        }
                    }
                }
            }
        }
        if (child instanceof NumericFilter) {
            if (pnlCustomSettings.getComponent(i * 5 + 3) instanceof JRangeSliderExtended) {
                JRangeSliderExtended theSlider = (JRangeSliderExtended) pnlCustomSettings.getComponent(i * 5 + 3);
                if (network != null) {
                    CyNetworkView networkView = applicationManager.getCurrentNetworkView();
                    if (networkView != null) {
                        NumberIndex numIndex = createNumberIndex((NumericFilter) child);
                        ;
                        if (numIndex != null) {
                            NumberRangeModel rangeModel = (NumberRangeModel) theSlider.getModel();
                            rangeModel.setMinValue(numIndex.getMinimumValue());
                            rangeModel.setMaxValue(numIndex.getMaximumValue());
                            NumericFilter aFilter = (NumericFilter) child;
                            aFilter.setIndex(numIndex);
                        }
                    }
                }
            }
        }
    }
}
Also used : CyFilter(org.cytoscape.filter.internal.filters.model.CyFilter) TextIndexComboBox(org.cytoscape.filter.internal.widgets.autocomplete.view.TextIndexComboBox) NumberIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.NumberIndex) TextIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.TextIndex) NumericFilter(org.cytoscape.filter.internal.filters.model.NumericFilter) NumberRangeModel(org.cytoscape.filter.internal.prefuse.data.query.NumberRangeModel) CyNetwork(org.cytoscape.model.CyNetwork) StringFilter(org.cytoscape.filter.internal.filters.model.StringFilter) JRangeSliderExtended(org.cytoscape.filter.internal.widgets.slider.JRangeSliderExtended) CyNetworkView(org.cytoscape.view.model.CyNetworkView)

Example 4 with TextIndex

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

the class FilterSettingPanel method createTextIndex.

private TextIndex createTextIndex(StringFilter pFilter) {
    CyNetwork cyNetwork = applicationManager.getCurrentNetwork();
    quickFind.reindexNetwork(cyNetwork, pFilter.getIndexType(), pFilter.getControllingAttribute(), new TaskMonitorBase());
    return (TextIndex) quickFind.getIndex(cyNetwork);
}
Also used : TextIndex(org.cytoscape.filter.internal.widgets.autocomplete.index.TextIndex) CyNetwork(org.cytoscape.model.CyNetwork) TaskMonitorBase(org.cytoscape.filter.internal.quickfind.util.TaskMonitorBase)

Aggregations

TextIndex (org.cytoscape.filter.internal.widgets.autocomplete.index.TextIndex)4 TextIndexComboBox (org.cytoscape.filter.internal.widgets.autocomplete.view.TextIndexComboBox)2 CyNetwork (org.cytoscape.model.CyNetwork)2 ActionListener (java.awt.event.ActionListener)1 BitSet (java.util.BitSet)1 JComboBox (javax.swing.JComboBox)1 JTextComponent (javax.swing.text.JTextComponent)1 CyFilter (org.cytoscape.filter.internal.filters.model.CyFilter)1 NumericFilter (org.cytoscape.filter.internal.filters.model.NumericFilter)1 StringFilter (org.cytoscape.filter.internal.filters.model.StringFilter)1 NumberRangeModel (org.cytoscape.filter.internal.prefuse.data.query.NumberRangeModel)1 TaskMonitorBase (org.cytoscape.filter.internal.quickfind.util.TaskMonitorBase)1 Hit (org.cytoscape.filter.internal.widgets.autocomplete.index.Hit)1 NumberIndex (org.cytoscape.filter.internal.widgets.autocomplete.index.NumberIndex)1 JRangeSliderExtended (org.cytoscape.filter.internal.widgets.slider.JRangeSliderExtended)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNode (org.cytoscape.model.CyNode)1 CyNetworkView (org.cytoscape.view.model.CyNetworkView)1