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

Please make Toolkit.enterNestedEventLoop and exitNestedEventLoop public API

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8
    • Fix Version/s: 9
    • Component/s: javafx
    • Environment:

      JavaFX 8

      Description

      This API can be used to for example allow the creation of Dialogs that donot require the use of a Stage (which itself has the showAndWait() method that makes use of this API). Stages are not always desirable for this. Alternatively, a special Pane could be created that offers a showAndWait() style method, but that may limit potential other uses of nested event loops.

      The API looks intuitive enough as it is currently, and could be moved as-is to Platform in the future.

      Below part of the mailinglist discussion:

      ---------------

      Hi John,

      Please file an RFE to introduce this public API.

      --
      best regards,
      Anthony

      On 11/13/2013 08:35 PM, John Hendrikx wrote:
      > On 13/11/2013 16:35, Stephen F Northover wrote:
      >> What is the difference?
      >>
      >> Dialog d = new Dialog() {
      >> public void onClose() {
      >> Platform.exitNestedEventLoop();
      >> }
      >> }
      >> Platform.enterNestedEventLoop();
      > I find the current API to work well, it is just in the wrong package
      > tree
      >
      > Considering I didn't know about nested event loops before, I find the
      > solution quite elegant -- leave the old event loop on the call stack,
      > and start a fresh one that can be exited to continue again where the
      > main event loop was halted -- it's almost like a 2nd thread gets
      > started, but there isn't
      >
      > --John
      >
      >>
      >> Steve
      >>
      >> On 2013-11-13 5:28 AM, Tom Schindl wrote:
      >>> What bothers me with the API as it is today is that I have call
      >>> enter/exit, I would find it more easy to work with an API like:
      >>>
      >>> -------8<-------
      >>> WaitCondition c = new WaitCondition();
      >>> Dialog d = new Dialog() {
      >>> public void onClose() {
      >>> c.release();
      >>> }
      >>> }
      >>> Platform.spinNestedEventLoop(c);
      >>> ------->8-------
      >>>
      >>> Tom
      >>>
      >>> On 13.11.13 11:18, Artem Ananiev wrote:
      >>>> I also think it's a good request for public API. In AWT/Swing, people
      >>>> had been using ugly workarounds with modal dialogs just to enter a
      >>>> nested event loop, until public java.awt API was finally provided:
      >>>>
      >>>> http://docs.oracle.com/javase/7/docs/api/java/awt/SecondaryLoop.html
      >>>>
      >>>> http://docs.oracle.com/javase/7/docs/api/java/awt/EventQueue.html#createSecondaryLoop()
      >>>>
      >>>>
      >>>>
      >>>> The same is here in JavaFX: unless Toolkit.enter/exitNestedEventLoop()
      >>>> is exposed at javafx.* level, people will have to workaround it by
      >>>> using
      >>>> Stage, or calling into com.sun.javafx.*, which is not good.
      >>>>
      >>>> Thanks,
      >>>>
      >>>> Artem
      >>>>
      >>>> On 11/13/2013 10:15 AM, John Hendrikx wrote:
      >>>>> Hi List,
      >>>>>
      >>>>> Any chance that Toolkit.getToolkit().enterNestedEventLoop() will in
      >>>>> the
      >>>>> future become public API?
      >>>>>
      >>>>> I'm currently using this to create Dialogs based on a Pane to avoid
      >>>>> creating Stages (which have the nice show and showAndWait
      >>>>> functionality). I duplicated this functionality in a Pane,
      >>>>> allowing me
      >>>>> to create Dialogs on top of existing Scenes without creating a Stage,
      >>>>> and it makes use of the enterNestedEventLoop and exitNestedEventLoop
      >>>>> functions in com.sun.javafx.tk.Toolkit.
      >>>>>
      >>>>> The reason I'm avoiding the Stages is because they donot play well
      >>>>> with
      >>>>> an application that never has the mouse or keyboard focus (my
      >>>>> application is fully remote controlled) -- creating a Stage, even
      >>>>> one to
      >>>>> just show a Dialog, will cause Windows to try and attract the user's
      >>>>> attention by flashing its taskbar button (for which I filed a
      >>>>> bug/feature request) and this is undesired.
      >>>>>
      >>>>> Regards,
      >>>>> John
      >>>>>
      >>>>> (Here's a part of the DialogPane to show and close it:)
      >>>>>
      >>>>> public R showDialog(Scene scene, boolean synchronous) {
      >>>>> this.synchronous = synchronous;
      >>>>> this.scene = scene;
      >>>>> this.oldFocusOwner = scene.getFocusOwner();
      >>>>>
      >>>>> Parent root = scene.getRoot();
      >>>>>
      >>>>> stackPane.getChildren().add(root);
      >>>>> stackPane.getChildren().add(this);
      >>>>>
      >>>>> scene.setRoot(stackPane);
      >>>>>
      >>>>> requestFocus();
      >>>>>
      >>>>> if(synchronous) {
      >>>>> return (R)Toolkit.getToolkit().enterNestedEventLoop(this);
      >>>>> }
      >>>>>
      >>>>> return null;
      >>>>> }
      >>>>>
      >>>>> public void close() {
      >>>>> Parent originalRoot = (Parent)stackPane.getChildren().remove(0);
      >>>>>
      >>>>> scene.setRoot(originalRoot);
      >>>>> scene = null;
      >>>>>
      >>>>> if(oldFocusOwner != null) {
      >>>>> oldFocusOwner.requestFocus();
      >>>>> }
      >>>>>
      >>>>> if(synchronous) {
      >>>>> Toolkit.getToolkit().exitNestedEventLoop(this, getResult());
      >>>>> }
      >>>>> }
      >>>>>
      >>>>>
      >>
      >

        Attachments

        1. 8090865.patch
          13 kB
        2. 8090865.patch
          13 kB
        3. 8090865.patch
          4 kB
        4. 8090865.patch
          4 kB

          Issue Links

            Activity

              People

              Assignee:
              jgiles Jonathan Giles
              Reporter:
              jhendrikx John Hendrikx
              Votes:
              1 Vote for this issue
              Watchers:
              7 Start watching this issue

                Dates

                Due:
                Created:
                Updated:
                Resolved:
                Imported: