List of usage examples for javax.swing RowFilter include
public abstract boolean include(Entry<? extends M, ? extends I> entry);
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; } }); } }