/** * Sets the {@link JTextField} used to edit the filter search {@link String}. */ public void setFilterEdit(JTextField filterEdit) { if(filterEdit == this.filterEdit) return; // clean up the old matcher editor boolean live = matcherEditor.isLive(); TextFilterator textFilterator = matcherEditor.getFilterator(); matcherEditor.dispose(); // prepare the new matcher editor this.matcherEditor = new TextComponentMatcherEditor(filterEdit, textFilterator, live); ((FilterList)source).setMatcherEditor(matcherEditor); }
/** * Toggle between filtering by the keystroke and not. * * @param live <code>true</code> to filter by the keystroke or <code>false</code> * to filter only when {@link java.awt.event.KeyEvent#VK_ENTER Enter} is pressed * within the {@link JTextComponent}. Note that non-live filtering is only * supported if <code>textComponent</code> is a {@link JTextField}. */ public void setLive(boolean live) { if (live == this.live) return; deregisterListeners(this.live); this.live = live; registerListeners(this.live); }
/** * Update the filter text from the contents of the Document. */ private void refilter() { try { final int mode = getMode(); final String text = document.getText(0, document.getLength()); final String[] filters; // in CONTAINS mode we treat the string as whitespace delimited if (mode == CONTAINS) filters = text.split("[ \t]"); // in STARTS_WITH, REGULAR_EXPRESSION, or EXACT modes we use the string in its entirety else if (mode == STARTS_WITH || mode == REGULAR_EXPRESSION || mode == EXACT) filters = new String[] {text}; else throw new IllegalStateException("Unknown mode: " + mode); setFilterText(filters); } catch (BadLocationException ble) { // this shouldn't ever, ever happen throw new RuntimeException(ble); } }
/** * This private constructor implements the actual construction work and thus * ensures that all public constructors agree on the construction logic. */ private TextComponentMatcherEditor(JTextComponent textComponent, Document document, TextFilterator<? super E> textFilterator, boolean live) { super(textFilterator); this.textComponent = textComponent; this.document = document; this.live = live; registerListeners(live); // if the document is non-empty to begin with! refilter(); }
/** * Creates a {@link TextFilterList} that filters the specified {@link EventList} * of elements using the specified {@link TextFilterator} to get the * {@link String}s to search. * * @param filterEdit a text field for typing in the filter text. */ public TextFilterList(EventList source, TextFilterator filterator, JTextField filterEdit) { super(new FilterList(source)); this.matcherEditor = new TextComponentMatcherEditor(filterEdit, filterator); this.filterEdit = filterEdit; ((FilterList)this.source).setMatcherEditor(matcherEditor); // handle changes this.source.addListEventListener(this); }
/** * Directs this filter to respond to changes to the {@link JTextField} as they are * made. This uses a {@link DocumentListener} and every time the * {@link JTextField} is modified, the list is refiltered. * * <p>To avoid the processing overhead of filtering for each keystroke, use * a not-live filter edit and trigger the {@link ActionListener} using a * button or by pressing <tt>ENTER</tt> in the {@link JTextField}. */ public void setLive(boolean live) { matcherEditor.setLive(live); }
/** * A cleanup method which stops this MatcherEditor from listening to * changes on the underlying {@link Document}, thus freeing the * MatcherEditor or Document to be garbage collected. */ public void dispose() { deregisterListeners(live); }
/** {@inheritDoc} */ @Override public void dispose() { FilterList filteredSource = (FilterList)source; super.dispose(); filteredSource.dispose(); matcherEditor.dispose(); } }
@Override public void actionPerformed(ActionEvent e) { matcherEditor.setFilterText(filterEdit.getText().split("[ \t]")); } }
/** * Creates a {@link TextFilterList} that filters the specified {@link EventList} * of elements using the specified {@link TextFilterator} to get the * {@link String}s to search. * * @param filterEdit a text field for typing in the filter text. */ public TextFilterList(EventList source, TextFilterator filterator, JTextField filterEdit) { super(new FilterList(source)); this.matcherEditor = new TextComponentMatcherEditor(filterEdit, filterator); this.filterEdit = filterEdit; ((FilterList)this.source).setMatcherEditor(matcherEditor); // handle changes this.source.addListEventListener(this); }
/** * This private constructor implements the actual construction work and thus * ensures that all public constructors agree on the construction logic. */ private TextComponentMatcherEditor(JTextComponent textComponent, Document document, TextFilterator<? super E> textFilterator, boolean live) { super(textFilterator); this.textComponent = textComponent; this.document = document; this.live = live; registerListeners(live); // if the document is non-empty to begin with! refilter(); }
/** * Directs this filter to respond to changes to the {@link JTextField} as they are * made. This uses a {@link DocumentListener} and every time the * {@link JTextField} is modified, the list is refiltered. * * <p>To avoid the processing overhead of filtering for each keystroke, use * a not-live filter edit and trigger the {@link ActionListener} using a * button or by pressing <tt>ENTER</tt> in the {@link JTextField}. */ public void setLive(boolean live) { matcherEditor.setLive(live); }
/** * A cleanup method which stops this MatcherEditor from listening to * changes on the underlying {@link Document}, thus freeing the * MatcherEditor or Document to be garbage collected. */ public void dispose() { deregisterListeners(live); }
/** {@inheritDoc} */ @Override public void dispose() { FilterList filteredSource = (FilterList)source; super.dispose(); filteredSource.dispose(); matcherEditor.dispose(); } }
public void actionPerformed(ActionEvent e) { matcherEditor.setFilterText(filterEdit.getText().split("[ \t]")); } }
/** * Sets the {@link JTextField} used to edit the filter search {@link String}. */ public void setFilterEdit(JTextField filterEdit) { if(filterEdit == this.filterEdit) return; // clean up the old matcher editor boolean live = matcherEditor.isLive(); TextFilterator textFilterator = matcherEditor.getFilterator(); matcherEditor.dispose(); // prepare the new matcher editor this.matcherEditor = new TextComponentMatcherEditor(filterEdit, textFilterator, live); ((FilterList)source).setMatcherEditor(matcherEditor); }
/** * Creates a {@link TextFilterList} that filters the specified {@link EventList} * of elements using the specified {@link TextFilterator} to get the * {@link String}s to search. * * @param filterEdit a text field for typing in the filter text. */ public TextFilterList(EventList source, TextFilterator filterator, JTextField filterEdit) { super(new FilterList(source)); this.matcherEditor = new TextComponentMatcherEditor(filterEdit, filterator); this.filterEdit = filterEdit; ((FilterList)this.source).setMatcherEditor(matcherEditor); // handle changes this.source.addListEventListener(this); }
/** * This private constructor implements the actual construction work and thus * ensures that all public constructors agree on the construction logic. */ private TextComponentMatcherEditor(JTextComponent textComponent, Document document, TextFilterator<? super E> textFilterator, boolean live) { super(textFilterator); this.textComponent = textComponent; this.document = document; this.live = live; registerListeners(live); // if the document is non-empty to begin with! refilter(); }
/** * Toggle between filtering by the keystroke and not. * * @param live <code>true</code> to filter by the keystroke or <code>false</code> * to filter only when {@link java.awt.event.KeyEvent#VK_ENTER Enter} is pressed * within the {@link JTextComponent}. Note that non-live filtering is only * supported if <code>textComponent</code> is a {@link JTextField}. */ public void setLive(boolean live) { if (live == this.live) return; deregisterListeners(this.live); this.live = live; registerListeners(this.live); }
/** * Update the filter text from the contents of the Document. */ private void refilter() { try { final int mode = getMode(); final String text = document.getText(0, document.getLength()); final String[] filters; // in CONTAINS mode we treat the string as whitespace delimited if (mode == CONTAINS) filters = text.split("[ \t]"); // in STARTS_WITH, REGULAR_EXPRESSION, or EXACT modes we use the string in its entirety else if (mode == STARTS_WITH || mode == REGULAR_EXPRESSION || mode == EXACT) filters = new String[] {text}; else throw new IllegalStateException("Unknown mode: " + mode); setFilterText(filters); } catch (BadLocationException ble) { // this shouldn't ever, ever happen throw new RuntimeException(ble); } }