Skip to content

Commit 2cb6c0e

Browse files
authored
Merge pull request #123 from BobHanson/master
minor fixes
2 parents a94e2ef + 1d03d16 commit 2cb6c0e

File tree

15 files changed

+330
-67
lines changed

15 files changed

+330
-67
lines changed
-1.01 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190724061400
1+
20190814182015
-1.01 KB
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20190724061400
1+
20190814182015
-1.01 KB
Binary file not shown.

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

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
Notes
22
=====
3+
updated 8/16/19 -- minor typos and added summary paragraph
34
updated 7/19/19 -- clarification that AWT and Swing classes are supported directly
45
updated 5/13/19 -- Mandarin U+79D8 reserved character; Missing Math methods; int and long
56
updated 5/10/19 -- adds a section on static issues in multi-(duplicate)-applet pages
67
updated 1/4/19 -- nio
7-
updated 9/15/18 -- adds integer 1/0 == 0
8+
updated 9/15/18 -- adds integer 1/0 == Infinity
89
updated 7/24/18 -- most classes replaced with https://github.com/frohoff/jdk8u-jdk
910
updated 6/5/17 -- reserved package name "window"
1011
updated 3/11/17 -- myClass.getField
@@ -537,14 +538,14 @@ qualified field and method names
537538

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

544545
missing Math methods
545546
--------------------
546547

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

567568
this.paint(getGraphics())
568569

569-
and really should not in Java, either, as it is technically a resource memory leak.
570+
and really should not work in Java, either, as it is technically a resource memory leak.
570571

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

@@ -601,7 +602,7 @@ Static classes such as:
601602

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

604-
AWTAccessor and AwtContext need to be customized
605+
AWTAccessor is not implemented.
605606

606607

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

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

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

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

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

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

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

795-
integer 1/0 == 0
796-
----------------
794+
integer 1/0 == Infinity
795+
-----------------------
797796

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

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

sources/net.sf.j2s.java.core/src/javax/swing/JFrame.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public void add(Component comp, Object constraints) {
170170
*/
171171
protected boolean rootPaneCheckingEnabled = false;
172172

173-
private boolean _boundsFrozen;
173+
private boolean 秘boundsFrozen;
174174

175175
/**
176176
* Constructs a new frame that is initially invisible.
@@ -915,15 +915,15 @@ protected String paramString() {
915915
+ ",rootPaneCheckingEnabled=" + rootPaneCheckingEnabledString;
916916
}
917917

918-
public void _freezeBounds(int w, int h) {
918+
public void 秘freezeBounds(int w, int h) {
919919
setSize(w, h);
920-
_boundsFrozen = true;
920+
秘boundsFrozen = true;
921921
resizable = false;
922922
}
923923

924924
@Override
925925
public void reshape(int x, int y, int width, int height) {
926-
if (!_boundsFrozen)
926+
if (!秘boundsFrozen)
927927
super.reshape(x, y, width, height);
928928
}
929929

sources/net.sf.j2s.java.core/src/swingjs/JSGraphics2D.java

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -790,9 +790,13 @@ public boolean hitClip(int x, int y, int width, int height) {
790790
return clipRect.intersects(x, y, width, height);
791791
}
792792

793+
private int alpha;
793794
private void setGraphicsColor(Color c) {
794795
if (c == null)
795796
return; // this was the case with a JRootPanel graphic call
797+
int a = c.getAlpha();
798+
if (a != alpha)
799+
ctx.globalAlpha = (alpha = a) / 256F;
796800
ctx.fillStyle = ctx.strokeStyle = JSToolkit.getCSSColor(c);
797801
}
798802

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

10121016
public void setAlpha(float f) {
1013-
/**
1014-
* @j2sNative
1015-
*
1016-
* this.ctx.globalAlpha = f;
1017-
*/
1018-
{
1019-
}
1017+
ctx.globalAlpha = f;
1018+
alpha = (int) Math.floor(f * 256 + 0.0039);
10201019
}
10211020

10221021
public HTML5Canvas getCanvas() {
@@ -1056,17 +1055,7 @@ public int mark() {
10561055
// note: This method is referred to in JComponent.java j2snative block as mark$
10571056
ctx.save();
10581057
Object[] map = new Object[SAVE_MAX];
1059-
1060-
float alpha = 0;
1061-
/**
1062-
* @j2sNative
1063-
*
1064-
* alpha = this.ctx.globalAlpha;
1065-
*
1066-
*/
1067-
{
1068-
}
1069-
map[SAVE_ALPHA] = Float.valueOf(alpha);
1058+
map[SAVE_ALPHA] = Float.valueOf(ctx.globalAlpha);
10701059
map[SAVE_COMPOSITE] = alphaComposite;
10711060
map[SAVE_STROKE] = currentStroke;
10721061
map[SAVE_TRANSFORM] = transform;
@@ -1089,8 +1078,9 @@ public void reset(int n0) {
10891078
Object[] map = HTML5CanvasContext2D.pop(ctx);
10901079
setComposite((Composite) map[SAVE_COMPOSITE]);
10911080
Float alpha = (Float) map[SAVE_ALPHA];
1092-
if (alpha != null)
1081+
if (alpha != null) {
10931082
setAlpha(alpha.floatValue());
1083+
}
10941084
setStroke((Stroke) map[SAVE_STROKE]);
10951085
setTransform((AffineTransform) map[SAVE_TRANSFORM]);
10961086
setFont((Font) map[SAVE_FONT]);

sources/net.sf.j2s.java.core/src/swingjs/api/js/HTML5CanvasContext2D.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ public class ImageData {
1616

1717
public String font, fillStyle, strokeStyle;
1818

19+
public float globalAlpha;
20+
1921
public abstract void drawImage(DOMNode img, int sx,
2022
int sy, int swidth, int sheight, int dx, int dy, int dwidth, int dheight);
2123

sources/net.sf.j2s.java.core/src/swingjs/plaf/JSComponentUI.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@
147147
public class JSComponentUI extends ComponentUI
148148
implements JSEventHandler, PropertyChangeListener, ChangeListener, DropTargetPeer {
149149

150+
public interface Embeddable {
151+
Object getEmbedded(String type);
152+
}
153+
150154
private static final int MENUITEM_OFFSET = 11;
151155

152156
final J2SInterface J2S = JSUtil.J2S;

0 commit comments

Comments
 (0)