Search in sources :

Example 1 with Hit

use of org.cytoscape.filter.internal.widgets.autocomplete.index.Hit 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 Hit

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

the class RangeSelectionListener method actionPerformed.

/**
 * User has made final selection.
 *
 * @param e ActionEvent Object.
 */
public void actionPerformed(ActionEvent e) {
    // Get Current Network
    final CyNetwork currentNetwork = applicationManager.getCurrentNetwork();
    // Get Current User Selection
    Object o = comboBox.getSelectedItem();
    if ((o != null) && o instanceof Hit) {
        Hit hit = (Hit) comboBox.getSelectedItem();
        quickFind.selectHit(currentNetwork, hit);
    }
}
Also used : Hit(org.cytoscape.filter.internal.widgets.autocomplete.index.Hit) CyNetwork(org.cytoscape.model.CyNetwork)

Example 3 with Hit

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

the class AutoCompleteDocument method populatePullDownMenu.

/**
 * Populates the Pull-Down menu with all words that begin with the
 * specific pattern.
 *
 * @param pattern String pattern.
 */
public void populatePullDownMenu(String pattern) {
    debug("Start :  populatePullDownMenu(), pattern=" + pattern);
    Hit[] hits = comboBox.getTextIndex().getHits(pattern, TextIndexComboBox.DEFAULT_MAX_HITS_SHOWN);
    // Populate Pull-Down Menu with matching items derived from TextIndex
    // Must set selecting flag to true, as modifying the model will
    // result is multiple calls to setSelectedItem(), which results
    // in an infinite loop.
    setSelecting(true);
    DefaultComboBoxModel model = (DefaultComboBoxModel) comboBox.getModel();
    debug("Start:  Remove all elements");
    model.removeAllElements();
    debug("End:  Remove all elements");
    if (hits.length > 0) {
        int stopHits = Math.min(hits.length, TextIndexComboBox.DEFAULT_MAX_HITS_SHOWN);
        for (int i = 0; i < stopHits; i++) {
            // When we call addElement and there is only one item in
            // the list, the DefaultComboBox will automatically call
            // setSelected();  this can result in an inifinte loop.
            // To prevent this, we set the set selecting flag to true.
            model.addElement(hits[i]);
        }
        editor.setBackground(Color.WHITE);
        editor.setForeground(Color.BLACK);
    } else {
        if ((comboBox.getTextIndex() != null) && (comboBox.getTextIndex().getNumKeys() > 0)) {
            model.addElement(new Hit(pattern, new Object[0]));
            editor.setBackground(new Color(212, 153, 159));
            editor.setForeground(Color.WHITE);
        }
    }
    // menu window.
    if (model.getSize() < TextIndexComboBox.DEFAULT_MAX_ROWS_VISIBLE) {
        comboBox.setMaximumRowCount(model.getSize());
    } else {
        comboBox.setMaximumRowCount(TextIndexComboBox.DEFAULT_MAX_ROWS_VISIBLE);
    }
    // Must set selected item to null;  otherwise, zeroeth
    // item in model is selected, and we don't want it to be.
    setSelectedItem(null);
    setSelecting(false);
    debug("End:  populatePullDownMenu(), pattern=" + pattern);
}
Also used : Hit(org.cytoscape.filter.internal.widgets.autocomplete.index.Hit)

Example 4 with Hit

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

the class TextBoxRenderer method getListCellRendererComponent.

/**
 * This method finds the image and text corresponding
 * to the selected value and returns the label, set up
 * to display the text and image.
 *
 * @param list         JList Object.
 * @param value        Object value.
 * @param index        Index value.
 * @param isSelected   is item selected flag.
 * @param cellHasFocus call has focus flag.
 * @return Component Object.
 */
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    // Create a JPanel Object
    JPanel panel = new JPanel();
    panel.setOpaque(true);
    // Set different colors, depending on state
    if (isSelected) {
        panel.setBackground(list.getSelectionBackground());
        panel.setForeground(list.getSelectionForeground());
    } else {
        panel.setBackground(list.getBackground());
        panel.setForeground(list.getForeground());
    }
    // Use Box Layout, X-AXIS
    panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS));
    panel.setBorder(new EmptyBorder(2, 2, 2, 2));
    // Create text match label, but do not (yet) set final text,
    // as we may need to truncate it.
    JLabel textMatchLabel = new JLabel("TEMP", JLabel.LEFT);
    panel.setToolTipText(value.toString());
    String numResults = getNumResults(value);
    JLabel numResultsLabel = new JLabel(numResults, JLabel.RIGHT);
    numResultsLabel.setFont(new Font("Monospaced", Font.PLAIN, numResultsLabel.getFont().getSize() - 1));
    // Set color to green (matches exist) or red (no matches exist);
    Color color = new Color(51, 102, 51);
    if (value instanceof Hit) {
        Hit hit = (Hit) value;
        if (hit.getAssociatedObjects() != null) {
            int numHits = hit.getAssociatedObjects().length;
            if (numHits == 0) {
                color = new Color(150, 0, 0);
            }
        }
    }
    numResultsLabel.setForeground(color);
    // Resize Labels
    resizeLabels(numResultsLabel, textMatchLabel, value.toString());
    // Add Label 1, then glue, then Label 2
    // The glue forces Label 1 to be left aligned, and Label 2 to be
    // right aligned
    panel.add(textMatchLabel);
    panel.add(Box.createHorizontalGlue());
    panel.add(numResultsLabel);
    return panel;
}
Also used : Hit(org.cytoscape.filter.internal.widgets.autocomplete.index.Hit) EmptyBorder(javax.swing.border.EmptyBorder)

Example 5 with Hit

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

the class TextBoxRenderer method getNumResults.

/**
 * Gets Number of Matching Results.
 *
 * @param value Object Value.
 * @return Number of Results String.
 */
private String getNumResults(Object value) {
    String numResults = null;
    if (value instanceof Hit) {
        Hit hit = (Hit) value;
        Object[] objects = hit.getAssociatedObjects();
        if (objects != null) {
            if (objects.length == 1) {
                numResults = "1 hit ";
            } else {
                numResults = objects.length + " hits ";
            }
        }
    }
    if (numResults == null) {
        numResults = " -- ";
    }
    return numResults;
}
Also used : Hit(org.cytoscape.filter.internal.widgets.autocomplete.index.Hit)

Aggregations

Hit (org.cytoscape.filter.internal.widgets.autocomplete.index.Hit)5 BitSet (java.util.BitSet)1 EmptyBorder (javax.swing.border.EmptyBorder)1 TextIndex (org.cytoscape.filter.internal.widgets.autocomplete.index.TextIndex)1 CyEdge (org.cytoscape.model.CyEdge)1 CyNetwork (org.cytoscape.model.CyNetwork)1 CyNode (org.cytoscape.model.CyNode)1