Skip to content

Commit 7a16d96

Browse files
committed
tests, transpiler
1 parent 0932924 commit 7a16d96

File tree

10 files changed

+153
-2
lines changed

10 files changed

+153
-2
lines changed
3 KB
Binary file not shown.
50 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200501101751
1+
20200501154159
Binary file not shown.
50 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200501101751
1+
20200501154159
3 KB
Binary file not shown.

sources/net.sf.j2s.java.core/src/java/util/concurrent/TimeUnit.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
package java.util.concurrent;
3737

38+
import swingjs.JSUtil;
39+
3840
/**
3941
* A <tt>TimeUnit</tt> represents time durations at a given unit of
4042
* granularity and provides utility methods to convert across units,
@@ -350,6 +352,7 @@ public void timedJoin(Thread thread, long timeout)
350352
* @see Thread#sleep
351353
*/
352354
public void sleep(long timeout) throws InterruptedException {
355+
JSUtil.notImplemented("TimeUnit.sleep will not work in JavaScript");
353356
if (timeout > 0) {
354357
long ms = toMillis(timeout);
355358
int ns = excessNanos(timeout, ms);
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package test;
2+
3+
import java.io.IOException;
4+
import java.net.URL;
5+
import java.net.URLConnection;
6+
import java.util.List;
7+
import java.util.Map;
8+
import java.util.Map.Entry;
9+
10+
public class CrossOriginRequestComPADRE {
11+
12+
public static void main(String[] args) {
13+
14+
System.out.println(
15+
"https://www.compadre.org/osp/services/REST/osp_tracker.cfm?OSPType=Tracker&OSPPrimary=Subject&OSPSubject=225&OSPSubjectDetail=248&OSPSubjectDetailDetail=1049");
16+
try {
17+
URL u = new URL("https://www.compadre.org/osp/services/REST/osp_tracker.cfm?OSPType=Tracker&OSPPrimary=Subject&OSPSubject=225&OSPSubjectDetail=248&OSPSubjectDetailDetail=1049");
18+
URLConnection uc = u.openConnection();
19+
Map<String, List<String>> fields = uc.getHeaderFields();
20+
System.out.println("URLConnection=\n\t"+uc);
21+
System.out.println("Header Fields n="+fields.size());
22+
for (Entry<String, List<String>> e : fields.entrySet()) {
23+
String key = e.getKey();
24+
List<String> list = e.getValue();
25+
System.out.println(key + " " + list);
26+
}
27+
} catch (IOException e) {
28+
e.getStackTrace();
29+
}
30+
31+
System.out.println(
32+
"\nhttps://www.compadre.org/profiles/bubble.jpg");
33+
try {
34+
URL u = new URL("https://www.compadre.org/profiles/bubble.jpg");
35+
URLConnection uc = u.openConnection();
36+
Map<String, List<String>> fields = uc.getHeaderFields();
37+
System.out.println("URLConnection=\n\t"+uc);
38+
System.out.println("Header Fields n="+fields.size());
39+
for (Entry<String, List<String>> e : fields.entrySet()) {
40+
String key = e.getKey();
41+
List<String> list = e.getValue();
42+
System.out.println(key + " " + list);
43+
}
44+
} catch (IOException e) {
45+
e.getStackTrace();
46+
}
47+
48+
49+
}
50+
51+
}
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
package test.components;
2+
3+
4+
import java.awt.BorderLayout;
5+
import java.awt.Component;
6+
import java.awt.Dimension;
7+
import java.awt.event.ActionListener;
8+
import java.util.concurrent.TimeUnit;
9+
10+
import javax.swing.JButton;
11+
import javax.swing.JFrame;
12+
import javax.swing.ProgressMonitor;
13+
import javax.swing.UIManager;
14+
15+
import javajs.async.AsyncSwingWorker;
16+
17+
public class ProgressMonitorExample {
18+
19+
private static ActionListener createStartTaskActionListener(Component parent) {
20+
UIManager.put("ProgressMonitor.progressText", "Test Progress");
21+
return (actionEvent) -> {
22+
new Thread(() -> {
23+
24+
new AsyncSwingWorker(parent, "Test Task", 200, 1, 100) {
25+
26+
@Override
27+
public void initAsync() {
28+
progressMonitor.setMillisToDecideToPopup(100);
29+
progressMonitor.setMillisToPopup(100);
30+
}
31+
32+
@Override
33+
public int doInBackgroundAsync(int i) {
34+
// nothing to do in this demo except increment i
35+
return ++i;
36+
}
37+
38+
@Override
39+
public void doneAsync() {
40+
// nothing to do when done for this demo (the ProgressManager is closed already)
41+
}
42+
43+
@Override
44+
public String getNote(int progress) {
45+
return "Task step: " + progress;
46+
}
47+
}.execute();
48+
}).start();
49+
};
50+
}
51+
52+
53+
54+
55+
private static ActionListener createStartTaskActionListenerOrig(Component parent) {
56+
// for progress monitor dialog title
57+
UIManager.put("ProgressMonitor.progressText", "Test Progress");
58+
return (ae) -> {
59+
// creating ProgressMonitor instance
60+
ProgressMonitor pm = new ProgressMonitor(parent, "Test Task", "Task starting", 0, 100);
61+
62+
// decide after 100 millis whether to show popup or not
63+
pm.setMillisToDecideToPopup(100);
64+
// after deciding if predicted time is longer than 100 show popup
65+
pm.setMillisToPopup(100);
66+
for (int i = 1; i <= 100; i++) {
67+
// updating ProgressMonitor note
68+
pm.setNote("Task step: " + i);
69+
// updating ProgressMonitor progress
70+
pm.setProgress(i);
71+
try {
72+
// delay for task simulation
73+
TimeUnit.MILLISECONDS.sleep(200);
74+
} catch (InterruptedException e) {
75+
System.err.println(e);
76+
}
77+
}
78+
pm.setNote("Task finished");
79+
};
80+
}
81+
82+
83+
public static void main(String[] args) {
84+
JFrame frame = createFrame("ProgressMonitor Example");
85+
JButton button = new JButton("start task");
86+
button.addActionListener(createStartTaskActionListener(frame));
87+
frame.add(button, BorderLayout.NORTH);
88+
frame.setVisible(true);
89+
}
90+
91+
public static JFrame createFrame(String title) {
92+
JFrame frame = new JFrame(title);
93+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
94+
frame.setSize(new Dimension(800, 700));
95+
return frame;
96+
}
97+
}

0 commit comments

Comments
 (0)