public class PopupPanel extends SimplePanel implements SourcesPopupEvents, EventPreview, HasAnimation, HasCloseHandlers<PopupPanel>
A PopupPanel should not generally be added to other panels; rather, it should
be shown and hidden using the show()
and hide()
methods.
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.
The PopupPanel can be optionally displayed with a "glass" element behind it,
which is commonly used to gray out the widgets behind it. It can be enabled
using setGlassEnabled(boolean)
. It has a default style name of
"gwt-PopupPanelGlass", which can be changed using
setGlassStyleName(String)
.
public class PopupPanelExample implements EntryPoint { 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 b1 = new Button("Click me to show popup"); b1.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { // Instantiate the popup and show it. new MyPopup().show(); } }); RootPanel.get().add(b1); Button b2 = new Button("Click me to show popup partway across the screen"); b2.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { // Create the new popup. final MyPopup popup = new MyPopup(); // Position the popup 1/3rd of the way down and across the screen, and // show the popup. Since the position calculation is based on the // offsetWidth and offsetHeight of the popup, you have to use the // setPopupPositionAndShow(callback) method. The alternative would // be to call show(), calculate the left and top positions, and // call setPopupPosition(left, top). This would have the ugly side // effect of the popup jumping from its original position to its // new position. popup.setPopupPositionAndShow(new PopupPanel.PositionCallback() { public void setPosition(int offsetWidth, int offsetHeight) { int left = (Window.getClientWidth() - offsetWidth) / 3; int top = (Window.getClientHeight() - offsetHeight) / 3; popup.setPopupPosition(left, top); } }); } }); RootPanel.get().add(b2); } }
Modifier and Type | Class and Description |
---|---|
static class |
PopupPanel.AnimationType
The type of animation to use when opening the popup.
|
static interface |
PopupPanel.PositionCallback
A callback that is used to set the position of a
PopupPanel right
before it is shown. |
(package private) static class |
PopupPanel.ResizeAnimation
An
Animation used to enlarge the popup into view. |
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
HasWidgets.ForIsWidget
widget
eventsToSink
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR
Constructor and Description |
---|
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" and "modal"
properties.
|
Modifier and Type | Method and Description |
---|---|
void |
addAutoHidePartner(Element partner)
Mouse events that occur within an autoHide partner will not hide a panel
set to autoHide.
|
HandlerRegistration |
addCloseHandler(CloseHandler<PopupPanel> handler)
Adds a
CloseEvent handler. |
void |
addPopupListener(PopupListener listener)
|
void |
center()
Centers the popup in the browser window and shows it.
|
PopupPanel.AnimationType |
getAnimationType()
Get the type of animation to use when opening and closing the popup.
|
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.
|
protected Element |
getGlassElement()
Get the glass element used by this
PopupPanel . |
java.lang.String |
getGlassStyleName()
Gets the style name to be used on the glass element.
|
int |
getOffsetHeight()
Gets the panel's offset height in pixels.
|
int |
getOffsetWidth()
Gets the panel's offset width in pixels.
|
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 and detaches it from the page.
|
void |
hide(boolean autoClosed)
Hides the popup and detaches it from the page.
|
boolean |
isAnimationEnabled()
Returns true if animations are enabled, false if not.
|
boolean |
isAutoHideEnabled()
Returns
true if the popup should be automatically hidden when
the user clicks outside of it. |
boolean |
isAutoHideOnHistoryEventsEnabled()
Returns
true if the popup should be automatically hidden when
the history token changes, such as when the user presses the browser's back
button. |
boolean |
isGlassEnabled()
Returns
true if a glass element will be displayed under the
PopupPanel . |
boolean |
isModal()
Returns
true if keyboard or mouse events that do not target
the PopupPanel or its children should be ignored. |
boolean |
isPreviewingAllNativeEvents()
Returns
true if the popup should preview all native events,
even if the event has already been consumed by another popup. |
boolean |
isShowing()
Determines whether or not this popup is showing.
|
boolean |
isVisible()
Determines whether or not this popup is visible.
|
(package private) void |
maybeUpdateSize()
We control size by setting our child widget's size.
|
boolean |
onEventPreview(Event event)
Deprecated.
|
boolean |
onKeyDownPreview(char key,
int modifiers)
Deprecated.
|
boolean |
onKeyPressPreview(char key,
int modifiers)
Deprecated.
|
boolean |
onKeyUpPreview(char key,
int modifiers)
Deprecated.
|
protected void |
onPreviewNativeEvent(Event.NativePreviewEvent event) |
protected void |
onUnload()
This method is called immediately before a widget will be detached from the
browser's document.
|
void |
removeAutoHidePartner(Element partner)
Remove an autoHide partner.
|
void |
removePopupListener(PopupListener listener)
Deprecated.
Use the
HandlerRegistration.removeHandler() method on the
object returned by addCloseHandler(com.google.gwt.event.logical.shared.CloseHandler<com.google.gwt.user.client.ui.PopupPanel>) instead |
(package private) void |
setAnimation(PopupPanel.ResizeAnimation animation)
Sets the animation used to animate this popup.
|
void |
setAnimationEnabled(boolean enable)
Enable or disable animations.
|
void |
setAnimationType(PopupPanel.AnimationType type)
Set the type of animation to use when opening and closing the popup.
|
void |
setAutoHideEnabled(boolean autoHide)
Enable or disable the autoHide feature.
|
void |
setAutoHideOnHistoryEventsEnabled(boolean enabled)
Enable or disable autoHide on history change events.
|
void |
setGlassEnabled(boolean enabled)
When enabled, the background will be blocked with a semi-transparent pane
the next time it is shown.
|
void |
setGlassStyleName(java.lang.String glassStyleName)
Sets the style name to be used on the glass element.
|
void |
setHeight(java.lang.String height)
Sets the height of the panel's child widget.
|
void |
setModal(boolean modal)
When the popup is modal, keyboard or mouse events that do not target the
PopupPanel or its children will be ignored.
|
void |
setPopupPosition(int left,
int top)
Sets the popup's position relative to the browser's client area.
|
void |
setPopupPositionAndShow(PopupPanel.PositionCallback callback)
Sets the popup's position using a
PopupPanel.PositionCallback , and shows the
popup. |
void |
setPreviewingAllNativeEvents(boolean previewAllNativeEvents)
When enabled, the popup will preview all native events, even if another
popup was opened after this one.
|
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 width of the panel's child widget.
|
void |
show()
Shows the popup and attach it to the page.
|
void |
showRelativeTo(UIObject target)
Normally, the popup is positioned directly below the relative target, with
its left edge aligned with the left edge of the target.
|
add, getWidget, iterator, remove, setWidget
add, adopt, clear, doAttachChildren, doDetachChildren, orphan, remove
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, ensureHandlers, fireEvent, getHandlerCount, getHandlerManager, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onBrowserEvent, onDetach, onLoad, removeFromParent, replaceElement, setLayoutData, setParent, sinkEvents, unsinkEvents
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, resolvePotentialElement, setElement, setElement, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setVisible, sinkBitlessEvent, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
fireEvent
public PopupPanel()
public PopupPanel(boolean autoHide)
autoHide
- true
if the popup should be automatically
hidden when the user clicks outside of it or the history token
changes.public PopupPanel(boolean autoHide, boolean modal)
autoHide
- true
if the popup should be automatically
hidden when the user clicks outside of it or the history token
changes.modal
- true
if keyboard or mouse events that do not
target the PopupPanel or its children should be ignoredpublic void addAutoHidePartner(Element partner)
partner
- the auto hide partner to addpublic HandlerRegistration addCloseHandler(CloseHandler<PopupPanel> handler)
HasCloseHandlers
CloseEvent
handler.addCloseHandler
in interface HasCloseHandlers<PopupPanel>
handler
- the handler@Deprecated public void addPopupListener(PopupListener listener)
addCloseHandler(com.google.gwt.event.logical.shared.CloseHandler<com.google.gwt.user.client.ui.PopupPanel>)
insteadSourcesPopupEvents
addPopupListener
in interface SourcesPopupEvents
listener
- the listener interface to add.public void center()
public java.lang.String getGlassStyleName()
public int getOffsetHeight()
setHeight(String)
before the panel's child widget is set will not
influence the offset height.getOffsetHeight
in class UIObject
public int getOffsetWidth()
setWidth(String)
before the panel's child widget is set will not influence the offset width.getOffsetWidth
in class UIObject
public int getPopupLeft()
public int getPopupTop()
public java.lang.String getTitle()
UIObject
public void hide()
public void hide(boolean autoClosed)
autoClosed
- the value that will be passed to
CloseHandler.onClose(CloseEvent)
when the popup is closedpublic boolean isAnimationEnabled()
HasAnimation
isAnimationEnabled
in interface HasAnimation
public boolean isAutoHideEnabled()
true
if the popup should be automatically hidden when
the user clicks outside of it.public boolean isAutoHideOnHistoryEventsEnabled()
true
if the popup should be automatically hidden when
the history token changes, such as when the user presses the browser's back
button.public boolean isGlassEnabled()
true
if a glass element will be displayed under the
PopupPanel
.public boolean isModal()
true
if keyboard or mouse events that do not target
the PopupPanel or its children should be ignored.public boolean isPreviewingAllNativeEvents()
true
if the popup should preview all native events,
even if the event has already been consumed by another popup.public boolean isShowing()
public boolean isVisible()
visibility
style attribute, which is set in the
setVisible(boolean)
method. If you want to know if the popup is
attached to the page, use isShowing()
instead.isVisible
in interface HasVisibility
isVisible
in class UIObject
true
if the object is visiblesetVisible(boolean)
@Deprecated public boolean onEventPreview(Event event)
onPreviewNativeEvent(com.google.gwt.user.client.Event.NativePreviewEvent)
insteadEventPreview
onEventPreview
in interface EventPreview
event
- the browser eventfalse
to cancel the eventDOM.addEventPreview(EventPreview)
@Deprecated public boolean onKeyDownPreview(char key, int modifiers)
onPreviewNativeEvent(com.google.gwt.user.client.Event.NativePreviewEvent)
insteadkey
- the key code of the depressed keymodifiers
- keyboard modifiers, as specified in
KeyCodes
.false
to suppress the event@Deprecated public boolean onKeyPressPreview(char key, int modifiers)
onPreviewNativeEvent(com.google.gwt.user.client.Event.NativePreviewEvent)
insteadkey
- the unicode character pressedmodifiers
- keyboard modifiers, as specified in
KeyCodes
.false
to suppress the event@Deprecated public boolean onKeyUpPreview(char key, int modifiers)
onPreviewNativeEvent(com.google.gwt.user.client.Event.NativePreviewEvent)
insteadkey
- the key code of the released keymodifiers
- keyboard modifiers, as specified in
KeyCodes
.false
to suppress the eventpublic void removeAutoHidePartner(Element partner)
partner
- the auto hide partner to remove@Deprecated public void removePopupListener(PopupListener listener)
HandlerRegistration.removeHandler()
method on the
object returned by addCloseHandler(com.google.gwt.event.logical.shared.CloseHandler<com.google.gwt.user.client.ui.PopupPanel>)
insteadSourcesPopupEvents
removePopupListener
in interface SourcesPopupEvents
listener
- the listener interface to remove.public void setAnimationEnabled(boolean enable)
HasAnimation
setAnimationEnabled
in interface HasAnimation
enable
- true to enable, false to disablepublic void setAutoHideEnabled(boolean autoHide)
autoHide
- true to enable autoHide, false to disablepublic void setAutoHideOnHistoryEventsEnabled(boolean enabled)
enabled
- true to enable, false to disablepublic void setGlassEnabled(boolean enabled)
enabled
- true to enable, false to disablepublic void setGlassStyleName(java.lang.String glassStyleName)
glassStyleName
- the glass element's style namepublic void setHeight(java.lang.String height)
Note that subclasses may have a different behavior. A subclass may decide not to change the height of the child widget. It may instead decide to change the height of an internal panel widget, which contains the child widget.
public void setModal(boolean modal)
modal
- true to make the popup modalpublic void setPopupPosition(int left, int top)
show()
.left
- the left position, in pixelstop
- the top position, in pixelspublic void setPopupPositionAndShow(PopupPanel.PositionCallback callback)
PopupPanel.PositionCallback
, and shows the
popup. The callback allows positioning to be performed based on the
offsetWidth and offsetHeight of the popup, which are normally not available
until the popup is showing. By positioning the popup before it is shown,
the popup will not jump from its original position to the new position.callback
- the callback to set the position of the popupPopupPanel.PositionCallback.setPosition(int offsetWidth, int offsetHeight)
public void setPreviewingAllNativeEvents(boolean previewAllNativeEvents)
When enabled, the popup will preview all native events, even if another popup was opened after this one.
If autoHide is enabled, enabling this feature will cause the popup to autoHide even if another non-modal popup was shown after it. If this feature is disabled, the popup will only autoHide if it was the last popup opened.
previewAllNativeEvents
- true to enable, false to disablepublic void setTitle(java.lang.String title)
UIObject
public void setVisible(boolean visible)
visibility
style attribute. You need to call show()
to actually attached/detach the PopupPanel
to the page.setVisible
in interface HasVisibility
setVisible
in class UIObject
visible
- true
to show the object, false
to
hide itshow()
,
hide()
public void setWidget(Widget w)
SimplePanel
setWidget
in interface HasOneWidget
setWidget
in class SimplePanel
w
- the panel's new widget, or null
to clear the panelpublic void setWidth(java.lang.String width)
Note that subclasses may have a different behavior. A subclass may decide not to change the width of the child widget. It may instead decide to change the width of an internal panel widget, which contains the child widget.
public void show()
public final void showRelativeTo(UIObject target)
target
- the target to show the popup belowprotected Element getContainerElement()
SimplePanel
Element
class defined in the
User
module to maintain backwards compatibility.getContainerElement
in class SimplePanel
protected Element getGlassElement()
PopupPanel
. The element is not
created until it is enabled via setGlassEnabled(boolean)
.protected Element getStyleElement()
UIObject
getStyleElement
in class UIObject
protected void onPreviewNativeEvent(Event.NativePreviewEvent event)
protected void onUnload()
Widget
void maybeUpdateSize()
void setAnimation(PopupPanel.ResizeAnimation animation)
animation
- the animation to use for this popuppublic void setAnimationType(PopupPanel.AnimationType type)
type
- the type of animation to usePopupPanel.AnimationType
public PopupPanel.AnimationType getAnimationType()
PopupPanel.AnimationType