Fixed the bug for mz and rt value search bars.
@@ -74,6 +74,25 @@ public class PeakListTableWindow extends JFrame implements ActionListener {
private JTextField filterTextIdentity;
private JTextField filterTextComment;
+ RowFilter<Object,Object > mzFilter = new RowFilter<Object, Object>() {
+ public boolean include(Entry<? extends Object, ? extends Object> entry) {
+ String mzValue = entry.getStringValue(1);
+ if (mzValue.startsWith(filterTextMz.getText())) {
+ return true;
+ }
+ return false;
+ }
+ };
+
+ RowFilter<Object,Object > rtFilter = new RowFilter<Object, Object>() {
+ public boolean include(Entry<? extends Object, ? extends Object> entry) {
+ String rtValue = entry.getStringValue(2);
+ if (rtValue.startsWith(filterTextRt.getText())) {
+ return true;
+ }
+ return false;
+ }
+ };
/**
* Constructor: initializes an empty visualizer
@@ -100,13 +119,13 @@ public class PeakListTableWindow extends JFrame implements ActionListener {
JPanel filterPane = new JPanel(new GridLayout(1,10));
- //filterBy = new JComboBox(new Object[]{"Nothing", "m/z", "RT","Identity","Comment"});
+
filterTextId = new JTextField(10);
filterTextMz = new JTextField(10);
filterTextRt = new JTextField(10);
filterTextIdentity = new JTextField(10);
filterTextComment = new JTextField(10);
- //filterPane.add(filterBy);
+
filterPane.add(new JLabel("ID:",SwingConstants.CENTER));
filterPane.add(filterTextId);
filterPane.add(new JLabel("m/z:",SwingConstants.CENTER));
@@ -175,27 +194,26 @@ public class PeakListTableWindow extends JFrame implements ActionListener {
});
}
+ @SuppressWarnings("unchecked")
public void updateFilter() {
- //Object selected = filterBy.getSelectedItem();
List<RowFilter<Object,Object>> rowSorters = new ArrayList<RowFilter<Object,Object>>();
- TableRowSorter<PeakListTableModel> sorter = table.getTableRowSorter();
+
+ TableRowSorter<PeakListTableModel> sorter = (TableRowSorter<PeakListTableModel>) table.getRowSorter();
String textId = "(?i)" + filterTextId.getText();
- String textMz = "(?i)" + filterTextMz.getText();
- String textRt = "(?i)" + filterTextRt.getText();
String textIdentity = "(?i)" + filterTextIdentity.getText();
String textComment = "(?i)" + filterTextComment.getText();
rowSorters.add(RowFilter.regexFilter(textId,0));
- rowSorters.add(RowFilter.regexFilter(textMz,1));
- rowSorters.add(RowFilter.regexFilter(textRt,2));
+ rowSorters.add(mzFilter);
+ rowSorters.add(rtFilter);
rowSorters.add(RowFilter.regexFilter(textIdentity,3));
rowSorters.add(RowFilter.regexFilter(textComment,4));
-
sorter.setRowFilter(RowFilter.andFilter(rowSorters));
+ table.setRowSorter(sorter);
}
