status messages in display window

Hi,

I'm interested in displaying custom messages in one of the corners of a VisAD 
display. I have determined several ways to do this, but I'm wondering what the 
most efficient way is.

In particular, it would be nice to be able to update the message without 
triggering a TRANSFORM_DONE event, since my messages will change when 
TRANSFORM_DONE events are received. Of course, I could work around this with 
boolean flags, but would prefer a cleaner approach if one exists.

One way I've found to display custom messages near the "Please wait . . ." 
indicator is to use (abuse?) the exception printing facility. Source code is 
below.

Anyone know of a better/faster/shorter/cleaner way to do this?

-Curtis

--
//
// DisplayMsgTest.java
//

import javax.swing.JFrame;

import visad.*;
import visad.java3d.DisplayImplJ3D;

public class DisplayMsgTest {

  public static void main(String[] args) throws Exception {
    DisplayImplJ3D d = new DisplayImplJ3D("display");
    final DataRenderer dr = d.getDisplayRenderer().makeDefaultRenderer();
    d.addDisplayListener(new DisplayListener() {
      public void displayChanged(DisplayEvent e) {
        if (e.getId() == DisplayEvent.TRANSFORM_DONE) {
          dr.clearExceptions();
          String[] msg = {
            "The exception facility can be used",
            "as a nifty status report mechanism"
          };
          for (int i=msg.length-1; i>=0; i--) {
            dr.addException(new VisADException(msg[i]));
          }
          System.out.println("TRANSFORM_DONE: " + System.currentTimeMillis());
        }
      }
    });
    DataReferenceImpl ref = new DataReferenceImpl("ref");
    d.addReferences(dr, ref);

    JFrame f = new JFrame("Exception message test");
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(d.getComponent());
    f.setBounds(300, 300, 300, 300);
    f.show();

    System.out.println("Waiting 10 seconds...");
    Thread.sleep(10000);
    while (true) {
      Thread.sleep(200);
      System.out.println("setData: " + System.currentTimeMillis());
      ref.setData(new Real(Math.random()));
    }
  }

}


  • 2004 messages navigation, sorted by:
    1. Thread
    2. Subject
    3. Author
    4. Date
    5. ↑ Table Of Contents
  • Search the visad archives: