NCSAHabanero

[ Previous ] [ Index ] [ Next ]

-------------------------------------------------------------------
How to share events from spawned windows
-------------------------------------------------------------------

Identifiable interface

Note: this pattern is not yet ready.

Background Information

When you spawn a new window (a Frame [Outside link]) from your hablet, its events do not get shared because they are not in the same MirrorFrame hierarchy. Because of this, you need to register the window with the CollObject. [Not yet written]

How does this work?

First, you need to select a GUI class containing the objects you want to share. Usually this is your Frame subclass. Tell this class to implement Identifiable. This tells Habanero that this class is supposed to be identified with a particular hablet.
Example 
public class IDframe extends Frame implements Identifiable, WindowListener 
 
At some point during initialization, you need to call registerIdentifable() on the CollObject [Not yet written]. You also need the Collobject later, so it is a good idea to save it in an instance variable.
Example 
In IDframe
   Collobject mirror;

   public IDframe(String L, Collobject mirror)
   {
     super(L);          /* Create a new Frame with the title L */
     this.mirror = mirror;
     mirror.registerIdentifiable(this);
   }
Then, in startInFrame(), (or should this be in init()?) on the main hablet class, you need to call this method when creating the IDframe: 
  idframe = IDframe("Extra Window",collobject);
(Is this correct? I didn't have sample code for this part, so I was guessing.) 
 
Finally, implement getUniqueId(), which should return a unique string for Habanero to refer to this Frame with.
Example
This example uses the session's key and the mirror's key to create a unique ID string, but you can use any other method that will gurantee a unique ID string. 

   public String getUniqueId() 
   { return (String) mirror.getSession().key() + "." + (String) mirror.key() + "UNIQUE NAME"; 
   } 

 
From this point on, Habanero will share the events in this Frame in the same way that it shares the events in the hablet's main window.
 
Summary of the Example
public class IDframe extends Frame implements Identifiable, WindowListener
{
  Collobject mirror;
  public IDframe(String L, Collobject mirror)
  {
    super(L);
    this.mirror = mirror;
    mirror.registerIdentifiable(this);
  }

  public String getUniqueId()
  {
    return (String) mirror.getSession().key() + "." + (String) mirror.key() + "UNIQUE NAME";
  }


  public void windowActivated(WindowEvent e)
  {
  }

  public void windowClosed(WindowEvent e)
  {
    System.out.println("Unregistering Window");
    mirror.unregisterIdentifiable(this);
  }

  public void windowClosing(WindowEvent e)
  {
  }

  public void windowDeactivated(WindowEvent e)
  {
  }

  public void windowDeiconified(WindowEvent e)
  {
  }

  public void windowIconified(WindowEvent e)
  {
  }

  public void windowOpened(WindowEvent e)
  {
  }
}
The empty methods are necessary to implement WinowListener -- they are not part of the Identifiable interface.

What next?

See the main page on event handling for specifics on how to individual events.


Habanero® is a registered trademark owned by The Board of Trustees of the University of Illinois. Copyright 1996-1998. All rights reserved.   Java(TM) is a proprietary trademark owned by Sun Microsystems, Inc.
NCSA
The National Center for Supercomputing Applications

University of Illinois at Urbana-Champaign

Contacts page