📄 window.java
字号:
*/ public boolean inPopup() { return _mode == POPUP; } /** Returns whether this is a highlighted window. */ public boolean inHighlighted() { return _mode == HIGHLIGHTED; } /** Makes this window as a modal dialog. * It will automatically center the window (ignoring {@link #getLeft} and * {@link #getTop}). * * <p>Notice: {@link Events#ON_MODAL} is posted if you specify * "modal" to this method and in a thread other than an event * listener ({@link Events#inEventListener}). * In other words, if this method is called with modal and * <em>not</em> in any event listener, the mode won't be changed * immediately (until {@link Events#ON_MODAL} is processed later). * * @exception SuspendNotAllowedException if there are too many suspended * processing thread than the deployer allows. * By default, there is no limit of # of suspended threads. * @exception InterruptedException thrown if the desktop or * the Web application is being destroyed, or * {@link org.zkoss.zk.ui.sys.DesktopCtrl#ceaseSuspendedThread}. * To tell the difference, check the getMessage method of InterruptedException. */ public void doModal() throws InterruptedException, SuspendNotAllowedException { Desktop desktop = getDesktop(); if (desktop == null) desktop = Executions.getCurrent().getDesktop(); if (!desktop.getWebApp().getConfiguration().isEventThreadEnabled()) { handleFailedModal(_mode, isVisible()); throw new SuspendNotAllowedException("Event processing thread is disabled"); } checkOverlappable(MODAL); if (_mode != MODAL) { if (!Events.inEventListener()) { Events.postEvent(Events.ON_MODAL, this, null); return; //done } int oldmode = _mode; boolean oldvisi = isVisible(); invalidate(); setVisible(true); //if MODAL, it must be visible; vice versa try { enterModal(); } catch (SuspendNotAllowedException ex) { handleFailedModal(oldmode, oldvisi); throw ex; } } } private void handleFailedModal(int oldmode, boolean oldvisi) { try { if (Executions.getCurrent() .getAttribute("javax.servlet.error.exception") != null) { //handle it specially if it is used for dispalying err setMode(HIGHLIGHTED); } else { setMode(oldmode); //restore setVisible(oldvisi); } } catch (Throwable ex) { log.realCauseBriefly("Causing another error", ex); } } /** Makes this window as overlapped with other components. */ public void doOverlapped() { checkOverlappable(OVERLAPPED); setNonModalMode(OVERLAPPED); } /** Makes this window as popup, which is overlapped with other component * and auto-hiden when user clicks outside of the window. */ public void doPopup() { checkOverlappable(POPUP); setNonModalMode(POPUP); } /** Makes this window as highlited. 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. */ public void doHighlighted() { checkOverlappable(HIGHLIGHTED); setNonModalMode(HIGHLIGHTED); } /** Makes this window as embeded with other components (Default). */ public void doEmbedded() { setNonModalMode(EMBEDDED); } /* Set non-modal mode. */ private void setNonModalMode(int mode) { if (_mode != mode) { if (_mode == MODAL) leaveModal(); _mode = mode; invalidate(); } setVisible(true); } /** Set mode to MODAL and suspend this thread. */ private void enterModal() throws InterruptedException { _mode = MODAL; //no need to synchronized (_mutex) because no racing is possible Executions.wait(_mutex); } /** Resumes the suspendded thread and set mode to OVERLAPPED. */ private void leaveModal() { _mode = OVERLAPPED; Executions.notifyAll(_mutex); } /** Makes sure it is not draggable. */ private void checkOverlappable(int mode) { if (!"false".equals(getDraggable())) throw new UiException("Draggable window cannot be modal, overlapped, popup, or highlighted: "+this); if (mode == MODAL || mode == HIGHLIGHTED) for (Component comp = this; (comp = comp.getParent()) != null;) if (!comp.isVisible()) throw new UiException("One of its ancestors, "+comp+", is not visible, so unable to be modal or highlighted"); } /** Returns whether to show a close button on the title bar. */ public boolean isClosable() { return _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. * * <p>Default: false. * * <p>You can intercept the default behavior by either overriding * {@link #onClose}, or listening the onClose event. * * <p>Note: the close button won't be displayed if no title or caption at all. */ public void setClosable(boolean closable) { if (_closable != closable) { _closable = closable; invalidate(); //re-init is required } } /** Returns whether the window is sizable. */ public boolean isSizable() { return _sizable; } /** Sets whether the window is sizable. * If true, an user can drag the border to change the window width. * <p>Default: false. */ public void setSizable(boolean sizable) { if (_sizable != sizable) { _sizable = sizable; smartUpdate("z.sizable", sizable); } } /** Returns how to position the window at the client screen. * It is meaningless if the embedded mode is used. * * <p>Default: null which depends on {@link #getMode}: * If overlapped or popup, {@link #setLeft} and {@link #setTop} are * assumed. If modal or highlighted, it is centered. */ public String getPosition() { return _pos; } /** Sets how to position the window at the client screen. * It is meaningless if the embedded mode is used. * * @param pos how to position. It can be null (the default), or * a combination of the following values (by separating with comma). * <dl> * <dt>center</dt> * <dd>Position the window at the center. {@link #setTop} and {@link #setLeft} * are both ignored.</dd> * <dt>left</dt> * <dd>Position the window at the left edge. {@link #setLeft} is ignored.</dd> * <dt>right</dt> * <dd>Position the window at the right edge. {@link #setLeft} is ignored.</dd> * <dt>top</dt> * <dd>Position the window at the top edge. {@link #setTop} is ignored.</dd> * <dt>bottom</dt> * <dd>Position the window at the bottom edge. {@link #setTop} is ignored.</dd> * </dl> * <p>For example, "left,center" means to position it at the center of * the left edge. */ public void setPosition(String pos) { //Note: we always update since the window might be dragged by an user _pos = pos; if (_mode != EMBEDDED) smartUpdate("z.pos", pos); } /** Process the onClose event sent when the close button is pressed. * <p>Default: detach itself. */ public void onClose() { detach(); } /** Process the onModal event by making itself a modal window. */ public void onModal() throws InterruptedException { doModal(); } /** Returns the CSS style for the content block of the window. */ public String getContentStyle() { return _cntStyle; } /** Sets the CSS style for the content block of the window. * * <p>Default: null. */ public void setContentStyle(String style) { if (!Objects.equals(_cntStyle, style)) { _cntStyle = style; smartUpdate("z.cntStyle", _cntStyle); } } /** Returns the style class used for the content block. * * <p>If {@link #setContentSclass} was called with a non-empty value, * say, "mycnt", then * <ol> * <li>Case 1: If {@link #getBorder} is "normal", "mycnt" is returned.</li> * <li>Case 2: Otherwise, "mycnt-<i>border</i>" is returned * where <i>border</i> is the value returned by {@link #getBorder}.</li> * </ol> * * <p>If {@link #setContentSclass} was not called, or called with null, * then the content style class is decided by {@link #getSclass} as follows: * <ol> * <li>Case 1: If {@link #getBorder} is "normal", "wc-<i>sclass</i>" is * returned, where <i>sclass</i> is the value returned by {@link #getSclass}.</li> * <li>Otherwise, "wc-<i>mode</i>-<i>border</i>", * where <i>border</i> is the value returned by {@link #getBorder}.</li> * </li> * @see #setContentSclass */ public String getContentSclass() { String cntscls = _cntscls; if (cntscls == null) { cntscls = getSclass(); cntscls = cntscls != null ? "wc-" + cntscls: "wc"; } final String border = getBorder(); return "normal".equals(border) ? cntscls: cntscls + '-' + border; } /** Sets the style class used for the content block. * * @see #getContentSclass * @since 3.0.0 */ public void setContentSclass(String scls) { if (!Objects.equals(_cntscls, scls)) { _cntscls = scls; smartUpdate("z.cntScls", getContentSclass()); } } /** Returns the style class used for the title. * * <p>It returns "wt-<i>sclass</i>" is returned, * where <i>sclass</i> is the value returned by {@link #getSclass}. */ public String getTitleSclass() { return "wt-" + getSclass(); } //-- super --// /** Returns the style class. * If the style class is not defined ({@link #setSclass} is not called * or called with null or empty), it returns {@link #getMode}. * In other words, the style class is, by default, the same as * the mode name. */ public String getSclass() { final String scls = super.getSclass(); return scls != null ? scls: getMode(); } //-- Component --// public boolean insertBefore(Component child, Component insertBefore) { if (child instanceof Caption) { if (_caption != null && _caption != child) throw new UiException("Only one caption is allowed: "+this); insertBefore = getFirstChild(); //always makes caption as the first child _caption = (Caption)child; invalidate(); } else if (insertBefore instanceof Caption) { throw new UiException("caption must be the first child"); } return super.insertBefore(child, insertBefore); } public void onChildRemoved(Component child) { if (child instanceof Caption) { _caption = null; invalidate(); } super.onChildRemoved(child); } public void setPage(Page page) { super.setPage(page); if (page == null && _mode == MODAL) leaveModal(); } public void setParent(Component parent) { super.setParent(parent); if (_mode == MODAL && getPage() == null) leaveModal(); } /** Changes the visibility of the window. * * <p>Note: If a modal dialog becomes invisible, the modal state * will be ended automatically. In other words, the mode ({@link #getMode}) * will become {@link #OVERLAPPED} and the suspending thread is resumed. */ public boolean setVisible(boolean visible) { if (!visible && _mode == MODAL) { leaveModal(); invalidate(); } return super.setVisible(visible); } //-- super --// public void setDraggable(String draggable) { if (_mode != EMBEDDED) { if (draggable != null && (draggable.length() > 0 && !"false".equals(draggable))) throw new UiException("Only embedded window could be draggable: "+this); } super.setDraggable(draggable); } protected String getRealStyle() { final String style = super.getRealStyle(); return _mode != EMBEDDED ? "position:absolute;" + style: style; //If no absolute, Opera ignores left and top } public String getOuterAttrs() { final StringBuffer sb = new StringBuffer(64).append(super.getOuterAttrs()); appendAsapAttr(sb, Events.ON_MOVE); appendAsapAttr(sb, Events.ON_SIZE); appendAsapAttr(sb, Events.ON_Z_INDEX); appendAsapAttr(sb, Events.ON_OK); appendAsapAttr(sb, Events.ON_CANCEL); appendAsapAttr(sb, Events.ON_CTRL_KEY); appendAsapAttr(sb, Events.ON_OPEN); //no need to generate ON_CLOSE since it is always sent (as ASAP) final String clkattrs = getAllOnClickAttrs(false); if (clkattrs != null) sb.append(clkattrs); //though widget.js handles onclick (if 3d), it is useful //to support onClick for groupbox if (_closable) sb.append(" z.closable=\"true\""); if (_sizable) sb.append(" z.sizable=\"true\""); if (_mode != EMBEDDED) { if (_pos != null) HTMLs.appendAttribute(sb, "z.pos", _pos); HTMLs.appendAttribute(sb, "z.mode", getMode()); } HTMLs.appendAttribute(sb, "z.ctkeys", _ctkeys); return sb.toString(); } //Cloneable// public Object clone() { final Window clone = (Window)super.clone(); clone.init(); if (clone._caption != null) clone.afterUnmarshal(); return clone; } private void afterUnmarshal() { for (Iterator it = getChildren().iterator(); it.hasNext();) { final Object child = it.next(); if (child instanceof Caption) { _caption = (Caption)child; break; } } } //Serializable// private synchronized void readObject(java.io.ObjectInputStream s) throws java.io.IOException, ClassNotFoundException { s.defaultReadObject(); init(); afterUnmarshal(); } //-- ComponentCtrl --// protected Object newExtraCtrl() { return new ExtraCtrl(); } /** A utility class to implement {@link #getExtraCtrl}. * It is used only by component developers. */ protected class ExtraCtrl extends XulElement.ExtraCtrl implements MultiBranch, Openable { //-- MultiBranch --// public boolean inDifferentBranch(Component child) { return child instanceof Caption; //in different branch } //-- Openable --// public void setOpenByClient(boolean open) { setVisible(open); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -