2727 */
2828package java .awt ;
2929
30- import java .awt .ContainerOrderFocusTraversalPolicy ;
31- import java .awt .HeadlessException ;
32- import java .awt .KeyboardFocusManager ;
33- import java .util .EventListener ;
34- import java .util .Set ;
35-
36- import javax .swing .JInternalFrame ;
37- import javax .swing .table .TableCellRenderer ;
38-
39- import javajs .util .Lst ;
40-
41-
4230import java .awt .event .AWTEventListener ;
4331import java .awt .event .ComponentEvent ;
4432import java .awt .event .ContainerEvent ;
5341import java .awt .peer .LightweightPeer ;
5442import java .beans .PropertyChangeListener ;
5543import java .beans .PropertyVetoException ;
44+ import java .util .EventListener ;
45+ import java .util .Set ;
46+
47+ import javax .swing .JInternalFrame ;
5648
49+ import javajs .util .Lst ;
5750import sun .awt .AppContext ;
5851import sun .awt .SunGraphicsCallback ;
5952import swingjs .JSFrameViewer ;
60- import swingjs .plaf .JSButtonUI ;
6153import swingjs .plaf .JSComponentUI ;
62- import swingjs .plaf .JSTableUI ;
6354
6455
6556/**
@@ -1595,7 +1586,7 @@ protected void validateTree() {
15951586 * Recursively descends the container tree and invalidates all
15961587 * contained components.
15971588 */
1598- void invalidateTree () {
1589+ public void invalidateTree () { // SwingJS -- need this public for ToolTipManager PopupFactory
15991590 synchronized (getTreeLock ()) {
16001591 for (int i = 0 ; i < children .size (); i ++) {
16011592 Component comp = children .get (i );
@@ -4387,79 +4378,85 @@ private boolean isMouseGrab(MouseEvent e) {
43874378 | InputEvent .BUTTON3_DOWN_MASK )) != 0 );
43884379 }
43894380
4390- /**
4391- * This method attempts to distribute a mouse event to a lightweight
4392- * component. It tries to avoid doing any unnecessary probes down
4393- * into the component tree to minimize the overhead of determining
4394- * where to route the event, since mouse movement events tend to
4395- * come in large and frequent amounts.
4396- */
4397- private boolean processMouseEvent (MouseEvent e ) {
4398- int id = e .getID ();
4399- // see swingjs.plaf.JSButtionUI
4400- Component mouseOver = /** @j2sNative e.bdata.jqevent && e.bdata.jqevent.target["data-component"] || */ null ;
4401-
4402- // sensitive to mouse events
4403-
4404- if (mouseOver == null )
4405- mouseOver = nativeContainer .getMouseEventTarget (e .getX (), e .getY (),
4406- Container .INCLUDE_SELF );
4381+ /**
4382+ * This method attempts to distribute a mouse event to a lightweight component.
4383+ * It tries to avoid doing any unnecessary probes down into the component tree
4384+ * to minimize the overhead of determining where to route the event, since mouse
4385+ * movement events tend to come in large and frequent amounts.
4386+ */
4387+ private boolean processMouseEvent (MouseEvent e ) {
4388+ int id = e .getID ();
4389+ // see swingjs.plaf.JSButtionUI
4390+ Component mouseOver = /** @j2sNative e.bdata.jqevent && e.bdata.jqevent.target["data-component"] || */
4391+ null ;
44074392
4408- trackMouseEnterExit ( mouseOver , e );
4393+ // sensitive to mouse events
44094394
4410- // 4508327 : MOUSE_CLICKED should only go to the recipient of
4411- // the accompanying MOUSE_PRESSED, so don't reset mouseEventTarget on a
4412- // MOUSE_CLICKED.
4413- if (!isMouseGrab (e ) && id != MouseEvent .MOUSE_CLICKED ) {
4414- mouseEventTarget = (mouseOver != nativeContainer ) ? mouseOver : null ;
4415- }
4395+ if (mouseOver == null )
4396+ mouseOver = (id == MouseEvent .MOUSE_EXITED ? targetLastEntered
4397+ : nativeContainer .getMouseEventTarget (e .getX (), e .getY (), Container .INCLUDE_SELF ));
44164398
4417- if (mouseEventTarget != null ) {
4418- switch (id ) {
4419- case MouseEvent .MOUSE_ENTERED :
4420- case MouseEvent .MOUSE_EXITED :
4421- break ;
4422- case MouseEvent .MOUSE_PRESSED :
4423- checkInternalFrameMouseDown ((JSComponent ) e .getSource ());
4424- retargetMouseEvent (mouseEventTarget , id , e );
4425- break ;
4426- case MouseEvent .MOUSE_RELEASED :
4427- retargetMouseEvent (mouseEventTarget , id , e );
4428- break ;
4429- case MouseEvent .MOUSE_CLICKED :
4430- // 4508327: MOUSE_CLICKED should never be dispatched to a Component
4431- // other than that which received the MOUSE_PRESSED event. If the
4432- // mouse is now over a different Component, don't dispatch the event.
4433- // The previous fix for a similar problem was associated with bug
4434- // 4155217.
4435- if (mouseOver == mouseEventTarget ) {
4436- retargetMouseEvent (mouseOver , id , e );
4437- }
4438- break ;
4439- case MouseEvent .MOUSE_MOVED :
4440- retargetMouseEvent (mouseEventTarget , id , e );
4441- break ;
4442- case MouseEvent .MOUSE_DRAGGED :
4443- if (isMouseGrab (e )) {
4444- retargetMouseEvent (mouseEventTarget , id , e );
4445- }
4446- break ;
4447- case MouseEvent .MOUSE_WHEEL :
4448- // This may send it somewhere that doesn't have MouseWheelEvents
4449- // enabled. In this case, Component.dispatchEventImpl() will
4450- // retarget the event to a parent that DOES have the events enabled.
4399+ // >>>>??trackMouseEnterExit(mouseOver, e);
4400+
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 ;
4406+ }
4407+
4408+ if (mouseEventTarget != null ) {
4409+ switch (id ) {
4410+ case MouseEvent .MOUSE_PRESSED :
4411+ checkInternalFrameMouseDown ((JSComponent ) e .getSource ());
4412+ retargetMouseEvent (mouseEventTarget , id , e );
4413+ break ;
4414+ case MouseEvent .MOUSE_RELEASED :
4415+ retargetMouseEvent (mouseEventTarget , id , e );
4416+ break ;
4417+ case MouseEvent .MOUSE_CLICKED :
4418+ // 4508327: MOUSE_CLICKED should never be dispatched to a Component
4419+ // other than that which received the MOUSE_PRESSED event. If the
4420+ // mouse is now over a different Component, don't dispatch the event.
4421+ // The previous fix for a similar problem was associated with bug
4422+ // 4155217.
4423+ if (mouseOver == mouseEventTarget ) {
4424+ retargetMouseEvent (mouseOver , id , e );
4425+ }
4426+ break ;
4427+ case MouseEvent .MOUSE_ENTERED :
4428+ targetLastEntered = mouseEventTarget ;
4429+ System .out .println ("LWD entered " + mouseEventTarget );
4430+ retargetMouseEvent (mouseEventTarget , id , e );
4431+ break ;
4432+ case MouseEvent .MOUSE_EXITED :
4433+ System .out .println ("LWD exited " + mouseEventTarget );
4434+ retargetMouseEvent (mouseEventTarget , id , e );
4435+ break ;
4436+ case MouseEvent .MOUSE_MOVED :
4437+ retargetMouseEvent (mouseEventTarget , id , e );
4438+ break ;
4439+ case MouseEvent .MOUSE_DRAGGED :
4440+ if (isMouseGrab (e )) {
4441+ retargetMouseEvent (mouseEventTarget , id , e );
4442+ }
4443+ break ;
4444+ case MouseEvent .MOUSE_WHEEL :
4445+ // This may send it somewhere that doesn't have MouseWheelEvents
4446+ // enabled. In this case, Component.dispatchEventImpl() will
4447+ // retarget the event to a parent that DOES have the events enabled.
44514448// if (eventLog.isLoggable(Level.FINEST) && (mouseOver != null)) {
44524449// eventLog.log(Level.FINEST, "retargeting mouse wheel to " +
44534450// mouseOver.getName() + ", " +
44544451// mouseOver.getClass());
44554452// }
4456- retargetMouseEvent (mouseOver , id , e );
4457- break ;
4458- }
4459- e .consume ();
4460- }
4461- return e .isConsumed ();
4462- }
4453+ retargetMouseEvent (mouseOver , id , e );
4454+ break ;
4455+ }
4456+ e .consume ();
4457+ }
4458+ return e .isConsumed ();
4459+ }
44634460
44644461// private boolean processDropTargetEvent(SunDropTargetEvent e) {
44654462// int id = e.getID();
@@ -4505,9 +4502,10 @@ private boolean processMouseEvent(MouseEvent e) {
45054502
45064503 public void checkInternalFrameMouseDown (JSComponent c ) {
45074504 JSFrameViewer fv = c .getFrameViewer ();
4508- if (fv .top .uiClassID == "InternalFrameUI" )
4505+ JSComponent top = fv .getTopComponent ();
4506+ if (top .uiClassID == "InternalFrameUI" )
45094507 try {
4510- ((JInternalFrame ) fv . top ).setSelected (true );
4508+ ((JInternalFrame ) top ).setSelected (true );
45114509 } catch (PropertyVetoException e ) {
45124510 }
45134511 }
@@ -4695,43 +4693,40 @@ public void eventDispatched(AWTEvent e) {
46954693 Component targetOver =
46964694 nativeContainer .getMouseEventTarget (me .getX (), me .getY (),
46974695 Container .INCLUDE_SELF );
4698- trackMouseEnterExit (targetOver , me );
4696+ //>>>?? trackMouseEnterExit(targetOver, me);
46994697 }
47004698
4701- /**
4702- * Sends a mouse event to the current mouse event recipient using
4703- * the given event (sent to the windowed host) as a srcEvent. If
4704- * the mouse event target is still in the component tree, the
4705- * coordinates of the event are translated to those of the target.
4706- * If the target has been removed, we don't bother to send the
4707- * message.
4708- *
4709- * Except for SwingJS we are using the parent frame as the native container,
4710- * and the PopupMenu does not have that as a parent.
4711- */
4712- void retargetMouseEvent (Component target , int id , MouseEvent e ) {
4713- if (target == null ) {
4714- return ; // mouse is over another hw component or target is disabled
4715- }
4699+ /**
4700+ * Sends a mouse event to the current mouse event recipient using the given
4701+ * event (sent to the windowed host) as a srcEvent. If the mouse event target is
4702+ * still in the component tree, the coordinates of the event are translated to
4703+ * those of the target. If the target has been removed, we don't bother to send
4704+ * the message.
4705+ *
4706+ * Except for SwingJS we are using the parent frame as the native container, and
4707+ * the PopupMenu does not have that as a parent.
4708+ */
4709+ void retargetMouseEvent (Component target , int id , MouseEvent e ) {
4710+ if (target == null ) {
4711+ return ; // mouse is over another hw component or target is disabled
4712+ }
47164713
4717- int x = e .getX (), y = e .getY ();
4718- Component component = target ;
4719- if (target .parent == null ) {
4720- component = ((JSComponentUI ) ((JSComponent ) target ).getUI ()).getTargetParent ();
4721- if (component != null )
4722- target = component ;
4723- }
4724- // SwingJS - TableCellRenderers do not have parents
4725- for (;
4726- component != null && component != nativeContainer ;
4727- component = component .getParent ()) {
4728- x -= component .x ;
4729- y -= component .y ;
4730- if (((JSComponent ) component ).uiClassID == "PopupMenuUI" )
4731- break ; // SwingJS not to worry
4732- }
4733- MouseEvent retargeted ;
4734- if (component != null ) {
4714+ int x = e .getX (), y = e .getY ();
4715+ Component component = target ;
4716+ if (target .parent == null ) {
4717+ component = ((JSComponentUI ) ((JSComponent ) target ).getUI ()).getTargetParent ();
4718+ if (component != null )
4719+ target = component ;
4720+ }
4721+ // SwingJS - TableCellRenderers do not have parents
4722+ for (; component != null && component != nativeContainer ; component = component .getParent ()) {
4723+ x -= component .x ;
4724+ y -= component .y ;
4725+ if (((JSComponent ) component ).uiClassID == "PopupMenuUI" )
4726+ break ; // SwingJS not to worry
4727+ }
4728+ MouseEvent retargeted ;
4729+ if (component != null ) {
47354730// if (e instanceof SunDropTargetEvent) {
47364731// retargeted = new SunDropTargetEvent(target,
47374732// id,
@@ -4740,56 +4735,36 @@ void retargetMouseEvent(Component target, int id, MouseEvent e) {
47404735// ((SunDropTargetEvent)e).getDispatcher());
47414736// } else
47424737//
4743- if (id == MouseEvent .MOUSE_WHEEL ) {
4744- retargeted = new MouseWheelEvent (target ,
4745- id ,
4746- e .getWhen (),
4747- e .getModifiersEx () | e .getModifiers (),
4748- x ,
4749- y ,
4750- e .getXOnScreen (),
4751- e .getYOnScreen (),
4752- e .getClickCount (),
4753- e .isPopupTrigger (),
4754- ((MouseWheelEvent )e ).getScrollType (),
4755- ((MouseWheelEvent )e ).getScrollAmount (),
4756- ((MouseWheelEvent )e ).getWheelRotation (),
4757- ((MouseWheelEvent )e ).getPreciseWheelRotation ());
4758- }
4759- else {
4760- retargeted = new MouseEvent (target ,
4761- id ,
4762- e .getWhen (),
4763- e .getModifiersEx () | e .getModifiers (),
4764- x ,
4765- y ,
4766- e .getXOnScreen (),
4767- e .getYOnScreen (),
4768- e .getClickCount (),
4769- e .isPopupTrigger (),
4770- e .getButton ());
4771- }
4738+ if (id == MouseEvent .MOUSE_WHEEL ) {
4739+ retargeted = new MouseWheelEvent (target , id , e .getWhen (), e .getModifiersEx () | e .getModifiers (), x , y ,
4740+ e .getXOnScreen (), e .getYOnScreen (), e .getClickCount (), e .isPopupTrigger (),
4741+ ((MouseWheelEvent ) e ).getScrollType (), ((MouseWheelEvent ) e ).getScrollAmount (),
4742+ ((MouseWheelEvent ) e ).getWheelRotation (), ((MouseWheelEvent ) e ).getPreciseWheelRotation ());
4743+ } else {
4744+ retargeted = new MouseEvent (target , id , e .getWhen (), e .getModifiersEx () | e .getModifiers (), x , y ,
4745+ e .getXOnScreen (), e .getYOnScreen (), e .getClickCount (), e .isPopupTrigger (), e .getButton ());
4746+ }
47724747
4773- ((AWTEvent )e ).copyPrivateDataInto (retargeted );
4748+ ((AWTEvent ) e ).copyPrivateDataInto (retargeted );
47744749
4775- if (target == nativeContainer ) {
4776- // avoid recursively calling LightweightDispatcher...
4777- ((Container )target ).dispatchEventToSelf (retargeted );
4778- } else {
4779- // assert AppContext.getAppContext() == target.appContext;
4750+ if (target == nativeContainer ) {
4751+ // avoid recursively calling LightweightDispatcher...
4752+ ((Container ) target ).dispatchEventToSelf (retargeted );
4753+ } else {
4754+ // assert AppContext.getAppContext() == target.appContext;
47804755
4781- if (nativeContainer .modalComp != null ) {
4782- if (((Container )nativeContainer .modalComp ).isAncestorOf (target )) {
4783- target .dispatchEvent (retargeted );
4784- } else {
4785- e .consume ();
4786- }
4787- } else {
4788- target .dispatchEvent (retargeted );
4789- }
4790- }
4791- }
4792- }
4756+ if (nativeContainer .modalComp != null ) {
4757+ if (((Container ) nativeContainer .modalComp ).isAncestorOf (target )) {
4758+ target .dispatchEvent (retargeted );
4759+ } else {
4760+ e .consume ();
4761+ }
4762+ } else {
4763+ target .dispatchEvent (retargeted );
4764+ }
4765+ }
4766+ }
4767+ }
47934768
47944769 // --- member variables -------------------------------
47954770
0 commit comments