KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > parserapplications > filterbuilder > wrappers > HasSiblingFilterWrapper


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2005 Derrick Oswald
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/parserapplications/filterbuilder/wrappers/HasSiblingFilterWrapper.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2005/02/13 20:43:06 $
10
// $Revision: 1.1 $
11
//
12
// This library is free software; you can redistribute it and/or
13
// modify it under the terms of the GNU Lesser General Public
14
// License as published by the Free Software Foundation; either
15
// version 2.1 of the License, or (at your option) any later version.
16
//
17
// This library is distributed in the hope that it will be useful,
18
// but WITHOUT ANY WARRANTY; without even the implied warranty of
19
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
// Lesser General Public License for more details.
21
//
22
// You should have received a copy of the GNU Lesser General Public
23
// License along with this library; if not, write to the Free Software
24
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
//
26

27 package org.htmlparser.parserapplications.filterbuilder.wrappers;
28
29 import java.awt.event.ActionEvent JavaDoc;
30 import java.awt.event.ActionListener JavaDoc;
31
32 import org.htmlparser.Node;
33 import org.htmlparser.NodeFilter;
34 import org.htmlparser.Parser;
35 import org.htmlparser.filters.HasSiblingFilter;
36 import org.htmlparser.parserapplications.filterbuilder.Filter;
37 import org.htmlparser.parserapplications.filterbuilder.SubFilterList;
38
39 /**
40  * Wrapper for HasSiblingFilters.
41  */

42 public class HasSiblingFilterWrapper
43     extends
44         Filter
45     implements
46         ActionListener JavaDoc
47 {
48     /**
49      * The underlying filter.
50      */

51     protected HasSiblingFilter mFilter;
52
53     /**
54      * The drop target container.
55      */

56     protected SubFilterList mContainer;
57     
58     /**
59      * Create a wrapper over a new HasParentFilter.
60      */

61     public HasSiblingFilterWrapper ()
62     {
63         mFilter = new HasSiblingFilter ();
64
65         // add the subfilter container
66
mContainer = new SubFilterList (this, "Sibling Filter", 1);
67         add (mContainer);
68     }
69
70     //
71
// Filter overrides and concrete implementations
72
//
73

74     public String JavaDoc getDescription ()
75     {
76         return ("Has Sibling");
77     }
78
79     public String JavaDoc getIconSpec ()
80     {
81         return ("images/HasSiblingFilter.gif");
82     }
83
84     public NodeFilter getNodeFilter ()
85     {
86         NodeFilter filter;
87         HasSiblingFilter ret;
88         
89         ret = new HasSiblingFilter ();
90
91         filter = mFilter.getSiblingFilter ();
92         if (null != filter)
93             ret.setSiblingFilter (((Filter)filter).getNodeFilter ());
94             
95         return (ret);
96     }
97
98     public void setNodeFilter (NodeFilter filter, Parser context)
99     {
100         mFilter = (HasSiblingFilter)filter;
101     }
102
103     public NodeFilter[] getSubNodeFilters ()
104     {
105         NodeFilter filter;
106         NodeFilter[] ret;
107
108         filter = mFilter.getSiblingFilter ();
109         if (null != filter)
110             ret = new NodeFilter[] { filter };
111         else
112             ret = new NodeFilter[0];
113
114         return (ret);
115     }
116
117     public void setSubNodeFilters (NodeFilter[] filters)
118     {
119         if (0 != filters.length)
120             mFilter.setSiblingFilter (filters[0]);
121         else
122             mFilter.setSiblingFilter (null);
123     }
124
125     public String JavaDoc toJavaCode (StringBuffer JavaDoc out, int[] context)
126     {
127         String JavaDoc name;
128         String JavaDoc ret;
129
130         if (null != mFilter.getSiblingFilter ())
131             name = ((Filter)mFilter.getSiblingFilter ()).toJavaCode (out, context);
132         else
133             name = null;
134         ret = "filter" + context[1]++;
135         spaces (out, context[0]);
136         out.append ("HasSiblingFilter ");
137         out.append (ret);
138         out.append (" = new HasSiblingFilter ();");
139         newline (out);
140         if (null != name)
141         {
142             spaces (out, context[0]);
143             out.append (ret);
144             out.append (".setSiblingFilter (");
145             out.append (name);
146             out.append (");");
147             newline (out);
148         }
149         
150         return (ret);
151     }
152
153     //
154
// NodeFilter interface
155
//
156

157     public boolean accept (Node node)
158     {
159         return (mFilter.accept (node));
160     }
161
162     //
163
// ActionListener interface
164
//
165

166     /**
167      * Invoked when an action occurs.
168      */

169     public void actionPerformed (ActionEvent JavaDoc event)
170     {
171     }
172 }
173
Popular Tags