1 27 package org.htmlparser.beans; 28 29 import java.awt.Dimension ; 30 import java.awt.FontMetrics ; 31 import java.beans.PropertyChangeEvent ; 32 import java.beans.PropertyChangeListener ; 33 import java.io.Serializable ; 34 import java.net.URLConnection ; 35 36 import javax.swing.JTextArea ; 37 38 43 public class HTMLTextBean extends JTextArea implements Serializable , PropertyChangeListener 44 { 45 48 protected StringBean mBean; 49 50 54 public HTMLTextBean () 55 { 56 getBean ().addPropertyChangeListener (this); 57 } 58 59 62 public Dimension getMinimumSize () 63 { 64 FontMetrics metrics; 65 int width; 66 int height; 67 68 metrics = getFontMetrics (getFont ()); 69 width = metrics.stringWidth ("Hello World"); 70 height = metrics.getLeading () + metrics.getHeight () + metrics.getDescent (); 71 72 return (new Dimension (width, height)); 73 } 74 75 81 public void addPropertyChangeListener (PropertyChangeListener listener) 82 { 83 super.addPropertyChangeListener (listener); 84 getBean ().addPropertyChangeListener (listener); 85 } 86 87 93 public void removePropertyChangeListener (PropertyChangeListener listener) 94 { 95 super.addPropertyChangeListener (listener); 96 getBean ().removePropertyChangeListener (listener); 97 } 98 99 103 108 public StringBean getBean () 109 { 110 if (null == mBean) 111 mBean = new StringBean (); 112 113 return (mBean); 114 } 115 116 121 public String getStrings () 122 { 123 return (getBean ().getStrings ()); 124 } 125 126 131 public boolean getLinks () 132 { 133 return (getBean ().getLinks ()); 134 } 135 136 141 public void setLinks (boolean links) 142 { 143 getBean ().setLinks (links); 144 } 145 146 151 public String getURL () 152 { 153 return (getBean ().getURL ()); 154 } 155 156 161 public void setURL (String url) 162 { 163 getBean ().setURL (url); 164 } 165 166 172 public boolean getReplaceNonBreakingSpaces () 173 { 174 return (getBean ().getReplaceNonBreakingSpaces ()); 175 } 176 177 183 public void setReplaceNonBreakingSpaces (boolean replace_space) 184 { 185 getBean ().setReplaceNonBreakingSpaces (replace_space); 186 } 187 188 200 public boolean getCollapse () 201 { 202 return (getBean ().getCollapse ()); 203 } 204 205 210 public void setCollapse (boolean collapse_whitespace) 211 { 212 getBean ().setCollapse (collapse_whitespace); 213 } 214 215 219 public URLConnection getConnection () 220 { 221 return (getBean ().getConnection ()); 222 } 223 224 228 public void setConnection (URLConnection connection) 229 { 230 getBean ().setConnection (connection); 231 } 232 233 237 241 public void propertyChange (PropertyChangeEvent event) 242 { 243 if (event.getPropertyName ().equals (StringBean.PROP_STRINGS_PROPERTY)) 244 { 245 setText (getBean ().getStrings ()); 246 setCaretPosition (0); 247 } 248 } 249 250 } 274 | Popular Tags |