1 47 48 package com.lowagie.text.pdf; 49 50 import java.util.ArrayList ; 51 58 public class PdfLayer extends PdfDictionary implements PdfOCG { 59 protected PdfIndirectReference ref; 60 protected ArrayList children; 61 protected PdfLayer parent; 62 protected String title; 63 64 67 private boolean on = true; 68 69 72 private boolean onPanel = true; 73 74 PdfLayer(String title) { 75 this.title = title; 76 } 77 78 85 public static PdfLayer createTitle(String title, PdfWriter writer) { 86 if (title == null) 87 throw new NullPointerException ("Title cannot be null."); 88 PdfLayer layer = new PdfLayer(title); 89 writer.registerLayer(layer); 90 return layer; 91 } 92 97 public PdfLayer(String name, PdfWriter writer) { 98 super(PdfName.OCG); 99 setName(name); 100 ref = writer.getPdfIndirectReference(); 101 writer.registerLayer(this); 102 } 103 104 String getTitle() { 105 return title; 106 } 107 108 112 public void addChild(PdfLayer child) { 113 if (child.parent != null) 114 throw new IllegalArgumentException ("The layer '" + ((PdfString)child.get(PdfName.NAME)).toUnicodeString() + "' already has a parent."); 115 child.parent = this; 116 if (children == null) 117 children = new ArrayList (); 118 children.add(child); 119 } 120 121 122 126 public PdfLayer getParent() { 127 return parent; 128 } 129 130 134 public ArrayList getChildren() { 135 return children; 136 } 137 138 142 public PdfIndirectReference getRef() { 143 return ref; 144 } 145 146 150 public void setName(String name) { 151 put(PdfName.NAME, new PdfString(name, PdfObject.TEXT_UNICODE)); 152 } 153 154 158 public PdfObject getPdfObject() { 159 return this; 160 } 161 162 166 public boolean isOn() { 167 return this.on; 168 } 169 170 174 public void setOn(boolean on) { 175 this.on = on; 176 } 177 178 private PdfDictionary getUsage() { 179 PdfDictionary usage = (PdfDictionary)get(PdfName.USAGE); 180 if (usage == null) { 181 usage = new PdfDictionary(); 182 put(PdfName.USAGE, usage); 183 } 184 return usage; 185 } 186 187 196 public void setCreatorInfo(String creator, String subtype) { 197 PdfDictionary usage = getUsage(); 198 PdfDictionary dic = new PdfDictionary(); 199 dic.put(PdfName.CREATOR, new PdfString(creator, PdfObject.TEXT_UNICODE)); 200 dic.put(PdfName.SUBTYPE, new PdfName(subtype)); 201 usage.put(PdfName.CREATORINFO, dic); 202 } 203 204 212 public void setLanguage(String lang, boolean preferred) { 213 PdfDictionary usage = getUsage(); 214 PdfDictionary dic = new PdfDictionary(); 215 dic.put(PdfName.LANG, new PdfString(lang, PdfObject.TEXT_UNICODE)); 216 if (preferred) 217 dic.put(PdfName.PREFERRED, PdfName.ON); 218 usage.put(PdfName.LANGUAGE, dic); 219 } 220 221 228 public void setExport(boolean export) { 229 PdfDictionary usage = getUsage(); 230 PdfDictionary dic = new PdfDictionary(); 231 dic.put(PdfName.EXPORTSTATE, export ? PdfName.ON : PdfName.OFF); 232 usage.put(PdfName.EXPORT, dic); 233 } 234 235 244 public void setZoom(float min, float max) { 245 if (min <= 0 && max < 0) 246 return; 247 PdfDictionary usage = getUsage(); 248 PdfDictionary dic = new PdfDictionary(); 249 if (min > 0) 250 dic.put(PdfName.MIN, new PdfNumber(min)); 251 if (max >= 0) 252 dic.put(PdfName.MAX, new PdfNumber(max)); 253 usage.put(PdfName.ZOOM, dic); 254 } 255 256 264 public void setPrint(String subtype, boolean printstate) { 265 PdfDictionary usage = getUsage(); 266 PdfDictionary dic = new PdfDictionary(); 267 dic.put(PdfName.SUBTYPE, new PdfName(subtype)); 268 dic.put(PdfName.PRINTSTATE, printstate ? PdfName.ON : PdfName.OFF); 269 usage.put(PdfName.PRINT, dic); 270 } 271 272 277 public void setView(boolean view) { 278 PdfDictionary usage = getUsage(); 279 PdfDictionary dic = new PdfDictionary(); 280 dic.put(PdfName.VIEWSTATE, view ? PdfName.ON : PdfName.OFF); 281 usage.put(PdfName.VIEW, dic); 282 } 283 284 288 public boolean isOnPanel() { 289 return this.onPanel; 290 } 291 292 298 public void setOnPanel(boolean onPanel) { 299 this.onPanel = onPanel; 300 } 301 302 } 303 | Popular Tags |