01: package sfs_attr_test;
02:
03: import java.awt.Image;
04: import org.openide.filesystems.FileObject;
05: import java.io.IOException;
06: import java.awt.Toolkit;
07: import java.net.URL;
08: import org.openide.util.Utilities;
09:
10: public abstract class Util {
11: private Util() {
12: }
13:
14: private static Image mergeIcons(FileObject fo) throws IOException {
15: int count = ((Integer) fo.getAttribute("iconCount")).intValue();
16: if (count < 2)
17: throw new IOException();
18: URL icon1 = (URL) fo.getAttribute("icon1");
19: System.out.println("Loading " + icon1 + " just to be sure...");
20: // Make sure it is really loadable:
21: icon1.openConnection().getInputStream().close();
22: Image img = Toolkit.getDefaultToolkit().getImage(icon1);
23: for (int i = 2; i <= count; i++) {
24: URL iconn = (URL) fo.getAttribute("icon" + i);
25: System.out.println("Loading " + iconn
26: + " just to be sure...");
27: iconn.openConnection().getInputStream().close();
28: Image added = Toolkit.getDefaultToolkit().getImage(iconn);
29: int x = ((Integer) fo.getAttribute("iconx" + count))
30: .intValue();
31: int y = ((Integer) fo.getAttribute("icony" + count))
32: .intValue();
33: img = Utilities.mergeImages(img, added, x, y);
34: }
35: return img;
36: }
37:
38: }
|