01: package fr.aliacom.form.swt.ui;
02:
03: import java.io.IOException;
04: import java.io.InputStream;
05:
06: import org.eclipse.swt.graphics.Color;
07: import org.eclipse.swt.graphics.Device;
08: import org.eclipse.swt.graphics.Image;
09:
10: import fr.aliacom.common.ui.IColor;
11: import fr.aliacom.common.ui.IIcon;
12: import fr.aliacom.form.common.Toolkit;
13:
14: /**
15: * @author tom
16: *
17: * (C) 2001, 2002 Thomas Cataldo
18: */
19: public class SWTIcon implements IIcon {
20:
21: private Image img;
22:
23: public SWTIcon(String iconName, Toolkit tk) {
24: InputStream stream = tk.loadIcon(iconName);
25: if (stream == null) {
26: System.out.println("Null stream to read icon");
27: img = null;
28: } else {
29: img = new Image((Device) tk.getDisplay(), stream);
30: try {
31: stream.close();
32: } catch (IOException e) {
33: e.printStackTrace();
34: }
35: }
36: }
37:
38: public SWTIcon(Image img) {
39: this .img = img;
40: }
41:
42: /**
43: * @see fr.aliacom.form.common.IFormComponent#getNativeWidget()
44: */
45: public Object getNativeWidget() {
46: return img;
47: }
48:
49: /**
50: * @see fr.aliacom.form.common.IFormComponent#reset()
51: */
52: public void reset() {
53: }
54:
55: /**
56: * @see fr.aliacom.form.common.IFormComponent#setValueBean(java.lang.Object)
57: */
58: public void setValueBean(Object bean) {
59: }
60:
61: /**
62: * @see fr.aliacom.common.ui.IIcon#setBackground(fr.aliacom.common.ui.IColor)
63: */
64: public void setBackground(IColor color) {
65: img.setBackground((Color) color.getNativeWidget());
66: }
67:
68: }
|