Package org.zkoss.zul

Class Window

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable, Component, Scope, IdSpace, ComponentCtrl, Framable
    Direct Known Subclasses:
    FileuploadDlg, MessageboxDlg

    public class Window
    extends XulElement
    implements Framable, IdSpace
    A window.

    Unlike other elements, each Window is an independent ID space (by implementing IdSpace). It means a window and all its descendants forms a ID space and the ID of each of them is unique in this space. You could retrieve any of them in this space by calling AbstractComponent.getFellow(java.lang.String).

    If a window X is a descendant of another window Y, X's descendants are not visible in Y's space. To retrieve a descendant, say Z, of X, you have to invoke Y.getFellow('X').getFellow('Z').

    Events:
    onMove, onOpen, onMaximize, onMinimize, and onClose.
    Note: to have better performance, onOpen is sent only if a non-deferrable event listener is registered (see Deferrable).

    onMaximize and onMinimize are supported. (since 3.5.0)

    onClose is sent when the close button is pressed (if isClosable() is true). The window has to detach or hide the window. By default, onClose() detaches the window. To prevent it from detached, you have to call Event.stopPropagation() to prevent onClose() is called.

    On the other hand, onOpen is sent when a popup window (i.e., getMode() is popup) is closed due to user's activity (such as press ESC). This event is only a notification. In other words, the popup is hidden before the event is sent to the server. The application cannot prevent the window from being hidden.

    Default getZclass(): z-window.(since 3.5.0)

    Author:
    tomyeh
    See Also:
    Serialized Form
    • Method Detail

      • isMaximized

        public boolean isMaximized()
        Returns whether the window is maximized.
        Specified by:
        isMaximized in interface Framable
        Since:
        3.5.0
      • setMaximized

        public void setMaximized​(boolean maximized)
        Sets whether the window is maximized, and then the size of the window will depend on it to show a appropriate size. In other words, if true, the size of the window will count on the size of its offset parent node whose position is absolute (by not inEmbedded()) or its parent node. Otherwise, its size will be original size. Note that the maximized effect will run at client's sizing phase not initial phase.

        Default: false.

        Throws:
        UiException - if isMaximizable() is false.
        Since:
        3.5.0
      • isMaximizable

        public boolean isMaximizable()
        Returns whether to display the maximizing button and allow the user to maximize the window.

        Default: false.

        Specified by:
        isMaximizable in interface Framable
        Since:
        3.5.0
      • setMaximizable

        public void setMaximizable​(boolean maximizable)
        Sets whether to display the maximizing button and allow the user to maximize the window, when a window is maximized, the button will automatically change to a restore button with the appropriate behavior already built-in that will restore the window to its previous size.

        Default: false.

        Note: the maximize button won't be displayed if no title or caption at all.

        Since:
        3.5.0
      • isMinimized

        public boolean isMinimized()
        Returns whether the window is minimized.

        Default: false.

        Since:
        3.5.0
      • setMinimized

        public void setMinimized​(boolean minimized)
        Sets whether the window is minimized.

        Default: false.

        Throws:
        UiException - if isMinimizable() is false.
        Since:
        3.5.0
      • isMinimizable

        public boolean isMinimizable()
        Returns whether to display the minimizing button and allow the user to minimize the window.

        Default: false.

        Specified by:
        isMinimizable in interface Framable
        Since:
        3.5.0
      • setMinimizable

        public void setMinimizable​(boolean minimizable)
        Sets whether to display the minimizing button and allow the user to minimize the window. Note that this button provides no implementation -- the behavior of minimizing a window is implementation-specific, so the MinimizeEvent event must be handled and a custom minimize behavior implemented for this option to be useful.

        Default: false.

        Note: the maximize button won't be displayed if no title or caption at all.

        Since:
        3.5.0
        See Also:
        MinimizeEvent
      • setMinheight

        public void setMinheight​(int minheight)
        Sets the minimum height in pixels allowed for this window. If negative, 100 is assumed.

        Default: 100.

        Note: Only applies when isSizable() = true.

        Since:
        3.5.0
      • getMinheight

        public int getMinheight()
        Returns the minimum height.

        Default: 100.

        Since:
        3.5.0
      • setMinwidth

        public void setMinwidth​(int minwidth)
        Sets the minimum width in pixels allowed for this window. If negative, 200 is assumed.

        Default: 200.

        Note: Only applies when isSizable() = true.

        Since:
        3.5.0
      • getMinwidth

        public int getMinwidth()
        Returns the minimum width.

        Default: 200.

        Since:
        3.5.0
      • getCaption

        public Caption getCaption()
        Returns the caption of this window.
      • getBorder

        public java.lang.String getBorder()
        Returns the border.

        Default: "none".

      • setBorder

        public void setBorder​(java.lang.String border)
        Sets the border (either none or normal).
        Parameters:
        border - the border. If null, "0" or "false", "none" is assumed. If "true", "normal" is assumed (since 5.0.8).
      • setBorder

        public void setBorder​(boolean border)
        Enables or disables the border.
        Parameters:
        border - whether to have a border. If true is specified, it is the same as setBorder("normal").
        Since:
        5.0.8
      • getTitle

        public java.lang.String getTitle()
        Returns the title. Besides this attribute, you could use Caption to define a more sophisticated caption (a.k.a., title).

        If a window has a caption whose label (LabelElement.getLabel()) is not empty, then this attribute is ignored.

        Default: empty.

        Specified by:
        getTitle in interface Framable
      • setTitle

        public void setTitle​(java.lang.String title)
        Sets the title.
      • getMode

        public java.lang.String getMode()
        Returns the current mode. One of "modal", "embedded", "overlapped", "popup", and "highlighted".
        See Also:
        getModeType()
      • setMode

        public void setMode​(Window.Mode mode)
        Sets the mode.
        Since:
        6.0.0
      • setMode

        public void setMode​(java.lang.String name)
        Sets the mode to overlapped, popup, modal, embedded or highlighted.

        Notice: Events.ON_MODAL is posted if you specify "modal" to this method. Unlike doModal(), Events.ON_MODAL is posted, so the window will become modal later (since 3.0.4). In other words, setMode("modal") never suspends the execution of the current thread. On the other hand, doModal() will suspends the execution if executed in an event listener, or throws an exception if not executed in an event listener.

        Refer to Overlapped, Popup, Modal, Highlighted and Embedded for more information.

        Parameters:
        name - the mode which could be one of "embedded", "overlapped", "popup", "modal", "highlighted". Note: it cannot be "modal". Use doModal() instead.
      • setMode

        public void setMode​(int mode)
        Sets the mode to overlapped, popup, modal, embedded or highlighted.
        See Also:
        setMode(String)
      • inModal

        public boolean inModal()
        Returns whether this is a modal dialog.
      • inEmbedded

        public boolean inEmbedded()
        Returns whether this is embedded with other components (Default).
        See Also:
        doEmbedded()
      • inOverlapped

        public boolean inOverlapped()
        Returns whether this is a overlapped window.
      • inPopup

        public boolean inPopup()
        Returns whether this is a popup window.
      • inHighlighted

        public boolean inHighlighted()
        Returns whether this is a highlighted window.
      • doOverlapped

        public void doOverlapped()
        Makes this window as overlapped with other components.
      • doPopup

        public void doPopup()
        Makes this window as popup, which is overlapped with other component and auto-hidden when user clicks outside of the window.
      • doHighlighted

        public void doHighlighted()
        Makes this window as highlighted. The visual effect is the similar to the modal window, but, like overlapped, it doesn't suspend (block) the execution at the server. In other words, it is more like an overlapped window from the server side's viewpoint.
      • doEmbedded

        public void doEmbedded()
        Makes this window as embedded with other components (Default).
      • isClosable

        public boolean isClosable()
        Returns whether to show a close button on the title bar.
        Specified by:
        isClosable in interface Framable
      • setClosable

        public void setClosable​(boolean closable)
        Sets whether to show a close button on the title bar. If closable, a button is displayed and the onClose event is sent if an user clicks the button.

        Default: false.

        You can intercept the default behavior by either overriding onClose(), or listening the onClose event.

        Note: the close button won't be displayed if no title or caption at all.

      • isSizable

        public boolean isSizable()
        Returns whether the window is sizable.
      • setSizable

        public void setSizable​(boolean sizable)
        Sets whether the window is sizable. If true, an user can drag the border to change the window width.

        Default: false.

      • isShadow

        public boolean isShadow()
        Returns whether to show the shadow of an overlapped/popup/modal window. It is meaningless if it is an embedded window.
        Since:
        3.6.0
      • setShadow

        public void setShadow​(boolean shadow)
        Sets whether to show the shadow of an overlapped/popup/modal window. It is meaningless if it is an embedded window.

        Default: true.

        Since:
        3.6.0
      • onClose

        public void onClose()
        Process the onClose event sent when the close button is pressed.

        Default: detach itself.

      • onModal

        public void onModal()
        Process the onModal event by making itself a modal window.
      • getContentStyle

        public java.lang.String getContentStyle()
        Returns the CSS style for the content block of the window.
      • setContentStyle

        public void setContentStyle​(java.lang.String style)
        Sets the CSS style for the content block of the window.

        Default: null.

      • setContentSclass

        public void setContentSclass​(java.lang.String scls)
        Sets the style class used for the content block.
        Since:
        3.0.0
        See Also:
        getContentSclass()
      • setTopmost

        public void setTopmost()
        Makes this window as topmost. It has no effect if this window is embedded.
        Since:
        5.0.0
      • setVisible

        public boolean setVisible​(boolean visible)
        Changes the visibility of the window.

        Note if you turned on the event thread:
        If a modal dialog becomes invisible, the modal state will be ended automatically. In other words, the mode (getMode()) will become OVERLAPPED and the suspending thread is resumed. In other words, the modal window (MODAL) can not be invisible (while a window in other modes could be invisible).

        However, if the event thread is not enabled (default), there is no such limitation. In other words, it remains the same mode when becoming invisible.

        Specified by:
        setVisible in interface Component
        Overrides:
        setVisible in class AbstractComponent
        Returns:
        the previous visibility
      • setDraggable

        public void setDraggable​(java.lang.String draggable)
        Description copied from class: HtmlBasedComponent
        Sets "true" or "false" to denote whether a component is draggable, or an identifier of a draggable type of objects.

        The simplest way to make a component draggable is to set this attribute to true. To disable it, set this to false.

        If there are several types of draggable objects, you could assign an identifier for each type of draggable object. The identifier could be anything but empty.

        Overrides:
        setDraggable in class HtmlBasedComponent
        Parameters:
        draggable - "false", "" or null to denote non-draggable; "true" for draggable with anonymous identifier; others for an identifier of draggable.
        Notice that if the parent is DragControl and draggable is null, then it means draggable.
      • clone

        public java.lang.Object clone()
        Description copied from interface: Component
        Clones the component. All of its children and descendants are cloned. Also, ID are preserved.
        Specified by:
        clone in interface Component
        Overrides:
        clone in class XulElement
        Returns:
        the new component. Notice that it doesn't belong to any page, nor desktop. It doesn't have a parent, either.
      • isCollapsible

        public boolean isCollapsible()
        Always return false.
        Specified by:
        isCollapsible in interface Framable
        Since:
        3.6.2