Skip to content

Commit 6e75b15

Browse files
hansonrhansonr
authored andcommitted
mouse work
1 parent acac4e2 commit 6e75b15

File tree

4 files changed

+71
-47
lines changed

4 files changed

+71
-47
lines changed

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

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4386,23 +4386,27 @@ private boolean isMouseGrab(MouseEvent e) {
43864386
*/
43874387
private boolean processMouseEvent(MouseEvent e) {
43884388
int id = e.getID();
4389-
// see swingjs.plaf.JSButtionUI
4390-
Component mouseOver = /** @j2sNative e.bdata.jqevent && e.bdata.jqevent.target["data-component"] || */
4391-
null;
43924389

4393-
// sensitive to mouse events
4390+
Component mouseOver = mouseEventTarget;
4391+
if (id != 505) {
4392+
// see swingjs.plaf.JSButtionUI
4393+
mouseOver = (/** @j2sNative e.bdata.jqevent && e.bdata.jqevent.target["data-component"] || */null);
43944394

4395-
if (mouseOver == null)
4396-
mouseOver = (id == MouseEvent.MOUSE_EXITED ? targetLastEntered
4397-
: nativeContainer.getMouseEventTarget(e.getX(), e.getY(), Container.INCLUDE_SELF));
4395+
// sensitive to mouse events
43984396

4399-
// >>>>??trackMouseEnterExit(mouseOver, e);
4397+
if (mouseOver == null)
4398+
mouseOver = (id == MouseEvent.MOUSE_EXITED ? targetLastEntered
4399+
: nativeContainer.getMouseEventTarget(e.getX(), e.getY(), Container.INCLUDE_SELF));
4400+
4401+
// >>>>??trackMouseEnterExit(mouseOver, e);
4402+
4403+
// 4508327 : MOUSE_CLICKED should only go to the recipient of
4404+
// the accompanying MOUSE_PRESSED, so don't reset mouseEventTarget on a
4405+
// MOUSE_CLICKED.
4406+
if (!isMouseGrab(e) && id != MouseEvent.MOUSE_CLICKED) {
4407+
mouseEventTarget = (mouseOver != nativeContainer) ? mouseOver : null;
4408+
}
44004409

4401-
// 4508327 : MOUSE_CLICKED should only go to the recipient of
4402-
// the accompanying MOUSE_PRESSED, so don't reset mouseEventTarget on a
4403-
// MOUSE_CLICKED.
4404-
if (!isMouseGrab(e) && id != MouseEvent.MOUSE_CLICKED) {
4405-
mouseEventTarget = (mouseOver != nativeContainer) ? mouseOver : null;
44064410
}
44074411

44084412
if (mouseEventTarget != null) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ public Graphics getGraphics() {
178178

179179

180180
public Graphics getGraphics(int wNew, int hNew, RootPaneContainer window) {
181+
if (window == null) // from, for example, a resize of the browser page
182+
window = top;
181183
// technically, a JApplet is not a Window, but it is a Container and it is a
182184
// RootPaneContainer
183185
JSComponent c = (JSComponent) window; // will be null from j2sApplet.js

sources/net.sf.j2s.java.core/srcjs/js/j2sApplet.js

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,7 +1472,7 @@ if (!J2S._version)
14721472

14731473
var doIgnore = function(ev) {
14741474
return (J2S._dmouseOwner || !ev.target || ("" + ev.target.className)
1475-
.indexOf("swingjs-ui") >= 0)
1475+
.indexOf("swingjs-ui") >= 0 || ev.target.tagName == "CANVAS")
14761476
};
14771477

14781478
var checkStopPropagation = function(ev, ui, handled) {
@@ -1486,16 +1486,18 @@ if (!J2S._version)
14861486

14871487

14881488
J2S.traceMouse = function(what,ev) {
1489-
System.out.println(["tracemouse " + what
1490-
,"who", J2S._mouseOwner && J2S._mouseOwner.id
1491-
,"dragging", J2S._mouseOwner && J2S._mouseOwner.isDragging
1492-
,"type",ev.type
1493-
,"doignore",doIgnore(ev)
1494-
,"target.id",ev.target.id
1495-
,"role",ev.target.getAttribute("role")
1496-
,"data-ui",ev.target["data-ui"]
1497-
,"data-component",ev.target["data-component"]
1498-
]);
1489+
System.out.println(["tracemouse:" + what
1490+
,"type:",ev.type
1491+
,"target.id:",ev.target.id
1492+
,"relatedtarget.id:",ev.originalEvent.relatedTarget && ev.originalEvent.relatedTarget.id
1493+
,"who:", who.id
1494+
,"dragging:", J2S._mouseOwner && J2S._mouseOwner.isDragging
1495+
,"doignore:",doIgnore(ev)
1496+
,"role:",ev.target.getAttribute("role")
1497+
,"data-ui:",ev.target["data-ui"]
1498+
,"data-component:",ev.target["data-component"]
1499+
,"mouseOwner:",J2S._mouseOwner && J2S._mouseOwner.id
1500+
].join().replace(":,",":"));
14991501
}
15001502

15011503
J2S.$bind(who, 'mousedown touchstart', function(ev) {
@@ -1636,7 +1638,9 @@ if (!J2S._version)
16361638
});
16371639

16381640
J2S.$bind(who, 'mouseout', function(ev) {
1639-
1641+
1642+
J2S._currentTarget = null;
1643+
16401644
if (J2S._traceMouse)
16411645
J2S.traceMouse("OUT", ev);
16421646

@@ -1645,7 +1649,7 @@ if (!J2S._version)
16451649
if (ev.target.getAttribute("role")) {
16461650
return true;
16471651
}
1648-
1652+
16491653
if (J2S._mouseOwner && !J2S._mouseOwner.isDragging)
16501654
J2S.setMouseOwner(null);
16511655
if (who.applet._appletPanel)
@@ -1659,6 +1663,9 @@ if (!J2S._version)
16591663

16601664
J2S.$bind(who, 'mouseover', function(ev) {
16611665

1666+
if (J2S._currentTarget == ev.target)
1667+
return true;
1668+
J2S._currentTarget = ev.target;
16621669
if (J2S._traceMouse)
16631670
J2S.traceMouse("ENTER", ev);
16641671

@@ -1692,7 +1699,7 @@ if (!J2S._version)
16921699
return true;
16931700
});
16941701

1695-
if (who.applet._is2D) {
1702+
if (who.applet._is2D && !who.applet._isApp) {
16961703
J2S.$resize(function() {
16971704
if (!who.applet)
16981705
return;
@@ -2136,13 +2143,15 @@ if (!J2S._version)
21362143
this._isLayered = Info._isLayered || false; // JSV or SwingJS are
21372144
// layered
21382145
this._isSwing = Info._isSwing || false;
2146+
this._isApp = !!Info._main;
21392147
this._isJSV = Info._isJSV || false;
21402148
this._isAstex = Info._isAstex || false;
21412149
this._platform = Info._platform || "";
21422150
if (checkOnly)
21432151
return this;
21442152
window[id] = this;
2145-
this._createCanvas(id, Info);
2153+
if (!this._isApp)
2154+
this._createCanvas(id, Info);
21462155
if (!this._isJNLP && (!J2S._document || this._deferApplet))
21472156
return this;
21482157
this._init();
@@ -2342,7 +2351,7 @@ if (!J2S._version)
23422351
if (s !== null)
23432352
applet.__Info.args = decodeURIComponent(s);
23442353
}
2345-
var isApp = !!applet.__Info.main;
2354+
var isApp = applet._isApp = !!applet.__Info.main;
23462355
try {
23472356
var clazz = (applet.__Info.main || applet.__Info.code);
23482357
try {
@@ -2497,7 +2506,7 @@ if (!J2S._version)
24972506
var container = J2S.$(applet, "appletdiv");
24982507
var w = Math.round(container.width());
24992508
var h = Math.round(container.height());
2500-
if (applet._is2D
2509+
if (applet._is2D && !applet._isApp
25012510
&& (applet._canvas.width != w || applet._canvas.height != h)) {
25022511
applet._newCanvas(true);
25032512
applet._appletPanel

sources/net.sf.j2s.java.core/srcjs/swingjs2.js

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12128,7 +12128,7 @@ if (!J2S._version)
1212812128

1212912129
var doIgnore = function(ev) {
1213012130
return (J2S._dmouseOwner || !ev.target || ("" + ev.target.className)
12131-
.indexOf("swingjs-ui") >= 0)
12131+
.indexOf("swingjs-ui") >= 0 || ev.target.tagName == "CANVAS")
1213212132
};
1213312133

1213412134
var checkStopPropagation = function(ev, ui, handled) {
@@ -12142,16 +12142,18 @@ if (!J2S._version)
1214212142

1214312143

1214412144
J2S.traceMouse = function(what,ev) {
12145-
System.out.println(["tracemouse " + what
12146-
,"who", J2S._mouseOwner && J2S._mouseOwner.id
12147-
,"dragging", J2S._mouseOwner && J2S._mouseOwner.isDragging
12148-
,"type",ev.type
12149-
,"doignore",doIgnore(ev)
12150-
,"target.id",ev.target.id
12151-
,"role",ev.target.getAttribute("role")
12152-
,"data-ui",ev.target["data-ui"]
12153-
,"data-component",ev.target["data-component"]
12154-
]);
12145+
System.out.println(["tracemouse:" + what
12146+
,"type:",ev.type
12147+
,"target.id:",ev.target.id
12148+
,"relatedtarget.id:",ev.originalEvent.relatedTarget && ev.originalEvent.relatedTarget.id
12149+
,"who:", who.id
12150+
,"dragging:", J2S._mouseOwner && J2S._mouseOwner.isDragging
12151+
,"doignore:",doIgnore(ev)
12152+
,"role:",ev.target.getAttribute("role")
12153+
,"data-ui:",ev.target["data-ui"]
12154+
,"data-component:",ev.target["data-component"]
12155+
,"mouseOwner:",J2S._mouseOwner && J2S._mouseOwner.id
12156+
].join().replace(":,",":"));
1215512157
}
1215612158

1215712159
J2S.$bind(who, 'mousedown touchstart', function(ev) {
@@ -12292,7 +12294,9 @@ if (!J2S._version)
1229212294
});
1229312295

1229412296
J2S.$bind(who, 'mouseout', function(ev) {
12295-
12297+
12298+
J2S._currentTarget = null;
12299+
1229612300
if (J2S._traceMouse)
1229712301
J2S.traceMouse("OUT", ev);
1229812302

@@ -12301,7 +12305,7 @@ if (!J2S._version)
1230112305
if (ev.target.getAttribute("role")) {
1230212306
return true;
1230312307
}
12304-
12308+
1230512309
if (J2S._mouseOwner && !J2S._mouseOwner.isDragging)
1230612310
J2S.setMouseOwner(null);
1230712311
if (who.applet._appletPanel)
@@ -12315,6 +12319,9 @@ if (!J2S._version)
1231512319

1231612320
J2S.$bind(who, 'mouseover', function(ev) {
1231712321

12322+
if (J2S._currentTarget == ev.target)
12323+
return true;
12324+
J2S._currentTarget = ev.target;
1231812325
if (J2S._traceMouse)
1231912326
J2S.traceMouse("ENTER", ev);
1232012327

@@ -12348,7 +12355,7 @@ if (!J2S._version)
1234812355
return true;
1234912356
});
1235012357

12351-
if (who.applet._is2D) {
12358+
if (who.applet._is2D && !who.applet._isApp) {
1235212359
J2S.$resize(function() {
1235312360
if (!who.applet)
1235412361
return;
@@ -12792,13 +12799,15 @@ if (!J2S._version)
1279212799
this._isLayered = Info._isLayered || false; // JSV or SwingJS are
1279312800
// layered
1279412801
this._isSwing = Info._isSwing || false;
12802+
this._isApp = !!Info._main;
1279512803
this._isJSV = Info._isJSV || false;
1279612804
this._isAstex = Info._isAstex || false;
1279712805
this._platform = Info._platform || "";
1279812806
if (checkOnly)
1279912807
return this;
1280012808
window[id] = this;
12801-
this._createCanvas(id, Info);
12809+
if (!this._isApp)
12810+
this._createCanvas(id, Info);
1280212811
if (!this._isJNLP && (!J2S._document || this._deferApplet))
1280312812
return this;
1280412813
this._init();
@@ -12998,7 +13007,7 @@ if (!J2S._version)
1299813007
if (s !== null)
1299913008
applet.__Info.args = decodeURIComponent(s);
1300013009
}
13001-
var isApp = !!applet.__Info.main;
13010+
var isApp = applet._isApp = !!applet.__Info.main;
1300213011
try {
1300313012
var clazz = (applet.__Info.main || applet.__Info.code);
1300413013
try {
@@ -13153,7 +13162,7 @@ if (!J2S._version)
1315313162
var container = J2S.$(applet, "appletdiv");
1315413163
var w = Math.round(container.width());
1315513164
var h = Math.round(container.height());
13156-
if (applet._is2D
13165+
if (applet._is2D && !applet._isApp
1315713166
&& (applet._canvas.width != w || applet._canvas.height != h)) {
1315813167
applet._newCanvas(true);
1315913168
applet._appletPanel

0 commit comments

Comments
 (0)