package com.onaro.util.jfc.tables.filter; import javax.swing.JTextField; import com.onaro.util.jfc.tables.FilterTable; /** * A filter editor displas a border-less popup window containig a text field in which the user types the search pattern. * The editor is closed whenever the table or the window changes or the mouse is clicked outside the editor. */ public class TextFieldFilterEditor extends AbstractFilterEditor { /** * Installs a borderless pop up window on top a column's header and configures the listeners needed to close * this popup. */ public TextFieldFilterEditor(FilterTable filterTable, int columnInModel, Filter filter) { super(filterTable, columnInModel, filter, new JTextField()); JTextField textfield = ((JTextField) field); Object filterPattern = filter.getPattern(); textfield.setText(filterPattern != null ? filterPattern.toString() : null); textfield.selectAll(); textfield.addActionListener(this); } public Object getPattern() { JTextField textfield = ((JTextField) field); String pattern = textfield.getText(); if (pattern != null) { pattern = pattern.trim(); if (pattern.length() == 0) pattern = null; } return pattern; } protected void hideLater(AbstractFilterEditor filterEditor) { super.hideLater(filterEditor); JTextField textfield = ((JTextField) field); textfield.removeActionListener(this); } }