Skip to content

Commit bd9f8a5

Browse files
author
jossonsmith
committed
Support asynchronous Class.forName with net.sf.j2s.ajax.AClass.load (clazzName, ...).
See ControlExamples
1 parent 09a4cb7 commit bd9f8a5

2 files changed

Lines changed: 157 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*******************************************************************************
2+
* Java2Script Pacemaker (http://j2s.sourceforge.net)
3+
*
4+
* Copyright (c) 2006 ognize.com and others.
5+
* All rights reserved. This program and the accompanying materials
6+
* are made available under the terms of the Eclipse Public License v1.0
7+
* which accompanies this distribution, and is available at
8+
* http://www.eclipse.org/legal/epl-v10.html
9+
*
10+
* Contributors:
11+
* ognize.com - initial API and implementation
12+
*******************************************************************************/
13+
14+
package net.sf.j2s.ajax;
15+
16+
/**
17+
* @author josson smith
18+
*
19+
* 2006-8-4
20+
*/
21+
public class AClass {
22+
23+
/**
24+
* @j2sIgnore
25+
*/
26+
protected AClass() {
27+
// prevent from instantialization
28+
}
29+
30+
/**
31+
* @param clazzName
32+
* @param afterLoaded
33+
*
34+
* @j2sNativeSrc
35+
* ClazzLoader.loadClass (clazzName, function () {
36+
* afterLoaded.run ();
37+
* }, false, true);
38+
* @j2sNative
39+
* ClazzLoader.loadClass (a, function () {
40+
* b.run ();
41+
* }, false, true);
42+
*/
43+
public static void load(final String clazzName, final Runnable afterLoaded) {
44+
new Thread(new Runnable() {
45+
public void run() {
46+
try {
47+
Class.forName(clazzName);
48+
} catch (ClassNotFoundException e) {
49+
e.printStackTrace();
50+
return ;
51+
}
52+
afterLoaded.run();
53+
}
54+
}).start();
55+
}
56+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
/*******************************************************************************
2+
* Java2Script Pacemaker (http://j2s.sourceforge.net)
3+
*
4+
* Copyright (c) 2006 ognize.com and others.
5+
* All rights reserved. This program and the accompanying materials
6+
* are made available under the terms of the Eclipse Public License v1.0
7+
* which accompanies this distribution, and is available at
8+
* http://www.eclipse.org/legal/epl-v10.html
9+
*
10+
* Contributors:
11+
* ognize.com - initial API and implementation
12+
*******************************************************************************/
13+
14+
package net.sf.j2s.ajax;
15+
16+
import org.eclipse.swt.widgets.Display;
17+
import org.eclipse.swt.widgets.Shell;
18+
19+
/**
20+
* @author josson smith
21+
*
22+
* 2006-8-4
23+
*/
24+
public class ASWTClass extends AClass {
25+
26+
/**
27+
* @j2sIgnore
28+
*/
29+
protected ASWTClass() {
30+
// prevent from instantialization
31+
}
32+
33+
/**
34+
* @param clazzName
35+
* @param afterLoaded
36+
*
37+
* @j2sNativeSrc
38+
* ClazzLoader.loadClass (clazzName, function () {
39+
* afterLoaded.run ();
40+
* }, false, true);
41+
* @j2sNative
42+
* ClazzLoader.loadClass (a, function () {
43+
* b.run ();
44+
* }, false, true);
45+
*/
46+
public static void swtLoad(final String clazzName, final Runnable afterLoaded) {
47+
Display display = Display.getCurrent();
48+
if (display == null) {
49+
display = Display.getDefault();
50+
}
51+
displayLoad(display, clazzName, afterLoaded);
52+
}
53+
54+
55+
/**
56+
* @param display
57+
* @param clazzName
58+
* @param afterLoaded
59+
*
60+
* @j2sNativeSrc
61+
* ClazzLoader.loadClass (clazzName, function () {
62+
* afterLoaded.run ();
63+
* }, false, true);
64+
* @j2sNative
65+
* ClazzLoader.loadClass (b, function () {
66+
* c.run ();
67+
* }, false, true);
68+
*/
69+
public static void displayLoad(Display display, final String clazzName, final Runnable afterLoaded) {
70+
display.asyncExec(new Runnable() {
71+
public void run() {
72+
try {
73+
Class.forName(clazzName);
74+
} catch (ClassNotFoundException e) {
75+
e.printStackTrace();
76+
return ;
77+
}
78+
79+
afterLoaded.run();
80+
}
81+
});
82+
}
83+
84+
/**
85+
* @param shell
86+
* @param clazzName
87+
* @param afterLoaded
88+
*
89+
* @j2sNativeSrc
90+
* ClazzLoader.loadClass (clazzName, function () {
91+
* afterLoaded.run ();
92+
* }, false, true);
93+
* @j2sNative
94+
* ClazzLoader.loadClass (b, function () {
95+
* c.run ();
96+
* }, false, true);
97+
*/
98+
public static void shellLoad(Shell shell, final String clazzName, final Runnable afterLoaded) {
99+
displayLoad(shell.getDisplay(), clazzName, afterLoaded);
100+
}
101+
}

0 commit comments

Comments
 (0)