Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Binary file modified sources/net.sf.j2s.core/dist/swingjs/SwingJS-site.zip
Binary file not shown.
Binary file modified sources/net.sf.j2s.core/dist/swingjs/net.sf.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 @@
20191025154731
20191027191514
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/SwingJS-site.zip
Binary file not shown.
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/net.sf.j2s.core.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
20191025154731
20191027191514
3 changes: 2 additions & 1 deletion sources/net.sf.j2s.core/src/net/sf/j2s/core/CorePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class CorePlugin extends Plugin {
* register the bundle version properly. So we use VERSION here instead.
*
*/
public static String VERSION = "3.2.4.08";
public static String VERSION = "3.2.4.09";
// BH 2019.10.27 -- 3.2.4.09 fixes problem with method of name c() becoming c$() -- constructor
// BH 2019.10.25 -- 3.2.4.09 adds j2s.compiler.java.version (default 8)
// BH 2019.10.25 -- 3.2.4.09 adds j2s.break.on.error (default false)
// BH 2019.10.25 -- 3.2.4.09 fixes missing resource copy for git projects
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5014,7 +5014,8 @@ private static boolean classHasNoParameterMethod(ITypeBinding methodClass, Strin
|| j2sName.indexOf("$", 2) >= 0 || j2sName.equals("c$")
|| className != null && NameMapper.isMethodNonqualified(className, mBinding.getName()))
return j2sName;
return j2sName + "$";
// c() must be changed to c$$, not c$, which is the constructor
return (j2sName.equals("c") ? "c$$" : j2sName + "$");
}

/**
Expand Down
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
77 changes: 77 additions & 0 deletions sources/net.sf.j2s.java.core/doc/Differences.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Notes
=====
updated 10/26/19 -- adds information about File.createTempFile()
updated 8/16/19 -- minor typos and added summary paragraph
updated 7/19/19 -- clarification that AWT and Swing classes are supported directly
updated 5/13/19 -- Mandarin U+79D8 reserved character; Missing Math methods; int and long
Expand Down Expand Up @@ -233,6 +234,12 @@ a2s components, which in turn subclass JComponents. So no changes in code are ne
successfully transpiled over 500 applets using this strategy. (Kind of surprising, actually, that
the original Java developers did not see that option. But we have a hindsight advantage here.)

Temporary Files
===============

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

UNIMPLEMENTED CLASSES BY DESIGN
===============================
Expand Down Expand Up @@ -459,6 +466,76 @@ It's a simple modification:
System.out.println("int value is " + value);
}

javax.swing.JOptionPane dialogs
-------------------------------

For this action to work, the parentComponent must implement
propertyChangeListener, and any call to JOptionPanel should allow for
asynchronous response.

In addition, for compatibility with the Java version, implementation should
wrap the call to getConfirmDialog or getOptionDialog in a method call to
handle the Java:

onDialogReturn(JOptionPane.showConfirmDialog(parentFrame,
messageOrMessagePanel, "title", JOptionPane.OK_CANCEL_OPTION));

Then parentFrame.propertyChange(event) should also call onDialogReturn.

This will then work in both Java and JavaScript.

Note that there is an int and an Object version of onDialogReturn().


In JavaScript:

The initial return from JOptionPane.showConfirmDialog and showMessageDialog
will be NaN, testable as an impossible Java int value using ret !=
Math.floor(ret) if the parent implements PropertyChangeListeneer, or -1
(CLOSE_OPTION) if not.

For showOptionDialog (which returns Object) or showInputDialog (which returns
String), the initial return will be JDialog.ASYNCHRONOUS_OBJECT, testable as
((Object) ret) instanceof javax.swing.plaf.UIResource if the parent implements
PropertyChangeListeneer, or null if not.

The second return will be the desired return.

In Java:

The initial return will be the one and only modal final return.



For full compatibility, The calling method must not continue beyond this
call.

All of the standard Java events associated with Components are also
available.

Certain fall back mechanisms are possible, where onReturn does not exist, but
only for the falling cases:


For showMessageDialog, for WARNING_MESSAGE and ERROR_MESSAGE, a simple
JavaScript alert() is used, returning 0 (OK_OPTION) or -1 (CLOSED_OPTION).

For showInputDialog, if the message is a string, a simple JavaScript prompt()
with input box is used, returning the entered string or null.

For showConfirmDialog, a simple JavaScript confirm() is used, in which case:

for YES_NO_OPTION: YES_OPTION or NO_OPTION

for YES_NO_CANCEL_OPTION: YES_OPTION or CANCEL_OPTION

for OK_CANCEL_OPTION or any other: OK_OPTION or CANCEL_OPTION

Note that you should implement a response for CLOSED_OPTION for
showConfirmDialog. For other dialogs, a null return indicates the dialog was
closed, just as for Java.




native methods
Expand Down
261 changes: 261 additions & 0 deletions sources/net.sf.j2s.java.core/src/java/lang/ref/Reference.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,261 @@
/*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

package java.lang.ref;

import sun.misc.Cleaner;

/**
* Abstract base class for reference objects. This class defines the
* operations common to all reference objects. Because reference objects are
* implemented in close cooperation with the garbage collector, this class may
* not be subclassed directly.
*
* @author Mark Reinhold
* @since 1.2
*/

public abstract class Reference<T> {

/* A Reference instance is in one of four possible internal states:
*
* Active: Subject to special treatment by the garbage collector. Some
* time after the collector detects that the reachability of the
* referent has changed to the appropriate state, it changes the
* instance's state to either Pending or Inactive, depending upon
* whether or not the instance was registered with a queue when it was
* created. In the former case it also adds the instance to the
* pending-Reference list. Newly-created instances are Active.
*
* Pending: An element of the pending-Reference list, waiting to be
* enqueued by the Reference-handler thread. Unregistered instances
* are never in this state.
*
* Enqueued: An element of the queue with which the instance was
* registered when it was created. When an instance is removed from
* its ReferenceQueue, it is made Inactive. Unregistered instances are
* never in this state.
*
* Inactive: Nothing more to do. Once an instance becomes Inactive its
* state will never change again.
*
* The state is encoded in the queue and next fields as follows:
*
* Active: queue = ReferenceQueue with which instance is registered, or
* ReferenceQueue.NULL if it was not registered with a queue; next =
* null.
*
* Pending: queue = ReferenceQueue with which instance is registered;
* next = this
*
* Enqueued: queue = ReferenceQueue.ENQUEUED; next = Following instance
* in queue, or this if at end of list.
*
* Inactive: queue = ReferenceQueue.NULL; next = this.
*
* With this scheme the collector need only examine the next field in order
* to determine whether a Reference instance requires special treatment: If
* the next field is null then the instance is active; if it is non-null,
* then the collector should treat the instance normally.
*
* To ensure that a concurrent collector can discover active Reference
* objects without interfering with application threads that may apply
* the enqueue() method to those objects, collectors should link
* discovered objects through the discovered field. The discovered
* field is also used for linking Reference objects in the pending list.
*/

private T referent; /* Treated specially by GC */
//
// volatile ReferenceQueue<? super T> queue;
//
// /* When active: NULL
// * pending: this
// * Enqueued: next reference in queue (or this if last)
// * Inactive: this
// */
// @SuppressWarnings("rawtypes")
// Reference next;
//
// /* When active: next element in a discovered reference list maintained by GC (or this if last)
// * pending: next element in the pending list (or null if last)
// * otherwise: NULL
// */
// transient private Reference<T> discovered; /* used by VM */
//
//
// /* Object used to synchronize with the garbage collector. The collector
// * must acquire this lock at the beginning of each collection cycle. It is
// * therefore critical that any code holding this lock complete as quickly
// * as possible, allocate no new objects, and avoid calling user code.
// */
// static private class Lock { };
// private static Lock lock = new Lock();
//
//
// /* List of References waiting to be enqueued. The collector adds
// * References to this list, while the Reference-handler thread removes
// * them. This list is protected by the above lock object. The
// * list uses the discovered field to link its elements.
// */
// private static Reference<Object> pending = null;
//
// /* High-priority thread to enqueue pending References
// */
// private static class ReferenceHandler extends Thread {
//
// ReferenceHandler(ThreadGroup g, String name) {
// super(g, name);
// }
//
// public void run() {
// for (;;) {
// Reference<Object> r;
// synchronized (lock) {
// if (pending != null) {
// r = pending;
// pending = r.discovered;
// r.discovered = null;
// } else {
// // The waiting on the lock may cause an OOME because it may try to allocate
// // exception objects, so also catch OOME here to avoid silent exit of the
// // reference handler thread.
// //
// // Explicitly define the order of the two exceptions we catch here
// // when waiting for the lock.
// //
// // We do not want to try to potentially load the InterruptedException class
// // (which would be done if this was its first use, and InterruptedException
// // were checked first) in this situation.
// //
// // This may lead to the VM not ever trying to load the InterruptedException
// // class again.
// try {
// try {
// lock.wait();
// } catch (OutOfMemoryError x) { }
// } catch (InterruptedException x) { }
// continue;
// }
// }
//
// // Fast path for cleaners
// if (r instanceof Cleaner) {
// ((Cleaner)r).clean();
// continue;
// }
//
// ReferenceQueue<Object> q = r.queue;
// if (q != ReferenceQueue.NULL) q.enqueue(r);
// }
// }
// }
//
// static {
// ThreadGroup tg = Thread.currentThread().getThreadGroup();
// for (ThreadGroup tgn = tg;
// tgn != null;
// tg = tgn, tgn = tg.getParent());
// Thread handler = new ReferenceHandler(tg, "Reference Handler");
// /* If there were a special system-only priority greater than
// * MAX_PRIORITY, it would be used here
// */
// handler.setPriority(Thread.MAX_PRIORITY);
// handler.setDaemon(true);
// handler.start();
// }
//

/* -- Referent accessor and setters -- */

/**
* Returns this reference object's referent. If this reference object has
* been cleared, either by the program or by the garbage collector, then
* this method returns <code>null</code>.
*
* @return The object to which this reference refers, or
* <code>null</code> if this reference object has been cleared
*/
public T get() {
return this.referent;
}

/**
* Clears this reference object. Invoking this method will not cause this
* object to be enqueued.
*
* <p> This method is invoked only by Java code; when the garbage collector
* clears references it does so directly, without invoking this method.
*/
public void clear() {
this.referent = null;
}


/* -- Queue operations -- */

/**
* Tells whether or not this reference object has been enqueued, either by
* the program or by the garbage collector. If this reference object was
* not registered with a queue when it was created, then this method will
* always return <code>false</code>.
*
* @return <code>true</code> if and only if this reference object has
* been enqueued
*/
public boolean isEnqueued() {
return false;
// return (this.queue == ReferenceQueue.ENQUEUED);
}

/**
* Adds this reference object to the queue with which it is registered,
* if any.
*
* <p> This method is invoked only by Java code; when the garbage collector
* enqueues references it does so directly, without invoking this method.
*
* @return <code>true</code> if this reference object was successfully
* enqueued; <code>false</code> if it was already enqueued or if
* it was not registered with a queue when it was created
*/
public boolean enqueue() {
return false;
// return this.queue.enqueue(this);
}


/* -- Constructors -- */

Reference(T referent) {
this(referent, null);
}

Reference(T referent, ReferenceQueue<? super T> queue) {
this.referent = referent;
// this.queue = (queue == null) ? ReferenceQueue.NULL : queue;
}

}
Loading