1 4 package org.oddjob.images; 5 6 import java.io.ByteArrayOutputStream ; 7 import java.io.IOException ; 8 import java.io.InputStream ; 9 import java.io.Serializable ; 10 import java.net.URL ; 11 import java.util.Locale ; 12 13 17 public class IconTip implements Serializable { 18 private static final long serialVersionUID = 20051114; 19 20 private final byte[] imageData; 21 private final String toolTip; 22 23 public IconTip(byte[] imageData, String toolTip) { 24 this.imageData = imageData; 25 this.toolTip = toolTip; 26 } 27 28 public IconTip(URL url, String toolTip) { 29 byte[] imageData = null; 30 try { 31 ByteArrayOutputStream out = new ByteArrayOutputStream (); 32 InputStream in = url.openStream(); 33 byte[] buf = new byte[1024]; 34 int len = 0; 35 while ((len = in.read(buf)) > 0) { 36 out.write(buf, 0, len); 37 } 38 in.close(); 39 out.close(); 40 imageData = out.toByteArray(); 41 } 42 catch (IOException e) { 43 e.printStackTrace(); 44 } 45 this.imageData = imageData; 46 this.toolTip = toolTip; 47 } 48 49 public byte[] getImageData() { 50 return this.imageData; 51 } 52 53 public String getToolTip() { 54 return this.toolTip; 55 } 56 57 public String getToolTip(Locale local) { 58 return getToolTip(); 59 } 60 } 61 | Popular Tags |