KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > images > IconTip


1 /*
2  * Copyright © 2004, Rob Gordon.
3  */

4 package org.oddjob.images;
5
6 import java.io.ByteArrayOutputStream JavaDoc;
7 import java.io.IOException JavaDoc;
8 import java.io.InputStream JavaDoc;
9 import java.io.Serializable JavaDoc;
10 import java.net.URL JavaDoc;
11 import java.util.Locale JavaDoc;
12
13 /**
14  *
15  * @author Rob Gordon.
16  */

17 public class IconTip implements Serializable JavaDoc {
18     private static final long serialVersionUID = 20051114;
19     
20     private final byte[] imageData;
21     private final String JavaDoc toolTip;
22     
23     public IconTip(byte[] imageData, String JavaDoc toolTip) {
24         this.imageData = imageData;
25         this.toolTip = toolTip;
26     }
27     
28     public IconTip(URL JavaDoc url, String JavaDoc toolTip) {
29         byte[] imageData = null;
30         try {
31             ByteArrayOutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc();
32             InputStream JavaDoc 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 JavaDoc 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 JavaDoc getToolTip() {
54         return this.toolTip;
55     }
56     
57     public String JavaDoc getToolTip(Locale JavaDoc local) {
58         return getToolTip();
59     }
60 }
61
Popular Tags