1 18 package org.apache.batik.swing.svg; 19 20 import org.apache.batik.util.XMLResourceDescriptor; 21 22 import org.apache.batik.bridge.ExternalResourceSecurity; 23 import org.apache.batik.bridge.RelaxedExternalResourceSecurity; 24 import org.apache.batik.bridge.RelaxedScriptSecurity; 25 import org.apache.batik.bridge.ScriptSecurity; 26 import org.apache.batik.util.ParsedURL; 27 import org.w3c.dom.Element ; 28 29 38 39 51 public class SVGUserAgentAdapter implements SVGUserAgent { 52 public SVGUserAgentAdapter() { } 53 54 57 public void displayError(String message) { 58 System.err.println(message); 59 } 60 61 64 public void displayError(Exception ex) { 65 ex.printStackTrace(); 66 } 67 68 72 public void displayMessage(String message) { 73 System.out.println(message); 74 } 75 76 79 public void showAlert(String message) { 80 System.err.println(message); 81 } 82 83 86 public String showPrompt(String message) { 87 return ""; 88 } 89 90 93 public String showPrompt(String message, String defaultValue) { 94 return defaultValue; 95 } 96 97 100 public boolean showConfirm(String message) { 101 return false; 102 } 103 104 107 public float getPixelUnitToMillimeter() { 108 return 0.26458333333333333333333333333333f; } 110 111 116 public float getPixelToMM() { 117 return getPixelUnitToMillimeter(); 118 119 } 120 121 124 public String getDefaultFontFamily() { 125 return "Serif"; 126 } 127 128 131 public float getMediumFontSize() { 132 return 9f * 25.4f / (72f * getPixelUnitToMillimeter()); 134 } 135 136 139 public float getLighterFontWeight(float f) { 140 int weight = ((int)((f+50)/100))*100; 142 switch (weight) { 143 case 100: return 100; 144 case 200: return 100; 145 case 300: return 200; 146 case 400: return 300; 147 case 500: return 400; 148 case 600: return 400; 149 case 700: return 400; 150 case 800: return 400; 151 case 900: return 400; 152 default: 153 throw new IllegalArgumentException ("Bad Font Weight: " + f); 154 } 155 } 156 157 160 public float getBolderFontWeight(float f) { 161 int weight = ((int)((f+50)/100))*100; 163 switch (weight) { 164 case 100: return 600; 165 case 200: return 600; 166 case 300: return 600; 167 case 400: return 600; 168 case 500: return 600; 169 case 600: return 700; 170 case 700: return 800; 171 case 800: return 900; 172 case 900: return 900; 173 default: 174 throw new IllegalArgumentException ("Bad Font Weight: " + f); 175 } 176 } 177 178 179 182 public String getLanguages() { 183 return "en"; 184 } 185 186 190 public String getUserStyleSheetURI() { 191 return null; 192 } 193 194 197 public String getXMLParserClassName() { 198 return XMLResourceDescriptor.getXMLParserClassName(); 199 } 200 201 205 public boolean isXMLParserValidating() { 206 return false; 207 } 208 209 212 public String getMedia() { 213 return "screen"; 214 } 215 216 219 public String getAlternateStyleSheet() { 220 return null; 221 } 222 223 228 public void openLink(String uri, boolean newc) { 229 } 230 231 235 public boolean supportExtension(String s) { 236 return false; 237 } 238 239 public void handleElement(Element elt, Object data){ 240 } 241 242 255 public ScriptSecurity getScriptSecurity(String scriptType, 256 ParsedURL scriptURL, 257 ParsedURL docURL){ 258 return new RelaxedScriptSecurity(scriptType, 259 scriptURL, 260 docURL); 261 270 } 271 272 290 public void checkLoadScript(String scriptType, 291 ParsedURL scriptURL, 292 ParsedURL docURL) throws SecurityException { 293 ScriptSecurity s = getScriptSecurity(scriptType, 294 scriptURL, 295 docURL); 296 297 if (s != null) { 298 s.checkLoadScript(); 299 } 300 } 301 302 313 public ExternalResourceSecurity 314 getExternalResourceSecurity(ParsedURL resourceURL, 315 ParsedURL docURL){ 316 return new RelaxedExternalResourceSecurity(resourceURL, 317 docURL); 318 324 } 325 326 342 public void 343 checkLoadExternalResource(ParsedURL resourceURL, 344 ParsedURL docURL) throws SecurityException { 345 ExternalResourceSecurity s 346 = getExternalResourceSecurity(resourceURL, docURL); 347 348 if (s != null) { 349 s.checkLoadExternalResource(); 350 } 351 } 352 }; 353 | Popular Tags |