Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8108489

Mouse events handled incorrectly after a Control has been translated.

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: fx1.2.1
    • Fix Version/s: None
    • Component/s: javafx
    • Environment:

      Mac OS X v10.6, JavaFX 1.2.1

      Description

      When a control is translated outside of its original bounds, it no longer responds to mouse events (found when creating a draggable control). The following code reproduces the error:

      package mousedragbug;

      import javafx.stage.Stage;
      import javafx.scene.Scene;
      import javafx.scene.shape.Rectangle;
      import javafx.scene.paint.Color;
      import javafx.scene.control.Control;
      import javafx.scene.control.Skin;
      import javafx.scene.control.Behavior;
      import javafx.scene.input.MouseEvent;

      class RectControl extends Control {
          override var skin = RectControlSkin {}
      }

      class RectControlSkin extends Skin {
          override var behavior = RectControlBehavior {}

          init {
              var rect:Rectangle = Rectangle {
                  width: 100
                  height: 100
                  fill: bind if (rect.hover) Color.LIGHTBLUE else Color.LIGHTGRAY
                  onMousePressed: function( me ) {
                      (behavior as RectControlBehavior).mousePress( me )
                  }
                  onMouseDragged: function( me ) {
                      (behavior as RectControlBehavior).mouseDrag( me )
                  }
              }
              node = rect
          }

          override function contains(localX:Number, localY:Number):Boolean {
              return node.contains(localX, localY);
          }

          override function intersects(localX:Number, localY:Number, localWidth:Number, localHeight:Number):Boolean {
              return node.intersects(localX, localY, localWidth, localHeight);
          }
      }

      class RectControlBehavior extends Behavior {
          var lastDragX = 0.0;
          var lastDragY = 0.0;

          public function mousePress( me:MouseEvent ) {
              lastDragX = lastDragY = 0.0;
          }

          public function mouseDrag( me:MouseEvent ) {
              skin.node.translateX += me.dragX - lastDragX;
              skin.node.translateY += me.dragY - lastDragY;
              lastDragX = me.dragX;
              lastDragY = me.dragY;
          }
      }

      Stage {
          title: "Draggable Control Bug"
          scene: Scene {
              var lastDragX = 0.0;
              var lastDragY = 0.0;
              var draggable:Rectangle;

              width: 400
              height: 400
              content: [
                  RectControl {}

                  // This rectangle just shows the original bounds of the control
                  Rectangle {
                      width: 100
                      height: 100
                      fill: Color.TRANSPARENT
                      stroke: Color.BLACK
                      strokeDashArray: [ 3, 5 ]
                  }
              ]
          }
      }

        Attachments

          Activity

            People

            • Assignee:
              rbair Richard Bair
              Reporter:
              diversonjfx Dean Iverson (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: