org.mozilla.webclient
Class NewWindowEvent

java.lang.Object
  extended by java.util.EventObject
      extended by org.mozilla.webclient.WebclientEvent
          extended by org.mozilla.webclient.NewWindowEvent
All Implemented Interfaces:
java.io.Serializable

public class NewWindowEvent
extends WebclientEvent

Indicates the browser is requesting a new window be created to display a new BrowserControlCanvas instance. This mechanism is only necessary if your embedding application wishes to allow the browser to pop up new windows (or tabs). Such is often the case when the user clicks on an href with a "target" attribute, or the embedding application wants to enable some right-click "open in new window" or "open in new tab" feature.

Usage contract:

The unfortunately complex usage contract to accomodate differences in the UI threading models in a platform indepent manner.

On the application main thread, do something like this:


final List realizeNewWindowRunnableList = 
   new CopyOnWriteArrayList();

eventRegistration.setNewWindowListener(new NewWindowListener() {
   public void eventDispatched(WebclientEvent wcEvent) {
     NewWindowEvent event = (NewWindowEvent) wcEvent;
     final BrowserControlCanvas secondCanvas;

     try {
       secondBrowserControl = 
         BrowserControlFactory.newBrowserControl();
       secondCanvas = (BrowserControlCanvas)
         secondBrowserControl.queryInterface(BrowserControl.BROWSER_CONTROL_CANVAS_NAME);
     } catch (Throwable e) {
       System.out.println(e.getMessage());
       fail();
       return;
     }
         event.setBrowserControl(secondBrowserControl);
     event.setRealizeNewWindowRunnableList(realizeNewWindowRunnableList);
     event.setRealizeNewWindowRunnable(new Runnable() {
       public void run() {
         secondFrame.add(secondCanvas, BorderLayout.CENTER);
         secondFrame.setVisible(true);
         secondCanvas.setVisible(true);
       }
       public String toString() {
         return "WindowCreatorTest newWindowRunnable";
         }
       });
    }  
  });

// ... continue with browser code.

  while (realizeNewWindowRunnableList.isEmpty()) {
    Thread.currentThread().sleep(1000);
  }

  for (Runnable cur : realizeNewWindowRunnableList) {
    cur.run();
  }
 

The above code accomplishes the folliwng goals:

Create a thread safe list data structure. This will hold the Runnable that we define to create the parent window and make it visible. Add a NewWindowListener instance to the "main" BrowserControl. When this listener instance receives an eventDispatched call (on a platform specific Thread), it must create a new BrowserControl, gets its BrowserControlCanvas, store the canvas into the event, store the thread safe list data structure into the event, and store a Runnable into the event that adds the canvas to its parent container, and sets the parent container and the canvas visible. This Runnable will be called at a platform specific time, on a platform specific Thread. The toString() implementation is just good practice for debugging.

Meanwhile, back on the main thread the thread safe list data structure mest be polled, as often as desired, until Runnable appears in the list. It will have been placed there by the Webclient API and the embedding application is required to run() it on the main thread.

See Also:
Serialized Form

Field Summary
protected  BrowserControl browserControl
           
protected  java.util.List<java.lang.Runnable> browserWillAdd
           
 
Fields inherited from class java.util.EventObject
source
 
Constructor Summary
NewWindowEvent(java.lang.Object source, long newType, java.lang.Object newEventData)
           
 
Method Summary
 BrowserControl getBrowserControl()
           
 java.lang.Runnable getRealizeNewWindowRunnable()
           
 java.util.List<java.lang.Runnable> getRealizeNewWindowRunnableList()
           
 void setBrowserControl(BrowserControl newBrowserControl)
           
 void setRealizeNewWindowRunnable(java.lang.Runnable realizeNewWindowRunnable)
           
 void setRealizeNewWindowRunnableList(java.util.List<java.lang.Runnable> browserWillAdd)
           
 
Methods inherited from class org.mozilla.webclient.WebclientEvent
getEventData, getType
 
Methods inherited from class java.util.EventObject
getSource, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

browserControl

protected BrowserControl browserControl

browserWillAdd

protected java.util.List<java.lang.Runnable> browserWillAdd
Constructor Detail

NewWindowEvent

public NewWindowEvent(java.lang.Object source,
                      long newType,
                      java.lang.Object newEventData)
Method Detail

getBrowserControl

public BrowserControl getBrowserControl()

setBrowserControl

public void setBrowserControl(BrowserControl newBrowserControl)

setRealizeNewWindowRunnableList

public void setRealizeNewWindowRunnableList(java.util.List<java.lang.Runnable> browserWillAdd)

getRealizeNewWindowRunnableList

public java.util.List<java.lang.Runnable> getRealizeNewWindowRunnableList()

getRealizeNewWindowRunnable

public java.lang.Runnable getRealizeNewWindowRunnable()

setRealizeNewWindowRunnable

public void setRealizeNewWindowRunnable(java.lang.Runnable realizeNewWindowRunnable)


Copyright © 2002-2007 Mozilla.org All Rights Reserved.