1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| |
16 |
| |
17 |
| |
18 |
| package org.ericmignot.modeler.gui; |
19 |
| |
20 |
| import java.awt.BorderLayout; |
21 |
| import java.lang.reflect.Method; |
22 |
| import java.net.URL; |
23 |
| |
24 |
| import javax.swing.JApplet; |
25 |
| |
26 |
| import org.ericmignot.modeler.Interoperable; |
27 |
| import org.ericmignot.modeler.data.BusinessObject; |
28 |
| import org.ericmignot.modeler.util.action.NotifyableAction; |
29 |
| |
30 |
| public class ModelerApplet extends JApplet implements Interoperable |
31 |
| { |
32 |
| public static final String LOAD_IN_PROGRESS = "Load in progress"; |
33 |
| public static final String LOAD_COMPLETED = "Load completed"; |
34 |
| |
35 |
| private Controller controller; |
36 |
| public String loadProgress; |
37 |
| |
38 |
| public static ModelerApplet instance; |
39 |
| |
40 |
4
| public ModelerApplet()
|
41 |
| { |
42 |
4
| ModelerApplet.instance = this;
|
43 |
4
| this.loadProgress = LOAD_IN_PROGRESS;
|
44 |
4
| this.controller = this.buildController();
|
45 |
4
| this.controller.setInteroperable(this);
|
46 |
4
| this.initController(this.controller);
|
47 |
| } |
48 |
| |
49 |
4
| public Controller buildController()
|
50 |
| { |
51 |
4
| return new Controller();
|
52 |
| } |
53 |
4
| public void initController(Controller controller)
|
54 |
| { |
55 |
| |
56 |
| } |
57 |
| |
58 |
0
| public static void showDocument(String aString)
|
59 |
| { |
60 |
0
| try
|
61 |
| { |
62 |
| |
63 |
0
| String jscmd = aString;
|
64 |
0
| Method getw = null, eval = null;
|
65 |
0
| Object jswin = null;
|
66 |
0
| Class c = Class.forName("netscape.javascript.JSObject");
|
67 |
0
| Method ms[] = c.getMethods();
|
68 |
0
| for (int i = 0; i < ms.length; i++)
|
69 |
| { |
70 |
0
| if (ms[i].getName().compareTo("getWindow") == 0)
|
71 |
| { |
72 |
0
| getw = ms[i];
|
73 |
| } |
74 |
0
| else if (ms[i].getName().compareTo("eval") == 0)
|
75 |
| { |
76 |
0
| eval = ms[i];
|
77 |
| } |
78 |
| } |
79 |
0
| Object a[] = new Object[1];
|
80 |
0
| a[0] = ModelerApplet.instance;
|
81 |
0
| jswin = getw.invoke(c, a);
|
82 |
0
| a[0] = jscmd;
|
83 |
0
| eval.invoke(jswin, a);
|
84 |
| } |
85 |
| catch (Throwable e) |
86 |
| { |
87 |
0
| try
|
88 |
| { |
89 |
| |
90 |
0
| ModelerApplet.instance.getAppletContext().showDocument(new URL(aString));
|
91 |
| } |
92 |
| catch (Throwable e1) |
93 |
| { |
94 |
0
| e1.printStackTrace();
|
95 |
| } |
96 |
| } |
97 |
| } |
98 |
0
| public void fireEvent(String event)
|
99 |
| { |
100 |
0
| if (event != null)
|
101 |
| { |
102 |
0
| showDocument(event);
|
103 |
| } |
104 |
| } |
105 |
0
| public void fireDoEvent(NotifyableAction action, BusinessObject target)
|
106 |
| { |
107 |
0
| if (action != null)
|
108 |
| { |
109 |
0
| String javascriptCall = action.getDoEvent();
|
110 |
0
| if (javascriptCall != null)
|
111 |
| { |
112 |
0
| if (javascriptCall.indexOf("xml") != -1)
|
113 |
| { |
114 |
0
| javascriptCall = javascriptCall.replaceAll("xml", "\"" + target.getXML() + "\"");
|
115 |
| } |
116 |
0
| fireEvent(javascriptCall);
|
117 |
| } |
118 |
| } |
119 |
| } |
120 |
0
| public void fireUndoEvent(NotifyableAction action, BusinessObject target)
|
121 |
| { |
122 |
0
| if (action != null)
|
123 |
| { |
124 |
0
| String javascriptCall = action.getUndoEvent();
|
125 |
0
| if (javascriptCall != null)
|
126 |
| { |
127 |
0
| if (javascriptCall.indexOf("xml") != -1)
|
128 |
| { |
129 |
0
| javascriptCall = javascriptCall.replaceAll("xml", "\"" + target.getXML() + "\"");
|
130 |
| } |
131 |
0
| fireEvent(javascriptCall);
|
132 |
| } |
133 |
| } |
134 |
| } |
135 |
| |
136 |
2
| public Controller getController()
|
137 |
| { |
138 |
2
| return this.controller;
|
139 |
| } |
140 |
| |
141 |
2
| public String getLoadProgress()
|
142 |
| { |
143 |
2
| return this.loadProgress;
|
144 |
| } |
145 |
| |
146 |
1
| public void setLoadProgress(String loadProgress)
|
147 |
| { |
148 |
1
| this.loadProgress = loadProgress;
|
149 |
| } |
150 |
0
| public void setData(String xml) throws IllegalArgumentException
|
151 |
| { |
152 |
0
| this.controller.setData(xml);
|
153 |
| } |
154 |
0
| public String getData()
|
155 |
| { |
156 |
0
| return this.controller.getModel().getXML();
|
157 |
| } |
158 |
0
| public int getVerticalScrollBarValue()
|
159 |
| { |
160 |
0
| return this.controller.getVerticalScrollBarValue();
|
161 |
| } |
162 |
| |
163 |
0
| public int getHorizontalScrollBarValue()
|
164 |
| { |
165 |
0
| return this.controller.getHorizontalScrollBarValue();
|
166 |
| } |
167 |
0
| public double getZoomFactor()
|
168 |
| { |
169 |
0
| return this.controller.getZoomFactor();
|
170 |
| } |
171 |
| |
172 |
0
| public void start()
|
173 |
| { |
174 |
0
| String xml = this.getParameter("Configuration");
|
175 |
| |
176 |
0
| if (xml != null)
|
177 |
| { |
178 |
0
| xml = xml.replaceAll("'", "\"");
|
179 |
0
| this.controller.setStaticValues(xml);
|
180 |
0
| this.controller.setData(xml);
|
181 |
| } |
182 |
| else |
183 |
| { |
184 |
0
| this.controller.initVisualComponents();
|
185 |
| } |
186 |
0
| this.getContentPane().removeAll();
|
187 |
0
| this.getContentPane().add(controller.createMainPanel(), BorderLayout.CENTER);
|
188 |
| |
189 |
| } |
190 |
| |
191 |
| |
192 |
| |
193 |
| } |