Skip to content

Commit 4694257

Browse files
authored
Merge pull request #7 from BobHanson/yadav1
Yadav1
2 parents 20a731f + a8c7d60 commit 4694257

40 files changed

+3205
-352
lines changed
152 Bytes
Binary file not shown.
152 Bytes
Binary file not shown.

sources/net.sf.j2s.core/src/net/sf/j2s/core/astvisitors/Java2ScriptVisitor.java

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -221,23 +221,24 @@ private void addApplication() {
221221
apps.add(getQualifiedClassName());
222222
}
223223

224-
private void checkAddApplet(ITypeBinding binding) {
224+
private boolean checkAddApplet(ITypeBinding binding) {
225225
if (Modifier.isAbstract(binding.getModifiers()))
226-
return;
226+
return false;
227227
ITypeBinding b = binding;
228228
while ((binding = binding.getSuperclass()) != null) {
229229
String name = binding.getQualifiedName();
230230
if (!("javax.swing.JApplet".equals(name))) {
231231
if (name.startsWith("java.") || name.startsWith("javax"))
232-
return;
232+
return false;
233233
continue;
234234
}
235235
if (applets == null)
236236
applets = new ArrayList<String>();
237237
name = b.getQualifiedName();
238238
applets.add(name);
239-
break;
239+
return true;
240240
}
241+
return false;
241242
}
242243

243244
public ArrayList<String> getAppList(boolean isApplets) {
@@ -265,6 +266,8 @@ private void setInnerGlobals(Java2ScriptVisitor parent, ASTNode node, String vis
265266

266267
private ASTNode innerTypeNode;
267268

269+
private boolean isUserApplet;
270+
268271
public boolean visit(PackageDeclaration node) {
269272
setMapJavaDoc(node);
270273
String name = node.getName().toString();
@@ -613,16 +616,18 @@ public boolean visit(MethodDeclaration node) {
613616
if (key != null)
614617
methodDeclareNameStack.push(key);
615618

616-
boolean isStatic = isStatic(node);
617-
boolean isNative = Modifier.isNative(node.getModifiers());
618-
619+
int mods = node.getModifiers();
620+
boolean isNative = Modifier.isNative(mods);
621+
619622
if (node.getBody() == null && !isNative) {
620623
// Abstract method
621624
return false;
622625
}
623626

627+
boolean isStatic = Modifier.isStatic(mods);
624628
boolean isConstructor = node.isConstructor();
625-
String name = getMethodNameOrArrayForDeclaration(node, mBinding, isConstructor);
629+
boolean addUnqualified = isUserApplet && !isConstructor && !isStatic && Modifier.isPublic(mods);
630+
String name = getMethodNameOrArrayForDeclaration(node, mBinding, isConstructor, addUnqualified);
626631
if (isConstructor && name.equals("'c$'") || mBinding.isVarargs() && mBinding.getParameterTypes().length == 1)
627632
haveDefaultConstructor = true; // in case we are not qualifying
628633
// names here
@@ -1100,7 +1105,7 @@ private boolean addClassOrInterface(ASTNode node, ITypeBinding binding, List<?>
11001105
// check for a JApplet
11011106

11021107
if (isTopLevel && !isEnum) {
1103-
checkAddApplet(binding);
1108+
isUserApplet = checkAddApplet(binding);
11041109
}
11051110

11061111
// add the anonymous wrapper if needed
@@ -2050,10 +2055,10 @@ public boolean visit(Assignment node) {
20502055
left.accept(this);
20512056
switch (op) {
20522057
case "|=":
2053-
buffer.append("||");
2058+
buffer.append("|"); // surprise! | not ||
20542059
break;
20552060
case "&=":
2056-
buffer.append("&&");
2061+
buffer.append("&"); // & not &&
20572062
break;
20582063
default:
20592064
case "^=":
@@ -3927,10 +3932,10 @@ private static void addGenericClassMethod(String classKey, String methodName, St
39273932
* @return j2s-qualified name or an array of j2s-qualified names
39283933
*/
39293934
private String getMethodNameOrArrayForDeclaration(MethodDeclaration node, IMethodBinding mBinding,
3930-
boolean isConstructor) {
3935+
boolean isConstructor, boolean addUnqualified) {
39313936
SimpleName nodeName = node.getName();
39323937
String methodName = (isConstructor ? "c$" : NameMapper.getJ2SName(nodeName));
3933-
String name = getJ2SQualifiedName(methodName, null, mBinding, null, false);
3938+
String qname = getJ2SQualifiedName(methodName, null, mBinding, null, false);
39343939
ITypeBinding methodClass = mBinding.getDeclaringClass();
39353940
List<String> names = null;
39363941
// System.err.println("checking methodList for " + nodeName.toString() +
@@ -3950,16 +3955,19 @@ private String getMethodNameOrArrayForDeclaration(MethodDeclaration node, IMetho
39503955
if (pname != null)
39513956
names.add(pname);
39523957
}
3958+
} else if (addUnqualified && !methodName.equals(qname)) {
3959+
names = new ArrayList<String>();
3960+
names.add(methodName);
39533961
}
39543962
if (names == null || names.size() == 0)
3955-
return "'" + name + "'";
3956-
name = ",'" + name + "'";
3963+
return "'" + qname + "'";
3964+
qname = ",'" + qname + "'";
39573965
for (int i = names.size(); --i >= 0;) {
39583966
String next = ",'" + names.get(i) + "'";
3959-
if (name.indexOf(next) < 0)
3960-
name += next;
3967+
if (qname.indexOf(next) < 0)
3968+
qname += next;
39613969
}
3962-
return "[" + name.substring(1) + "]";
3970+
return "[" + qname.substring(1) + "]";
39633971
}
39643972

39653973
/**
2.87 MB
Binary file not shown.

sources/net.sf.j2s.java.core/build_core_applet.xml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,22 @@
280280
${javaCoreAppletFiles}
281281
" />
282282
</antcall>
283+
284+
<echo>creating swingjs2.js</echo>
285+
<concat destfile="srcjs/swingjs2.js">
286+
<filelist dir="srcjs/js" files="jquery.js,j2sJQueryExt.js,j2sApplet.js,j2sClazz.js,SwingJSApplet.js" />
287+
</concat>
288+
289+
<echo>copying srcjs files into site</echo>
290+
<copy todir="site/swingjs/js">
291+
<fileset dir="srcjs"/>
292+
</copy>
293+
294+
<echo>TODO: Could delete demo html files? </echo>
295+
296+
<echo>creating SwingJS-site.zip </echo>
297+
<zip destfile="SwingJS-site.zip" basedir="site" />
298+
283299
</target>
284300

285301

sources/net.sf.j2s.java.core/src/a2s/A2SEvent.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ static Event convertToOld(AWTEvent e) {
133133
getOldEventKey(ke),
134134
(ke.getModifiers() & ~InputEvent.BUTTON1_MASK));
135135

136+
case MouseEvent.MOUSE_CLICKED:
136137
case MouseEvent.MOUSE_PRESSED:
137138
case MouseEvent.MOUSE_RELEASED:
138139
case MouseEvent.MOUSE_MOVED:
@@ -233,7 +234,10 @@ public static Component addListener(JComponent container, Component comp) {
233234
if (top == null)
234235
top = ((A2SContainer) ((JComponent) comp).getTopLevelAncestor());
235236
if (top == null)
236-
return comp;
237+
if (comp instanceof A2SContainer)
238+
top = (A2SContainer) comp;
239+
else
240+
return comp;
237241
A2SListener listener = top.getA2SListener();
238242
if (comp instanceof AbstractButton) {
239243
if (!isListener(((AbstractButton) comp).getActionListeners(), listener))

sources/net.sf.j2s.java.core/src/a2s/Applet.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,13 @@ public A2SListener getA2SListener() {
5555
// public void init() {
5656
// }
5757

58+
private boolean paintMeNotified;
59+
5860
protected void paintMe(Graphics g) {
59-
System.out.println("paintMe has not been implemented!");
61+
if (!paintMeNotified) {
62+
System.out.println("paintMe has not been implemented for " + this);
63+
paintMeNotified = true;
64+
}
6065
}
6166

6267

sources/net.sf.j2s.java.core/src/a2s/Scrollbar.java

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,21 @@
22

33
import javax.swing.JScrollBar;
44

5-
public class Scrollbar extends JScrollBar {
5+
public class Scrollbar extends JScrollBar implements A2SContainer {
66

77
public Scrollbar(int direction) {
88
super(direction);
9+
A2SEvent.addListener(null, this);
910
}
1011

1112
public Scrollbar() {
1213
super();
14+
A2SEvent.addListener(null, this);
1315
}
1416

1517
public Scrollbar(int orientation, int value, int extent, int min, int max) {
1618
super(orientation, value, extent, min, max);
19+
A2SEvent.addListener(null, this);
1720
}
1821

1922
@Override
@@ -36,6 +39,17 @@ public int getValue() {
3639
return super.getValue();
3740
}
3841

42+
43+
// JCheckBox does not allow access to fireAdjustmentChanged.
44+
// It really does not matter who holds the listener, actually.
45+
A2SListener listener = null;
46+
@Override
47+
public A2SListener getA2SListener() {
48+
if (listener == null)
49+
listener = new A2SListener();
50+
return listener;
51+
}
52+
3953
// public void addMouseListener(MouseListener c) {
4054
// //super.addMouseListener(c);
4155
//
@@ -44,4 +58,5 @@ public int getValue() {
4458
// //super.addMouseMotionListener(c);
4559
// }
4660

61+
4762
}

sources/net.sf.j2s.java.core/src/java/awt/JSComponent.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ public static void ensurePropertyChangeListener(Component c, Component listener)
7676
*
7777
*/
7878

79+
public boolean isFramedApplet;
80+
7981
public String htmlName;
8082
protected int num;
8183
private static int incr;

0 commit comments

Comments
 (0)