Skip to content

Commit bdc67b1

Browse files
hansonrhansonr
authored andcommitted
isWindowOrJSApplet()
1 parent b2b3e50 commit bdc67b1

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2976,12 +2976,12 @@ public void setLocationRelativeTo(Component c) {
29762976
Container root=null;
29772977

29782978
if (c != null) {
2979-
if (c instanceof Window || c instanceof JSApplet) {
2979+
if (c.isWindowOrJSApplet()) {
29802980
root = (Container)c;
29812981
} else {
29822982
Container parent;
29832983
for(parent = c.getParent() ; parent != null ; parent = parent.getParent()) {
2984-
if (parent instanceof Window || parent instanceof JSApplet) {
2984+
if (parent.isWindowOrJSApplet()) {
29852985
root = parent;
29862986
break;
29872987
}

sources/net.sf.j2s.java.core/src/java/awt/event/WindowEvent.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828

2929
package java.awt.event;
3030

31+
import java.applet.JSApplet;
32+
import java.awt.Component;
3133
import java.awt.Window;
3234
import sun.awt.AppContext;
3335
import sun.awt.SunToolkit;
@@ -282,7 +284,8 @@ public WindowEvent(Window source, int id) {
282284
* @return the Window object that originated the event
283285
*/
284286
public Window getWindow() {
285-
return (source instanceof Window) ? (Window)source : null;
287+
// SwingJS we are saying that embedded applets are windows here
288+
return (((Component)source).isWindowOrJSApplet()) ? (Window)source : null;
286289
}
287290

288291
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ void showTipWindow() {
281281
if (insideComponent == null || !insideComponent.isShowing())
282282
return;
283283
Component win = insideComponent.getTopLevelAncestor();
284-
if (win instanceof Window) {
284+
if (win.isWindowOrJSApplet()) {
285285
if (((Window) win).getModalBlocker() != null)
286286
return;
287287
}

sources/net.sf.j2s.java.core/src/swingjs/a2s/Applet.java

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import javax.swing.JApplet;
1111
import javax.swing.JComponent;
1212

13+
import swingjs.JSUtil;
14+
1315
public class Applet extends JApplet implements A2SContainer {
1416

1517

@@ -34,22 +36,17 @@ public Applet() throws HeadlessException {
3436
*
3537
*/
3638
static void fixAWTPaint(Component c, Class<?> cl) {
37-
39+
Object f = JSUtil.getJ2SAlias(c, "paint$java_awt_Graphics");
40+
if (JSUtil.isOverridden(f, cl)
41+
&& f.toString().indexOf("C$.superclazz.prototype.paint$java_awt_Graphics.apply(this") < 0) {
3842
/**@j2sNative
3943
*
40-
* try{
41-
* var f = c.paint$java_awt_Graphics;
42-
* if (f.exClazz != cl.$clazz$ && f.toString().indexOf("C$.superclazz.prototype.paint$java_awt_Graphics.apply(this") < 0) {
43-
* var oldPaint = f;
4444
* c.paint$java_awt_Graphics = function(g) {
4545
* cl.$clazz$.prototype.paint$java_awt_Graphics.apply(c,[g]);
46-
* oldPaint.apply(c,[g]);
47-
* };
48-
* }
49-
* } catch(e) {
50-
* System.out.println("java.applet.Applet.fixAppletPaint() exception: " + e);
51-
* }
46+
* f.apply(c,[g]);
47+
* }
5248
*/
49+
}
5350
}
5451

5552

0 commit comments

Comments
 (0)