< prev index next >

modules/graphics/src/main/java/javafx/scene/Scene.java

Print this page




  77 import javafx.scene.paint.Color;
  78 import javafx.scene.paint.Paint;
  79 import javafx.stage.PopupWindow;
  80 import javafx.stage.Stage;
  81 import javafx.stage.StageStyle;
  82 import javafx.stage.Window;
  83 import javafx.util.Callback;
  84 import javafx.util.Duration;
  85 import sun.util.logging.PlatformLogger;
  86 import sun.util.logging.PlatformLogger.Level;
  87 
  88 import java.security.AccessControlContext;
  89 import java.security.AccessController;
  90 import java.security.PrivilegedAction;
  91 import java.util.*;
  92 import java.util.concurrent.CopyOnWriteArrayList;
  93 
  94 import com.sun.javafx.logging.PulseLogger;
  95 
  96 import static com.sun.javafx.logging.PulseLogger.PULSE_LOGGING_ENABLED;


  97 
  98 /**
  99  * The JavaFX {@code Scene} class is the container for all content in a scene graph.
 100  * The background of the scene is filled as specified by the {@code fill} property.
 101  * <p>
 102  * The application must specify the root {@code Node} for the scene graph by setting
 103  * the {@code root} property.   If a {@code Group} is used as the root, the
 104  * contents of the scene graph will be clipped by the scene's width and height and
 105  * changes to the scene's size (if user resizes the stage) will not alter the
 106  * layout of the scene graph.    If a resizable node (layout {@code Region} or
 107  * {@code Control} is set as the root, then the root's size will track the
 108  * scene's size, causing the contents to be relayed out as necessary.
 109  * <p>
 110  * The scene's size may be initialized by the application during construction.
 111  * If no size is specified, the scene will automatically compute its initial
 112  * size based on the preferred size of its content. If only one dimension is specified,
 113  * the other dimension is computed using the specified dimension, respecting content bias
 114  * of a root.
 115  * <p>
 116  * An application may request depth buffer support or scene anti-aliasing


 360                 public PerformanceTracker getPerfTracker(Scene scene) {
 361                     synchronized (trackerMonitor) {
 362                         return scene.tracker;
 363                     }
 364                 }
 365             });
 366             FXRobotHelper.setSceneAccessor(new FXRobotHelper.FXRobotSceneAccessor() {
 367                 public void processKeyEvent(Scene scene, KeyEvent keyEvent) {
 368                     scene.impl_processKeyEvent(keyEvent);
 369                 }
 370                 public void processMouseEvent(Scene scene, MouseEvent mouseEvent) {
 371                     scene.impl_processMouseEvent(mouseEvent);
 372                 }
 373                 public void processScrollEvent(Scene scene, ScrollEvent scrollEvent) {
 374                     scene.processGestureEvent(scrollEvent, scene.scrollGesture);
 375                 }
 376                 public ObservableList<Node> getChildren(Parent parent) {
 377                     return parent.getChildren(); //was impl_getChildren
 378                 }
 379                 public Object renderToImage(Scene scene, Object platformImage) {
 380                     return scene.snapshot(null).impl_getPlatformImage();
 381                 }
 382             });
 383             SceneHelper.setSceneAccessor(
 384                     new SceneHelper.SceneAccessor() {
 385                         @Override
 386                         public void setPaused(boolean paused) {
 387                             Scene.paused = paused;
 388                         }
 389 
 390                         @Override
 391                         public void parentEffectiveOrientationInvalidated(
 392                                 final Scene scene) {
 393                             scene.parentEffectiveOrientationInvalidated();
 394                         }
 395 
 396                         @Override
 397                         public Camera getEffectiveCamera(Scene scene) {
 398                             return scene.getEffectiveCamera();
 399                         }
 400 


1973         // fire all the events
1974         for (TouchPoint tp : touchPoints) {
1975             if (tp.getTarget() != null) {
1976                 EventType<TouchEvent> type = null;
1977                 switch (tp.getState()) {
1978                     case MOVED:
1979                         type = TouchEvent.TOUCH_MOVED;
1980                         break;
1981                     case PRESSED:
1982                         type = TouchEvent.TOUCH_PRESSED;
1983                         break;
1984                     case RELEASED:
1985                         type = TouchEvent.TOUCH_RELEASED;
1986                         break;
1987                     case STATIONARY:
1988                         type = TouchEvent.TOUCH_STATIONARY;
1989                         break;
1990                 }
1991 
1992                 for (TouchPoint t : touchPoints) {
1993                     t.impl_reset();
1994                 }
1995 
1996                 TouchEvent te = new TouchEvent(type, tp, touchList,
1997                         touchEventSetId, e.isShiftDown(), e.isControlDown(),
1998                         e.isAltDown(), e.isMetaDown());
1999 
2000                 Event.fireEvent(tp.getTarget(), te);
2001             }
2002         }
2003 
2004         // process grabbing
2005         for (TouchPoint tp : touchPoints) {
2006             EventTarget grabbed = tp.getGrabbed();
2007             if (grabbed != null) {
2008                 touchTargets.put(tp.getId(), grabbed);
2009             };
2010 
2011             if (grabbed == null || tp.getState() == TouchPoint.State.RELEASED) {
2012                 touchTargets.remove(tp.getId());
2013             }


2921 
2922     /*******************************************************************************
2923      *                                                                             *
2924      * Drag and Drop                                                               *
2925      *                                                                             *
2926      ******************************************************************************/
2927 
2928     class DropTargetListener implements TKDropTargetListener {
2929 
2930         /*
2931          * This function is called when an drag operation enters a valid drop target.
2932          * This may be from either an internal or external dnd operation.
2933          */
2934         @Override
2935         public TransferMode dragEnter(double x, double y, double screenX, double screenY,
2936                                       TransferMode transferMode, TKClipboard dragboard)
2937         {
2938             if (dndGesture == null) {
2939                 dndGesture = new DnDGesture();
2940             }
2941             Dragboard db = Dragboard.impl_createDragboard(dragboard);
2942             dndGesture.dragboard = db;
2943             DragEvent dragEvent =
2944                     new DragEvent(DragEvent.ANY, dndGesture.dragboard, x, y, screenX, screenY,
2945                             transferMode, null, null, pick(x, y));
2946             return dndGesture.processTargetEnterOver(dragEvent);
2947         }
2948 
2949         @Override
2950         public TransferMode dragOver(double x, double y, double screenX, double screenY,
2951                                      TransferMode transferMode)
2952         {
2953             if (Scene.this.dndGesture == null) {
2954                 System.err.println("GOT A dragOver when dndGesture is null!");
2955                 return null;
2956             } else {
2957                 if (dndGesture.dragboard == null) {
2958                     throw new RuntimeException("dndGesture.dragboard is null in dragOver");
2959                 }
2960                 DragEvent dragEvent =
2961                         new DragEvent(DragEvent.ANY, dndGesture.dragboard, x, y, screenX, screenY,


3007                 } finally {
3008                     DragboardHelper.setDataAccessRestriction(
3009                             dndGesture.dragboard, true);
3010                 }
3011 
3012                 if (dndGesture.source == null) {
3013                     dndGesture.dragboard = null;
3014                     dndGesture = null;
3015                 }
3016                 return tm;
3017             }
3018         }
3019     }
3020 
3021     class DragGestureListener implements TKDragGestureListener {
3022 
3023        @Override
3024        public void dragGestureRecognized(double x, double y, double screenX, double screenY,
3025                                          int button, TKClipboard dragboard)
3026        {
3027            Dragboard db = Dragboard.impl_createDragboard(dragboard);
3028            dndGesture = new DnDGesture();
3029            dndGesture.dragboard = db;
3030            // TODO: support mouse buttons in DragEvent
3031            DragEvent dragEvent = new DragEvent(DragEvent.ANY, db, x, y, screenX, screenY,
3032                    null, null, null, pick(x, y));
3033            dndGesture.processRecognized(dragEvent);
3034            dndGesture = null;
3035         }
3036     }
3037 
3038     /**
3039      * A Drag and Drop gesture has a lifespan that lasts from mouse
3040      * PRESSED event to mouse RELEASED event.
3041      */
3042     class DnDGesture {
3043         private final double hysteresisSizeX =
3044                 Toolkit.getToolkit().getMultiClickMaxX();
3045         private final double hysteresisSizeY =
3046                 Toolkit.getToolkit().getMultiClickMaxY();
3047 


3063          */
3064         private void fireEvent(EventTarget target, Event e) {
3065             if (target != null) {
3066                 Event.fireEvent(target, e);
3067             }
3068         }
3069 
3070         /**
3071          * Called when DRAG_DETECTED event is going to be processed by
3072          * application
3073          */
3074         private void processingDragDetected() {
3075             dragDetected = DragDetectedState.PROCESSING;
3076         }
3077 
3078         /**
3079          * Called after DRAG_DETECTED event has been processed by application
3080          */
3081         private void dragDetectedProcessed() {
3082             dragDetected = DragDetectedState.DONE;
3083             final boolean hasContent = (dragboard != null) && (dragboard.impl_contentPut());
3084             if (hasContent) {
3085                 /* start DnD */
3086                 Toolkit.getToolkit().startDrag(Scene.this.peer,
3087                                                 sourceTransferModes,
3088                                                 new DragSourceListener(),
3089                                                 dragboard);
3090             } else if (fullPDRSource != null) {
3091                 /* start PDR */
3092                 Scene.this.mouseHandler.enterFullPDR(fullPDRSource);
3093             }
3094 
3095             fullPDRSource = null;
3096         }
3097 
3098         /**
3099          * Sets the default dragDetect value
3100          */
3101         private void processDragDetection(MouseEvent mouseEvent) {
3102 
3103             if (dragDetected != DragDetectedState.NOT_YET) {


3402             sourceTransferModes = t;
3403             return dragboard;
3404         }
3405 
3406         /*
3407          * This starts the full PDR gesture.
3408          */
3409         private void startFullPDR(EventTarget source) {
3410             fullPDRSource = source;
3411         }
3412 
3413         private Dragboard createDragboard(final DragEvent de, boolean isDragSource) {
3414             Dragboard dragboard = null;
3415             if (de != null) {
3416                 dragboard = de.getDragboard();
3417                 if (dragboard != null) {
3418                     return dragboard;
3419                 }
3420             }
3421             TKClipboard dragboardPeer = peer.createDragboard(isDragSource);
3422             return Dragboard.impl_createDragboard(dragboardPeer);
3423         }
3424     }
3425 
3426     /**
3427      * State of a drag gesture with regards to DRAG_DETECTED event.
3428      */
3429     private enum DragDetectedState {
3430         NOT_YET,
3431         PROCESSING,
3432         DONE
3433     }
3434 
3435     class DragSourceListener implements TKDragSourceListener {
3436 
3437         @Override
3438         public void dragDropEnd(double x, double y, double screenX, double screenY,
3439                                 TransferMode transferMode)
3440         {
3441             if (dndGesture != null) {
3442                 if (dndGesture.dragboard == null) {




  77 import javafx.scene.paint.Color;
  78 import javafx.scene.paint.Paint;
  79 import javafx.stage.PopupWindow;
  80 import javafx.stage.Stage;
  81 import javafx.stage.StageStyle;
  82 import javafx.stage.Window;
  83 import javafx.util.Callback;
  84 import javafx.util.Duration;
  85 import sun.util.logging.PlatformLogger;
  86 import sun.util.logging.PlatformLogger.Level;
  87 
  88 import java.security.AccessControlContext;
  89 import java.security.AccessController;
  90 import java.security.PrivilegedAction;
  91 import java.util.*;
  92 import java.util.concurrent.CopyOnWriteArrayList;
  93 
  94 import com.sun.javafx.logging.PulseLogger;
  95 
  96 import static com.sun.javafx.logging.PulseLogger.PULSE_LOGGING_ENABLED;
  97 import com.sun.javafx.scene.input.ClipboardHelper;
  98 import com.sun.javafx.scene.input.TouchPointHelper;
  99 
 100 /**
 101  * The JavaFX {@code Scene} class is the container for all content in a scene graph.
 102  * The background of the scene is filled as specified by the {@code fill} property.
 103  * <p>
 104  * The application must specify the root {@code Node} for the scene graph by setting
 105  * the {@code root} property.   If a {@code Group} is used as the root, the
 106  * contents of the scene graph will be clipped by the scene's width and height and
 107  * changes to the scene's size (if user resizes the stage) will not alter the
 108  * layout of the scene graph.    If a resizable node (layout {@code Region} or
 109  * {@code Control} is set as the root, then the root's size will track the
 110  * scene's size, causing the contents to be relayed out as necessary.
 111  * <p>
 112  * The scene's size may be initialized by the application during construction.
 113  * If no size is specified, the scene will automatically compute its initial
 114  * size based on the preferred size of its content. If only one dimension is specified,
 115  * the other dimension is computed using the specified dimension, respecting content bias
 116  * of a root.
 117  * <p>
 118  * An application may request depth buffer support or scene anti-aliasing


 362                 public PerformanceTracker getPerfTracker(Scene scene) {
 363                     synchronized (trackerMonitor) {
 364                         return scene.tracker;
 365                     }
 366                 }
 367             });
 368             FXRobotHelper.setSceneAccessor(new FXRobotHelper.FXRobotSceneAccessor() {
 369                 public void processKeyEvent(Scene scene, KeyEvent keyEvent) {
 370                     scene.impl_processKeyEvent(keyEvent);
 371                 }
 372                 public void processMouseEvent(Scene scene, MouseEvent mouseEvent) {
 373                     scene.impl_processMouseEvent(mouseEvent);
 374                 }
 375                 public void processScrollEvent(Scene scene, ScrollEvent scrollEvent) {
 376                     scene.processGestureEvent(scrollEvent, scene.scrollGesture);
 377                 }
 378                 public ObservableList<Node> getChildren(Parent parent) {
 379                     return parent.getChildren(); //was impl_getChildren
 380                 }
 381                 public Object renderToImage(Scene scene, Object platformImage) {
 382                     return Toolkit.getImageAccessor().getPlatformImage(scene.snapshot(null));
 383                 }
 384             });
 385             SceneHelper.setSceneAccessor(
 386                     new SceneHelper.SceneAccessor() {
 387                         @Override
 388                         public void setPaused(boolean paused) {
 389                             Scene.paused = paused;
 390                         }
 391 
 392                         @Override
 393                         public void parentEffectiveOrientationInvalidated(
 394                                 final Scene scene) {
 395                             scene.parentEffectiveOrientationInvalidated();
 396                         }
 397 
 398                         @Override
 399                         public Camera getEffectiveCamera(Scene scene) {
 400                             return scene.getEffectiveCamera();
 401                         }
 402 


1975         // fire all the events
1976         for (TouchPoint tp : touchPoints) {
1977             if (tp.getTarget() != null) {
1978                 EventType<TouchEvent> type = null;
1979                 switch (tp.getState()) {
1980                     case MOVED:
1981                         type = TouchEvent.TOUCH_MOVED;
1982                         break;
1983                     case PRESSED:
1984                         type = TouchEvent.TOUCH_PRESSED;
1985                         break;
1986                     case RELEASED:
1987                         type = TouchEvent.TOUCH_RELEASED;
1988                         break;
1989                     case STATIONARY:
1990                         type = TouchEvent.TOUCH_STATIONARY;
1991                         break;
1992                 }
1993 
1994                 for (TouchPoint t : touchPoints) {
1995                     TouchPointHelper.reset(t);
1996                 }
1997 
1998                 TouchEvent te = new TouchEvent(type, tp, touchList,
1999                         touchEventSetId, e.isShiftDown(), e.isControlDown(),
2000                         e.isAltDown(), e.isMetaDown());
2001 
2002                 Event.fireEvent(tp.getTarget(), te);
2003             }
2004         }
2005 
2006         // process grabbing
2007         for (TouchPoint tp : touchPoints) {
2008             EventTarget grabbed = tp.getGrabbed();
2009             if (grabbed != null) {
2010                 touchTargets.put(tp.getId(), grabbed);
2011             };
2012 
2013             if (grabbed == null || tp.getState() == TouchPoint.State.RELEASED) {
2014                 touchTargets.remove(tp.getId());
2015             }


2923 
2924     /*******************************************************************************
2925      *                                                                             *
2926      * Drag and Drop                                                               *
2927      *                                                                             *
2928      ******************************************************************************/
2929 
2930     class DropTargetListener implements TKDropTargetListener {
2931 
2932         /*
2933          * This function is called when an drag operation enters a valid drop target.
2934          * This may be from either an internal or external dnd operation.
2935          */
2936         @Override
2937         public TransferMode dragEnter(double x, double y, double screenX, double screenY,
2938                                       TransferMode transferMode, TKClipboard dragboard)
2939         {
2940             if (dndGesture == null) {
2941                 dndGesture = new DnDGesture();
2942             }
2943             Dragboard db = DragboardHelper.createDragboard(dragboard);
2944             dndGesture.dragboard = db;
2945             DragEvent dragEvent =
2946                     new DragEvent(DragEvent.ANY, dndGesture.dragboard, x, y, screenX, screenY,
2947                             transferMode, null, null, pick(x, y));
2948             return dndGesture.processTargetEnterOver(dragEvent);
2949         }
2950 
2951         @Override
2952         public TransferMode dragOver(double x, double y, double screenX, double screenY,
2953                                      TransferMode transferMode)
2954         {
2955             if (Scene.this.dndGesture == null) {
2956                 System.err.println("GOT A dragOver when dndGesture is null!");
2957                 return null;
2958             } else {
2959                 if (dndGesture.dragboard == null) {
2960                     throw new RuntimeException("dndGesture.dragboard is null in dragOver");
2961                 }
2962                 DragEvent dragEvent =
2963                         new DragEvent(DragEvent.ANY, dndGesture.dragboard, x, y, screenX, screenY,


3009                 } finally {
3010                     DragboardHelper.setDataAccessRestriction(
3011                             dndGesture.dragboard, true);
3012                 }
3013 
3014                 if (dndGesture.source == null) {
3015                     dndGesture.dragboard = null;
3016                     dndGesture = null;
3017                 }
3018                 return tm;
3019             }
3020         }
3021     }
3022 
3023     class DragGestureListener implements TKDragGestureListener {
3024 
3025        @Override
3026        public void dragGestureRecognized(double x, double y, double screenX, double screenY,
3027                                          int button, TKClipboard dragboard)
3028        {
3029            Dragboard db = DragboardHelper.createDragboard(dragboard);
3030            dndGesture = new DnDGesture();
3031            dndGesture.dragboard = db;
3032            // TODO: support mouse buttons in DragEvent
3033            DragEvent dragEvent = new DragEvent(DragEvent.ANY, db, x, y, screenX, screenY,
3034                    null, null, null, pick(x, y));
3035            dndGesture.processRecognized(dragEvent);
3036            dndGesture = null;
3037         }
3038     }
3039 
3040     /**
3041      * A Drag and Drop gesture has a lifespan that lasts from mouse
3042      * PRESSED event to mouse RELEASED event.
3043      */
3044     class DnDGesture {
3045         private final double hysteresisSizeX =
3046                 Toolkit.getToolkit().getMultiClickMaxX();
3047         private final double hysteresisSizeY =
3048                 Toolkit.getToolkit().getMultiClickMaxY();
3049 


3065          */
3066         private void fireEvent(EventTarget target, Event e) {
3067             if (target != null) {
3068                 Event.fireEvent(target, e);
3069             }
3070         }
3071 
3072         /**
3073          * Called when DRAG_DETECTED event is going to be processed by
3074          * application
3075          */
3076         private void processingDragDetected() {
3077             dragDetected = DragDetectedState.PROCESSING;
3078         }
3079 
3080         /**
3081          * Called after DRAG_DETECTED event has been processed by application
3082          */
3083         private void dragDetectedProcessed() {
3084             dragDetected = DragDetectedState.DONE;
3085             final boolean hasContent = (dragboard != null) && (ClipboardHelper.contentPut(dragboard));
3086             if (hasContent) {
3087                 /* start DnD */
3088                 Toolkit.getToolkit().startDrag(Scene.this.peer,
3089                                                 sourceTransferModes,
3090                                                 new DragSourceListener(),
3091                                                 dragboard);
3092             } else if (fullPDRSource != null) {
3093                 /* start PDR */
3094                 Scene.this.mouseHandler.enterFullPDR(fullPDRSource);
3095             }
3096 
3097             fullPDRSource = null;
3098         }
3099 
3100         /**
3101          * Sets the default dragDetect value
3102          */
3103         private void processDragDetection(MouseEvent mouseEvent) {
3104 
3105             if (dragDetected != DragDetectedState.NOT_YET) {


3404             sourceTransferModes = t;
3405             return dragboard;
3406         }
3407 
3408         /*
3409          * This starts the full PDR gesture.
3410          */
3411         private void startFullPDR(EventTarget source) {
3412             fullPDRSource = source;
3413         }
3414 
3415         private Dragboard createDragboard(final DragEvent de, boolean isDragSource) {
3416             Dragboard dragboard = null;
3417             if (de != null) {
3418                 dragboard = de.getDragboard();
3419                 if (dragboard != null) {
3420                     return dragboard;
3421                 }
3422             }
3423             TKClipboard dragboardPeer = peer.createDragboard(isDragSource);
3424             return DragboardHelper.createDragboard(dragboardPeer);
3425         }
3426     }
3427 
3428     /**
3429      * State of a drag gesture with regards to DRAG_DETECTED event.
3430      */
3431     private enum DragDetectedState {
3432         NOT_YET,
3433         PROCESSING,
3434         DONE
3435     }
3436 
3437     class DragSourceListener implements TKDragSourceListener {
3438 
3439         @Override
3440         public void dragDropEnd(double x, double y, double screenX, double screenY,
3441                                 TransferMode transferMode)
3442         {
3443             if (dndGesture != null) {
3444                 if (dndGesture.dragboard == null) {


< prev index next >