Skip to content

Commit a726869

Browse files
hansonrhansonr
authored andcommitted
final mouse event work, including n-click; matches Java
1 parent 49ffb92 commit a726869

File tree

5 files changed

+52
-19
lines changed

5 files changed

+52
-19
lines changed
-38 Bytes
Binary file not shown.

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,15 @@ public boolean processEvent(int id, int x, int y, int modifiers, long time, Obje
7575
case MouseEvent.MOUSE_RELEASED:
7676
released(time, x, y, modifiers);
7777
// simulate a mouseClicked event for us
78-
if (x == xWhenPressed && y == yWhenPressed
79-
&& modifiers == modifiersWhenPressed10) {
80-
// the underlying code will turn this into dbl clicks for us
81-
clicked(time, x, y, modifiers, 1);
82-
}
78+
// if (x == xWhenPressed && y == yWhenPressed
79+
// && modifiers == modifiersWhenPressed10) {
80+
// // the underlying code will turn this into dbl clicks for us
81+
// clicked(time, x, y, modifiers, 1);
82+
// }
83+
break;
84+
case MouseEvent.MOUSE_CLICKED:
85+
int n = /** @j2sNative jqevent.originalEvent.detail || */ 0;
86+
clicked(time, x, y, modifiers, n);
8387
break;
8488
default:
8589
return false;

sources/net.sf.j2s.java.core/src/test/Test_Applet_Scroll.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ public void actionPerformed(ActionEvent event) {
129129

130130
@Override
131131
public void mouseClicked(MouseEvent e) {
132-
// TODO Auto-generated method stub
132+
133+
System.out.println("BTN2 clicked " + e.getClickCount());
133134

134135
}
135136

@@ -218,8 +219,10 @@ public void actionPerformed(ActionEvent event) {
218219

219220
@Override
220221
public void mouseClicked(MouseEvent e) {
221-
// TODO Auto-generated method stub
222+
223+
System.out.println("PANEL clicked " + e.getClickCount());
222224

225+
223226
}
224227

225228
@Override

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,24 @@ if (!J2S._version)
15241524
return J2S._drag(who, ev, 503);
15251525
});
15261526

1527+
J2S.$bind(who, 'click', function(ev) {
1528+
if (J2S._traceMouse)
1529+
J2S.traceMouse("CLICK " + ev.originalEvent.detail, ev);
1530+
1531+
if (doIgnore(ev))
1532+
return true;
1533+
if (ev.target.getAttribute("role")) {
1534+
return true;
1535+
}
1536+
1537+
J2S.setMouseOwner(null);
1538+
var xym = J2S._jsGetXY(who, ev, 0);
1539+
if (!xym)
1540+
return false;
1541+
who.applet._processEvent(500, xym, ev, who._frameViewer);// MouseEvent.MOUSE_CLICK
1542+
return false;
1543+
});
1544+
15271545
J2S.$bind(who, 'DOMMouseScroll mousewheel', function(ev) { // Zoom
15281546
// not for wheel event, or action will not take place on handle and
15291547
// track
@@ -1758,7 +1776,7 @@ if (!J2S._version)
17581776
J2S
17591777
.$bind(
17601778
who,
1761-
'mousedown touchstart mousemove touchmove mouseup touchend DOMMouseScroll mousewheel contextmenu mouseleave mouseenter mousemoveoutjsmol',
1779+
'click mousedown touchstart mousemove touchmove mouseup touchend DOMMouseScroll mousewheel contextmenu mouseleave mouseenter mousemoveoutjsmol',
17621780
null);
17631781
J2S.setMouseOwner(null);
17641782
}
@@ -1844,7 +1862,6 @@ if (!J2S._version)
18441862
x = ev.pageX - offsets.left;
18451863
y = ev.pageY - offsets.top;
18461864
}
1847-
// System.out.println([x,y,getMouseModifiers(ev)])
18481865
return (x == undefined ? null : [ Math.round(x), Math.round(y),
18491866
getMouseModifiers(ev, id) ]);
18501867
}
@@ -2536,7 +2553,6 @@ if (!J2S._version)
25362553
} else {
25372554
f();
25382555
}
2539-
// System.out.println(applet._appletPanel.getFullName())
25402556
}
25412557

25422558
/**
@@ -2550,7 +2566,6 @@ if (!J2S._version)
25502566
var id = "echo_" + echoName + path + (bytes ? "_" + bytes.length : "");
25512567
var canvas = J2S.getHiddenCanvas(platform.vwr.html5Applet, id, 0, 0,
25522568
false, true);
2553-
// System.out.println(["JSmol.js loadImage ",id,path,canvas,image])
25542569
if (canvas == null) {
25552570
if (image == null) {
25562571
image = new Image();
@@ -2607,8 +2622,6 @@ if (!J2S._version)
26072622
d.height = d.style.height = height;
26082623
d.id = id;
26092624
J2S._canvasCache[id] = d;
2610-
// System.out.println("JSmol.js loadImage setting cache" + id + " to
2611-
// " + d)
26122625
}
26132626

26142627
return d;

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

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12180,6 +12180,24 @@ if (!J2S._version)
1218012180
return J2S._drag(who, ev, 503);
1218112181
});
1218212182

12183+
J2S.$bind(who, 'click', function(ev) {
12184+
if (J2S._traceMouse)
12185+
J2S.traceMouse("CLICK " + ev.originalEvent.detail, ev);
12186+
12187+
if (doIgnore(ev))
12188+
return true;
12189+
if (ev.target.getAttribute("role")) {
12190+
return true;
12191+
}
12192+
12193+
J2S.setMouseOwner(null);
12194+
var xym = J2S._jsGetXY(who, ev, 0);
12195+
if (!xym)
12196+
return false;
12197+
who.applet._processEvent(500, xym, ev, who._frameViewer);// MouseEvent.MOUSE_CLICK
12198+
return false;
12199+
});
12200+
1218312201
J2S.$bind(who, 'DOMMouseScroll mousewheel', function(ev) { // Zoom
1218412202
// not for wheel event, or action will not take place on handle and
1218512203
// track
@@ -12414,7 +12432,7 @@ if (!J2S._version)
1241412432
J2S
1241512433
.$bind(
1241612434
who,
12417-
'mousedown touchstart mousemove touchmove mouseup touchend DOMMouseScroll mousewheel contextmenu mouseleave mouseenter mousemoveoutjsmol',
12435+
'click mousedown touchstart mousemove touchmove mouseup touchend DOMMouseScroll mousewheel contextmenu mouseleave mouseenter mousemoveoutjsmol',
1241812436
null);
1241912437
J2S.setMouseOwner(null);
1242012438
}
@@ -12500,7 +12518,6 @@ if (!J2S._version)
1250012518
x = ev.pageX - offsets.left;
1250112519
y = ev.pageY - offsets.top;
1250212520
}
12503-
// System.out.println([x,y,getMouseModifiers(ev)])
1250412521
return (x == undefined ? null : [ Math.round(x), Math.round(y),
1250512522
getMouseModifiers(ev, id) ]);
1250612523
}
@@ -13192,7 +13209,6 @@ if (!J2S._version)
1319213209
} else {
1319313210
f();
1319413211
}
13195-
// System.out.println(applet._appletPanel.getFullName())
1319613212
}
1319713213

1319813214
/**
@@ -13206,7 +13222,6 @@ if (!J2S._version)
1320613222
var id = "echo_" + echoName + path + (bytes ? "_" + bytes.length : "");
1320713223
var canvas = J2S.getHiddenCanvas(platform.vwr.html5Applet, id, 0, 0,
1320813224
false, true);
13209-
// System.out.println(["JSmol.js loadImage ",id,path,canvas,image])
1321013225
if (canvas == null) {
1321113226
if (image == null) {
1321213227
image = new Image();
@@ -13263,8 +13278,6 @@ if (!J2S._version)
1326313278
d.height = d.style.height = height;
1326413279
d.id = id;
1326513280
J2S._canvasCache[id] = d;
13266-
// System.out.println("JSmol.js loadImage setting cache" + id + " to
13267-
// " + d)
1326813281
}
1326913282

1327013283
return d;

0 commit comments

Comments
 (0)