Re: error

Dependence on JDK 1.3 was accidentally introduced in the
visad/DisplayActivity.java class. A new version of this
class that does not depend on JDK 1.3 is attached. I will
try to update the ftp server tommorrow.

As to your other error, and the errors you sent me privately,
do you have both source and the visad.jar file containing
precompiled class files in your CLASSPATH? The 'Invalid class
file format' error is a mystery to me, unless there are
classes in your CLASSPATH compiled under different JDK versions.

Bill

On Mon, 29 Oct 2001, Chhaya Mudgal wrote:
>  I am getting following error
> 
> DisplayActivity.java:4: Class java.util.Timer not found in import.
> import java.util.Timer;
>        ^
> DisplayActivity.java:154: Superclass java.util.TimerTask of inner class 
> visad.DisplayActivity. BusyTask not found.
>     extends java.util.TimerTask
>             ^
> error: Invalid class file format in ./ij/process/ImageProcessor.class.  
> invalid constant type: 0
> /export/home/johnf/chhaya/visad/util/DataUtility.java:0: Class 
> ij.process.ImageProcessor not found in class ij.process.ColorProcessor.
> //
> 
>  please tell me what am i missing.
> thanks
> 
> Chhaya
> 
> 
> 
package visad;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import java.util.ArrayList;

import javax.swing.Timer;

import visad.DisplayImpl;

public class DisplayActivity
{
  private static final int DEFAULT_IDLE_SECONDS = 1;

  private static final boolean DEBUG = false;

  private transient DisplayImpl dpy;
  private int interval;

  private long lastBusyEvt;
  private boolean isBusy;
  private transient Timer busyTimer;
  private transient BusyAction busyAction;

  private transient ArrayList handlerList;

  /**
   * Manage busy/idle handlers for a Display, using a default
   * idle time of 1 second.
   *
   * @param dpy Display to manage.
   */
  public DisplayActivity(DisplayImpl dpy)
  {
    this(dpy, DEFAULT_IDLE_SECONDS);
  }

  /**
   * Manage busy/idle handlers for a Display, using the specified
   * idle time.
   *
   * @param dpy Display to manage.
   * @param seconds Number of seconds to wait before the Display
   *                is considered idle.
   */
  public DisplayActivity(DisplayImpl dpy, int seconds)
  {
    this.dpy = dpy;
    this.interval = seconds * 1000;

    lastBusyEvt = System.currentTimeMillis() - this.interval;
    isBusy = false;

    busyAction = new BusyAction();
    busyTimer = new Timer(this.interval, busyAction);

    busyTimer.removeActionListener(busyAction);
    busyAction = null;

    handlerList = new ArrayList();
  }

  /**
   * Stop the idle timer and any running tasks.
   */
  public void destroy()
  {
    synchronized (busyTimer) {
      if (busyAction != null) {
        busyTimer.removeActionListener(busyAction);
        busyAction = null;
      }

      busyTimer.stop();
    }
  }

  /**
   * Add a new activity handler.
   */
  public void addHandler(ActivityHandler ah)
    throws VisADException
  {
    if (handlerList == null) {
      throw new VisADException("No handler list found; was this object 
serialized?");
    }

    if (!busyTimer.isRunning()) {
      busyTimer.restart();
    }

    handlerList.add(ah);
  }

  /**
   * Remove an activity handler.
   */
  public void removeHandler(ActivityHandler ah)
    throws VisADException
  {
    if (handlerList == null) {
      throw new VisADException("No handler list found; was this object 
serialized?");
    }

    handlerList.remove(ah);

    if (handlerList.size() == 0 && busyTimer.isRunning()) {
      busyTimer.stop();
    }
  }

  /**
   * Notify all handlers of a transition from idle to busy or vice versa.
   *
   * @param isBusy <tt>true</tt> if the Display is now busy.
   */
  private void notifyList(boolean isBusy)
  {
    if (handlerList != null && busyTimer != null) {
      synchronized (handlerList) {
        final int len = handlerList.size();
        for (int i = 0; i < len; i++) {
          ActivityHandler ah = (ActivityHandler )handlerList.get(i);
          if (isBusy) {
            ah.busyDisplay(dpy);
          } else {
            ah.idleDisplay(dpy);
          }
        }
      }
    }
  }

  /**
   * Notify the activity monitor that work has been done.
   */
  public void updateBusyStatus()
  {
    final long now = System.currentTimeMillis();

    if (!isBusy && (now < lastBusyEvt || now > lastBusyEvt + interval)) {
      // Display is doing something...
      isBusy = true;

      if (busyAction == null && busyTimer != null) {
        synchronized (busyTimer) {
          if (busyAction == null) {
            // create a busy task
            busyAction = new BusyAction();

            // have busy action called at the specified interval
            busyTimer.addActionListener(busyAction);
            if (DEBUG) System.err.println("STARTED");
          }
        }
      }

      if (DEBUG) System.err.println("BUSY");

      // let handlers know that Display is busy
      notifyList(true);
    }

    // remember when Display was last busy
    lastBusyEvt = now;
  }

  private class BusyAction
    implements ActionListener
  {
    private static final int MAX_IDLE = 10;

    private int idleCount = 0;

    BusyAction() { }

    public void actionPerformed(ActionEvent evt)
    {
      if (!isBusy) {
        // another interval has passed where display wasn't busy
        idleCount++;

        // if it's been long enough...
        if (idleCount > MAX_IDLE) {

          // ... and there's a timer object...
          if (busyTimer != null) {

            // ...stop the timer
            synchronized (busyTimer) {
              busyTimer.removeActionListener(busyAction);
              busyAction = null;
              if (DEBUG) System.err.println("CANCELLED");
            }
          }
        }
      } else {
        final long now = System.currentTimeMillis();

        if (lastBusyEvt + interval <= now) {
          // if we're past the waiting period, we must be idle
          isBusy = false;
          idleCount = 0;

          if (DEBUG) System.err.println("IDLE");

          // let handlers know that Display is idle
          notifyList(false);
        }
      }
    }
  }
}
  • 2001 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: