com.itmill.toolkit.ui
Class Window

java.lang.Object
  extended by com.itmill.toolkit.ui.AbstractComponent
      extended by com.itmill.toolkit.ui.AbstractComponentContainer
          extended by com.itmill.toolkit.ui.Panel
              extended by com.itmill.toolkit.ui.Window
All Implemented Interfaces:
Action.Container, MethodEventSource, Paintable, ParameterHandler, Scrollable, Sizeable, URIHandler, VariableOwner, Component, ComponentContainer, ComponentContainer.ComponentAttachListener, ComponentContainer.ComponentDetachListener, EventListener

public class Window
extends Panel
implements URIHandler, ParameterHandler

Application window component.

Since:
3.0
Version:
5.3.0
Author:
IT Mill Ltd.

Nested Class Summary
 class Window.CloseEvent
           
static interface Window.CloseListener
           
static class Window.Notification
          A notification message, used to display temporary messages to the user - for example "Document saved", or "Save failed".
 
Nested classes/interfaces inherited from class com.itmill.toolkit.ui.AbstractComponent
AbstractComponent.ComponentErrorEvent, AbstractComponent.ComponentErrorHandler
 
Nested classes/interfaces inherited from interface com.itmill.toolkit.terminal.URIHandler
URIHandler.ErrorEvent
 
Nested classes/interfaces inherited from interface com.itmill.toolkit.terminal.ParameterHandler
ParameterHandler.ErrorEvent
 
Nested classes/interfaces inherited from interface com.itmill.toolkit.ui.ComponentContainer
ComponentContainer.ComponentAttachEvent, ComponentContainer.ComponentAttachListener, ComponentContainer.ComponentDetachEvent, ComponentContainer.ComponentDetachListener
 
Nested classes/interfaces inherited from interface com.itmill.toolkit.ui.Component
Component.ErrorEvent, Component.ErrorListener, Component.Event, Component.Focusable, Component.Listener
 
Nested classes/interfaces inherited from interface com.itmill.toolkit.terminal.Paintable
Paintable.RepaintRequestEvent, Paintable.RepaintRequestListener
 
Field Summary
static int BORDER_DEFAULT
          Window with default borders.
static int BORDER_MINIMAL
          Window with only minimal border.
static int BORDER_NONE
          Window with no border.
 
Fields inherited from class com.itmill.toolkit.ui.Panel
STYLE_LIGHT
 
Fields inherited from interface com.itmill.toolkit.terminal.Sizeable
SIZE_UNDEFINED, UNIT_SYMBOLS, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
 
Constructor Summary
Window()
          Creates a new empty unnamed window with default layout.
Window(String caption)
          Creates a new empty window with default layout.
Window(String caption, Layout layout)
          Creates a new window.
 
Method Summary
 void addListener(Window.CloseListener listener)
          Adds the listener.
 void addParameterHandler(ParameterHandler handler)
          Adds the new parameter handler to this window.
 void addURIHandler(URIHandler handler)
          Adds the new URI handler to this window.
 void addWindow(Window window)
          Adds a window inside another window.
 void center()
          Request to center this window on the screen.
 void changeVariables(Object source, Map variables)
          Called when one or more variables handled by the implementing class are changed.
protected  void close()
          Method that handles window closing (from UI).
protected  void fireClose()
           
 Application getApplication()
          Gets the application instance of the component.
 int getBorder()
          Returns the border.
 Set getChildWindows()
          Get the set of all child windows.
 String getName()
          Gets the unique name of the window that indentifies it on the terminal.
 Component getParent()
          Getter for property parent.
 int getPositionX()
          Gets the distance of Window left border in pixels from left border of the containing (main window).
 int getPositionY()
          Gets the distance of Window top border in pixels from top border of the containing (main window).
 String getTag()
          Gets the component UIDL tag.
 Terminal getTerminal()
          Gets the terminal type.
 String getTheme()
          Gets the theme for this window.
 URL getURL()
          Returns the full url of the window, this returns window specific url even for the main window.
 Window getWindow()
          Gets the window of the component.
 void handleParameters(Map parameters)
           Handles the given parameters.
 DownloadStream handleURI(URL context, String relativeUri)
          Handles uri recursively.
 boolean isModal()
           
 boolean isResizable()
           
 void open(Resource resource)
          Opens the given resource in this window.
 void open(Resource resource, String windowName)
          Opens the given resource in named terminal window.
 void open(Resource resource, String windowName, int width, int height, int border)
          Opens the given resource in named terminal window with given size and border properties.
 void paintContent(PaintTarget target)
          Paints the content of this component.
 void removeListener(Window.CloseListener listener)
          Removes the listener.
 void removeParameterHandler(ParameterHandler handler)
          Removes the given URI handler from this window.
 void removeURIHandler(URIHandler handler)
          Removes the given URI handler from this window.
 void removeWindow(Window window)
          Remove the given subwindow from this window.
 void setApplication(Application application)
          Sets the application this window is connected to.
 void setBorder(int border)
          Sets the border.
 void setLayout(Layout newLayout)
          Sets the layout of the panel.
 void setModal(boolean modality)
          Sets sub-window modal, so that widgets behind it cannot be accessed.
 void setName(String name)
          Sets the name.
 void setParent(Component parent)
          Setter for property parent.
 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 resizeability)
          Sets sub-window resizable.
 void setTerminal(Terminal type)
          Sets the terminal type.
 void setTheme(String theme)
          Sets the theme for this window.
 void showNotification(String caption)
          Shows a notification message on the middle of the window.
 void showNotification(String caption, int type)
          Shows a notification message the window.
 void showNotification(String caption, String description)
          Shows a notification consisting of a bigger caption and a smaller description on the middle of the window.
 void showNotification(String caption, String description, int type)
          Shows a notification consisting of a bigger caption and a smaller description.
 void showNotification(Window.Notification notification)
          Shows a notification message.
 
Methods inherited from class com.itmill.toolkit.ui.Panel
addActionHandler, addComponent, attach, componentAttachedToContainer, componentDetachedFromContainer, detach, getComponentIterator, getLayout, getScrollLeft, getScrollOffsetX, getScrollOffsetY, getScrollTop, isScrollable, removeActionHandler, removeAllComponents, removeComponent, replaceComponent, requestRepaintAll, setScrollable, setScrollLeft, setScrollOffsetX, setScrollOffsetY, setScrollTop
 
Methods inherited from class com.itmill.toolkit.ui.AbstractComponentContainer
addListener, addListener, fireComponentAttachEvent, fireComponentDetachEvent, moveComponentsFrom, removeListener, removeListener, setEnabled, setHeight, setWidth
 
Methods inherited from class com.itmill.toolkit.ui.AbstractComponent
addListener, addListener, addListener, addListener, addStyleName, childRequestedRepaint, fireComponentErrorEvent, fireComponentEvent, fireEvent, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorHandler, getErrorMessage, getHeight, getHeightUnits, getIcon, getLocale, getStyle, getStyleName, getWidth, getWidthUnits, handleError, isEnabled, isImmediate, isReadOnly, isVisible, paint, removeListener, removeListener, removeListener, removeListener, removeListener, removeStyleName, requestRepaint, requestRepaintRequests, setCaption, setComponentError, setData, setDebugId, setDescription, setErrorHandler, setHeight, setHeight, setHeightUnits, setIcon, setImmediate, setLocale, setReadOnly, setSizeFull, setSizeUndefined, setStyle, setStyleName, setWidth, setWidth, setWidthUnits, setVisible
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.itmill.toolkit.ui.Component
addListener, addStyleName, childRequestedRepaint, getCaption, getIcon, getLocale, getStyleName, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setIcon, setReadOnly, setStyleName, setVisible
 
Methods inherited from interface com.itmill.toolkit.terminal.Paintable
addListener, getDebugId, paint, removeListener, requestRepaint, requestRepaintRequests, setDebugId
 
Methods inherited from interface com.itmill.toolkit.terminal.VariableOwner
isImmediate
 
Methods inherited from interface com.itmill.toolkit.terminal.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightUnits, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthUnits
 

Field Detail

BORDER_NONE

public static final int BORDER_NONE
Window with no border.

See Also:
Constant Field Values

BORDER_MINIMAL

public static final int BORDER_MINIMAL
Window with only minimal border.

See Also:
Constant Field Values

BORDER_DEFAULT

public static final int BORDER_DEFAULT
Window with default borders.

See Also:
Constant Field Values
Constructor Detail

Window

public Window()
Creates a new empty unnamed window with default layout.

To show the window in application, it must be added to application with Application.addWindow method.

The windows are scrollable by default.

Parameters:
caption - the Title of the window.

Window

public Window(String caption)
Creates a new empty window with default layout.

To show the window in application, it must be added to application with Application.addWindow method.

The windows are scrollable by default.

Parameters:
caption - the Title of the window.

Window

public Window(String caption,
              Layout layout)
Creates a new window.

To show the window in application, it must be added to application with Application.addWindow method.

The windows are scrollable by default.

Parameters:
caption - the Title of the window.
layout - the Layout of the window.
Method Detail

setLayout

public void setLayout(Layout newLayout)
Description copied from class: Panel
Sets the layout of the panel. If given layout is null, a VerticalLayout with margins set is used as a default. Components from old layout are not moved to new layout by default (changed in 5.2.2). Use function in Layout interface manually.

Overrides:
setLayout in class Panel
Parameters:
newLayout - the New layout of the panel.

getTerminal

public Terminal getTerminal()
Gets the terminal type.

Returns:
the Value of property terminal.

getWindow

public final Window getWindow()
Gets the window of the component. Returns the window where this component belongs to. If the component does not yet belong to a window the returns null.

Specified by:
getWindow in interface Component
Overrides:
getWindow in class AbstractComponent
Returns:
the parent window of the component.

getApplication

public final Application getApplication()
Gets the application instance of the component. Returns the application where this component belongs to. If the component does not yet belong to a application the returns null.

Specified by:
getApplication in interface Component
Overrides:
getApplication in class AbstractComponent
Returns:
the parent application of the component.

getParent

public final Component getParent()
Getter for property parent.

Parent is the visual parent of a component. Each component can belong to only one ComponentContainer at time.

For windows attached directly to the application, parent is null. For windows inside other windows, parent is the window containing this window.

Specified by:
getParent in interface Component
Overrides:
getParent in class AbstractComponent
Returns:
the Value of property parent.

setParent

public void setParent(Component parent)
Setter for property parent.

Parent is the visual parent of a component. This is mostly called by containers add method and should not be called directly

Specified by:
setParent in interface Component
Overrides:
setParent in class AbstractComponent
Parameters:
parent - the New value of property parent.

getTag

public String getTag()
Gets the component UIDL tag.

Overrides:
getTag in class Panel
Returns:
the Component UIDL tag as string.

addURIHandler

public void addURIHandler(URIHandler handler)
Adds the new URI handler to this window. For sub-windows, URI handlers are attached to root level window.

Parameters:
handler - the URI handler to add.

removeURIHandler

public void removeURIHandler(URIHandler handler)
Removes the given URI handler from this window.

Parameters:
handler - the URI handler to remove.

handleURI

public DownloadStream handleURI(URL context,
                                String relativeUri)
Handles uri recursively. Windows uri handler passes uri to all URIHandlers added to it.

Note, that instead of overriding this method developer should consider using addURIHandler(URIHandler) to add uri handler to Window.

Specified by:
handleURI in interface URIHandler
Parameters:
context -
relativeUri -
Returns:
the download stream object.

addParameterHandler

public void addParameterHandler(ParameterHandler handler)
Adds the new parameter handler to this window. For sub windows, parameter handlers are attached to parent windows.

Parameters:
handler - the parameter handler to add.

removeParameterHandler

public void removeParameterHandler(ParameterHandler handler)
Removes the given URI handler from this window.

Parameters:
handler - the parameter handler to remove.

handleParameters

public void handleParameters(Map parameters)
Description copied from interface: ParameterHandler

Handles the given parameters. The parameters are given as inmodifieable name to value map. All parameters names are of type: String. All the parameter values are arrays of strings.

Specified by:
handleParameters in interface ParameterHandler
Parameters:
parameters - the Inmodifiable name to value[] mapping.

getTheme

public String getTheme()
Gets the theme for this window.

Subwindows do not support themes and thus return theme used by the parent

Returns:
the Name of the theme used in window. If the theme for this individual window is not explicitly set, the application theme is used instead. If application is not assigned the terminal.getDefaultTheme is used. If terminal is not set, null is returned

setTheme

public void setTheme(String theme)
Sets the theme for this window. Setting theme for subwindows is not supported. In Toolkit 5 terminal will reload its host page on theme changes.

Parameters:
theme - the New theme for this window. Null implies the default theme.

paintContent

public void paintContent(PaintTarget target)
                  throws PaintException
Paints the content of this component.

Overrides:
paintContent in class Panel
Parameters:
event - the Paint Event.
Throws:
PaintException - if the paint operation failed.

open

public void open(Resource resource)
Opens the given resource in this window.

Parameters:
resource -

open

public void open(Resource resource,
                 String windowName)
Opens the given resource in named terminal window. Empty or null window name results the resource to be opened in this window.

Parameters:
resource - the resource.
windowName - the name of the window.

open

public void open(Resource resource,
                 String windowName,
                 int width,
                 int height,
                 int border)
Opens the given resource in named terminal window with given size and border properties. Empty or null window name results the resource to be opened in this window.

Parameters:
resource -
windowName -
width -
height -
border -

getURL

public URL getURL()
Returns the full url of the window, this returns window specific url even for the main window.

Returns:
the URL of the window.

getName

public String getName()
Gets the unique name of the window that indentifies it on the terminal.

Name identifies the URL used to access application-level windows, but is not used for windows inside other windows. all application-level windows can be accessed by their names in url http://host:port/foo/bar/ where http://host:port/foo/ is the application url as returned by getURL() and bar is the name of the window. Also note that not all windows should be added to application - one can also add windows inside other windows - these windows show as smaller windows inside those windows.

Returns:
the Name of the Window.

getBorder

public int getBorder()
Returns the border.

Returns:
the border.

setBorder

public void setBorder(int border)
Sets the border.

Parameters:
border - the border to set.

setApplication

public void setApplication(Application application)
Sets the application this window is connected to.

This method should not be invoked directly. Instead the Application.addWindow(Window) method should be used to add the window to an application and Application.removeWindow(Window) method for removing the window from the applicion. These methods call this method implicitly.

The method invokes Component.attach() and Component.detach() methods when necessary.

Parameters:
application - the application to set.

setName

public void setName(String name)
Sets the name.

The name of the window must be unique inside the application.

If the name is null, the the window is given name automatically when it is added to an application.

Parameters:
name - the name to set.

setTerminal

public void setTerminal(Terminal type)
Sets the terminal type. The terminal type is set by the the terminal adapter and may change from time to time.

Parameters:
type - the terminal type to set.

changeVariables

public void changeVariables(Object source,
                            Map variables)
Called when one or more variables handled by the implementing class are changed.

Specified by:
changeVariables in interface VariableOwner
Overrides:
changeVariables in class Panel
Parameters:
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.
See Also:
VariableOwner.changeVariables(java.lang.Object, java.util.Map)

close

protected void close()
Method that handles window closing (from UI).

By default, sub-windows are removed from their respective parent windows and thus visually closed on browser-side. Browser-level windows also closed on the client-side, but they are not implicitly removed from the application.

If one wants change the default behavior, register a window close listenter and do something else. For example, you could re-open the browser-level window with mainWindow.open(), re-add the removed sub-window back to its parent or remove browser-level window automatically from the application.


getPositionX

public int getPositionX()
Gets the distance of Window left border in pixels from left border of the containing (main window).

Returns:
the Distance of Window left border in pixels from left border of the containing (main window). or -1 if unspecified.
Since:
4.0.0

setPositionX

public void setPositionX(int positionX)
Sets the distance of Window left border in pixels from left border of the containing (main window).

Parameters:
positionX - the Distance of Window left border in pixels from left border of the containing (main window). or -1 if unspecified.
Since:
4.0.0

getPositionY

public int getPositionY()
Gets the distance of Window top border in pixels from top border of the containing (main window).

Returns:
Distance of Window top border in pixels from top border of the containing (main window). or -1 if unspecified .
Since:
4.0.0

setPositionY

public void setPositionY(int positionY)
Sets the distance of Window top border in pixels from top border of the containing (main window).

Parameters:
positionY - the Distance of Window top border in pixels from top border of the containing (main window). or -1 if unspecified
Since:
4.0.0

addListener

public void addListener(Window.CloseListener listener)
Adds the listener.

Parameters:
listener - the listener to add.

removeListener

public void removeListener(Window.CloseListener listener)
Removes the listener.

Parameters:
listener - the listener to remove.

fireClose

protected void fireClose()

addWindow

public void addWindow(Window window)
               throws IllegalArgumentException,
                      NullPointerException
Adds a window inside another window.

Adding windows inside another window creates "subwindows". These windows should not be added to application directly and are not accessible directly with any url. Addding windows implicitly sets their parents.

Only one level of subwindows are supported. Thus you can add windows inside such windows whose parent is null.

Parameters:
window -
Throws:
IllegalArgumentException - if a window is added inside non-application level window.
NullPointerException - if the given Window is null.

removeWindow

public void removeWindow(Window window)
Remove the given subwindow from this window.

Parameters:
window - Window to be removed.

getChildWindows

public Set getChildWindows()
Get the set of all child windows.

Returns:
Set of child windows.

setModal

public void setModal(boolean modality)
Sets sub-window modal, so that widgets behind it cannot be accessed. Note: affects sub-windows only.

Parameters:
modality - true if modality is to be turned on

isModal

public boolean isModal()
Returns:
true if this window is modal.

setResizable

public void setResizable(boolean resizeability)
Sets sub-window resizable. Note: affects sub-windows only.

Parameters:
resizable - true if resizability is to be turned on

isResizable

public boolean isResizable()
Returns:
true if window is resizable by the end-user, otherwise false.

center

public void center()
Request to center this window on the screen. Note: affects sub-windows only.


showNotification

public void showNotification(String caption)
Shows a notification message on the middle of the window. The message automatically disappears ("humanized message").

Parameters:
caption - The message
See Also:
showNotification(com.itmill.toolkit.ui.Window.Notification), Window.Notification

showNotification

public void showNotification(String caption,
                             int type)
Shows a notification message the window. The position and behavior of the message depends on the type, which is one of the basic types defined in Window.Notification, for instance Notification.TYPE_WARNING_MESSAGE.

Parameters:
caption - The message
type - The message type
See Also:
showNotification(com.itmill.toolkit.ui.Window.Notification), Window.Notification

showNotification

public void showNotification(String caption,
                             String description)
Shows a notification consisting of a bigger caption and a smaller description on the middle of the window. The message automatically disappears ("humanized message").

Parameters:
caption - The caption of the message
description - The message description
See Also:
showNotification(com.itmill.toolkit.ui.Window.Notification), Window.Notification

showNotification

public void showNotification(String caption,
                             String description,
                             int type)
Shows a notification consisting of a bigger caption and a smaller description. The position and behavior of the message depends on the type, which is one of the basic types defined in Window.Notification, for instance Notification.TYPE_WARNING_MESSAGE.

Parameters:
caption - The caption of the message
description - The message description
type - The message type
See Also:
showNotification(com.itmill.toolkit.ui.Window.Notification), Window.Notification

showNotification

public void showNotification(Window.Notification notification)
Shows a notification message.

Parameters:
notification - The notification message to show
See Also:
Window.Notification, showNotification(String), showNotification(String, int), showNotification(String, String), showNotification(String, String, int)


Copyright © 2000-2009 IT Mill Ltd. All Rights Reserved.