svn-gvsig-desktop / branches / v10 / extensions / extScripting / src / org / gvsig / scripting / xul / XULPanel.java @ 9331
History | View | Annotate | Download (3.29 KB)
1 |
package org.gvsig.scripting.xul; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.io.File; |
5 |
import java.io.FileInputStream; |
6 |
import java.io.IOException; |
7 |
import java.io.InputStream; |
8 |
import java.net.MalformedURLException; |
9 |
import java.net.URL; |
10 |
import java.util.Enumeration; |
11 |
import java.util.HashMap; |
12 |
import java.util.Map; |
13 |
import java.util.ResourceBundle; |
14 |
|
15 |
import javax.swing.JPanel; |
16 |
|
17 |
import com.iver.andami.PluginServices; |
18 |
|
19 |
import thinlet.Thinlet; |
20 |
|
21 |
public class XULPanel extends Thinlet implements IXULPanel { |
22 |
|
23 |
private static final long serialVersionUID = -7549083932449351947L; |
24 |
|
25 |
private XULJPanel panel =null; |
26 |
|
27 |
private String xulFile = null; |
28 |
|
29 |
private Map data = new HashMap(); |
30 |
|
31 |
|
32 |
public XULPanel() {
|
33 |
MyResources r = new MyResources(this.getClass()); |
34 |
setResourceBundle(r); |
35 |
panel = new XULJPanel(this); |
36 |
} |
37 |
|
38 |
public XULPanel(XULJPanel panel) {
|
39 |
MyResources r = new MyResources(this.getClass()); |
40 |
setResourceBundle(r); |
41 |
this.panel = panel;
|
42 |
} |
43 |
|
44 |
public String translate(String msg) { |
45 |
return PluginServices.getText(this,msg); |
46 |
} |
47 |
|
48 |
|
49 |
public Object parse(String path, Object handler) throws IOException { |
50 |
InputStream inputstream = null; |
51 |
try {
|
52 |
inputstream = getClass().getResourceAsStream(path); |
53 |
if (inputstream == null) { |
54 |
|
55 |
try {
|
56 |
inputstream = new URL(path).openStream(); |
57 |
} catch (MalformedURLException mfe) { |
58 |
try {
|
59 |
File file = new File(path); |
60 |
inputstream = new FileInputStream(file); |
61 |
} catch (Exception e) { |
62 |
/* thows nullpointerexception*/
|
63 |
e.printStackTrace(); |
64 |
} |
65 |
} |
66 |
|
67 |
} |
68 |
return super.parse(inputstream,handler); |
69 |
} finally{
|
70 |
if(inputstream != null) try{inputstream.close();}catch(IOException ignore){} |
71 |
} |
72 |
} |
73 |
|
74 |
//==============================================================
|
75 |
// Implementacion del interface IXULPanel
|
76 |
//
|
77 |
public void setXULFile (String xulFile) throws IOException { |
78 |
try {
|
79 |
this.xulFile = xulFile;
|
80 |
add(parse(xulFile)); |
81 |
} catch (IOException e) { |
82 |
// TODO Auto-generated catch block
|
83 |
e.printStackTrace(); |
84 |
throw e;
|
85 |
} |
86 |
panel.setLayout(new BorderLayout()); |
87 |
panel.add(this,BorderLayout.CENTER); |
88 |
} |
89 |
|
90 |
public Object createComponent(String name) { |
91 |
return create(name);
|
92 |
} |
93 |
|
94 |
public String getXULFile() { |
95 |
return xulFile;
|
96 |
} |
97 |
|
98 |
public JPanel getJPanel() { |
99 |
return panel;
|
100 |
} |
101 |
|
102 |
public Object getEngine() { |
103 |
return this; |
104 |
} |
105 |
|
106 |
public void close(){ |
107 |
panel.close(); |
108 |
} |
109 |
|
110 |
public void showWindow(){ |
111 |
panel.showWindow(); |
112 |
} |
113 |
|
114 |
public void setTitle(String title) { |
115 |
panel.setTitle(title); |
116 |
} |
117 |
|
118 |
public void setPalette(boolean state) { |
119 |
panel.setPalette(state); |
120 |
} |
121 |
|
122 |
public Object get(Object key) { |
123 |
return data.get(key);
|
124 |
} |
125 |
|
126 |
public Object put(Object key, Object value) { |
127 |
return data.put(key,value);
|
128 |
} |
129 |
|
130 |
public int getSize(Object component) { |
131 |
return getCount(component);
|
132 |
} |
133 |
|
134 |
} |
135 |
|
136 |
class MyResources extends ResourceBundle { |
137 |
|
138 |
Class theClass = null; |
139 |
|
140 |
public MyResources(Class theClass) { |
141 |
this.theClass = theClass;
|
142 |
} |
143 |
|
144 |
public Object handleGetObject(String key) { |
145 |
String msg = PluginServices.getText(theClass,key);
|
146 |
return msg;
|
147 |
} |
148 |
|
149 |
public Enumeration getKeys() { |
150 |
return null; |
151 |
} |
152 |
} |