public class DialogBox extends DecoratedPopupPanel implements HasHTML, HasSafeHtml, MouseListener
PopupPanel.setWidth(String)
and
PopupPanel.setHeight(String)
will set the width and height of the dialog box
itself, even if a widget has not been added as yet.
public class DialogBoxExample implements EntryPoint, ClickHandler { private static class MyDialog extends DialogBox { public MyDialog() { // Set the dialog box's caption. setText("My First Dialog"); // Enable animation. setAnimationEnabled(true); // Enable glass background. setGlassEnabled(true); // DialogBox is a SimplePanel, so you have to set its widget property to // whatever you want its contents to be. Button ok = new Button("OK"); ok.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { MyDialog.this.hide(); } }); setWidget(ok); } } public void onModuleLoad() { Button b = new Button("Click me"); b.addClickHandler(this); RootPanel.get().add(b); } public void onClick(ClickEvent event) { // Instantiate the dialog box and show it. new MyDialog().show(); } }
DialogBox elements in UiBinder
templates can have one widget child and one <g:caption> child.
(Note the lower case "c", meant to signal that the caption is not a runtime
object, and so cannot have a ui:field
attribute.) The body of
the caption can be html.
For example:
<g:DialogBox autoHide="true" modal="true"> <g:caption><b>Caption text</b></g:caption> <g:HTMLPanel> Body text <g:Button ui:field='cancelButton'>Cancel</g:Button> <g:Button ui:field='okButton'>Okay</g:Button> </g:HTMLPanel> </g:DialogBox>You may also create your own header caption. The caption must implement
DialogBox.Caption
.
For example:
<g:DialogBox autoHide="true" modal="true">
<-- foo is your prefix and Bar is a class that implements DialogBox.Caption
-->
<g:customCaption><foo:Bar/></g:customCaption>
<g:HTMLPanel>
Body text
<g:Button ui:field='cancelButton'>Cancel</g:Button>
<g:Button ui:field='okButton'>Okay</g:Button>
</g:HTMLPanel>
</g:DialogBox>
Modifier and Type | Class and Description |
---|---|
static interface |
DialogBox.Caption
Set of characteristic interfaces supported by the
DialogBox
caption. |
static class |
DialogBox.CaptionImpl
Default implementation of Caption.
|
PopupPanel.AnimationType, PopupPanel.PositionCallback, PopupPanel.ResizeAnimation
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
HasWidgets.ForIsWidget
Modifier and Type | Field and Description |
---|---|
(package private) HandlerRegistration |
resizeHandlerRegistration |
widget
eventsToSink
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR
Constructor and Description |
---|
DialogBox()
Creates an empty dialog box.
|
DialogBox(boolean autoHide)
Creates an empty dialog box specifying its "auto-hide" property.
|
DialogBox(boolean autoHide,
boolean modal)
Creates an empty dialog box specifying its "auto-hide" and "modal"
properties.
|
DialogBox(boolean autoHide,
boolean modal,
DialogBox.Caption captionWidget)
Creates an empty dialog box specifying its "auto-hide", "modal" properties
and an implementation a custom
DialogBox.Caption . |
DialogBox(DialogBox.Caption captionWidget)
Creates an empty dialog box specifying its
DialogBox.Caption . |
Modifier and Type | Method and Description |
---|---|
protected void |
beginDragging(MouseDownEvent event)
Called on mouse down in the caption area, begins the dragging loop by
turning on event capture.
|
protected void |
continueDragging(MouseMoveEvent event)
Called on mouse move in the caption area, continues dragging if it was
started by
beginDragging(com.google.gwt.event.dom.client.MouseDownEvent) . |
protected void |
doAttachChildren()
If a widget contains one or more child widgets that are not in the logical
widget hierarchy (the child is physically connected only on the DOM level),
it must override this method and call
Widget.onAttach() for each of its
child widgets. |
protected void |
doDetachChildren()
If a widget contains one or more child widgets that are not in the logical
widget hierarchy (the child is physically connected only on the DOM level),
it must override this method and call
Widget.onDetach() for each of its
child widgets. |
protected void |
endDragging(MouseUpEvent event)
Called on mouse up in the caption area, ends dragging by ending event
capture.
|
DialogBox.Caption |
getCaption()
Provides access to the dialog's caption.
|
java.lang.String |
getHTML()
Gets this object's contents as HTML.
|
java.lang.String |
getText()
Gets this object's text.
|
void |
hide(boolean autoClosed)
Hides the popup and detaches it from the page.
|
void |
onBrowserEvent(Event event)
Fired whenever a browser event is received.
|
protected void |
onEnsureDebugId(java.lang.String baseID)
Affected Elements:
-caption = text at the top of the
DialogBox .
-content = the container around the content.
|
void |
onMouseDown(Widget sender,
int x,
int y)
Deprecated.
|
void |
onMouseEnter(Widget sender)
Deprecated.
|
void |
onMouseLeave(Widget sender)
Deprecated.
|
void |
onMouseMove(Widget sender,
int x,
int y)
Deprecated.
|
void |
onMouseUp(Widget sender,
int x,
int y)
Deprecated.
|
protected void |
onPreviewNativeEvent(Event.NativePreviewEvent event) |
void |
setHTML(SafeHtml html)
Sets the html string inside the caption by calling its
setHTML(SafeHtml) method. |
void |
setHTML(java.lang.String html)
Sets the html string inside the caption by calling its
setHTML(SafeHtml) method. |
void |
setText(java.lang.String text)
Sets the text inside the caption by calling its
setText(String)
method. |
void |
show()
Shows the popup and attach it to the page.
|
clear, getCellElement, getWidget, iterator, remove, setWidget
addAutoHidePartner, addCloseHandler, addPopupListener, center, getAnimationType, getContainerElement, getGlassElement, getGlassStyleName, getOffsetHeight, getOffsetWidth, getPopupLeft, getPopupTop, getStyleElement, getTitle, hide, isAnimationEnabled, isAutoHideEnabled, isAutoHideOnHistoryEventsEnabled, isGlassEnabled, isModal, isPreviewingAllNativeEvents, isShowing, isVisible, maybeUpdateSize, onEventPreview, onKeyDownPreview, onKeyPressPreview, onKeyUpPreview, onUnload, removeAutoHidePartner, removePopupListener, setAnimation, setAnimationEnabled, setAnimationType, setAutoHideEnabled, setAutoHideOnHistoryEventsEnabled, setGlassEnabled, setGlassStyleName, setHeight, setModal, setPopupPosition, setPopupPositionAndShow, setPreviewingAllNativeEvents, setTitle, setVisible, setWidth, showRelativeTo
add, setWidget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, ensureHandlers, fireEvent, getHandlerCount, getHandlerManager, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onDetach, onLoad, removeFromParent, replaceElement, setLayoutData, setParent, sinkEvents, unsinkEvents
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, isVisible, 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
HandlerRegistration resizeHandlerRegistration
public DialogBox()
SimplePanel.add(Widget)
.public DialogBox(boolean autoHide)
SimplePanel.add(Widget)
.autoHide
- true
if the dialog should be automatically
hidden when the user clicks outside of itpublic DialogBox(DialogBox.Caption captionWidget)
DialogBox.Caption
. It should not
be shown until its child widget has been added using SimplePanel.add(Widget)
.captionWidget
- the widget that is the DialogBox's header.public DialogBox(boolean autoHide, boolean modal)
SimplePanel.add(Widget)
.autoHide
- true
if the dialog should be automatically
hidden when the user clicks outside of itmodal
- true
if keyboard and mouse events for widgets not
contained by the dialog should be ignoredpublic DialogBox(boolean autoHide, boolean modal, DialogBox.Caption captionWidget)
DialogBox.Caption
. It should not be shown
until its child widget has been added using SimplePanel.add(Widget)
.autoHide
- true
if the dialog should be automatically
hidden when the user clicks outside of itmodal
- true
if keyboard and mouse events for widgets not
contained by the dialog should be ignoredcaptionWidget
- the widget that is the DialogBox's header.public DialogBox.Caption getCaption()
public java.lang.String getHTML()
HasHTML
public java.lang.String getText()
HasText
public void hide(boolean autoClosed)
PopupPanel
hide
in class PopupPanel
autoClosed
- the value that will be passed to
CloseHandler.onClose(CloseEvent)
when the popup is closedpublic void onBrowserEvent(Event event)
EventListener
onBrowserEvent
in interface EventListener
onBrowserEvent
in class Widget
event
- the event received@Deprecated public void onMouseDown(Widget sender, int x, int y)
beginDragging(com.google.gwt.event.dom.client.MouseDownEvent)
and getCaption()
insteadMouseListener
onMouseDown
in interface MouseListener
sender
- the widget sending the eventx
- the x coordinate of the mousey
- the y coordinate of the mouse@Deprecated public void onMouseEnter(Widget sender)
HasMouseOverHandlers.addMouseOverHandler(com.google.gwt.event.dom.client.MouseOverHandler)
insteadMouseListener
onMouseEnter
in interface MouseListener
sender
- the widget sending the event@Deprecated public void onMouseLeave(Widget sender)
HasMouseOutHandlers.addMouseOutHandler(com.google.gwt.event.dom.client.MouseOutHandler)
insteadMouseListener
onMouseLeave
in interface MouseListener
sender
- the widget sending the event@Deprecated public void onMouseMove(Widget sender, int x, int y)
continueDragging(com.google.gwt.event.dom.client.MouseMoveEvent)
and getCaption()
insteadMouseListener
onMouseMove
in interface MouseListener
sender
- the widget sending the eventx
- the x coordinate of the mousey
- the y coordinate of the mouse@Deprecated public void onMouseUp(Widget sender, int x, int y)
endDragging(com.google.gwt.event.dom.client.MouseUpEvent)
and getCaption()
insteadMouseListener
onMouseUp
in interface MouseListener
sender
- the widget sending the eventx
- the x coordinate of the mousey
- the y coordinate of the mousepublic void setHTML(SafeHtml html)
setHTML(SafeHtml)
method.
Use DecoratedPopupPanel.setWidget(Widget)
to set the contents inside the
DialogBox
.setHTML
in interface HasSafeHtml
html
- the object's new HTMLpublic void setHTML(java.lang.String html)
setHTML(SafeHtml)
method. Only known safe HTML should be inserted
in here.
Use DecoratedPopupPanel.setWidget(Widget)
to set the contents inside the
DialogBox
.public void setText(java.lang.String text)
setText(String)
method.
Use DecoratedPopupPanel.setWidget(Widget)
to set the contents inside the
DialogBox
.public void show()
PopupPanel
show
in class PopupPanel
protected void beginDragging(MouseDownEvent event)
event
- the mouse down event that triggered draggingDOM.setCapture(com.google.gwt.dom.client.Element)
,
continueDragging(com.google.gwt.event.dom.client.MouseMoveEvent)
protected void continueDragging(MouseMoveEvent event)
beginDragging(com.google.gwt.event.dom.client.MouseDownEvent)
.event
- the mouse move event that continues draggingbeginDragging(com.google.gwt.event.dom.client.MouseDownEvent)
,
endDragging(com.google.gwt.event.dom.client.MouseUpEvent)
protected void doAttachChildren()
Widget
Widget.onAttach()
for each of its
child widgets.doAttachChildren
in class DecoratedPopupPanel
Widget.onAttach()
protected void doDetachChildren()
Widget
Widget.onDetach()
for each of its
child widgets.doDetachChildren
in class DecoratedPopupPanel
Widget.onDetach()
protected void endDragging(MouseUpEvent event)
event
- the mouse up event that ended draggingDOM.releaseCapture(com.google.gwt.dom.client.Element)
,
beginDragging(com.google.gwt.event.dom.client.MouseDownEvent)
,
endDragging(com.google.gwt.event.dom.client.MouseUpEvent)
protected void onEnsureDebugId(java.lang.String baseID)
DialogBox
.onEnsureDebugId
in class UIObject
baseID
- the base ID used by the main elementUIObject.onEnsureDebugId(String)
protected void onPreviewNativeEvent(Event.NativePreviewEvent event)
onPreviewNativeEvent
in class PopupPanel