com.google.gwt.user.client.ui
Class PopupPanel

java.lang.Object
  extended bycom.google.gwt.user.client.ui.UIObject
      extended bycom.google.gwt.user.client.ui.Widget
          extended bycom.google.gwt.user.client.ui.Panel
              extended bycom.google.gwt.user.client.ui.SimplePanel
                  extended bycom.google.gwt.user.client.ui.PopupPanel
All Implemented Interfaces:
EventListener, EventPreview, HasWidgets, SourcesPopupEvents
Direct Known Subclasses:
DialogBox

public class PopupPanel
extends SimplePanel
implements SourcesPopupEvents, EventPreview

A panel that can "pop up" over other widgets. It overlays the browser's client area (and any previously-created popups).

The width and height of the PopupPanel cannot be explicitly set; they are determined by the PopupPanel's widget. Calls to setWidth(String) and setHeight(String) will call these methods on the PopupPanel's widget.

Example

public class PopupPanelExample implements EntryPoint, ClickListener {

  private static class MyPopup extends PopupPanel {

    public MyPopup() {
      // PopupPanel's constructor takes 'auto-hide' as its boolean parameter.
      // If this is set, the panel closes itself automatically when the user
      // clicks outside of it.
      super(true);

      // PopupPanel is a SimplePanel, so you have to set it's widget property to
      // whatever you want its contents to be.
      setWidget(new Label("Click outside of this popup to close it"));
    }
  }

  public void onModuleLoad() {
    Button b = new Button("Click me");
    b.addClickListener(this);

    RootPanel.get().add(b);
  }

  public void onClick(Widget sender) {
    // Instantiate the popup and show it.
    new MyPopup().show();
  }
}


Constructor Summary
PopupPanel()
          Creates an empty popup panel.
PopupPanel(boolean autoHide)
          Creates an empty popup panel, specifying its "auto-hide" property.
PopupPanel(boolean autoHide, boolean modal)
          Creates an empty popup panel, specifying its "auto-hide" property.
 
Method Summary
 void addPopupListener(PopupListener listener)
          Adds a listener interface to receive popup events.
 void center()
          Centers the popup in the browser window.
protected  Element getContainerElement()
          Override this method to specify that an element other than the root element be the container for the panel's child widget.
 int getPopupLeft()
          Gets the popup's left position relative to the browser's client area.
 int getPopupTop()
          Gets the popup's top position relative to the browser's client area.
protected  Element getStyleElement()
          Template method that returns the element to which style names will be applied.
 java.lang.String getTitle()
          Gets the title associated with this object.
 void hide()
          Hides the popup.
protected  void onDetach()
          This method is called when a widget is detached from the browser's document.
 boolean onEventPreview(Event event)
          Called when a browser event occurs and this event preview is on top of the preview stack.
 boolean onKeyDownPreview(char key, int modifiers)
          Popups get an opportunity to preview keyboard events before they are passed to a widget contained by the Popup.
 boolean onKeyPressPreview(char key, int modifiers)
          Popups get an opportunity to preview keyboard events before they are passed to a widget contained by the Popup.
 boolean onKeyUpPreview(char key, int modifiers)
          Popups get an opportunity to preview keyboard events before they are passed to a widget contained by the Popup.
 void removePopupListener(PopupListener listener)
          Removes a previously added popup listener.
 void setHeight(java.lang.String height)
          Sets the object's height.
 void setPopupPosition(int left, int top)
          Sets the popup's position relative to the browser's client area.
 void setTitle(java.lang.String title)
          Sets the title associated with this object.
 void setVisible(boolean visible)
          Sets whether this object is visible.
 void setWidget(Widget w)
          Sets this panel's widget.
 void setWidth(java.lang.String width)
          Sets the object's width.
 void show()
          Shows the popup.
 
Methods inherited from class com.google.gwt.user.client.ui.SimplePanel
add, getWidget, iterator, remove
 
Methods inherited from class com.google.gwt.user.client.ui.Panel
adopt, clear, disown, onAttach
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
getParent, isAttached, onBrowserEvent, onLoad, onUnload, removeFromParent, setElement
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleName, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleName, isVisible, isVisible, removeStyleName, resetStyleName, setPixelSize, setSize, setStyleName, setStyleName, setVisible, sinkEvents, toString, unsinkEvents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PopupPanel

public PopupPanel()
Creates an empty popup panel. A child widget must be added to it before it is shown.


PopupPanel

public PopupPanel(boolean autoHide)
Creates an empty popup panel, specifying its "auto-hide" property.

Parameters:
autoHide - true if the popup should be automatically hidden when the user clicks outside of it

PopupPanel

public PopupPanel(boolean autoHide,
                  boolean modal)
Creates an empty popup panel, specifying its "auto-hide" property.

Parameters:
autoHide - true if the popup should be automatically hidden when the user clicks outside of it
modal - true if keyboard or mouse events that do not target the PopupPanel or its children should be ignored
Method Detail

addPopupListener

public void addPopupListener(PopupListener listener)
Description copied from interface: SourcesPopupEvents
Adds a listener interface to receive popup events.

Specified by:
addPopupListener in interface SourcesPopupEvents
Parameters:
listener - the listener interface to add.

center

public void center()
Centers the popup in the browser window.

Note that the popup must be shown before this method is called.


getPopupLeft

public int getPopupLeft()
Gets the popup's left position relative to the browser's client area.

Returns:
the popup's left position

getPopupTop

public int getPopupTop()
Gets the popup's top position relative to the browser's client area.

Returns:
the popup's top position

getTitle

public java.lang.String getTitle()
Description copied from class: UIObject
Gets the title associated with this object. The title is the 'tool-tip' displayed to users when they hover over the object.

Overrides:
getTitle in class UIObject
Returns:
the object's title

hide

public void hide()
Hides the popup. This has no effect if it is not currently visible.


onEventPreview

public boolean onEventPreview(Event event)
Description copied from interface: EventPreview
Called when a browser event occurs and this event preview is on top of the preview stack.

Specified by:
onEventPreview in interface EventPreview
Parameters:
event - the browser event
Returns:
false to cancel the event
See Also:
DOM.addEventPreview(EventPreview)

onKeyDownPreview

public boolean onKeyDownPreview(char key,
                                int modifiers)
Popups get an opportunity to preview keyboard events before they are passed to a widget contained by the Popup.

Parameters:
key - the key code of the depressed key
modifiers - keyboard modifiers, as specified in KeyboardListener.
Returns:
false to suppress the event

onKeyPressPreview

public boolean onKeyPressPreview(char key,
                                 int modifiers)
Popups get an opportunity to preview keyboard events before they are passed to a widget contained by the Popup.

Parameters:
key - the unicode character pressed
modifiers - keyboard modifiers, as specified in KeyboardListener.
Returns:
false to suppress the event

onKeyUpPreview

public boolean onKeyUpPreview(char key,
                              int modifiers)
Popups get an opportunity to preview keyboard events before they are passed to a widget contained by the Popup.

Parameters:
key - the key code of the released key
modifiers - keyboard modifiers, as specified in KeyboardListener.
Returns:
false to suppress the event

removePopupListener

public void removePopupListener(PopupListener listener)
Description copied from interface: SourcesPopupEvents
Removes a previously added popup listener.

Specified by:
removePopupListener in interface SourcesPopupEvents
Parameters:
listener - the listener interface to remove.

setHeight

public void setHeight(java.lang.String height)
Description copied from class: UIObject
Sets the object's height. This height does not include decorations such as border, margin, and padding.

Overrides:
setHeight in class UIObject
Parameters:
height - the object's new height, in CSS units (e.g. "10px", "1em")

setPopupPosition

public void setPopupPosition(int left,
                             int top)
Sets the popup's position relative to the browser's client area. The popup's position may be set before calling show().

Parameters:
left - the left position, in pixels
top - the top position, in pixels

setTitle

public void setTitle(java.lang.String title)
Description copied from class: UIObject
Sets the title associated with this object. The title is the 'tool-tip' displayed to users when they hover over the object.

Overrides:
setTitle in class UIObject
Parameters:
title - the object's new title

setVisible

public void setVisible(boolean visible)
Sets whether this object is visible.

Overrides:
setVisible in class UIObject
Parameters:
visible - true to show the object, false to hide it

setWidget

public void setWidget(Widget w)
Description copied from class: SimplePanel
Sets this panel's widget. Any existing child widget will be removed.

Overrides:
setWidget in class SimplePanel
Parameters:
w - the panel's new widget (null will clear the panel)

setWidth

public void setWidth(java.lang.String width)
Description copied from class: UIObject
Sets the object's width. This width does not include decorations such as border, margin, and padding.

Overrides:
setWidth in class UIObject
Parameters:
width - the object's new width, in CSS units (e.g. "10px", "1em")

show

public void show()
Shows the popup. It must have a child widget before this method is called.


getContainerElement

protected Element getContainerElement()
Description copied from class: SimplePanel
Override this method to specify that an element other than the root element be the container for the panel's child widget. This can be useful when you want to create a simple panel that decorates its contents.

Overrides:
getContainerElement in class SimplePanel
Returns:
the element to be used as the panel's container

getStyleElement

protected Element getStyleElement()
Description copied from class: UIObject
Template method that returns the element to which style names will be applied. By default it returns the root element, but this method may be overridden to apply styles to a child element.

Overrides:
getStyleElement in class UIObject
Returns:
the element to which style names will be applied

onDetach

protected void onDetach()
This method is called when a widget is detached from the browser's document. To receive notification before the PopupPanel is removed from the document, override the Widget.onUnload() method instead.

Overrides:
onDetach in class Panel