1 50 51 package com.lowagie.text; 52 53 import java.net.MalformedURLException ; 54 import java.net.URL ; 55 import java.util.ArrayList ; 56 import java.util.Iterator ; 57 58 74 75 public class Anchor extends Phrase { 76 77 private static final long serialVersionUID = -852278536049236911L; 79 80 82 83 protected String name = null; 84 85 86 protected String reference = null; 87 88 90 93 public Anchor() { 94 super(16); 95 } 96 97 102 103 public Anchor(float leading) { 104 super(leading); 105 } 106 107 112 public Anchor(Chunk chunk) { 113 super(chunk); 114 } 115 116 121 public Anchor(String string) { 122 super(string); 123 } 124 125 132 public Anchor(String string, Font font) { 133 super(string, font); 134 } 135 136 143 public Anchor(float leading, Chunk chunk) { 144 super(leading, chunk); 145 } 146 147 154 public Anchor(float leading, String string) { 155 super(leading, string); 156 } 157 158 166 public Anchor(float leading, String string, Font font) { 167 super(leading, string, font); 168 } 169 170 175 public Anchor(Phrase phrase) { 176 super(phrase); 177 if (phrase instanceof Anchor) { 178 Anchor a = (Anchor) phrase; 179 setName(a.name); 180 setReference(a.reference); 181 } 182 } 183 184 186 193 public boolean process(ElementListener listener) { 194 try { 195 Chunk chunk; 196 Iterator i = getChunks().iterator(); 197 boolean localDestination = (reference != null && reference.startsWith("#")); 198 boolean notGotoOK = true; 199 while (i.hasNext()) { 200 chunk = (Chunk) i.next(); 201 if (name != null && notGotoOK && !chunk.isEmpty()) { 202 chunk.setLocalDestination(name); 203 notGotoOK = false; 204 } 205 if (localDestination) { 206 chunk.setLocalGoto(reference.substring(1)); 207 } 208 listener.add(chunk); 209 } 210 return true; 211 } 212 catch(DocumentException de) { 213 return false; 214 } 215 } 216 217 222 public ArrayList getChunks() { 223 ArrayList tmp = new ArrayList (); 224 Chunk chunk; 225 Iterator i = iterator(); 226 boolean localDestination = (reference != null && reference.startsWith("#")); 227 boolean notGotoOK = true; 228 while (i.hasNext()) { 229 chunk = (Chunk) i.next(); 230 if (name != null && notGotoOK && !chunk.isEmpty()) { 231 chunk.setLocalDestination(name); 232 notGotoOK = false; 233 } 234 if (localDestination) { 235 chunk.setLocalGoto(reference.substring(1)); 236 } 237 else if (reference != null) 238 chunk.setAnchor(reference); 239 tmp.add(chunk); 240 } 241 return tmp; 242 } 243 244 249 public int type() { 250 return Element.ANCHOR; 251 } 252 253 255 260 public void setName(String name) { 261 this.name = name; 262 } 263 264 269 public void setReference(String reference) { 270 this.reference = reference; 271 } 272 273 275 280 public String getName() { 281 return name; 282 } 283 284 289 public String getReference() { 290 return reference; 291 } 292 293 298 public URL getUrl() { 299 try { 300 return new URL (reference); 301 } 302 catch(MalformedURLException mue) { 303 return null; 304 } 305 } 306 307 309 316 public Anchor(java.util.Properties attributes) { 317 this(com.lowagie.text.factories.ElementFactory.getAnchor(attributes)); 318 } 319 320 326 public String name() { 327 return getName(); 328 } 329 330 336 public String reference() { 337 return getReference(); 338 } 339 340 346 public URL url() { 347 return getUrl(); 348 } 349 } 350 | Popular Tags |