001: /* Popup.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Fri Sep 23 09:49:49 2005, Created by tomyeh
010: }}IS_NOTE
011:
012: Copyright (C) 2005 Potix Corporation. All Rights Reserved.
013:
014: {{IS_RIGHT
015: This program is distributed under GPL Version 2.0 in the hope that
016: it will be useful, but WITHOUT ANY WARRANTY.
017: }}IS_RIGHT
018: */
019: package org.zkoss.zul;
020:
021: import org.zkoss.lang.Objects;
022: import org.zkoss.xml.HTMLs;
023:
024: import org.zkoss.zk.ui.Component;
025: import org.zkoss.zk.ui.event.Events;
026: import org.zkoss.zk.ui.ext.render.ZidRequired;
027: import org.zkoss.zk.ui.ext.render.Floating;
028:
029: import org.zkoss.zul.impl.XulElement;
030: import org.zkoss.zul.au.out.AuPopup;
031:
032: /**
033: * A container that is displayed as a popup.
034: * The popup window does not have any special frame.
035: * Popups can be displayed when an element is clicked by assigning
036: * the id of the popup to either the {@link #setPopup},
037: * {@link #setContext} or {@link #setTooltip} attribute of the element.
038: *
039: * <p>Default {@link #getSclass}: ctxpopup.
040: *
041: * @author tomyeh
042: */
043: public class Popup extends XulElement {
044: public Popup() {
045: super .setVisible(false);
046: if (!(this instanceof Menupopup))
047: setSclass("ctxpopup");
048: }
049:
050: /**
051: * Opens this popup to the specified location at the client.
052: *
053: * <p>In most cases, the popup is shown automatically when specified
054: * in the tooltip, popup and context properties
055: * ({@link XulElement#setTooltip}, {@link XulElement#setPopup},
056: * and {@link XulElement#setContext}).
057: * However, if you want to show it manually, you can invoke this
058: * method directly.
059: *
060: * @param x the X coordinate
061: * @param y the Y coordinate
062: * @since 3.0.0
063: */
064: public void open(String x, String y) {
065: response("popup", new AuPopup(this , x, y));
066: }
067:
068: /**
069: * Opens this popup to the specified location at the client.
070: *
071: * <p>In most cases, the popup is shown automatically when specified
072: * in the tooltip, popup and context properties
073: * ({@link XulElement#setTooltip}, {@link XulElement#setPopup},
074: * and {@link XulElement#setContext}).
075: * However, if you want to show it manually, you can invoke this
076: * method directly.
077: *
078: * @param x the X coordinate
079: * @param y the Y coordinate
080: * @since 3.0.0
081: */
082: public void open(int x, int y) {
083: response("popup", new AuPopup(this , Integer.toString(x),
084: Integer.toString(y)));
085: }
086:
087: /**
088: * Opens this popup right below the specified component at the cleint.
089: * <p>In most cases, the popup is shown automatically when specified
090: * in the tooltip, popup and context properties
091: * ({@link XulElement#setTooltip}, {@link XulElement#setPopup},
092: * and {@link XulElement#setContext}).
093: * However, if you want to show it manually, you can invoke this
094: * method directly.
095: *
096: * @param ref the reference component to position the popup.
097: * It cannot be null.
098: * @since 3.0.0
099: */
100: public void open(Component ref) {
101: response("popup", new AuPopup(this , ref));
102: }
103:
104: /**
105: * Closes this popup at the client.
106: *
107: * <p>In most cases, the popup is closed automatically when the user
108: * clicks outside of the popup.
109: * @since 3.0.0
110: */
111: public void close() {
112: response("popup", new AuPopup(this , false));
113: }
114:
115: //super//
116: /** Not allowd.
117: * Use {@link #open} to open, and {@link #close} to close.
118: */
119: public boolean setVisible(boolean visible) {
120: throw new UnsupportedOperationException(
121: "Use open/close instead");
122: }
123:
124: public String getOuterAttrs() {
125: //Note: don't generate z.type here because Menupopup's z.type diff
126: final StringBuffer sb = appendAsapAttr(null, Events.ON_OPEN);
127: final String attrs = super .getOuterAttrs();
128: return sb != null ? sb.append(attrs).toString() : attrs;
129: }
130:
131: //-- ComponentCtrl --//
132: protected Object newExtraCtrl() {
133: return new ExtraCtrl();
134: }
135:
136: /** A utility class to implement {@link #getExtraCtrl}.
137: * It is used only by component developers.
138: */
139: protected class ExtraCtrl extends XulElement.ExtraCtrl implements
140: ZidRequired, Floating {
141: //ZidRequired//
142: public boolean isZidRequired() {
143: return !(getParent() instanceof Menu);
144: }
145:
146: //Floating//
147: public boolean isFloating() {
148: return true;
149: }
150: }
151: }
|