Hello all,

 

I’m trying to modify the style of the cursor when my client

application is waiting for long running server elaborations.

 

The intent is to replace the client hourglass with a custom cursor any time

the user request a long running operation.

I’ve inherited from java.awt.EventQueue the following class:

 

import java.awt.AWTEvent;

import java.awt.Component;

import java.awt.Cursor;

import java.awt.EventQueue;

import java.awt.MenuComponent;

import java.awt.MenuContainer;

 

import javax.swing.JDesktopPane;

import javax.swing.SwingUtilities;

 

public class MyEventQueue extends EventQueue {

 

 

    private int delay;

    private JDesktopPane _desk;

    private WaitCursorTimer waitTimer;

 

      public MyEventQueue(int delay, JDesktopPane desk) {

            this.delay = delay;

            this._desk = desk;

            waitTimer = new WaitCursorTimer();

            waitTimer.setDaemon(true);

            waitTimer.start();

      }

 

      protected void dispatchEvent(AWTEvent event) {

          waitTimer.startTimer(event);

          try {

              super.dispatchEvent(event);

          }

          finally {

              waitTimer.stopTimer();

          }

      }

 

    private class WaitCursorTimer extends Thread {

 

          synchronized void startTimer(Object source) {

              this.source = ((AWTEvent)source).getSource();

              //this.id     = ((AWTEvent)source).getID();

              notify();

          }

 

          synchronized void stopTimer() {

              if (parent == null)

                  interrupt();

              else {

                  parent.setCursor(null);

                  parent = null;

              }

          }

 

          public synchronized void run() {

              while (true) {

                  try {

                      //wait for notification from startTimer()

                      wait();

     

                      //wait for event processing to reach the threshold, or

                      //interruption from stopTimer()

                      wait(delay);

     

                      if (source instanceof Component)

                          parent = SwingUtilities.getRoot((Component)source);

                      else if (source instanceof MenuComponent) {

                          MenuContainer mParent = ((MenuComponent)source).getParent();

                          if (mParent instanceof Component)

                              parent = SwingUtilities.getRoot( (Component)mParent);

                      }

                     

                      if (parent != null && parent.isShowing())

                         // for debug purpouse I use a HAND_CURSOR instead of a WAIT_CURSOR

                         parent.setCursor( Cursor.getPredefinedCursor( Cursor.HAND_CURSOR));

                  }

                  catch (InterruptedException ie) { }

              }

          }

 

             private Object source;

             private Component parent;

       }

}

 

And I’ve pushed the new listener in my RootPane half object client class in the following way:

 

      EventQueue waitQueue = new MyEventQueue(cursorTime, getDesktopPane());

      Toolkit.getDefaultToolkit().getSystemEventQueue().push(waitQueue);

 

When I run my application, the WAIT cursor appear as a HAND cursor only for a few time, then it change back to

the default Hourglass.

It seams that, when ULC start sending messages to the server my event queue is replaced by another ULC system

event queue. It may be possible?

 

I’m new to ULC and I don’t know how it works (I try to add the RoudTripListener to my server-side ApplicationContext

Without any results).

Can you help me in solving this problem?

 

 Best regards

 

 Giorgio Z.

 

 

Reply via email to