01: /*
02: * Created on Nov 29, 2003
03: */
04: package net.charabia.jsmoothgen.application.swtgui.resources;
05:
06: import java.io.IOException;
07: import java.io.InputStream;
08: import java.net.URL;
09: import java.util.PropertyResourceBundle;
10: import java.util.ResourceBundle;
11:
12: import org.eclipse.swt.graphics.Image;
13: import org.eclipse.swt.widgets.Display;
14:
15: /**
16: * Contains the resources used by JSmooth. Provides static methods and constants
17: * for access.
18: *
19: * NOTE: Before accessing any constant, the constructor must be called.
20: *
21: * @author Dumon
22: */
23: public final class JSmoothResources {
24: public static Image IMG_SWITCHER_SKELETON_PAGE;
25: public static Image IMG_SWITCHER_APPLICATION;
26: public static Image IMG_SWITCHER_EXECUTABLE;
27: public static Image IMG_SWITCHER_WELCOME;
28:
29: public static String TEXT_HELP_WELCOME;
30:
31: private ResourceBundle bundle;
32: private Display display;
33:
34: public JSmoothResources(Display display) {
35: Class clazz = getClass();
36: URL url = clazz.getResource("jsmooth.properties");
37: try {
38: bundle = new PropertyResourceBundle(url.openStream());
39: } catch (IOException e) {
40: // Shouldn't happen. Ignore.
41: }
42: loadImages(this .display = display);
43: loadText();
44: }
45:
46: public void loadImages(Display display) {
47: System.out.println("[DEBUG] Loading images...");
48: String name = bundle.getString("img.switcher.skeleton");
49: IMG_SWITCHER_SKELETON_PAGE = new Image(display, getClass()
50: .getResourceAsStream(name));
51:
52: name = bundle.getString("img.switcher.application");
53: IMG_SWITCHER_APPLICATION = new Image(display, getClass()
54: .getResourceAsStream(name));
55:
56: name = bundle.getString("img.switcher.executable");
57: IMG_SWITCHER_EXECUTABLE = new Image(display, getClass()
58: .getResourceAsStream(name));
59:
60: name = bundle.getString("img.switcher.welcome");
61: IMG_SWITCHER_WELCOME = new Image(display, getClass()
62: .getResourceAsStream(name));
63: }
64:
65: public void loadText() {
66: System.out.println("[DEBUG] Loading text...");
67: InputStream stream = getClass().getResourceAsStream(
68: "welcome.xml");
69: byte[] bytes = new byte[5000]; // 50 KB Should be enough.
70: try {
71: stream.read(bytes);
72: TEXT_HELP_WELCOME = (new String(bytes)).trim();
73: stream.close();
74: } catch (IOException e1) {
75: // TODO: Throw some exception at init time.
76: }
77: }
78: }
|