KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > htmlparser > beans > HTMLLinkBean


1 // HTMLParser Library $Name: v1_5_20050313 $ - A java-based parser for HTML
2
// http://sourceforge.org/projects/htmlparser
3
// Copyright (C) 2004 Derrick Oswald
4
//
5
// Revision Control Information
6
//
7
// $Source: /cvsroot/htmlparser/htmlparser/src/org/htmlparser/beans/HTMLLinkBean.java,v $
8
// $Author: derrickoswald $
9
// $Date: 2004/01/02 16:24:53 $
10
// $Revision: 1.21 $
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.beans;
28
29 import java.awt.Dimension JavaDoc;
30 import java.awt.FontMetrics JavaDoc;
31 import java.beans.PropertyChangeEvent JavaDoc;
32 import java.beans.PropertyChangeListener JavaDoc;
33 import java.io.Serializable JavaDoc;
34 import java.net.URL JavaDoc;
35 import java.net.URLConnection JavaDoc;
36
37 import javax.swing.JList JavaDoc;
38
39 /**
40  * Display the links from a URL.
41  * @author Derrick Oswald
42  * Created on December 24, 2002, 3:49 PM
43  */

44 public class HTMLLinkBean extends JList JavaDoc implements Serializable JavaDoc, PropertyChangeListener JavaDoc
45 {
46     /**
47      * The underlying bean that provides our htmlparser specific properties.
48      */

49     protected LinkBean mBean;
50
51     /**
52      * Creates a new HTMLTextBean.
53      * This uses an underlying StringBean and displays the text.
54      */

55     public HTMLLinkBean ()
56     {
57         getBean ().addPropertyChangeListener (this);
58     }
59
60     /**
61      * Return the underlying bean object.
62      * Creates a new one if it hasn't been initialized yet.
63      * @return The StringBean this bean uses to fetch text.
64      */

65     protected LinkBean getBean ()
66     {
67         if (null == mBean)
68             mBean = new LinkBean ();
69
70         return (mBean);
71     }
72
73     /**
74      * Return the minimum dimension for this visible bean.
75      */

76     public Dimension JavaDoc getMinimumSize ()
77     {
78         FontMetrics JavaDoc metrics;
79         int width;
80         int height;
81
82         metrics = getFontMetrics (getFont ());
83         width = metrics.stringWidth ("http://localhost");
84         height = metrics.getLeading () + metrics.getHeight () + metrics.getDescent ();
85
86         return (new Dimension JavaDoc (width, height));
87     }
88
89     /**
90      * Add a PropertyChangeListener to the listener list.
91      * The listener is registered for all properties.
92      * <p><em>Delegates to the underlying StringBean</em>
93      * @param listener The PropertyChangeListener to be added.
94      */

95     public void addPropertyChangeListener (PropertyChangeListener JavaDoc listener)
96     {
97         super.addPropertyChangeListener (listener);
98         getBean ().addPropertyChangeListener (listener);
99     }
100
101     /**
102      * Remove a PropertyChangeListener from the listener list.
103      * This removes a PropertyChangeListener that was registered for all properties.
104      * <p><em>Delegates to the underlying StringBean</em>
105      * @param listener The PropertyChangeListener to be removed.
106      */

107     public void removePropertyChangeListener (PropertyChangeListener JavaDoc listener)
108     {
109         super.addPropertyChangeListener (listener);
110         getBean ().removePropertyChangeListener (listener);
111     }
112
113     //
114
// Properties
115
//
116

117     /**
118      * Getter for property links.
119      * <p><em>Delegates to the underlying StringBean</em>
120      * @return Value of property links.
121      */

122     public URL JavaDoc[] getLinks ()
123     {
124         return (getBean ().getLinks ());
125     }
126
127     /**
128      * Getter for property URL.
129      * <p><em>Delegates to the underlying StringBean</em>
130      * @return Value of property URL.
131      */

132     public String JavaDoc getURL ()
133     {
134         return (getBean ().getURL ());
135     }
136
137     /**
138      * Setter for property URL.
139      * <p><em>Delegates to the underlying StringBean</em>
140      * @param url New value of property URL.
141      */

142     public void setURL (String JavaDoc url)
143     {
144         getBean ().setURL (url);
145     }
146
147     /**
148      * Getter for property Connection.
149      * @return Value of property Connection.
150      */

151     public URLConnection JavaDoc getConnection ()
152     {
153         return (getBean ().getConnection ());
154     }
155
156     /**
157      * Setter for property Connection.
158      * @param connection New value of property Connection.
159      */

160     public void setConnection (URLConnection JavaDoc connection)
161     {
162         getBean ().setConnection (connection);
163     }
164
165     //
166
// PropertyChangeListener inteface
167
//
168

169     /**
170      * Responds to changes in the underlying bean's properties.
171      * @param event The event triggering this listener method call.
172      */

173     public void propertyChange (PropertyChangeEvent JavaDoc event)
174     {
175         if (event.getPropertyName ().equals (LinkBean.PROP_LINKS_PROPERTY))
176         {
177             setListData (getBean ().getLinks ());
178         }
179     }
180
181 // /**
182
// * Unit test.
183
// */
184
// public static void main (String[] args)
185
// {
186
// HTMLLinkBean lb = new HTMLLinkBean ();
187
// lb.setURL ("http://cbc.ca");
188
// javax.swing.JFrame frame = new javax.swing.JFrame ();
189
// frame.getContentPane ().setLayout (new BorderLayout ());
190
// frame.getContentPane ().add (new JScrollPane (lb), BorderLayout.CENTER);
191
// frame.addWindowListener (new java.awt.event.WindowListener () {
192
// public void windowOpened (java.awt.event.WindowEvent e) {}
193
// public void windowClosing (java.awt.event.WindowEvent e) {System.exit (0);}
194
// public void windowClosed (java.awt.event.WindowEvent e) {}
195
// public void windowDeiconified (java.awt.event.WindowEvent e) {}
196
// public void windowIconified (java.awt.event.WindowEvent e) {}
197
// public void windowActivated (java.awt.event.WindowEvent e) {}
198
// public void windowDeactivated (java.awt.event.WindowEvent e) {}
199
// });
200
// frame.setBounds (100, 100, 640, 480);
201
// frame.show ();
202
// }
203
}
204
205
206
207
Popular Tags