1 6 package org.objectweb.jac.aspects.gui.web.html; 7 8 11 import java.awt.Dimension ; 12 import java.io.File ; 13 import java.io.FileInputStream ; 14 import java.io.IOException ; 15 import org.mortbay.util.Code; 16 17 18 23 public class Image extends Tag 24 { 25 26 public Image(String src, String alt) 27 { 28 super("img"); 29 attribute("src",src); 30 alt(alt); 31 } 32 33 34 public Image(String src, String alt, Dimension size) 35 { 36 super("img"); 37 attribute("src",src); 38 alt(alt); 39 if (size!=null) { 40 width(size.width); 41 height(size.height); 42 } 43 } 44 45 46 48 56 57 58 60 public Image(File gif) 61 { 62 super("img"); 63 attribute("src",gif.getName()); 64 setSizeFromGif(gif); 65 } 66 67 68 76 77 78 public Image border(int b) 79 { 80 attribute("border",b); 81 return this; 82 } 83 84 85 public Image alt(String alt) 86 { 87 attribute("alt",alt); 88 return this; 89 } 90 91 92 98 public Image setSizeFromGif(String dirname, 99 String pathname) 100 { 101 String filename =dirname + pathname.replace('/',File.separatorChar); 102 return setSizeFromGif(filename); 103 } 104 105 106 108 public Image setSizeFromGif(String filename) 109 { 110 return setSizeFromGif(new File (filename)); 111 } 112 113 114 116 public Image setSizeFromGif(File gif) 117 { 118 if (gif.canRead()) 119 { 120 try{ 121 byte [] buf = new byte[10]; 122 FileInputStream in = new FileInputStream (gif); 123 if (in.read(buf,0,10)==10) 124 { 125 Code.debug("Image "+gif.getName()+ 126 " is " + 127 ((0x00ff&buf[7])*256+(0x00ff&buf[6])) + 128 " x " + 129 (((0x00ff&buf[9])*256+(0x00ff&buf[8])))); 130 width((0x00ff&buf[7])*256+(0x00ff&buf[6])); 131 height(((0x00ff&buf[9])*256+(0x00ff&buf[8]))); 132 } 133 } 134 catch (IOException e){ 135 Code.ignore(e); 136 } 137 } 138 139 return this; 140 } 141 142 } 143 | Popular Tags |