001: /* Menubar.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Thu Sep 22 10:34:31 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 java.io.IOException;
022:
023: import org.zkoss.lang.JVMs;
024:
025: import org.zkoss.zk.ui.Component;
026: import org.zkoss.zk.ui.HtmlBasedComponent;
027: import org.zkoss.zk.ui.UiException;
028: import org.zkoss.zk.ui.WrongValueException;
029:
030: import org.zkoss.zul.impl.XulElement;
031:
032: /**
033: * A container that usually contains menu elements.
034: *
035: * <p>Default {@link #getSclass}: menubar.
036: *
037: * @author tomyeh
038: */
039: public class Menubar extends XulElement {
040: private boolean _autodrop;
041:
042: public Menubar() {
043: setSclass("menubar");
044: setMold("horizontal");
045: }
046:
047: /**
048: * @param orient either horizontal or vertical
049: */
050: public Menubar(String orient) {
051: setSclass("menubar");
052: setOrient(orient);
053: }
054:
055: /** Returns the orient (the same as {@link #getMold}).
056: * <p>Default: "horizontal".
057: */
058: public String getOrient() {
059: return getMold();
060: }
061:
062: /** Sets the orient.
063: * @param orient either horizontal or vertical
064: */
065: public void setOrient(String orient) throws WrongValueException {
066: if (!"horizontal".equals(orient) && !"vertical".equals(orient))
067: throw new WrongValueException("orient cannot be " + orient);
068:
069: setMold(orient);
070: }
071:
072: /** Returns whether to automatically drop down menus if user moves mouse
073: * over it.
074: * <p>Default: false.
075: */
076: public final boolean isAutodrop() {
077: return _autodrop;
078: }
079:
080: /** Sets whether to automatically drop down menus if user moves mouse
081: * over it.
082: */
083: public void setAutodrop(boolean autodrop) {
084: if (_autodrop != autodrop) {
085: _autodrop = autodrop;
086: smartUpdate("z.autodrop", autodrop);
087: }
088: }
089:
090: //-- Component --//
091: public String getOuterAttrs() {
092: final String attrs = super .getOuterAttrs();
093: return _autodrop ? attrs + " z.autodrop=\"true\"" : attrs;
094: }
095:
096: public boolean insertBefore(Component child, Component insertBefore) {
097: if (!(child instanceof Menu) && !(child instanceof Menuitem))
098: throw new UiException("Unsupported child for menubar: "
099: + child);
100: return super .insertBefore(child, insertBefore);
101: }
102:
103: public void onDrawNewChild(Component child, StringBuffer out)
104: throws IOException {
105: if ("vertical".equals(getOrient())) {
106: final StringBuffer sb = new StringBuffer(32).append(
107: "<tr id=\"").append(child.getUuid()).append(
108: "!chdextr\"");
109: if (child instanceof HtmlBasedComponent) {
110: final String height = ((HtmlBasedComponent) child)
111: .getHeight();
112: if (height != null)
113: sb.append(" height=\"").append(height).append('"');
114: }
115: sb.append('>');
116: if (JVMs.isJava5())
117: out.insert(0, sb); //Bug 1682844
118: else
119: out.insert(0, sb.toString());
120: out.append("</tr>");
121: }
122: }
123: }
|