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

Add reflection-based SwingUtilities.invokeLater and invokeAndWait methods

XMLWordPrintable

    • generic, x86
    • generic, windows_2000

      Name: rmT116609 Date: 04/15/2004


      A DESCRIPTION OF THE REQUEST :
      Add methods
      SwingUtilities.invokeLater(Object target, Method method, Object params)
      SwingUtilities.invokeAndWait(Object target, Method method, Object params)

      to javax.swing.SwingUtilities

      JUSTIFICATION :
      InvokeLater and InwokeAndWait is really really usefull for GUI-applications that have to be multithreaded (like Corba or what I'm doing: playing several videos in a synchronized way throug windows media player).

      But all over the code I have Runnable r = new Runnable(){ ... };
      It is quite messy. It would be easier to be able to use invokeLater without having to define a zillion runnables.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The behaviour would be that the method gets called on the object, just like you would do with a runnable (except you don't have to inline an anonymous class declaration).

      ---------- BEGIN SOURCE ----------
      /* The problem applies to many examples, here is one case.
      DirectShow / windows media player 9 controller methods MUST be called from the thread that instantiated the player */

      String m_url;
      NativeWindowsPlayer m_nativeplayer;
      BufferedImage m_videoframe;
      volatile boolean m_playingToFirstFrame = false;

      void realizePlayer(){
        createNativePlayer(m_url); // not shown
        playToFirstFrame();
      }

      public void play() { m_nativeplayer.play();}
      public void stop() { m_nativeplayer.stop();}

      void playToFirstFrame(){
        m_playingToFirstFrame = true;
        m_nativeplayer.play();
      }

      public void receiveFrameBufferCallback(long time, int[] imgbuffer) {
        if(m_playingToFirstFrame){
          m_playingToFirstFrame = false;

          SwingUtilities.invokeLater(this,
                                    getClass().getDeclaredMethod("stop", null),
                                    null);

         }
        // update image buffer and repaint
        // ...
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      You can always get around this by using new Runnable(){ ... }
      (Incident Review ID: 217482)
      ======================================================================

            serb Sergey Bylokhov
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: