1 27 package org.htmlparser.parserapplications.filterbuilder.wrappers; 28 29 import java.awt.event.ActionEvent ; 30 import java.awt.event.ActionListener ; 31 32 import javax.swing.JCheckBox ; 33 34 import org.htmlparser.Node; 35 import org.htmlparser.NodeFilter; 36 import org.htmlparser.Parser; 37 import org.htmlparser.filters.HasChildFilter; 38 import org.htmlparser.parserapplications.filterbuilder.Filter; 39 import org.htmlparser.parserapplications.filterbuilder.SubFilterList; 40 41 44 public class HasChildFilterWrapper 45 extends 46 Filter 47 implements 48 ActionListener 49 { 50 53 protected HasChildFilter mFilter; 54 55 58 protected JCheckBox mRecursive; 59 60 63 protected SubFilterList mContainer; 64 65 68 public HasChildFilterWrapper () 69 { 70 mFilter = new HasChildFilter (); 71 72 mRecursive = new JCheckBox ("Recursive"); 74 add (mRecursive); 75 mRecursive.addActionListener (this); 76 mRecursive.setSelected (mFilter.getRecursive ()); 77 78 mContainer = new SubFilterList (this, "Child Filter", 1); 80 add (mContainer); 81 } 82 83 87 public String getDescription () 88 { 89 return ("Has Child"); 90 } 91 92 public String getIconSpec () 93 { 94 return ("images/HasChildFilter.gif"); 95 } 96 97 public NodeFilter getNodeFilter () 98 { 99 NodeFilter filter; 100 HasChildFilter ret; 101 102 ret = new HasChildFilter (); 103 104 ret.setRecursive (mFilter.getRecursive ()); 105 filter = mFilter.getChildFilter (); 106 if (null != filter) 107 ret.setChildFilter (((Filter)filter).getNodeFilter ()); 108 109 return (ret); 110 } 111 112 public void setNodeFilter (NodeFilter filter, Parser context) 113 { 114 mFilter = (HasChildFilter)filter; 115 mRecursive.setSelected (mFilter.getRecursive ()); 116 } 117 118 public NodeFilter[] getSubNodeFilters () 119 { 120 NodeFilter filter; 121 NodeFilter[] ret; 122 123 filter = mFilter.getChildFilter (); 124 if (null != filter) 125 ret = new NodeFilter[] { filter }; 126 else 127 ret = new NodeFilter[0]; 128 129 return (ret); 130 } 131 132 public void setSubNodeFilters (NodeFilter[] filters) 133 { 134 if (0 != filters.length) 135 mFilter.setChildFilter (filters[0]); 136 else 137 mFilter.setChildFilter (null); 138 } 139 140 public String toJavaCode (StringBuffer out, int[] context) 141 { 142 String name; 143 String ret; 144 145 if (null != mFilter.getChildFilter ()) 146 name = ((Filter)mFilter.getChildFilter ()).toJavaCode (out, context); 147 else 148 name = null; 149 ret = "filter" + context[1]++; 150 spaces (out, context[0]); 151 out.append ("HasChildFilter "); 152 out.append (ret); 153 out.append (" = new HasChildFilter ();"); 154 newline (out); 155 spaces (out, context[0]); 156 out.append (ret); 157 out.append (".setRecursive ("); 158 out.append (mFilter.getRecursive () ? "true" : "false"); 159 out.append (");"); 160 newline (out); 161 if (null != name) 162 { 163 spaces (out, context[0]); 164 out.append (ret); 165 out.append (".setChildFilter ("); 166 out.append (name); 167 out.append (");"); 168 newline (out); 169 } 170 171 return (ret); 172 } 173 174 178 public boolean accept (Node node) 179 { 180 return (mFilter.accept (node)); 181 } 182 183 187 190 public void actionPerformed (ActionEvent event) 191 { 192 Object source; 193 boolean recursive; 194 195 source = event.getSource (); 196 if (source == mRecursive) 197 { 198 recursive = mRecursive.isSelected (); 199 mFilter.setRecursive (recursive); 200 } 201 } 202 } 203 | Popular Tags |