|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.Widget
com.google.gwt.user.client.ui.Panel
com.google.gwt.user.client.ui.SimplePanel
com.google.gwt.user.client.ui.PopupPanel
public class PopupPanel
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 tosetWidth(String)
and
setHeight(String)
will call these methods on the PopupPanel's
widget.
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.addClickListener(new ClickListener() { public void onClick(Widget sender) { // 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.addClickListener(new ClickListener() { public void onClick(Widget sender) { // 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); } }
Nested Class Summary | |
---|---|
static interface |
PopupPanel.PositionCallback
A callback that is used to set the position of a PopupPanel right
before it is shown. |
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 and shows it. |
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 |
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. |
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 height of the panel's child widget. |
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 |
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. |
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, adopt, clear, disown, doAttachChildren, doDetachChildren, onLoad, onUnload, orphan |
Methods inherited from class com.google.gwt.user.client.ui.Widget |
---|
getParent, isAttached, onAttach, onBrowserEvent, removeFromParent, setElement |
Methods inherited from class com.google.gwt.user.client.ui.UIObject |
---|
addStyleDependentName, addStyleName, getAbsoluteLeft, getAbsoluteTop, getElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, isVisible, isVisible, removeStyleDependentName, removeStyleName, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setVisible, sinkEvents, toString, unsinkEvents |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public PopupPanel()
public PopupPanel(boolean autoHide)
autoHide
- true
if the popup should be automatically
hidden when the user clicks outside of itpublic PopupPanel(boolean autoHide, boolean modal)
autoHide
- true
if the popup should be automatically
hidden when the user clicks outside of itmodal
- true
if keyboard or mouse events that do not
target the PopupPanel or its children should be ignoredMethod Detail |
---|
public void addPopupListener(PopupListener listener)
SourcesPopupEvents
addPopupListener
in interface SourcesPopupEvents
listener
- the listener interface to add.public void center()
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
getTitle
in class UIObject
public void hide()
public boolean onEventPreview(Event event)
EventPreview
onEventPreview
in interface EventPreview
event
- the browser event
false
to cancel the eventDOM.addEventPreview(EventPreview)
public boolean onKeyDownPreview(char key, int modifiers)
key
- the key code of the depressed keymodifiers
- keyboard modifiers, as specified in
KeyboardListener
.
false
to suppress the eventpublic boolean onKeyPressPreview(char key, int modifiers)
key
- the unicode character pressedmodifiers
- keyboard modifiers, as specified in
KeyboardListener
.
false
to suppress the eventpublic boolean onKeyUpPreview(char key, int modifiers)
key
- the key code of the released keymodifiers
- keyboard modifiers, as specified in
KeyboardListener
.
false
to suppress the eventpublic void removePopupListener(PopupListener listener)
SourcesPopupEvents
removePopupListener
in interface SourcesPopupEvents
listener
- the listener interface to remove.public void setHeight(java.lang.String height)
setHeight
in class UIObject
height
- the object's new height, in CSS units (e.g. "10px", "1em")public 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 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 setTitle(java.lang.String title)
UIObject
setTitle
in class UIObject
title
- the object's new titlepublic void setVisible(boolean visible)
setVisible
in class UIObject
visible
- true
to show the object, false
to hide itpublic void setWidget(Widget w)
SimplePanel
setWidget
in class SimplePanel
w
- the panel's new widget, or null
to clear the panelpublic void setWidth(java.lang.String width)
setWidth
in class UIObject
width
- the object's new width, in CSS units (e.g. "10px", "1em")public void show()
protected Element getContainerElement()
SimplePanel
getContainerElement
in class SimplePanel
protected Element getStyleElement()
UIObject
getStyleElement
in class UIObject
protected void onDetach()
Widget.onUnload()
method instead.
onDetach
in class Widget
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |