Skip to content

Commit bf3338b

Browse files
authored
Merge pull request #137 from BobHanson/master
async, SwingWorker, additional fixes
2 parents eb80dce + 0e93016 commit bf3338b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+3701
-575
lines changed
33.7 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20191031001912
1+
20191103054350
33.7 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20191031001912
1+
20191103054350
33.7 KB
Binary file not shown.

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

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Notes
22
=====
3+
4+
updated 11/03/19 -- adds information about File.exists() and points to src/test/async
35
updated 10/26/19 -- adds information about File.createTempFile()
46
updated 8/16/19 -- minor typos and added summary paragraph
57
updated 7/19/19 -- clarification that AWT and Swing classes are supported directly
@@ -147,7 +149,7 @@ Modal Dialogs
147149
Although true modal dialogs are not possible with only one thread, a functional equivalent --
148150
asynchronous modal dialogs -- is relatively easy to set up. All the JOptionPane dialogs will
149151
return PropertyChangeEvents to signal that they have been disposed of and containing the results.
150-
More on this later....
152+
See below.
151153

152154

153155
Native calls
@@ -234,12 +236,22 @@ a2s components, which in turn subclass JComponents. So no changes in code are ne
234236
successfully transpiled over 500 applets using this strategy. (Kind of surprising, actually, that
235237
the original Java developers did not see that option. But we have a hindsight advantage here.)
236238

237-
Temporary Files
238-
===============
239+
Working with Files
240+
==================
241+
242+
SwingJS will always return File.exists() == true. If this is being tested, provide a J2sNative
243+
block that gives an appropriate "OK" message, for example:
244+
245+
(/** @j2sNative 1 ? false : */ outputfile.exits())
246+
247+
or
248+
249+
(/** @j2sNative 1 ? true : */ inputfile.exits())
250+
251+
Temporary files can be created in SwingJS. SwingJS will maintain a pseudo-filesystem for files
252+
created with File.createTempFile(). This is useful in that closure of writing to a temporary file
253+
does not generate a pseudo-download to the user's machine.
239254

240-
SwingJS will maintain a pseudo-filesystem for files created with File.createTempFile(). This
241-
is useful in that closure of writing to the file does not generate a download to the user's
242-
machine (which typically requires user intervention).
243255

244256
UNIMPLEMENTED CLASSES BY DESIGN
245257
===============================
@@ -466,12 +478,20 @@ It's a simple modification:
466478
System.out.println("int value is " + value);
467479
}
468480

481+
482+
Developers are encouraged to create a separate class that handles general calls to JFileDialog.
483+
An example class can be found in the SwingJS distribution as
484+
485+
/sources/net.sf.j2s.java.core/src/test/async/AsyncFileChooser.java.
486+
487+
469488
javax.swing.JOptionPane dialogs
470489
-------------------------------
471490

472491
For this action to work, the parentComponent must implement
473492
propertyChangeListener, and any call to JOptionPanel should allow for
474-
asynchronous response.
493+
an asynchronous response, meaning that there is no actionable code following the
494+
call to the dialog opening.
475495

476496
In addition, for compatibility with the Java version, implementation should
477497
wrap the call to getConfirmDialog or getOptionDialog in a method call to
@@ -490,12 +510,12 @@ Note that there is an int and an Object version of onDialogReturn().
490510
In JavaScript:
491511

492512
The initial return from JOptionPane.showConfirmDialog and showMessageDialog
493-
will be NaN, testable as an impossible Java int value using ret !=
494-
Math.floor(ret) if the parent implements PropertyChangeListeneer, or -1
513+
will be (SwingJS) JDialog.ASYNCHRONOUS_INTEGER (NaN), testable as an impossible
514+
Java int value using ret != -(-ret) if the parent implements PropertyChangeListener, or -1
495515
(CLOSE_OPTION) if not.
496516

497517
For showOptionDialog (which returns Object) or showInputDialog (which returns
498-
String), the initial return will be JDialog.ASYNCHRONOUS_OBJECT, testable as
518+
String), the initial return will be (SwingJS) JDialog.ASYNCHRONOUS_OBJECT, testable as
499519
((Object) ret) instanceof javax.swing.plaf.UIResource if the parent implements
500520
PropertyChangeListeneer, or null if not.
501521

@@ -514,7 +534,7 @@ All of the standard Java events associated with Components are also
514534
available.
515535

516536
Certain fall back mechanisms are possible, where onReturn does not exist, but
517-
only for the falling cases:
537+
only for the following cases:
518538

519539

520540
For showMessageDialog, for WARNING_MESSAGE and ERROR_MESSAGE, a simple
@@ -535,8 +555,8 @@ Note that you should implement a response for CLOSED_OPTION for
535555
showConfirmDialog. For other dialogs, a null return indicates the dialog was
536556
closed, just as for Java.
537557

538-
539-
558+
Developers are encouraged to create a separate class that handles general calls.
559+
An example class can be found in the SwingJS distribution as src/test/async/AsyncDialog.java.
540560

541561
native methods
542562
--------------

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

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -448,36 +448,35 @@ public void setTrayIconWindow(boolean isTrayIconWindow) {
448448
}
449449

450450

451-
// /**
452-
// * This was never ever any use, since Frame subclasses Window
453-
// *
454-
// * Constructs a new, initially invisible window with the specified
455-
// * <code>Frame</code> as its owner. The window will not be focusable unless
456-
// * its owner is showing on the screen.
457-
// * <p>
458-
// * If there is a security manager, this method first calls the security
459-
// * manager's <code>checkTopLevelWindow</code> method with <code>this</code> as
460-
// * its argument to determine whether or not the window must be displayed with
461-
// * a warning banner.
462-
// *
463-
// * @param owner
464-
// * the <code>Frame</code> to act as owner or <code>null</code> if
465-
// * this window has no owner
466-
// * @exception IllegalArgumentException
467-
// * if the <code>owner</code>'s <code>GraphicsConfiguration</code>
468-
// * is not from a screen device
469-
// * @exception HeadlessException
470-
// * when <code>GraphicsEnvironment.isHeadless</code> returns
471-
// * <code>true</code>
472-
// *
473-
// * @see java.awt.GraphicsEnvironment#isHeadless
474-
// * @see java.lang.SecurityManager#checkTopLevelWindow
475-
// * @see #isShowing
476-
// *
477-
// */
478-
// public Window(Frame owner) {
479-
// this(owner, null);
480-
// }
451+
/**
452+
*
453+
* Constructs a new, initially invisible window with the specified
454+
* <code>Frame</code> as its owner. The window will not be focusable unless
455+
* its owner is showing on the screen.
456+
* <p>
457+
* If there is a security manager, this method first calls the security
458+
* manager's <code>checkTopLevelWindow</code> method with <code>this</code> as
459+
* its argument to determine whether or not the window must be displayed with
460+
* a warning banner.
461+
*
462+
* @param owner
463+
* the <code>Frame</code> to act as owner or <code>null</code> if
464+
* this window has no owner
465+
* @exception IllegalArgumentException
466+
* if the <code>owner</code>'s <code>GraphicsConfiguration</code>
467+
* is not from a screen device
468+
* @exception HeadlessException
469+
* when <code>GraphicsEnvironment.isHeadless</code> returns
470+
* <code>true</code>
471+
*
472+
* @see java.awt.GraphicsEnvironment#isHeadless
473+
* @see java.lang.SecurityManager#checkTopLevelWindow
474+
* @see #isShowing
475+
*
476+
*/
477+
public Window(Frame owner) {
478+
this(owner, null);
479+
}
481480

482481
/**
483482
* Constructs a new, initially invisible window with the specified

sources/net.sf.j2s.java.core/src/java/io/BufferedOutputStream.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,13 @@ public synchronized void write(int oneByte) throws IOException {
176176
}
177177
buf[count++] = (byte) oneByte;
178178
}
179+
180+
@Override
181+
public int hashCode() {
182+
try {
183+
flush();
184+
} catch (IOException e) {
185+
}
186+
return out.hashCode();
187+
}
179188
}

sources/net.sf.j2s.java.core/src/java/io/ByteArrayOutputStream.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,5 +282,10 @@ public synchronized String toString(int hibyte) {
282282
@Override
283283
public void close() throws IOException {
284284
}
285+
286+
@Override
287+
public int hashCode() {
288+
return buf.hashCode();
289+
}
285290

286291
}

sources/net.sf.j2s.java.core/src/java/lang/Class.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/*
2+
23
* Copyright 1994-2006 Sun Microsystems, Inc. All Rights Reserved.
34
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
45
*
@@ -664,7 +665,7 @@ private String getName0() {
664665
* code = this.$clazz$.__CLASS_NAME$__ ||
665666
* this.$clazz$.__CLASS_NAME__;
666667
*
667-
* if (code) return code;
668+
* if (code) return (code.indexOf(".") < 0 ? "java.lang." + code : code);
668669
*
669670
* code = this.$clazz$.__PARAMCODE;
670671
*

0 commit comments

Comments
 (0)