/** * Get the underlying node filter object. * @return The node filter object suitable for serialization. */ public NodeFilter getNodeFilter () { RegexFilter ret; ret = new RegexFilter (); ret.setStrategy (mFilter.getStrategy ()); ret.setPattern (mFilter.getPattern ()); return (ret); }
/** * Predicate to determine whether or not to keep the given node. * The behaviour based on this outcome is determined by the context * in which it is called. It may lead to the node being added to a list * or printed out. See the calling routine for details. * @return <code>true</code> if the node is to be kept, <code>false</code> * if it is to be discarded. * @param node The node to test. */ public boolean accept (Node node) { return (mFilter.accept (node)); }
/** * Creates a new instance of RegexFilter that accepts string nodes matching * a regular expression. * @param pattern The pattern to search for. * @param strategy The type of match: * <ol> * <li>{@link #MATCH} use matches() method: attempts to match * the entire input sequence against the pattern</li> * <li>{@link #LOOKINGAT} use lookingAt() method: attempts to match * the input sequence, starting at the beginning, against the pattern</li> * <li>{@link #FIND} use find() method: scans the input sequence looking * for the next subsequence that matches the pattern</li> * </ol> */ public RegexFilter (String pattern, int strategy) { setPattern (pattern); setStrategy (strategy); }
/** * Create a wrapper over a new RegexFilter. */ public RegexFilterWrapper () { mFilter = new RegexFilter (); // add the text pattern mPattern = new JTextArea (2, 20); mPattern.setBorder (new BevelBorder (BevelBorder.LOWERED)); add (mPattern); mPattern.getDocument ().addDocumentListener (this); mPattern.setText (mFilter.getPattern ()); // add the strategy choice mStrategy = new JComboBox (); mStrategy.addItem ("MATCH"); mStrategy.addItem ("LOOKINGAT"); mStrategy.addItem ("FIND"); add (mStrategy); mStrategy.addActionListener (this); mStrategy.setSelectedIndex (strategyToIndex (mFilter.getStrategy ())); }
/** * Assign the underlying node filter for this wrapper. * @param filter The filter to wrap. * @param context The parser to use for conditioning this filter. * Some filters need contextual information to provide to the user, * i.e. for tag names or attribute names or values, * so the Parser context is provided. */ public void setNodeFilter (NodeFilter filter, Parser context) { mFilter = (RegexFilter)filter; mPattern.setText (mFilter.getPattern ()); mStrategy.setSelectedIndex (strategyToIndex (mFilter.getStrategy ())); }
/** * Handle an insert update event. * @param e Details about the insert event. */ public void insertUpdate (DocumentEvent e) { Document doc; doc = e.getDocument (); try { mFilter.setPattern (doc.getText (0, doc.getLength ())); } catch (BadLocationException ble) { ble.printStackTrace (); } }
/** * Invoked when an action occurs on the combo box. * @param event Details about the action event. */ public void actionPerformed (ActionEvent event) { Object source; source = event.getSource (); if (source == mStrategy) mFilter.setStrategy (indexToStrategy (mStrategy.getSelectedIndex ())); }
/** * Creates a new instance of RegexFilter that accepts string nodes matching * a regular expression. * @param pattern The pattern to search for. * @param strategy The type of match: * <ol> * <li>{@link #MATCH} use matches() method: attempts to match * the entire input sequence against the pattern</li> * <li>{@link #LOOKINGAT} use lookingAt() method: attempts to match * the input sequence, starting at the beginning, against the pattern</li> * <li>{@link #FIND} use find() method: scans the input sequence looking * for the next subsequence that matches the pattern</li> * </ol> */ public RegexFilter (String pattern, int strategy) { setPattern (pattern); setStrategy (strategy); }
out.append (ret); out.append (".setStrategy (RegexFilter."); out.append (strategyToString (mFilter.getStrategy ())); out.append (");"); newline (out); out.append (ret); out.append (".setPattern (\""); out.append (mFilter.getPattern ()); out.append ("\");"); newline (out);
/** * Handle a remove update event. * @param e Details about the remove event. */ public void removeUpdate (DocumentEvent e) { Document doc; doc = e.getDocument (); try { mFilter.setPattern (doc.getText (0, doc.getLength ())); } catch (BadLocationException ble) { ble.printStackTrace (); } }