Example usage for javax.swing RowFilter include

List of usage examples for javax.swing RowFilter include

Introduction

In this page you can find the example usage for javax.swing RowFilter include.

Prototype

public abstract boolean include(Entry<? extends M, ? extends I> entry);

Source Link

Document

Returns true if the specified entry should be shown; returns false if the entry should be hidden.

Usage

From source file:org.yccheok.jstock.gui.StockDatabaseJDialog.java

@SuppressWarnings("unchecked")
private void newFilter() {
    final String text = jTextField1.getText();

    // I really have no idea what the second parameter is.
    final RowFilter<StockInfoTableModel, Integer> rf;

    // If current expression doesn't parse, don't update.
    try {/*  ww w  .j a v  a 2s.co m*/
        // (?i) is for case insensitive.
        rf = RowFilter.regexFilter("^(?i)" + Pattern.quote(text));
    } catch (java.util.regex.PatternSyntaxException e) {
        return;
    }

    if (org.yccheok.jstock.engine.Utils.isPinyinTSTSearchEngineRequiredForSymbol() == false) {
        ((TableRowSorter<StockInfoTableModel>) jTable1.getRowSorter()).setRowFilter(rf);
    } else {
        ((TableRowSorter<StockInfoTableModel>) jTable1.getRowSorter())
                .setRowFilter(new RowFilter<StockInfoTableModel, Integer>() {

                    @Override
                    public boolean include(Entry<? extends StockInfoTableModel, ? extends Integer> entry) {
                        // Try regexFilter first.
                        if (rf.include(entry)) {
                            return true;
                        }
                        // Fail. Further try with pinyin. Pinyin is in lower case.
                        final String lower_text = text.toLowerCase();
                        final StockInfoTableModel model = entry.getModel();
                        final Symbol symbol = model.getStockInfos().get(entry.getIdentifier()).symbol;
                        List<String> pinyins = org.yccheok.jstock.gui.Utils.toHanyuPinyin(symbol.toString());
                        for (String pinyin : pinyins) {
                            if (pinyin.startsWith(lower_text)) {
                                return true;
                            }
                        }
                        return false;
                    }

                });
    }
}