Skip to content

Commit 2378e72

Browse files
authored
Merge pull request #127 from BobHanson/hanson1
character set note
2 parents 44689c4 + 899209a commit 2378e72

File tree

18 files changed

+842
-116
lines changed

18 files changed

+842
-116
lines changed
567 Bytes
Binary file not shown.
191 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20191103225630
1+
20191105122130
567 Bytes
Binary file not shown.
191 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20191103225630
1+
20191105122130

sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptCompilationParticipant.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public void buildFinished(IJavaProject project) {
137137
int ntotal = 0, nerror = 0;
138138
for (int j = 0; j < contexts.size(); j++) {
139139
BuildContext[] files = contexts.get(j);
140-
System.out.println("J2S building JavaScript for " + files.length + " file"+plural(files.length));
140+
System.out.println("J2S building JavaScript for " + files.length + " file" + plural(files.length));
141141

142142
for (int i = 0, n = files.length; i < n; i++) {
143143
// trying to keep the progess monitor running - didn't work
@@ -157,23 +157,29 @@ public void buildFinished(IJavaProject project) {
157157
System.out.println("J2S excluded " + filePath);
158158
} else {
159159
System.out.println("J2S transpiling (" + (i + 1) + "/" + n + ") " + filePath);
160-
if (j2sCompiler.compileToJavaScript(f)) {
161-
ntotal++;
162-
} else {
163-
nerror++;
164-
System.out.println("J2S Error processing " + filePath);
165-
if (breakOnError)
166-
break;
160+
try {
161+
if (j2sCompiler.compileToJavaScript(f)) {
162+
ntotal++;
163+
} else {
164+
nerror++;
165+
System.out.println("J2S Error processing " + filePath);
166+
if (breakOnError)
167+
break;
168+
}
169+
} catch (Exception e) {
170+
System.out.println("J2S Exception " + e);
171+
e.printStackTrace(System.out);
172+
e.printStackTrace(System.err);
167173
}
168174
}
169175
}
170176
}
171177
j2sCompiler.finalizeProject();
172178
contexts = null;
173-
System.out.println(
174-
"J2S buildFinished " + ntotal + " file"+plural(ntotal) + " transpiled for " + project.getProject().getLocation());
179+
System.out.println("J2S buildFinished " + ntotal + " file" + plural(ntotal) + " transpiled for "
180+
+ project.getProject().getLocation());
175181
System.out.println("J2S buildFinished nerror = " + nerror + " " + new Date());
176-
}
182+
}
177183
isCleanBuild = false;
178184
}
179185

sources/net.sf.j2s.core/src/net/sf/j2s/core/Java2ScriptCompiler.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,18 @@ boolean compileToJavaScript(IFile javaSource) {
390390
if (pt >= 0)
391391
packageName = packageName.substring(0, pt);
392392
if (!copyResources.contains(packageName)) {
393-
copyResources.add(packageName);
394-
String sourceDir = sourceLocation.substring(0, sourceLocation.lastIndexOf("/" + packageName + "/"));
395-
File src = new File(sourceDir, packageName);
396-
File dest = new File(j2sPath, packageName);
397-
copySiteResources(src, dest);
393+
copyResources.add(packageName);
394+
pt = sourceLocation.lastIndexOf("/" + packageName + "/");
395+
if (pt <= 0) {
396+
// also don't allow "" root directory
397+
if (!"_".equals(packageName))
398+
System.out.println("J2S ignoring bad sourceLocation for package \"" + packageName + "\": " + sourceLocation);
399+
} else {
400+
String sourceDir = sourceLocation.substring(0, pt);
401+
File src = new File(sourceDir, packageName);
402+
File dest = new File(j2sPath, packageName);
403+
copySiteResources(src, dest);
404+
}
398405
}
399406
}
400407
return true;
567 Bytes
Binary file not shown.

sources/net.sf.j2s.java.core/doc/Differences.txt

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
Notes
22
=====
33

4+
---IMPORTANT CHARACTER SET NOTE---
5+
6+
It is critical that all development work in Java2Script
7+
be done in UTF-8. This means:
8+
9+
- making sure your Exclipse project is set up for UTF-8 (not the Eclipse default?)
10+
- making sure your server can serve up UTF-8 by default for any browser-loaded files
11+
- making sure you don't edit a Java2Script class file or one of the site .js files
12+
using a non-UTF-8 editor. It may replace non-Latin characters with "?" or garbage.
13+
14+
In particular, the Mandarin character 秘 (mi; "secret") is used extensively throughout
15+
the SwingJS class files to distinguish j2s-specific fields and methods that must not
16+
ever be overridden by subclasses. As in java.lang.Thread.java:
17+
18+
public static JSThread 秘thisThread;
19+
20+
21+
----------------------------------
22+
23+
424
updated 11/03/19 -- adds information about File.exists() and points to src/test/async
525
updated 10/26/19 -- adds information about File.createTempFile()
626
updated 8/16/19 -- minor typos and added summary paragraph
@@ -557,6 +577,46 @@ closed, just as for Java.
557577

558578
Developers are encouraged to create a separate class that handles general calls.
559579
An example class can be found in the SwingJS distribution as src/test/async/AsyncDialog.java.
580+
Very simple modifications to the Java allows asynchronous operation using AsyncDialog. Here
581+
is a simple "do you want to close this frame" example, where you can see that what we have
582+
done is to set the reply into an ActionListener that is defined in the constructor of
583+
the AsyncDisplay object:
584+
585+
// Original:
586+
//
587+
// private void promptQuit() {
588+
// int sel = JOptionPane.showConfirmDialog(null, PROMPT_EXIT, NAME, JOptionPane.YES_NO_OPTION);
589+
// switch (sel) {
590+
// case JOptionPane.YES_OPTION:
591+
// resultsTab.clean();
592+
// seqs.dispose();
593+
// if (fromMain) {
594+
// System.exit(0);
595+
// }
596+
// break;
597+
// }
598+
// }
599+
600+
private void promptQuitAsync() {
601+
new AsyncDialog(new ActionListener() {
602+
603+
@Override
604+
public void actionPerformed(ActionEvent e) {
605+
int sel = ((AsyncDialog)e.getSource()).getOption();
606+
switch (sel) {
607+
case JOptionPane.YES_OPTION:
608+
resultsTab.clean();
609+
seqs.dispose();
610+
if (fromMain) {
611+
System.exit(0);
612+
}
613+
break;
614+
}
615+
}}).showConfirmDialog(null, PROMPT_EXIT, NAME, JOptionPane.YES_NO_OPTION);
616+
}
617+
618+
Very simple!
619+
560620

561621
native methods
562622
--------------

0 commit comments

Comments
 (0)