Skip to content

Commit 2808d4a

Browse files
committed
JLayeredPane z-index; see Test_Video
transparent backgrounds working.
1 parent 774962a commit 2808d4a

File tree

16 files changed

+201
-100
lines changed

16 files changed

+201
-100
lines changed
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200419115937
1+
20200420001218
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20200419115937
1+
20200420001218
Binary file not shown.

sources/net.sf.j2s.java.core/src/java/applet/JSApplet.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ public JSApplet() {
8888
// }
8989
}
9090

91-
91+
public Object getClientProperty(Object key) {
92+
return null;
93+
}
94+
9295
/**
9396
* SwingJS -- from Window
9497
*

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
package java.awt;
2929

3030
import java.awt.event.KeyListener;
31+
import java.awt.image.BufferedImage;
3132
import java.awt.peer.ComponentPeer;
3233
import java.awt.peer.LightweightPeer;
3334
import java.beans.PropertyChangeListener;
@@ -52,6 +53,7 @@
5253
import swingjs.JSFrameViewer;
5354
import swingjs.JSGraphics2D;
5455
import swingjs.JSUtil;
56+
import swingjs.api.js.DOMNode;
5557
import swingjs.api.js.HTML5Canvas;
5658
import swingjs.plaf.JSComponentUI;
5759

@@ -113,6 +115,7 @@ public interface A2SWrappedComponent {
113115
protected int 秘num;
114116
private static int 秘incr;
115117
private Insets 秘tempInsets;
118+
public JSGraphics2D 秘g;
116119
public JSGraphics2D 秘gtemp; // indicates that we are painting, so that g.setBackground() should also be set
117120

118121
public boolean 秘isRootPane, 秘isContentPane;
@@ -578,6 +581,19 @@ public void removeKeyListener(KeyListener l) {
578581
return 秘isFocusableSet && isFocusable();
579582
}
580583

584+
585+
protected Graphics 秘checkG() {
586+
boolean isNew = ((Object) 秘g) == Boolean.TRUE;
587+
if (isNew || 秘g.getWidth() != width || 秘g.getHeight() != height) {
588+
if (!isNew)
589+
DOMNode.dispose(秘g.getCanvas());
590+
秘g = (JSGraphics2D) (Object) ((BufferedImage) createImage(width, height)).秘getImageGraphic();
591+
DOMNode c = 秘g.getCanvas();
592+
秘getUI().getDOMNode().prepend(c);
593+
}
594+
return (Graphics) (Object) this.秘g;
595+
}
596+
581597
/**
582598
* This method is added to ensure that if a jpanel or other object's
583599
* background is painted to, that it becomes transparent -- since the actual

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

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import java.awt.event.InputEvent;
5252
import java.awt.event.KeyEvent;
5353
import java.awt.event.MouseEvent;
54+
import java.awt.image.BufferedImage;
5455
import java.beans.PropertyChangeListener;
5556
import java.util.ArrayList;
5657
import java.util.Enumeration;
@@ -75,6 +76,7 @@
7576
import sun.font.FontDesignMetrics;
7677
import swingjs.JSGraphics2D;
7778
import swingjs.JSUtil;
79+
import swingjs.api.js.DOMNode;
7880
import swingjs.plaf.JSComponentUI;
7981

8082
/**
@@ -581,18 +583,11 @@ public JComponent() {
581583
* @return a <code>Graphics</code> object configured for this component
582584
*/
583585
protected Graphics getComponentGraphics(Graphics g) {
584-
Graphics componentGraphics = g;
585-
// if (ui != null && DEBUG_GRAPHICS_LOADED) {
586-
// if ((DebugGraphics.debugComponentCount() != 0) &&
587-
// (shouldDebugGraphics() != 0) &&
588-
// !(g instanceof DebugGraphics)) {
589-
// componentGraphics = new DebugGraphics(g,this);
590-
// }
591-
// }
592-
componentGraphics.setColor(getForeground());
593-
componentGraphics.setFont(getFont());
594-
595-
return componentGraphics;
586+
if (秘g != null)
587+
g = 秘checkG();
588+
g.setColor(getForeground());
589+
g.setFont(getFont());
590+
return g;
596591
}
597592

598593
/**
@@ -624,13 +619,7 @@ protected void paintComponent(Graphics g) {
624619
if (ui != null && g != null) {
625620
Graphics scratchGraphics = g.create();
626621
try {
627-
// note that this update will fill the component's background, but
628-
// that is not what we are worried about. What we are worried about
629-
// is if this method is overridden and is written to.
630-
//秘isBackgroundPainted = false;
631622
ui.update(scratchGraphics, this);
632-
//JSGraphics2D jsg = 秘getJSGraphic2D(scratchGraphics);
633-
//秘isBackgroundPainted = (jsg != null && jsg.isBackgroundPainted());
634623
} catch (Throwable t) {
635624
t.printStackTrace();
636625
} finally {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public class JLayeredPane extends JComponent /* implements Accessible */ {
171171
/** Convenience object defining the Drag layer. Equivalent to new Integer(400).*/
172172
public final static Integer DRAG_LAYER = new Integer(400);
173173
/** Convenience object defining the Frame Content layer.
174-
* This layer is normally only use to positon the contentPane and menuBar
174+
* This layer is normally only use to position the contentPane and menuBar
175175
* components of JFrame.
176176
* Equivalent to new Integer(-30000).
177177
* @see JFrame

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

Lines changed: 11 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import java.awt.FontMetrics;
99
import java.awt.GradientPaint;
1010
import java.awt.Graphics;
11-
import java.awt.Graphics2D;
1211
import java.awt.GraphicsConfiguration;
1312
import java.awt.Image;
1413
import java.awt.Paint;
@@ -34,13 +33,9 @@
3433
import java.awt.image.RenderedImage;
3534
import java.awt.image.renderable.RenderableImage;
3635
import java.text.AttributedCharacterIterator;
37-
import java.util.ArrayList;
3836
import java.util.Hashtable;
39-
import java.util.List;
4037
import java.util.Map;
41-
import java.util.Map.Entry;
4238

43-
import sun.font.TextSource;
4439
import swingjs.api.js.DOMNode;
4540
import swingjs.api.js.HTML5Canvas;
4641
import swingjs.api.js.HTML5CanvasContext2D;
@@ -65,8 +60,6 @@ public class JSGraphics2D implements
6560
private static final int DRAW_CLOSE = 1;
6661
private static final int FILL = 2;
6762

68-
// private boolean backgroundPainted;
69-
7063
public int constrainX;
7164
public int constrainY;
7265

@@ -249,7 +242,6 @@ private double toRad(double a) {
249242
}
250243

251244
public void clearRect(int x, int y, int width, int height) {
252-
// backgroundPainted = true;
253245
clearRectPriv(x, y, width, height);
254246
}
255247

@@ -325,7 +317,6 @@ public void drawRect(int x, int y, int width, int height) {
325317
public void fillRect(int x, int y, int width, int height) {
326318
if (width <= 0 || height <= 0)
327319
return;
328-
// backgroundPainted = true;
329320
ctx.fillRect(x, y, width, height);
330321
}
331322

@@ -587,7 +578,6 @@ public boolean drawImage(Image img, int x, int y, int width, int height, Color b
587578
public boolean drawImage(Image img, int x, int y, int width, int height, ImageObserver observer) {
588579
if (width <= 0 || height <= 0)
589580
return true;
590-
// backgroundPainted = true;
591581
if (img != null) {
592582
DOMNode imgNode = ((BufferedImage) img).秘getImageNode(BufferedImage.GET_IMAGE_ALLOW_NULL);
593583
if (imgNode == null) {
@@ -625,7 +615,6 @@ public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1,
625615
@SuppressWarnings("unused")
626616
public boolean drawImage(Image img, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2,
627617
ImageObserver observer) {
628-
// backgroundPainted = true;
629618
if (img != null) {
630619
byte[] bytes = null;
631620
DOMNode imgNode = ((BufferedImage) img).秘getImageNode(BufferedImage.GET_IMAGE_ALLOW_NULL);
@@ -770,9 +759,6 @@ private void getBuf8(int x, int y, int w, int h) {
770759
}
771760
}
772761

773-
private void loadCTX(int x, int y, int w, int h, int[] pixels, double m4, double m5, boolean isOpaque) {
774-
}
775-
776762
private static boolean isTranslationOnly(double[] m) {
777763
return (m[0] == 1 && m[1] == 0 && m[2] == 0 && m[3] == 1);
778764
}
@@ -988,15 +974,14 @@ public boolean hitClip(int x, int y, int width, int height) {
988974
return clipRect.intersects(x, y, width, height);
989975
}
990976

991-
private int alpha;
992-
993977
private void setGraphicsColor(Color c) {
994978
if (c == null)
995979
return; // this was the case with a JRootPanel graphic call
996980
int a = c.getAlpha();
997981
// set alpha only if it is new and if this color has an alpha not 0xFF
998-
if (a != alpha && a != 255)
999-
ctx.globalAlpha = (alpha = a) / 256F;
982+
float fa = a / 255F;
983+
if (ctx.globalAlpha != fa)
984+
ctx.globalAlpha = fa;
1000985
ctx.fillStyle = ctx.strokeStyle = JSToolkit.getCSSColor(c);
1001986
}
1002987

@@ -1219,22 +1204,12 @@ public void drawImage(BufferedImage img, BufferedImageOp op, int x, int y) {
12191204

12201205
public void setAlpha(float f) {
12211206
ctx.globalAlpha = f;
1222-
alpha = (int) Math.floor(f * 256 + 0.0039);
12231207
}
12241208

12251209
public HTML5Canvas getCanvas() {
12261210
return canvas;
12271211
}
12281212

1229-
// /**
1230-
// * used to determine if it is likely that the background was painted
1231-
// *
1232-
// * @return background taint count
1233-
// */
1234-
// public boolean isBackgroundPainted() {
1235-
// return backgroundPainted;
1236-
// }
1237-
12381213
/////////////// saving of the state ////////////////
12391214

12401215
private final static int SAVE_ALPHA = 0;
@@ -1243,7 +1218,6 @@ public HTML5Canvas getCanvas() {
12431218
private final static int SAVE_TRANSFORM = 3;
12441219
private final static int SAVE_FONT = 4;
12451220
private final static int SAVE_CLIP = 5;
1246-
private final static int SAVE_BACKGROUND_PAINTED = 6;
12471221
private final static int SAVE_MAX = 7;
12481222

12491223
/**
@@ -1272,8 +1246,6 @@ private int mark(boolean isClone) {
12721246
map[SAVE_TRANSFORM] = transform;
12731247
map[SAVE_FONT] = font;
12741248
map[SAVE_CLIP] = currentClip;
1275-
// map[SAVE_BACKGROUND_PAINTED] = (backgroundPainted ? Boolean.TRUE : Boolean.FALSE);
1276-
// backgroundPainted = false;
12771249
return HTML5CanvasContext2D.push(ctx, map);
12781250
}
12791251

@@ -1342,16 +1314,11 @@ private void setState(Object[] map) {
13421314
@SuppressWarnings("unused")
13431315
int a = SAVE_ALPHA;
13441316
setAlpha(/** @j2sNative map[a] || */0);
1345-
// Float alpha = (Float) map[SAVE_ALPHA];
1346-
// if (alpha != null) {
1347-
// setAlpha(alpha.floatValue());
1348-
// }
13491317
shader = null;
13501318
setStroke((Stroke) map[SAVE_STROKE]);
13511319
setTransform((AffineTransform) map[SAVE_TRANSFORM]);
13521320
setFont((Font) map[SAVE_FONT]);
13531321
currentClip = (Shape) map[SAVE_CLIP];
1354-
// backgroundPainted = ((Boolean) map[SAVE_BACKGROUND_PAINTED]).booleanValue();
13551322
}
13561323

13571324
public Graphics create(int x, int y, int width, int height) {
@@ -1421,4 +1388,12 @@ public void dispose() {
14211388
reset(initialState);
14221389
}
14231390

1391+
public int getWidth() {
1392+
return width;
1393+
}
1394+
1395+
public int getHeight() {
1396+
return height;
1397+
}
1398+
14241399
}

0 commit comments

Comments
 (0)