Skip to content

Commit 711045f

Browse files
authored
Merge pull request #57 from BobHanson/hanson1
Hanson1
2 parents 491063d + 1e6b850 commit 711045f

File tree

17 files changed

+444
-331
lines changed

17 files changed

+444
-331
lines changed

sources/net.sf.j2s.core/dist/README.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
This is the main README file for the Java2Script/SwingJS distribution
22

3+
34
https://github.com/BobHanson/java2script/blob/master/sources/net.sf.j2s.core/dist/README.txt
45

56
8/14/2018 Bob Hanson hansonr@stolaf.edu
-259 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20180827160909
1+
20180901005436
-259 Bytes
Binary file not shown.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
20180827160909
1+
20180901005436
-259 Bytes
Binary file not shown.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7217,6 +7217,7 @@ protected String paramString() {
72177217
protected String paramStringComp() {
72187218
String thisName = getName();
72197219
String str = (thisName != null ? thisName : "");
7220+
str += (/** @j2sNative this.__JSID__ + */"");
72207221
if (!isValid()) {
72217222
str += ",invalid";
72227223
}

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

Lines changed: 115 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -2691,6 +2691,9 @@ public void addNotify() {
26912691
* SwingJS set by JSAppletViewer
26922692
*/
26932693
public void setDispatcher() {
2694+
if (dispatcher != null)
2695+
return;
2696+
System.err.println("LWD dispatch for "+ this);
26942697
dispatcher = new LightweightDispatcher(this);
26952698
}
26962699
/**
@@ -4291,6 +4294,8 @@ class LightweightDispatcher implements AWTEventListener {
42914294
*/
42924295
private static final int LWD_MOUSE_DRAGGED_OVER = 1500;
42934296

4297+
private Component targetLastDown, targetLastKnown;
4298+
42944299
// private static final Logger eventLog = Logger.getLogger("java.awt.event.LightweightDispatcher");
42954300

42964301
LightweightDispatcher(Container nativeContainer) {
@@ -4304,7 +4309,6 @@ class LightweightDispatcher implements AWTEventListener {
43044309
* should be called from Container.removeNotify
43054310
*/
43064311
void dispose() {
4307-
//System.out.println("Disposing lw dispatcher");
43084312
stopListeningForOtherDrags();
43094313
mouseEventTarget = null;
43104314
}
@@ -4387,35 +4391,51 @@ private boolean isMouseGrab(MouseEvent e) {
43874391
private boolean processMouseEvent(MouseEvent e) {
43884392
int id = e.getID();
43894393

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);
4394-
4395-
// sensitive to mouse events
4394+
// sensitive to mouse events
43964395

4397-
if (mouseOver == null)
4398-
mouseOver = (id == MouseEvent.MOUSE_EXITED ? targetLastEntered
4399-
: nativeContainer.getMouseEventTarget(e.getX(), e.getY(), Container.INCLUDE_SELF));
4396+
Component mouseOver = targetLastKnown = nativeContainer.getMouseEventTarget(e.getX(), e.getY(), Container.INCLUDE_SELF);
44004397

4401-
// >>>>??trackMouseEnterExit(mouseOver, e);
4398+
trackMouseEnterExit(mouseOver, e);
44024399

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-
}
4400+
Component actualTarget;
44094401

4402+
switch (id) {
4403+
case MouseEvent.MOUSE_DRAGGED:
4404+
case MouseEvent.MOUSE_RELEASED:
4405+
actualTarget = targetLastDown;
4406+
break;
4407+
case MouseEvent.MOUSE_EXITED:
4408+
actualTarget = targetLastKnown;
4409+
break;
4410+
default:
4411+
// see swingjs.plaf.JSButtionUI
4412+
actualTarget = (/** @j2sNative e.bdata.jqevent && e.bdata.jqevent.target["data-component"] || */
4413+
null);
4414+
break;
44104415
}
44114416

4417+
// 4508327 : MOUSE_CLICKED should only go to the recipient of
4418+
// the accompanying MOUSE_PRESSED, so don't reset mouseEventTarget on a
4419+
// MOUSE_CLICKED.
4420+
4421+
if (actualTarget != null)
4422+
mouseEventTarget = actualTarget;
4423+
else if (!isMouseGrab(e) && id != MouseEvent.MOUSE_CLICKED) {
4424+
mouseEventTarget = (mouseOver != nativeContainer) ? mouseOver : null;
4425+
}
4426+
44124427
if (mouseEventTarget != null) {
44134428
switch (id) {
4429+
case MouseEvent.MOUSE_ENTERED:
4430+
case MouseEvent.MOUSE_EXITED:
4431+
break;
44144432
case MouseEvent.MOUSE_PRESSED:
44154433
checkInternalFrameMouseDown((JSComponent) e.getSource());
4434+
targetLastDown = mouseEventTarget;
44164435
retargetMouseEvent(mouseEventTarget, id, e);
44174436
break;
44184437
case MouseEvent.MOUSE_RELEASED:
4438+
targetLastDown = null;
44194439
retargetMouseEvent(mouseEventTarget, id, e);
44204440
break;
44214441
case MouseEvent.MOUSE_CLICKED:
@@ -4424,19 +4444,11 @@ private boolean processMouseEvent(MouseEvent e) {
44244444
// mouse is now over a different Component, don't dispatch the event.
44254445
// The previous fix for a similar problem was associated with bug
44264446
// 4155217.
4447+
targetLastDown = null;
44274448
if (mouseOver == mouseEventTarget) {
44284449
retargetMouseEvent(mouseOver, id, e);
44294450
}
44304451
break;
4431-
case MouseEvent.MOUSE_ENTERED:
4432-
targetLastEntered = mouseEventTarget;
4433-
System.out.println("LWD entered " + mouseEventTarget);
4434-
retargetMouseEvent(mouseEventTarget, id, e);
4435-
break;
4436-
case MouseEvent.MOUSE_EXITED:
4437-
System.out.println("LWD exited " + mouseEventTarget);
4438-
retargetMouseEvent(mouseEventTarget, id, e);
4439-
break;
44404452
case MouseEvent.MOUSE_MOVED:
44414453
retargetMouseEvent(mouseEventTarget, id, e);
44424454
break;
@@ -4515,13 +4527,15 @@ public void checkInternalFrameMouseDown(JSComponent c) {
45154527
}
45164528

45174529
/*
4518-
* Generates enter/exit events as mouse moves over lw components
4519-
* @param targetOver Target mouse is over (including native container)
4520-
* @param e Mouse event in native container
4521-
*/
4522-
private void trackMouseEnterExit(Component targetOver, MouseEvent e) {
4523-
Component targetEnter = null;
4524-
int id = e.getID();
4530+
* Generates enter/exit events as mouse moves over lw components
4531+
*
4532+
* @param targetOver Target mouse is over (including native container)
4533+
*
4534+
* @param e Mouse event in native container
4535+
*/
4536+
private void trackMouseEnterExit(Component targetOver, MouseEvent e) {
4537+
Component targetEnter = null;
4538+
int id = e.getID();
45254539

45264540
// if (e instanceof SunDropTargetEvent &&
45274541
// id == MouseEvent.MOUSE_ENTERED &&
@@ -4533,52 +4547,49 @@ private void trackMouseEnterExit(Component targetOver, MouseEvent e) {
45334547
// targetLastEntered = null;
45344548
// } else
45354549
//
4536-
if ( id != MouseEvent.MOUSE_EXITED &&
4537-
id != MouseEvent.MOUSE_DRAGGED &&
4538-
id != LWD_MOUSE_DRAGGED_OVER &&
4539-
isMouseInNativeContainer == false ) {
4540-
// any event but an exit or drag means we're in the native container
4541-
isMouseInNativeContainer = true;
4542-
startListeningForOtherDrags();
4543-
} else if ( id == MouseEvent.MOUSE_EXITED ) {
4544-
isMouseInNativeContainer = false;
4545-
stopListeningForOtherDrags();
4546-
}
4547-
4548-
if (isMouseInNativeContainer) {
4549-
targetEnter = targetOver;
4550-
}
4550+
if (id == MouseEvent.MOUSE_EXITED) {
4551+
isMouseInNativeContainer = false;
4552+
stopListeningForOtherDrags();
4553+
} else if (id != MouseEvent.MOUSE_DRAGGED && id != LWD_MOUSE_DRAGGED_OVER
4554+
&& isMouseInNativeContainer == false) {
4555+
// any event but an exit or drag means we're in the native container
4556+
isMouseInNativeContainer = true;
4557+
startListeningForOtherDrags();
4558+
}
4559+
4560+
if (isMouseInNativeContainer) {
4561+
targetEnter = targetOver;
4562+
}
45514563

4552-
if (targetLastEntered == targetEnter) {
4553-
return;
4554-
}
4564+
if (targetLastEntered == targetEnter) {
4565+
return;
4566+
}
45554567

4556-
if (targetLastEntered != null) {
4557-
retargetMouseEvent(targetLastEntered, MouseEvent.MOUSE_EXITED, e);
4558-
}
4559-
if (id == MouseEvent.MOUSE_EXITED) {
4560-
// consume native exit event if we generate one
4561-
e.consume();
4562-
}
4568+
if (targetLastEntered != null) {
4569+
retargetMouseEvent(targetLastEntered, MouseEvent.MOUSE_EXITED, e);
4570+
}
4571+
if (id == MouseEvent.MOUSE_EXITED) {
4572+
// consume native exit event if we generate one
4573+
e.consume();
4574+
}
45634575

4564-
if (targetEnter != null) {
4565-
retargetMouseEvent(targetEnter, MouseEvent.MOUSE_ENTERED, e);
4566-
}
4567-
if (id == MouseEvent.MOUSE_ENTERED) {
4568-
// consume native enter event if we generate one
4569-
e.consume();
4570-
}
4576+
if (targetEnter != null) {
4577+
retargetMouseEvent(targetEnter, MouseEvent.MOUSE_ENTERED, e);
4578+
}
4579+
if (id == MouseEvent.MOUSE_ENTERED) {
4580+
// consume native enter event if we generate one
4581+
e.consume();
4582+
}
45714583

4572-
targetLastEntered = targetEnter;
4573-
}
4584+
targetLastEntered = targetEnter;
4585+
}
45744586

45754587
/*
45764588
* Listens to global mouse drag events so even drags originating
45774589
* from other heavyweight containers will generate enter/exit
45784590
* events in this container
45794591
*/
45804592
private void startListeningForOtherDrags() {
4581-
// //System.out.println("Adding AWTEventListener");
45824593
// java.security.AccessController.doPrivileged(
45834594
// new java.security.PrivilegedAction() {
45844595
// public Object run() {
@@ -4593,7 +4604,6 @@ private void startListeningForOtherDrags() {
45934604
}
45944605

45954606
private void stopListeningForOtherDrags() {
4596-
// //System.out.println("Removing AWTEventListener");
45974607
// java.security.AccessController.doPrivileged(
45984608
// new java.security.PrivilegedAction() {
45994609
// public Object run() {
@@ -4691,24 +4701,24 @@ public void eventDispatched(AWTEvent e) {
46914701
// me.translatePoint( ptSrcOrigin.x - ptDstOrigin.x, ptSrcOrigin.y - ptDstOrigin.y );
46924702
// }
46934703
}
4694-
//System.out.println("Track event: " + me);
46954704
// feed the 'dragged-over' event directly to the enter/exit
46964705
// code (not a real event so don't pass it to dispatchEvent)
46974706
Component targetOver =
46984707
nativeContainer.getMouseEventTarget(me.getX(), me.getY(),
46994708
Container.INCLUDE_SELF);
4700-
//>>>??trackMouseEnterExit(targetOver, me);
4709+
trackMouseEnterExit(targetOver, me);
47014710
}
47024711

47034712
/**
4704-
* Sends a mouse event to the current mouse event recipient using the given
4705-
* event (sent to the windowed host) as a srcEvent. If the mouse event target is
4706-
* still in the component tree, the coordinates of the event are translated to
4707-
* those of the target. If the target has been removed, we don't bother to send
4708-
* the message.
4713+
* Sends a mouse event to the current mouse event recipient using
4714+
* the given event (sent to the windowed host) as a srcEvent. If
4715+
* the mouse event target is still in the component tree, the
4716+
* coordinates of the event are translated to those of the target.
4717+
* If the target has been removed, we don't bother to send the
4718+
* message.
47094719
*
4710-
* Except for SwingJS we are using the parent frame as the native container, and
4711-
* the PopupMenu does not have that as a parent.
4720+
* Except for SwingJS we are using the parent frame as the native container,
4721+
* and the PopupMenu does not have that as a parent.
47124722
*/
47134723
void retargetMouseEvent(Component target, int id, MouseEvent e) {
47144724
if (target == null) {
@@ -4740,13 +4750,33 @@ void retargetMouseEvent(Component target, int id, MouseEvent e) {
47404750
// } else
47414751
//
47424752
if (id == MouseEvent.MOUSE_WHEEL) {
4743-
retargeted = new MouseWheelEvent(target, id, e.getWhen(), e.getModifiersEx() | e.getModifiers(), x, y,
4744-
e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(), e.isPopupTrigger(),
4745-
((MouseWheelEvent) e).getScrollType(), ((MouseWheelEvent) e).getScrollAmount(),
4746-
((MouseWheelEvent) e).getWheelRotation(), ((MouseWheelEvent) e).getPreciseWheelRotation());
4747-
} else {
4748-
retargeted = new MouseEvent(target, id, e.getWhen(), e.getModifiersEx() | e.getModifiers(), x, y,
4749-
e.getXOnScreen(), e.getYOnScreen(), e.getClickCount(), e.isPopupTrigger(), e.getButton());
4753+
retargeted = new MouseWheelEvent(target,
4754+
id,
4755+
e.getWhen(),
4756+
e.getModifiersEx() | e.getModifiers(),
4757+
x,
4758+
y,
4759+
e.getXOnScreen(),
4760+
e.getYOnScreen(),
4761+
e.getClickCount(),
4762+
e.isPopupTrigger(),
4763+
((MouseWheelEvent)e).getScrollType(),
4764+
((MouseWheelEvent)e).getScrollAmount(),
4765+
((MouseWheelEvent)e).getWheelRotation(),
4766+
((MouseWheelEvent)e).getPreciseWheelRotation());
4767+
}
4768+
else {
4769+
retargeted = new MouseEvent(target,
4770+
id,
4771+
e.getWhen(),
4772+
e.getModifiersEx() | e.getModifiers(),
4773+
x,
4774+
y,
4775+
e.getXOnScreen(),
4776+
e.getYOnScreen(),
4777+
e.getClickCount(),
4778+
e.isPopupTrigger(),
4779+
e.getButton());
47504780
}
47514781

47524782
((AWTEvent) e).copyPrivateDataInto(retargeted);

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,6 @@ private void initiateToolTip(MouseEvent event) {
509509
* @param event the event in question
510510
*/
511511
public void mouseExited(MouseEvent event) {
512-
System.out.println("mouse exit " + event.getSource());
513512
hasFired = true;
514513
boolean shouldHide = true;
515514
if (insideComponent == null) {

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;

0 commit comments

Comments
 (0)