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.
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 @@
20191031001912
20191103054350
Binary file modified sources/net.sf.j2s.core/dist/swingjs/ver/3.2.4/SwingJS-site.zip
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 @@
20191031001912
20191103054350
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
46 changes: 33 additions & 13 deletions sources/net.sf.j2s.java.core/doc/Differences.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Notes
=====

updated 11/03/19 -- adds information about File.exists() and points to src/test/async
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
Expand Down Expand Up @@ -147,7 +149,7 @@ Modal Dialogs
Although true modal dialogs are not possible with only one thread, a functional equivalent --
asynchronous modal dialogs -- is relatively easy to set up. All the JOptionPane dialogs will
return PropertyChangeEvents to signal that they have been disposed of and containing the results.
More on this later....
See below.


Native calls
Expand Down Expand Up @@ -234,12 +236,22 @@ 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
===============
Working with Files
==================

SwingJS will always return File.exists() == true. If this is being tested, provide a J2sNative
block that gives an appropriate "OK" message, for example:

(/** @j2sNative 1 ? false : */ outputfile.exits())

or

(/** @j2sNative 1 ? true : */ inputfile.exits())

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

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 @@ -466,12 +478,20 @@ It's a simple modification:
System.out.println("int value is " + value);
}


Developers are encouraged to create a separate class that handles general calls to JFileDialog.
An example class can be found in the SwingJS distribution as

/sources/net.sf.j2s.java.core/src/test/async/AsyncFileChooser.java.


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

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

In addition, for compatibility with the Java version, implementation should
wrap the call to getConfirmDialog or getOptionDialog in a method call to
Expand All @@ -490,12 +510,12 @@ 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
will be (SwingJS) JDialog.ASYNCHRONOUS_INTEGER (NaN), testable as an impossible
Java int value using ret != -(-ret) if the parent implements PropertyChangeListener, 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
String), the initial return will be (SwingJS) JDialog.ASYNCHRONOUS_OBJECT, testable as
((Object) ret) instanceof javax.swing.plaf.UIResource if the parent implements
PropertyChangeListeneer, or null if not.

Expand All @@ -514,7 +534,7 @@ 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:
only for the following cases:


For showMessageDialog, for WARNING_MESSAGE and ERROR_MESSAGE, a simple
Expand All @@ -535,8 +555,8 @@ 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.



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

native methods
--------------
Expand Down
59 changes: 29 additions & 30 deletions sources/net.sf.j2s.java.core/src/java/awt/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,36 +448,35 @@ public void setTrayIconWindow(boolean isTrayIconWindow) {
}


// /**
// * This was never ever any use, since Frame subclasses Window
// *
// * Constructs a new, initially invisible window with the specified
// * <code>Frame</code> as its owner. The window will not be focusable unless
// * its owner is showing on the screen.
// * <p>
// * If there is a security manager, this method first calls the security
// * manager's <code>checkTopLevelWindow</code> method with <code>this</code> as
// * its argument to determine whether or not the window must be displayed with
// * a warning banner.
// *
// * @param owner
// * the <code>Frame</code> to act as owner or <code>null</code> if
// * this window has no owner
// * @exception IllegalArgumentException
// * if the <code>owner</code>'s <code>GraphicsConfiguration</code>
// * is not from a screen device
// * @exception HeadlessException
// * when <code>GraphicsEnvironment.isHeadless</code> returns
// * <code>true</code>
// *
// * @see java.awt.GraphicsEnvironment#isHeadless
// * @see java.lang.SecurityManager#checkTopLevelWindow
// * @see #isShowing
// *
// */
// public Window(Frame owner) {
// this(owner, null);
// }
/**
*
* Constructs a new, initially invisible window with the specified
* <code>Frame</code> as its owner. The window will not be focusable unless
* its owner is showing on the screen.
* <p>
* If there is a security manager, this method first calls the security
* manager's <code>checkTopLevelWindow</code> method with <code>this</code> as
* its argument to determine whether or not the window must be displayed with
* a warning banner.
*
* @param owner
* the <code>Frame</code> to act as owner or <code>null</code> if
* this window has no owner
* @exception IllegalArgumentException
* if the <code>owner</code>'s <code>GraphicsConfiguration</code>
* is not from a screen device
* @exception HeadlessException
* when <code>GraphicsEnvironment.isHeadless</code> returns
* <code>true</code>
*
* @see java.awt.GraphicsEnvironment#isHeadless
* @see java.lang.SecurityManager#checkTopLevelWindow
* @see #isShowing
*
*/
public Window(Frame owner) {
this(owner, null);
}

/**
* Constructs a new, initially invisible window with the specified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,13 @@ public synchronized void write(int oneByte) throws IOException {
}
buf[count++] = (byte) oneByte;
}

@Override
public int hashCode() {
try {
flush();
} catch (IOException e) {
}
return out.hashCode();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -282,5 +282,10 @@ public synchronized String toString(int hibyte) {
@Override
public void close() throws IOException {
}

@Override
public int hashCode() {
return buf.hashCode();
}

}
3 changes: 2 additions & 1 deletion sources/net.sf.j2s.java.core/src/java/lang/Class.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*

* Copyright 1994-2006 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -664,7 +665,7 @@ private String getName0() {
* code = this.$clazz$.__CLASS_NAME$__ ||
* this.$clazz$.__CLASS_NAME__;
*
* if (code) return code;
* if (code) return (code.indexOf(".") < 0 ? "java.lang." + code : code);
*
* code = this.$clazz$.__PARAMCODE;
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright (c) 1998, 2012, 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;

/**
* This class extends <tt>ThreadLocal</tt> to provide inheritance of values
* from parent thread to child thread: when a child thread is created, the
* child receives initial values for all inheritable thread-local variables
* for which the parent has values. Normally the child's values will be
* identical to the parent's; however, the child's value can be made an
* arbitrary function of the parent's by overriding the <tt>childValue</tt>
* method in this class.
*
* <p>Inheritable thread-local variables are used in preference to
* ordinary thread-local variables when the per-thread-attribute being
* maintained in the variable (e.g., User ID, Transaction ID) must be
* automatically transmitted to any child threads that are created.
*
* @author Josh Bloch and Doug Lea
* @see ThreadLocal
* @since 1.2
*/

public class InheritableThreadLocal<T> extends ThreadLocal<T> {
/**
* Computes the child's initial value for this inheritable thread-local
* variable as a function of the parent's value at the time the child
* thread is created. This method is called from within the parent
* thread before the child is started.
* <p>
* This method merely returns its input argument, and should be overridden
* if a different behavior is desired.
*
* @param parentValue the parent thread's value
* @return the child thread's initial value
*/
protected T childValue(T parentValue) {
return parentValue;
}

/**
* Get the map associated with a ThreadLocal.
*
* @param t the current thread
*/
ThreadLocalMap getMap(Thread t) {
return t.inheritableThreadLocals;
}

/**
* Create the map associated with a ThreadLocal.
*
* @param t the current thread
* @param firstValue value for the initial entry of the table.
*/
void createMap(Thread t, T firstValue) {
t.inheritableThreadLocals = new ThreadLocalMap(this, firstValue);
}
}
26 changes: 13 additions & 13 deletions sources/net.sf.j2s.java.core/src/java/lang/Thread.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,16 @@ private static synchronized int nextThreadNum() {
return threadInitNumber++;
}

// /* ThreadLocal values pertaining to this thread. This map is maintained
// * by the ThreadLocal class. */
// ThreadLocal.ThreadLocalMap threadLocals = null;
//
// /*
// * InheritableThreadLocal values pertaining to this thread. This map is
// * maintained by the InheritableThreadLocal class.
// */
// ThreadLocal.ThreadLocalMap inheritableThreadLocals = null;
//
/* ThreadLocal values pertaining to this thread. This map is maintained
* by the ThreadLocal class. */
ThreadLocal.ThreadLocalMap threadLocals = null;

/*
* InheritableThreadLocal values pertaining to this thread. This map is
* maintained by the InheritableThreadLocal class.
*/
ThreadLocal.ThreadLocalMap inheritableThreadLocals = null;

// /*
// * The requested stack size for this thread, or 0 if the creator did
// * not specify a stack size. It is up to the VM to do whatever it
Expand Down Expand Up @@ -432,9 +432,9 @@ private void init(ThreadGroup g, Runnable target, String name,
// acc != null ? acc : AccessController.getContext();
this.target = target;
setPriority(priority);
// if (parent.inheritableThreadLocals != null)
// this.inheritableThreadLocals =
// ThreadLocal.createInheritedMap(parent.inheritableThreadLocals);
if (parent.inheritableThreadLocals != null)
this.inheritableThreadLocals =
ThreadLocal.createInheritedMap(parent.inheritableThreadLocals);
/* Stash the specified stack size in case the VM cares */
// this.stackSize = stackSize;

Expand Down
Loading