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 @@
20190724061400
20190814182015
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 @@
20190724061400
20190814182015
Binary file modified sources/net.sf.j2s.java.core/dist/SwingJS-site.zip
Binary file not shown.
41 changes: 27 additions & 14 deletions sources/net.sf.j2s.java.core/doc/Differences.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
Notes
=====
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
updated 5/10/19 -- adds a section on static issues in multi-(duplicate)-applet pages
updated 1/4/19 -- nio
updated 9/15/18 -- adds integer 1/0 == 0
updated 9/15/18 -- adds integer 1/0 == Infinity
updated 7/24/18 -- most classes replaced with https://github.com/frohoff/jdk8u-jdk
updated 6/5/17 -- reserved package name "window"
updated 3/11/17 -- myClass.getField
Expand Down Expand Up @@ -537,14 +538,14 @@ qualified field and method names

In order to minimize the chance of added SwingJS field and method names colliding with ones
developers might use in subclassing Java classes, we have added U+79D8 (first character of Mandarin
"secrect") to the characters already disrecommended by Java documentation ("$" and "_"). The only problem
"secret") to the characters already disrecommended by Java documentation ("$" and "_"). The only problem
would be if you use that character followed by certain English words in certain classes. For example
\u79D8canvas for JComponents (in java.awt.JSComponent) and \u79D8byte (in java.io.File).

missing Math methods
--------------------

java.lang.Math is worked out, but some methods are missing, eithr because they
java.lang.Math is worked out, but some methods are missing, either because they
involve long integer value that are inaccessible in JavaScript, or because I just
didn't implement them. This is a result of continued Java development.
It is easy enough to add these methods if you have the source. They go into j2sClazz.js,
Expand All @@ -566,7 +567,7 @@ For example, this will definitely NOT work in SwingJS:

this.paint(getGraphics())

and really should not in Java, either, as it is technically a resource memory leak.
and really should not work in Java, either, as it is technically a resource memory leak.

Instead, if you really do not want to use repaint(), use this:

Expand Down Expand Up @@ -601,7 +602,7 @@ Static classes such as:

which are created using Class.forName are implemented using classes in the swingjs package.

AWTAccessor and AwtContext need to be customized
AWTAccessor is not implemented.


AWT component peers and component "ui" user interfaces
Expand Down Expand Up @@ -739,7 +740,7 @@ to BigInteger:
* the integer storage bit length to 24, giving 48 for long and leaving
* the last 16 bits clear for the exponent of the double number. This should
* not affect performance significantly. It does increase the storage
* size by about 33%. By bring an "int" to 3 bytes, we can easily construct
* size by about 33%. By bringing an "int" to 3 bytes, we can easily construct
* and use byte[] data intended for the original BitSet.

"Easily" may be a bit strong there. This was a serious challenge.
Expand Down Expand Up @@ -772,13 +773,11 @@ JEditorPane (JavaScript <div>)

For the initial implementation, we don't implement infinite undo/redo, and the abstract
document model is much less elaborate. Only PlainDocument (in the form of JSPlainDocument)
is implemented.
The Document returned by JTextField.getDocument() is a javax.swing.text.Document.
is implemented. The Document returned by JTextField.getDocument() is a javax.swing.text.Document.

all scrolling is handled by HTML5
javax.swing.AutoScroller is not implemented
All scrolling is handled by HTML5. javax.swing.AutoScroller is not implemented.
public static methods .stop, .isRunning, .processMouseDragged require true Java threading
javax.swing.text.View and its subclasses are not implemented.
and so are not implmented. javax.swing.text.View and its subclasses are not implemented.

The JS document model does not allow two text fields to address the same underlying document.

Expand All @@ -792,9 +791,23 @@ Matcher.start(groupID) is not supported.

java.util.Formatter will function correctly for all standard %... patterns.

integer 1/0 == 0
----------------
integer 1/0 == Infinity
-----------------------

1/0 in Java throws "java.lang.ArithmeticException: / by zero", but in JavaScript is just Infinity.




Summary
-------

These are all the known limitations of SwingJS. We have not found any of these limitations
to be show-stoppers. The primary issue for newcomers to SwingJS is having the source code.
You must check that source code for all your library jar files is available or, if you
choose, you will need to decompile those classes. We have used decompilation on some projects,
and it works just fine. So, technically, all we really need are JAR/class files. But the
source is by far superior. It's generally prettier, and it has the license information that
may or may not be present with the JAR or class files. Use class files at your own risk.

Bob Hanson
2019.08.16
8 changes: 4 additions & 4 deletions sources/net.sf.j2s.java.core/src/javax/swing/JFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public void add(Component comp, Object constraints) {
*/
protected boolean rootPaneCheckingEnabled = false;

private boolean _boundsFrozen;
private boolean 秘boundsFrozen;

/**
* Constructs a new frame that is initially invisible.
Expand Down Expand Up @@ -915,15 +915,15 @@ protected String paramString() {
+ ",rootPaneCheckingEnabled=" + rootPaneCheckingEnabledString;
}

public void _freezeBounds(int w, int h) {
public void 秘freezeBounds(int w, int h) {
setSize(w, h);
_boundsFrozen = true;
秘boundsFrozen = true;
resizable = false;
}

@Override
public void reshape(int x, int y, int width, int height) {
if (!_boundsFrozen)
if (!秘boundsFrozen)
super.reshape(x, y, width, height);
}

Expand Down
28 changes: 9 additions & 19 deletions sources/net.sf.j2s.java.core/src/swingjs/JSGraphics2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -790,9 +790,13 @@ public boolean hitClip(int x, int y, int width, int height) {
return clipRect.intersects(x, y, width, height);
}

private int alpha;
private void setGraphicsColor(Color c) {
if (c == null)
return; // this was the case with a JRootPanel graphic call
int a = c.getAlpha();
if (a != alpha)
ctx.globalAlpha = (alpha = a) / 256F;
ctx.fillStyle = ctx.strokeStyle = JSToolkit.getCSSColor(c);
}

Expand Down Expand Up @@ -1010,13 +1014,8 @@ public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) {
}

public void setAlpha(float f) {
/**
* @j2sNative
*
* this.ctx.globalAlpha = f;
*/
{
}
ctx.globalAlpha = f;
alpha = (int) Math.floor(f * 256 + 0.0039);
}

public HTML5Canvas getCanvas() {
Expand Down Expand Up @@ -1056,17 +1055,7 @@ public int mark() {
// note: This method is referred to in JComponent.java j2snative block as mark$
ctx.save();
Object[] map = new Object[SAVE_MAX];

float alpha = 0;
/**
* @j2sNative
*
* alpha = this.ctx.globalAlpha;
*
*/
{
}
map[SAVE_ALPHA] = Float.valueOf(alpha);
map[SAVE_ALPHA] = Float.valueOf(ctx.globalAlpha);
map[SAVE_COMPOSITE] = alphaComposite;
map[SAVE_STROKE] = currentStroke;
map[SAVE_TRANSFORM] = transform;
Expand All @@ -1089,8 +1078,9 @@ public void reset(int n0) {
Object[] map = HTML5CanvasContext2D.pop(ctx);
setComposite((Composite) map[SAVE_COMPOSITE]);
Float alpha = (Float) map[SAVE_ALPHA];
if (alpha != null)
if (alpha != null) {
setAlpha(alpha.floatValue());
}
setStroke((Stroke) map[SAVE_STROKE]);
setTransform((AffineTransform) map[SAVE_TRANSFORM]);
setFont((Font) map[SAVE_FONT]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class ImageData {

public String font, fillStyle, strokeStyle;

public float globalAlpha;

public abstract void drawImage(DOMNode img, int sx,
int sy, int swidth, int sheight, int dx, int dy, int dwidth, int dheight);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@
public class JSComponentUI extends ComponentUI
implements JSEventHandler, PropertyChangeListener, ChangeListener, DropTargetPeer {

public interface Embeddable {
Object getEmbedded(String type);
}

private static final int MENUITEM_OFFSET = 11;

final J2SInterface J2S = JSUtil.J2S;
Expand Down
59 changes: 43 additions & 16 deletions sources/net.sf.j2s.java.core/src/swingjs/plaf/JSFrameUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
* @author hansonr
*
*/
public class JSFrameUI extends JSWindowUI implements FramePeer {
public class JSFrameUI extends JSWindowUI implements FramePeer, JSComponentUI.Embeddable {

private static final Insets ZERO_INSETS = new Insets(0, 0, 0, 0);

Expand Down Expand Up @@ -111,24 +111,11 @@ public DOMNode updateDOMNode() {
h = defaultHeight;
DOMNode.setSize(frameNode, w, h);
DOMNode.setTopLeftAbsolute(frameNode, 0, 0);
String fname = frame.getName();
DOMNode node = DOMNode.getElement(fname + "-div");
DOMNode node = (DOMNode) getEmbedded("init");
if (node != null) {
embeddingNode = node;
doEmbed = (DOMNode.getWidth(embeddingNode) > 0);
doEmbed = (DOMNode.getWidth(node) > 0);
isHidden = !doEmbed;
if (doEmbed) {
frame.setUndecorated(true);
frame.setLocation(0, 0);
} else {
DOMNode.setStyles(embeddingNode, "position", "relative", "overflow", "hidden");
}

int ew = DOMNode.getWidth(node);
int eh = DOMNode.getHeight(node);
if (ew > 0 && eh > 0) {
frame._freezeBounds(ew, eh);
}
}
setWindowClass();
if (!frame.isUndecorated()) {
Expand Down Expand Up @@ -182,6 +169,46 @@ public DOMNode updateDOMNode() {
return domNode;
}

/**
* Note: DO NOT CHANGE THE NAME OF THIS METHOD
*
* @param frame
* @param type
* one of: "name", "node", "init", "dim"
* @return
*/
@Override
@SuppressWarnings("unused")
public Object getEmbedded(String type) {
String name = frame.getName();
DOMNode node = DOMNode.getElement(name + "-div");
if (node == null)
return null;
switch (type) {
case "name":
return name;
case "node":
return node;
case "dim":
return new Dimension(DOMNode.getWidth(node), DOMNode.getHeight(node));
case "init":
if (node == null)
return null;
Dimension dim = (Dimension) getEmbedded("dim");
if (dim.width > 0) {
frame.setUndecorated(true);
frame.setLocation(0, 0);
String resize = DOMNode.getStyle(node, "resize");
if (resize == "none")
frame.秘freezeBounds(dim.width, dim.height);
} else {
DOMNode.setStyles(node, "position", "relative", "overflow", "hidden");
}
return node;
}
return null;
}

@Override
protected boolean isFrameIndependent() {
return !doEmbed;
Expand Down
8 changes: 8 additions & 0 deletions sources/net.sf.j2s.java.core/src/test/Test_Array.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ class Test_Array extends Test_ {

static int y;
static {


int[][] ia = (int[][])c33def2b;
int[][] ib = ia.clone();
assert("[[I".equals(ib.getClass().getName()));

int x = 3;
y = x;
Test_Array[] a = new Test_Array[3];
Expand Down Expand Up @@ -82,8 +88,10 @@ public static void main(String[] args) {
double[] da = new double[3];
System.out.println(da[iI]);
assert (ii3[2] == 1 && j == 1);


System.out.println("Test_Array OK");
}


}
Loading