Skip to content

Commit 27989e0

Browse files
author
jossonsmith
committed
Add class ARunnable, so getClazz() can be used in #run in a more convenient way.
1 parent fa2f96a commit 27989e0

4 files changed

Lines changed: 59 additions & 34 deletions

File tree

sources/net.sf.j2s.ajax/ajaxcore/net/sf/j2s/ajax/AClass.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,30 @@ protected AClass() {
3333
*
3434
* @j2sNativeSrc
3535
* ClazzLoader.loadClass (clazzName, function () {
36+
* if (Clazz.instanceOf (afterLoaded, net.sf.j2s.ajax.ARunnable)) {
37+
* var clz = Clazz.evalType (clazzName);
38+
* afterLoaded.setClazz (clz);
39+
* }
3640
* afterLoaded.run ();
3741
* }, false, true);
3842
* @j2sNative
3943
* ClazzLoader.loadClass (a, function () {
44+
* if (Clazz.instanceOf (b, net.sf.j2s.ajax.ARunnable)) {
45+
* var clz = Clazz.evalType (a);
46+
* b.setClazz (clz);
47+
* }
4048
* b.run ();
4149
* }, false, true);
4250
*/
4351
public static void load(final String clazzName, final Runnable afterLoaded) {
4452
new Thread(new Runnable() {
4553
public void run() {
4654
try {
47-
Class.forName(clazzName);
55+
Class clz = Class.forName(clazzName);
56+
if (afterLoaded instanceof ARunnable) {
57+
ARunnable runnable = (ARunnable) afterLoaded;
58+
runnable.setClazz(clz);
59+
}
4860
} catch (ClassNotFoundException e) {
4961
e.printStackTrace();
5062
return ;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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 abstract class ARunnable implements Runnable {
22+
private Class clazz;
23+
24+
public Class getClazz() {
25+
return clazz;
26+
}
27+
28+
public void setClazz(Class clazz) {
29+
this.clazz = clazz;
30+
}
31+
}

sources/net.sf.j2s.ajax/ajaxswt/net/sf/j2s/ajax/ASWTClass.java

Lines changed: 15 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,7 @@ protected ASWTClass() {
3030
// prevent from instantialization
3131
}
3232

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) {
33+
public static void swtLoad(String clazzName, Runnable afterLoaded) {
4734
Display display = Display.getCurrent();
4835
if (display == null) {
4936
display = Display.getDefault();
@@ -59,18 +46,30 @@ public static void swtLoad(final String clazzName, final Runnable afterLoaded) {
5946
*
6047
* @j2sNativeSrc
6148
* ClazzLoader.loadClass (clazzName, function () {
49+
* if (Clazz.instanceOf (afterLoaded, net.sf.j2s.ajax.ARunnable)) {
50+
* var clz = Clazz.evalType (clazzName);
51+
* afterLoaded.setClazz (clz);
52+
* }
6253
* afterLoaded.run ();
6354
* }, false, true);
6455
* @j2sNative
6556
* ClazzLoader.loadClass (b, function () {
57+
* if (Clazz.instanceOf (c, net.sf.j2s.ajax.ARunnable)) {
58+
* var clz = Clazz.evalType (b);
59+
* c.setClazz (clz);
60+
* }
6661
* c.run ();
6762
* }, false, true);
6863
*/
6964
public static void displayLoad(Display display, final String clazzName, final Runnable afterLoaded) {
7065
display.asyncExec(new Runnable() {
7166
public void run() {
7267
try {
73-
Class.forName(clazzName);
68+
Class clz = Class.forName(clazzName);
69+
if (afterLoaded instanceof ARunnable) {
70+
ARunnable runnable = (ARunnable) afterLoaded;
71+
runnable.setClazz(clz);
72+
}
7473
} catch (ClassNotFoundException e) {
7574
e.printStackTrace();
7675
return ;
@@ -81,21 +80,7 @@ public void run() {
8180
});
8281
}
8382

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) {
83+
public static void shellLoad(Shell shell, String clazzName, Runnable afterLoaded) {
9984
displayLoad(shell.getDisplay(), clazzName, afterLoaded);
10085
}
10186
}

sources/net.sf.j2s.ajax/ajaxswt/net/sf/j2s/ajax/XHRCallbackSWTAdapter.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,6 @@
2121
* @author josson smith
2222
*
2323
* 2006-2-11
24-
*
25-
* @j2sIgnoreImport java.lang.Runnable, org.eclipse.swt.widgets.Display
26-
*
2724
*/
2825
public class XHRCallbackSWTAdapter implements IXHRCallback {
2926

0 commit comments

Comments
 (0)