public class Window extends Panel implements FieldEvents.FocusNotifier, FieldEvents.BlurNotifier
UI
. A window is added to a UI
using
UI.addWindow(Window)
.
The contents of a window is set using AbstractSingleComponentContainer.setContent(Component)
or by
using the Window(String, Component)
constructor.
A window can be positioned on the screen using absolute coordinates (pixels)
or set to be centered using center()
The caption is displayed in the window header.
In Vaadin versions prior to 7.0.0, Window was also used as application level
windows. This function is now covered by the UI
class.
Modifier and Type | Class and Description |
---|---|
static class |
Window.CloseEvent |
static interface |
Window.CloseListener
An interface used for listening to Window close events.
|
static class |
Window.CloseShortcut
A
ShortcutListener specifically made to define a keyboard
shortcut that closes the window. |
static class |
Window.ResizeEvent
Resize events are fired whenever the client-side fires a resize-event
(e.g.
|
static interface |
Window.ResizeListener
Listener for window resize events.
|
static class |
Window.WindowModeChangeEvent
Event which is fired when the mode of the Window changes.
|
static interface |
Window.WindowModeChangeListener
An interface used for listening to Window maximize / restore events.
|
static class |
Window.WindowOrderChangeEvent
Event which is fired when the window order position is changed.
|
static interface |
Window.WindowOrderChangeListener
An interface used for listening to Window order change events.
|
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
Sizeable.Unit
HasComponents.ComponentAttachDetachNotifier, HasComponents.ComponentAttachEvent, HasComponents.ComponentAttachListener, HasComponents.ComponentDetachEvent, HasComponents.ComponentDetachListener
actionManager
DESIGN_ATTR_PLAIN_TEXT
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
Constructor and Description |
---|
Window()
Creates a new, empty window.
|
Window(String caption)
Creates a new, empty window with a given title.
|
Window(String caption,
Component content)
Creates a new, empty window with the given content and title.
|
Modifier and Type | Method and Description |
---|---|
Registration |
addBlurListener(FieldEvents.BlurListener listener)
Adds a
BlurListener to the Component which gets fired
when a Field loses keyboard focus. |
Registration |
addCloseListener(Window.CloseListener listener)
Adds a CloseListener to the window.
|
void |
addCloseShortcut(int keyCode,
int... modifiers)
Adds a close shortcut - pressing this key while holding down all (if any)
modifiers specified while this Window is in focus will close the Window.
|
Registration |
addFocusListener(FieldEvents.FocusListener listener)
Adds a
FocusListener to the Component which gets fired
when a Field receives keyboard focus. |
Registration |
addResizeListener(Window.ResizeListener listener)
Add a resize listener.
|
Registration |
addWindowModeChangeListener(Window.WindowModeChangeListener listener)
Adds a WindowModeChangeListener to the window.
|
Registration |
addWindowOrderChangeListener(Window.WindowOrderChangeListener listener)
Adds a WindowOrderChangeListener to the window.
|
void |
bringToFront()
If there are currently several windows visible, calling this method makes
this window topmost.
|
void |
center()
Sets this window to be centered relative to its parent window.
|
void |
changeVariables(Object source,
Map<String,Object> variables)
Called when one or more variables handled by the implementing class are
changed.
|
void |
close()
Method that handles window closing (from UI).
|
protected void |
fireClose() |
protected void |
fireResize()
Fire the resize event.
|
protected void |
fireWindowOrderChange(Integer order) |
protected void |
fireWindowWindowModeChange() |
void |
focus()
Moves keyboard focus to the component.
|
Component[] |
getAssistiveDescription()
Gets the components that are used as assistive description.
|
String |
getAssistivePostfix()
Gets the accessibility postfix for the window caption.
|
String |
getAssistivePrefix()
Gets the accessibility prefix for the window caption.
|
WindowRole |
getAssistiveRole()
Gets the WAI-ARIA role the window.
|
Collection<Window.CloseShortcut> |
getCloseShortcuts()
Returns an unmodifiable collection of
Window.CloseShortcut objects
currently registered with this Window . |
protected Collection<String> |
getCustomAttributes()
Returns a collection of attributes that should not be handled by the
basic implementation of the
AbstractComponent.readDesign(Element, DesignContext)
and AbstractComponent.writeDesign(Element, DesignContext) methods. |
int |
getOrderPosition()
Returns the position of this window in the order of all open windows for
this UI.
|
int |
getPositionX()
Gets the distance of Window left border in pixels from left border of the
containing (main window) when the window is in
WindowMode.NORMAL . |
int |
getPositionY()
Gets the distance of Window top border in pixels from top border of the
containing (main window) when the window is in
WindowMode.NORMAL
state, or when next set to that state. |
protected WindowState |
getState()
Returns the shared state bean with information to be sent from the server
to the client.
|
protected WindowState |
getState(boolean markAsDirty)
Returns the shared state for this connector.
|
String |
getTabStopBottomAssistiveText()
Gets the message that is provided to users of assistive devices when the
user reaches the bottom of the window when leaving a window with the tab
key is prevented.
|
String |
getTabStopTopAssistiveText()
Gets the message that is provided to users of assistive devices when the
user reaches the top of the window when leaving a window with the tab key
is prevented.
|
WindowMode |
getWindowMode()
Gets the current mode of the window.
|
boolean |
hasCloseShortcut(int keyCode,
int... modifiers)
Checks if a close window shortcut key has already been registered.
|
boolean |
isClosable()
Returns the closable status of the window.
|
boolean |
isDraggable()
Indicates whether a window can be dragged or not.
|
boolean |
isModal() |
boolean |
isResizable() |
boolean |
isResizeLazy() |
boolean |
isTabStopEnabled()
Get if it is prevented to leave a window with the tab key.
|
void |
paintContent(PaintTarget target)
Paints the Paintable into a UIDL stream.
|
void |
readDesign(org.jsoup.nodes.Element design,
DesignContext context)
Reads the component state from the given design.
|
protected void |
readDesignChildren(org.jsoup.select.Elements children,
DesignContext context)
Reads the content and possible assistive descriptions from the list of
child elements of a design.
|
void |
removeAllCloseShortcuts()
Removes all close shortcuts.
|
void |
removeCloseListener(Window.CloseListener listener)
Deprecated.
|
void |
removeCloseShortcut()
Deprecated.
Use
removeCloseShortcut(int, int...) instead. |
void |
removeCloseShortcut(int keyCode,
int... modifiers)
Removes a close shortcut previously added with
addCloseShortcut(int, int...) . |
void |
removeResizeListener(Window.ResizeListener listener)
Deprecated.
|
void |
removeWindowModeChangeListener(Window.WindowModeChangeListener listener)
Deprecated.
|
void |
setAssistiveDescription(Component... components)
Allows to specify which components contain the description for the
window.
|
void |
setAssistivePostfix(String assistivePostfix)
Sets the accessibility postfix for the window caption.
|
void |
setAssistivePrefix(String prefix)
Sets the accessibility prefix for the window caption.
|
void |
setAssistiveRole(WindowRole role)
Sets the WAI-ARIA role the window.
|
void |
setClosable(boolean closable)
Sets the closable status for the window.
|
void |
setCloseShortcut(int keyCode,
int... modifiers)
Deprecated.
Use
addCloseShortcut(int, int...) instead. |
void |
setDraggable(boolean draggable)
Enables or disables that a window can be dragged (moved) by the user.
|
void |
setModal(boolean modal)
Sets window modality.
|
void |
setParent(HasComponents parent)
Sets the parent connector of the component.
|
void |
setPosition(int x,
int y)
Sets the position of the window on the screen using
setPositionX(int) and setPositionY(int) . |
void |
setPositionX(int positionX)
Sets the distance of Window left border in pixels from left border of the
containing (main window).
|
void |
setPositionY(int positionY)
Sets the distance of Window top border in pixels from top border of the
containing (main window).
|
void |
setResizable(boolean resizable)
Sets window resizable.
|
void |
setResizeLazy(boolean resizeLazy)
Should resize operations be lazy, i.e.
|
void |
setTabStopBottomAssistiveText(String bottomMessage)
Sets the message that is provided to users of assistive devices when the
user reaches the bottom of the window when leaving a window with the tab
key is prevented.
|
void |
setTabStopEnabled(boolean tabStop)
Set if it should be prevented to set the focus to a component outside a
non-modal window with the tab key.
|
void |
setTabStopTopAssistiveText(String topMessage)
Sets the message that is provided to users of assistive devices when the
user reaches the top of the window when leaving a window with the tab key
is prevented.
|
void |
setWindowMode(WindowMode windowMode)
Sets the mode for the window.
|
void |
writeDesign(org.jsoup.nodes.Element design,
DesignContext context)
Writes the component state to the given design.
|
addAction, addActionHandler, addClickListener, getActionManager, getScrollLeft, getScrollTop, getTabIndex, removeAction, removeActionHandler, removeAllActionHandlers, removeClickListener, setCaption, setScrollLeft, setScrollTop, setTabIndex
addComponentAttachListener, addComponentDetachListener, fireComponentAttachEvent, fireComponentDetachEvent, getComponentCount, getContent, iterator, removeComponentAttachListener, removeComponentDetachListener, removeFromParent, setContent, setHeight, setWidth
addContextClickListener, addListener, addShortcutListener, addStyleName, attach, beforeClientResponse, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorMessage, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isOrHasAncestor, isReadOnly, isRequiredIndicatorVisible, isResponsive, isVisible, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setDescription, setEnabled, setHeight, setHeightUndefined, setIcon, setId, setLocale, setPrimaryStyleName, setReadOnly, setRequiredIndicatorVisible, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth, setWidthUndefined
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
markAsDirty
isEnabled
addListener, addStyleName, addStyleNames, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isVisible, removeListener, removeStyleName, removeStyleNames, setEnabled, setIcon, setId, setPrimaryStyleName, setStyleName, setStyleName, setVisible
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
getConnectorId
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthUndefined
forEach, spliterator
public Window()
public Window(String caption)
caption
- the title of the window.public void paintContent(PaintTarget target) throws PaintException
LegacyComponent
Paints the Paintable into a UIDL stream. This method creates the UIDL sequence describing it and outputs it to the given UIDL stream.
It is called when the contents of the component should be painted in response to the component first being shown or having been altered so that its visual representation is changed.
paintContent
in interface LegacyComponent
paintContent
in class Panel
target
- the target UIDL stream where the component should paint itself
to.PaintException
- if the paint operation failed.public void setParent(HasComponents parent)
Component
This method automatically calls Component.attach()
if the component
becomes attached to the session, regardless of whether it was attached
previously. Conversely, if the component currently is attached to the
session, ClientConnector.detach()
is called for the connector before attaching
it to a new parent.
This method is rarely called directly.
ComponentContainer.addComponent(Component)
or a
HasComponents
specific method is normally used for adding
components to a parent and the used method will call this method
implicitly.
setParent
in interface Component
setParent
in class AbstractComponent
parent
- the parent connectorpublic void changeVariables(Object source, Map<String,Object> variables)
Panel
changeVariables
in interface VariableOwner
changeVariables
in class Panel
source
- the Source of the variable change. This is the origin of the
event. For example in Web Adapter this is the request.variables
- the Mapping from variable names to new variable values.VariableOwner.changeVariables(Object, Map)
public void close()
By default, windows are removed from their respective UIs and thus visually closed on browser-side.
To react to a window being closed (after it is closed), register a
Window.CloseListener
.
public int getPositionX()
WindowMode.NORMAL
.public void setPosition(int x, int y)
setPositionX(int)
and setPositionY(int)
.x
- The new x coordinate for the windowy
- The new y coordinate for the windowpublic void setPositionX(int positionX)
WindowMode.NORMAL
mode.positionX
- the Distance of Window left border in pixels from left border
of the containing (main window). or -1 if unspecified.public int getPositionY()
WindowMode.NORMAL
state, or when next set to that state.public int getOrderPosition()
Window with position 0 is on the bottom, and window with greatest
position is at the top. If window has no position (it's not yet attached
or hidden) then position is -1
.
UI.addWindowOrderUpdateListener(com.vaadin.ui.UI.WindowOrderUpdateListener)
public void setPositionY(int positionY)
WindowMode.NORMAL
mode.positionY
- the Distance of Window top border in pixels from top border of
the containing (main window). or -1 if unspecifiedpublic Registration addWindowOrderChangeListener(Window.WindowOrderChangeListener listener)
The WindowOrderChangeEvent is fired when the order position is changed. It can happen when some window (this or other) is brought to front or detached.
The other way to listen positions of all windows in UI is
UI.addWindowOrderUpdateListener(com.vaadin.ui.UI.WindowOrderUpdateListener)
listener
- the WindowModeChangeListener to add.UI.addWindowOrderUpdateListener(com.vaadin.ui.UI.WindowOrderUpdateListener)
protected void fireWindowOrderChange(Integer order)
public Registration addCloseListener(Window.CloseListener listener)
Since Vaadin 6.5, removing windows using #removeWindow(Window)
does fire the CloseListener.
listener
- the CloseListener to add, not null@Deprecated public void removeCloseListener(Window.CloseListener listener)
For more information on CloseListeners see Window.CloseListener
.
listener
- the CloseListener to remove.protected void fireClose()
public Registration addWindowModeChangeListener(Window.WindowModeChangeListener listener)
setWindowMode(WindowMode)
.listener
- the WindowModeChangeListener to add.@Deprecated public void removeWindowModeChangeListener(Window.WindowModeChangeListener listener)
listener
- the WindowModeChangeListener to remove.protected void fireWindowWindowModeChange()
public Registration addResizeListener(Window.ResizeListener listener)
listener
- the listener to add, not nullRegistration
@Deprecated public void removeResizeListener(Window.ResizeListener listener)
listener
- protected void fireResize()
public void bringToFront()
This method can only be called if this window connected a UI. Else an illegal state exception is thrown. Also if there are modal windows and this window is not modal, and illegal state exception is thrown.
public void setModal(boolean modal)
Keyboard navigation is restricted by blocking the tab key at the top and bottom of the window by activating the tab stop function internally.
modal
- true if modality is to be turned onpublic boolean isModal()
public void setResizable(boolean resizable)
resizable
- true if resizability is to be turned onpublic boolean isResizable()
public boolean isResizeLazy()
public void setResizeLazy(boolean resizeLazy)
resizeLazy
- true to use a delay before recalculating sizes, false to
calculate immediately.public void center()
NOTE: This method has several issues as currently implemented. Please refer to http://dev.vaadin.com/ticket/8971 for details.
public boolean isClosable()
public void setClosable(boolean closable)
closable
- determines if the window can be closed by the user.public boolean isDraggable()
true
if window is draggable; false
if notpublic void setDraggable(boolean draggable)
draggable
- true if the window can be dragged by the userpublic WindowMode getWindowMode()
WindowMode
public void setWindowMode(WindowMode windowMode)
windowMode
- The new modeWindowMode
@Deprecated public void setCloseShortcut(int keyCode, int... modifiers)
addCloseShortcut(int, int...)
instead.Window
- to preserve compatibility with existing code under the
new functionality, this method now first removes all registered close
shortcuts, then adds the default ESCAPE shortcut key, and then attempts
to add the shortcut provided as parameters to this method. This method,
and its companion removeCloseShortcut()
, are now considered
deprecated, as their main function is to preserve exact backwards
compatibility with old code. For all new code, use the new keyboard
shortcuts API: addCloseShortcut(int,int...)
,
removeCloseShortcut(int,int...)
,
removeAllCloseShortcuts()
, hasCloseShortcut(int,int...)
and getCloseShortcuts()
.
Original description: Makes it possible to close the window by pressing
the given ShortcutAction.KeyCode
and (optional) ShortcutAction.ModifierKey
s.
Note that this shortcut only reacts while the window has focus, closing
itself - if you want to close a window from a UI, use
UI.addAction(com.vaadin.event.Action)
of the UI instead.
keyCode
- the keycode for invoking the shortcutmodifiers
- the (optional) modifiers for invoking the shortcut. Can be set
to null to be explicit about not having modifiers.@Deprecated public void removeCloseShortcut()
removeCloseShortcut(int, int...)
instead.setCloseShortcut(int, int...)
and
addCloseShortcut(int, int...)
, then adds the default
ShortcutAction.KeyCode.ESCAPE
shortcut.
This is the old way of removing the (single) keyboard close shortcut, and
is retained only for exact backwards compatibility. For all new code, use
the new keyboard shortcuts API: addCloseShortcut(int,int...)
,
removeCloseShortcut(int,int...)
,
removeAllCloseShortcuts()
, hasCloseShortcut(int,int...)
and getCloseShortcuts()
.
public void addCloseShortcut(int keyCode, int... modifiers)
keyCode
- the keycode for invoking the shortcutmodifiers
- the (optional) modifiers for invoking the shortcut. Can be set
to null to be explicit about not having modifiers.public void removeCloseShortcut(int keyCode, int... modifiers)
addCloseShortcut(int, int...)
.keyCode
- the keycode for invoking the shortcutmodifiers
- the (optional) modifiers for invoking the shortcut. Can be set
to null to be explicit about not having modifiers.public void removeAllCloseShortcuts()
removeCloseShortcut(int, int...)
.public boolean hasCloseShortcut(int keyCode, int... modifiers)
keyCode
- the keycode for invoking the shortcutmodifiers
- the (optional) modifiers for invoking the shortcut. Can be set
to null to be explicit about not having modifiers.public Collection<Window.CloseShortcut> getCloseShortcuts()
Window.CloseShortcut
objects
currently registered with this Window
. This method is provided
mainly so that users can implement their own serialization routines. To
check if a certain combination of keys has been registered as a close
shortcut, use the hasCloseShortcut(int, int...)
method instead.public Registration addFocusListener(FieldEvents.FocusListener listener)
FieldEvents.FocusNotifier
FocusListener
to the Component which gets fired
when a Field
receives keyboard focus.addFocusListener
in interface FieldEvents.FocusNotifier
listener
- the focus listener to add, not nullFieldEvents.FocusListener
,
Registration
public Registration addBlurListener(FieldEvents.BlurListener listener)
FieldEvents.BlurNotifier
BlurListener
to the Component which gets fired
when a Field
loses keyboard focus.addBlurListener
in interface FieldEvents.BlurNotifier
listener
- the blur listener to add, not nullFieldEvents.BlurListener
,
Registration
public void focus()
Component.Focusable.focus()
Cause the window to be brought on top of other windows and gain keyboard
focus.focus
in interface Component.Focusable
focus
in class Panel
FieldEvents
,
FieldEvents.FocusEvent
,
FieldEvents.FocusListener
,
FieldEvents.BlurEvent
,
FieldEvents.BlurListener
protected WindowState getState()
AbstractComponent
protected WindowState getState(boolean markAsDirty)
AbstractClientConnector
getState
in class Panel
markAsDirty
- true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()
public void setAssistiveDescription(Component... components)
components
- the components to use as descriptionpublic Component[] getAssistiveDescription()
public void setAssistivePrefix(String prefix)
prefix
- String that is placed before the window captionpublic String getAssistivePrefix()
public void setAssistivePostfix(String assistivePostfix)
assistivePostfix
- String that is placed after the window captionpublic String getAssistivePostfix()
public void setAssistiveRole(WindowRole role)
role
- WAI-ARIA role to set for the windowpublic WindowRole getAssistiveRole()
public void setTabStopEnabled(boolean tabStop)
This is meant to help users of assistive devices to not leaving the window unintentionally.
For modal windows, this function is activated automatically, while preserving the stored value of tabStop.
tabStop
- true to keep the focus inside the window when reaching the top
or bottom, false (default) to allow leaving the windowpublic boolean isTabStopEnabled()
public void setTabStopTopAssistiveText(String topMessage)
This message is not visible on the screen.
topMessage
- String provided when the user navigates with Shift-Tab keys to
the top of the windowpublic void setTabStopBottomAssistiveText(String bottomMessage)
This message is not visible on the screen.
bottomMessage
- String provided when the user navigates with the Tab key to
the bottom of the windowpublic String getTabStopTopAssistiveText()
public String getTabStopBottomAssistiveText()
public void readDesign(org.jsoup.nodes.Element design, DesignContext context)
Component
The component is responsible not only for updating its own state but also for ensuring that its children update their state based on the design.
It is assumed that the component is in its default state when this method is called. Reading should only take into consideration attributes specified in the design and not reset any unspecified attributes to their defaults.
This method must not modify the design.
readDesign
in interface Component
readDesign
in class Panel
design
- The element to obtain the state fromcontext
- The DesignContext instance used for parsing the designprotected void readDesignChildren(org.jsoup.select.Elements children, DesignContext context)
:assistive-description
attribute, adds the parsed component to
the list of components used as the assistive description of this Window.
Otherwise, sets the component as the content of this Window. If there are
multiple non-description elements, throws a DesignException.readDesignChildren
in class AbstractSingleComponentContainer
children
- child elements in a designcontext
- the DesignContext instance used to parse the designDesignException
- if there are multiple non-description child elementsDesignException
- if a child element could not be parsed as a ComponentAbstractSingleComponentContainer.setContent(Component)
,
setAssistiveDescription(Component...)
public void writeDesign(org.jsoup.nodes.Element design, DesignContext context)
Component
The component is responsible not only for writing its own state but also for ensuring that its children write their state to the design.
This method must not modify the component state.
writeDesign
in interface Component
writeDesign
in class Panel
design
- The element to write the component state to. Any previous
attributes or child nodes are not cleared.context
- The DesignContext instance used for writing the designprotected Collection<String> getCustomAttributes()
AbstractComponent
AbstractComponent.readDesign(Element, DesignContext)
and AbstractComponent.writeDesign(Element, DesignContext)
methods. Typically these
are handled in a custom way in the overridden versions of the above
methodsgetCustomAttributes
in class Panel
Copyright © 2018 Vaadin Ltd. All rights reserved.