1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.sf.glxdesktop.gui.glade;
17
18 import java.io.FileInputStream;
19 import java.io.FileNotFoundException;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.util.ResourceBundle;
23
24 import net.sf.glxdesktop.gui.Messages;
25
26 import org.gnu.glade.GladeXMLException;
27 import org.gnu.glade.LibGlade;
28
29 public class LoadGlade {
30
31 private LibGlade glade;
32
33 public LoadGlade(String templatePath, Object owner)
34 throws LoadGladeException {
35 this(templatePath, owner, null);
36 }
37
38 public LoadGlade(String templatePath, Object owner, String root)
39 throws LoadGladeException {
40 try {
41 InputStream inputStream = getGladeTemplateAsStream(templatePath);
42 glade = new LibGlade(inputStream, owner, root);
43 } catch (GladeXMLException e) {
44 throw new LoadGladeException(templatePath + " " + Messages
45 .getString("LoadGlade.glade_xml_exception"),e);
46 } catch (IOException e) {
47 throw new LoadGladeException(templatePath + " " + Messages
48 .getString("LoadGlade.glade_IO_exception"), e);
49 } catch (Exception e) {
50
51 e.printStackTrace();
52 }
53 }
54
55 public LibGlade getGlade() {
56 return glade;
57 }
58
59 public void i18GladeTemplate(ResourceBundle bundle, String[] labels) {
60 I18GladeTemplate template = new I18GladeTemplate(glade, labels, bundle);
61 template.localizeTemplate();
62 }
63
64 private InputStream getGladeTemplateAsStream(String file)
65 throws LoadGladeException {
66 InputStream inputStream;
67 try {
68 inputStream = new FileInputStream(file);
69 return inputStream;
70 } catch (FileNotFoundException e) {
71 inputStream = ClassLoader.getSystemClassLoader().getResourceAsStream(file);
72 if (inputStream == null) {
73 throw new LoadGladeException(
74 Messages.getString("LoadGlade.glade_template") + file + Messages.getString("LoadGlade.glade_template_not_found"), e);
75 }
76 return inputStream;
77 }
78 }
79 }