Thanks to visit codestin.com
Credit goes to github.com

Skip to content

maybe nothing? #229

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bfdac97
legacy Hashtable upgrade to use JavaScript map, as in SwingJS version.
BobHanson Nov 28, 2023
c799ad7
upgrade for JavaScript Map part 2
BobHanson Dec 1, 2023
81bbdfd
Quaternion div(2) to arrayDiv
BobHanson Dec 1, 2023
63bfc38
Optimimizations for SwingJS runtime - Graphics2D, Rectangle,
BobHanson Dec 11, 2023
efaa9f8
Minor JSMOuse update and Float/Double efficiencies
BobHanson Dec 13, 2023
8a79cd1
Mouse event fix for right-button and shift drag
BobHanson Dec 14, 2023
b60190b
fix of optimization of JSGraphics2D AffineTransform save/restore
BobHanson Dec 14, 2023
cc89039
fixes issue with resize release over applet
BobHanson Dec 14, 2023
cd55f14
JSON parser changed to LinkedHashMap to ensure order-by-added rerieval.
BobHanson Dec 23, 2023
bd37505
allowing x-www-encoded file transfer; bug in GET
BobHanson Dec 23, 2023
c80fc16
javajs/http and javajs/util/JSONParser
BobHanson Dec 23, 2023
1cf235d
Update README.md
BobHanson Dec 31, 2023
5cc4bee
expanding JSUtil to include Java open URL in browser
BobHanson Jan 4, 2024
e5a0f95
JTabbedPane and JPopupMenu tweaks.
BobHanson Jan 7, 2024
4cfb80d
adds spellcheck="false" to test HTML System.out
BobHanson Jan 7, 2024
e7e77f0
template.html
BobHanson Jan 7, 2024
5f2ca67
fixes titled border failure after optimizing clip to simple int[4]
BobHanson Jan 7, 2024
5155425
TitleBorder broken in recent optimizations
BobHanson Jan 7, 2024
b7e620f
CIFDataParser allow selective reading
BobHanson Jan 19, 2024
254dade
Corrects J2sNative return from getResourceAsStream
BobHanson Jan 19, 2024
478c7ee
Better mouse and touch response
BobHanson Jan 19, 2024
795d5ef
removes T3d.addF
BobHanson Jan 19, 2024
b84c33d
site updates
BobHanson Jan 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,31 @@ within Eclipse, with immediate JavaScript testing and debugging in a browser bas
in Java. Using the java2script/SwingJS Eclipse plug-in, both Java .class files and their equivalent .js files are created simultaneously.


java2script/SwingJS includes an Eclipse plug-in (technically a "drop-in"), net.sf.j2s.core.zip
java2script/SwingJS includes an Eclipse plug-in (technically a "drop-in"), net.sf.j2s.cor

e.zip
(see https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/swingjs),
along with a JavaScript version of the Java Virtual Machine (SwingJS, https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.java.core/SwingJS-site.zip)
to allow the rapid and
automated production of browser-ready JavaScript versions of Java applications and applets.


# Working Examples

Examples of SwingJS applied to allow single-source Java+JavaScript development include:

Jmol-SwingJS https://github.com/BobHanson/Jmol-SwingJS

JalView-JS https://www.jalview.org/jalview-js

MathePrisma https://www.matheprisma.de/ (over 600 applets)

Open Source Physics (OSP) https://github.com/OpenSourcePhysics/osp/tree/swingJS

TrackerJS https://physlets.org/tracker/trackerJS



# QuickStart

See https://github.com/BobHanson/java2script/tree/master/sources/net.sf.j2s.core/dist and the README file in that directory.
Expand Down
Binary file modified sources/net.sf.j2s.core/dist/swingjs/j2s.core.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20231128000108
20240114215407
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/SwingJS-site.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/ver/5.0.1/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20231128000108
20240114215407
84 changes: 37 additions & 47 deletions sources/net.sf.j2s.core/src/j2s/jmol/J2SASTVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,12 @@ public boolean visit(PackageDeclaration node) {

public boolean visit(Block node) {
blockLevel++;
if (buffer != null) {
buffer.append("{\r\n");
}
ASTNode parent = node.getParent();
if (parent instanceof MethodDeclaration) {
MethodDeclaration method = (MethodDeclaration) parent;
Javadoc javadoc = method.getJavadoc();
/*
* if comment contains "@j2sNative", then output the given native JavaScript
* codes directly.
*/
// if comment contains "@j2sNative", then output the given native JavaScript
// codes directly.
if (!processJ2STags(javadoc, node, true)) {
return false;
}
Expand All @@ -118,10 +113,10 @@ public boolean visit(Block node) {
superclass = superclass.getSuperclass();
}
if (containsSuperPrivateMethod) {
buffer.append("var $private = Clazz.checkPrivateMethod (arguments);\r\n");
buffer.append("if ($private != null) {\r\n");
buffer.append("return $private.apply (this, arguments);\r\n");
buffer.append("}\r\n");
buffer.append("var $private = Clazz.checkPrivateMethod (arguments);\n");
buffer.append("if ($private != null) {\n");
buffer.append("return $private.apply (this, arguments);\n");
buffer.append("}\n");
}
}
}
Expand Down Expand Up @@ -244,8 +239,24 @@ protected boolean processJ2STags(Javadoc javadoc, Block node, boolean superVisit
if ("@j2sNative".equals(tagEl.getTagName())) {
if (superVisit)
super.visit(node);
if (buffer != null)
writeJavaScript(tagEl);
if (buffer != null) {
List<?> fragments = tagEl.fragments();
boolean isFirstLine = true;
StringBuffer buf = new StringBuffer();
for (Iterator<?> iterator = fragments.iterator(); iterator
.hasNext();) {
TextElement commentEl = (TextElement) iterator.next();
String text = commentEl.getText().trim();
if (isFirstLine) {
if (text.length() == 0) {
continue;
}
}
buf.append(text);
buf.append("\n");
}
buffer.append(fixCommentBlock(buf.toString()));
}
return false;
}
}
Expand All @@ -254,25 +265,6 @@ protected boolean processJ2STags(Javadoc javadoc, Block node, boolean superVisit
return true;
}

private void writeJavaScript(TagElement tagEl) {
List<?> fragments = tagEl.fragments();
boolean isFirstLine = true;
StringBuffer buf = new StringBuffer();
for (Iterator<?> iterator = fragments.iterator(); iterator
.hasNext();) {
TextElement commentEl = (TextElement) iterator.next();
String text = commentEl.getText().trim();
if (isFirstLine) {
if (text.length() == 0) {
continue;
}
}
buf.append(text);
buf.append("\r\n");
}
buffer.append(fixCommentBlock(buf.toString()));
}

private String fixCommentBlock(String text) {
if (text == null || text.length() == 0) {
return text;
Expand All @@ -284,16 +276,19 @@ private String fixCommentBlock(String text) {

/**
* Write JavaScript source from @j2sNative and @J2SIgnore
*
* @return true if JavaScript was written
*/
protected boolean writeJ2SSources(BodyDeclaration node, String tagName, String prefix, String suffix, boolean both) {
boolean existed = false;
protected boolean writeJ2STags(BodyDeclaration node, boolean needScope) {
String prefix = (needScope ? "{\n" : "");
String suffix = (needScope ? "\n}" : "");
Javadoc javadoc = node.getJavadoc();
if (javadoc != null) {
List<?> tags = javadoc.tags();
if (tags.size() != 0) {
for (Iterator<?> iter = tags.iterator(); iter.hasNext();) {
TagElement tagEl = (TagElement) iter.next();
if (tagName.equals(tagEl.getTagName())) {
if ("@j2sNative".equals(tagEl.getTagName())) {
List<?> fragments = tagEl.fragments();
StringBuffer buf = new StringBuffer();
boolean isFirstLine = true;
Expand All @@ -306,19 +301,16 @@ protected boolean writeJ2SSources(BodyDeclaration node, String tagName, String p
}
}
buf.append(text);
buf.append("\r\n");
buf.append("\n");
}
String sources = buf.toString().trim();
sources = sources.replaceAll("(\\/)-\\*|\\*-(\\/)", "$1*$2").replaceAll("<@>", "@");
buffer.append(prefix + sources + suffix);
existed = true;
return true;
}
}
}
}
if (existed && !both) {
return existed;
}
List<?> modifiers = node.modifiers();
for (Iterator<?> iter = modifiers.iterator(); iter.hasNext();) {
Object obj = iter.next();
Expand All @@ -327,9 +319,7 @@ protected boolean writeJ2SSources(BodyDeclaration node, String tagName, String p
String qName = annotation.getTypeName().getFullyQualifiedName();
int index = qName.indexOf("J2S");
if (index != -1) {
String annName = qName.substring(index);
annName = annName.replaceFirst("J2S", "@j2s");
if (annName.startsWith(tagName)) {
if (qName.substring(index).startsWith("J2SNative")) {
StringBuffer buf = new StringBuffer();
IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding();
if (annotationBinding != null) {
Expand All @@ -342,23 +332,23 @@ protected boolean writeJ2SSources(BodyDeclaration node, String tagName, String p
Object[] lines = (Object[]) value;
for (int j = 0; j < lines.length; j++) {
buf.append(lines[j]);
buf.append("\r\n");
buf.append("\n");
}
} else if (value instanceof String) {
buf.append(value);
buf.append("\r\n");
buf.append("\n");
}
}
}
}
}
buffer.append(prefix + buf.toString().trim() + suffix);
existed = true;
return true;
}
}
}
}
return existed;
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,8 @@ public boolean visit(TypeDeclaration node) {
allClassBindings.add(resolveBinding);
}
readJ2sImportTags(node);

processImports(node);
processJ2SRequireImport(node);
//visitForOptionals(node);
return super.visit(node);
}

Expand All @@ -345,7 +343,6 @@ public boolean visit(EnumDeclaration node) {
allClassBindings.add(resolveBinding);
}
readJ2sImportTags(node);

imports.add("java.lang.Enum");
processImports(node);
processJ2SRequireImport(node);
Expand Down Expand Up @@ -508,8 +505,8 @@ public boolean visit(MethodInvocation node) {

public boolean visit(Initializer node) {
if (J2SUtil.getJ2STag(node, "@j2sIgnore") != null) {
return false;
}
return false;
}
return super.visit(node);
}

Expand Down Expand Up @@ -842,7 +839,6 @@ private void processImports(AbstractTypeDeclaration node) {
if (mustAddDependency(qualifiedName, node, false)) {
imports.add(qn);
}
//musts.add(superBinding.getQualifiedName());
}
}
List<?> superInterfaces = null;
Expand Down
Loading