001: /* Listfooter.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Fri Jan 13 12:42:38 2006, Created by tomyeh
010: }}IS_NOTE
011:
012: Copyright (C) 2006 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.util.List;
022: import java.util.Iterator;
023:
024: import org.zkoss.xml.HTMLs;
025:
026: import org.zkoss.zk.ui.Component;
027: import org.zkoss.zk.ui.UiException;
028: import org.zkoss.zul.impl.LabelImageElement;
029:
030: /**
031: * A column of the footer of a list box ({@link Listbox}).
032: * Its parent must be {@link Listfoot}.
033: *
034: * <p>Unlike {@link Listheader}, you could place any child in a list footer.
035: * <p>Note: {@link Listcell} also accepts children.
036: *
037: * @author tomyeh
038: */
039: public class Listfooter extends LabelImageElement {
040: private int _span = 1;
041:
042: public Listfooter() {
043: }
044:
045: public Listfooter(String label) {
046: setLabel(label);
047: }
048:
049: public Listfooter(String label, String src) {
050: setLabel(label);
051: setImage(src);
052: }
053:
054: /** Returns the listbox that this belongs to.
055: */
056: public Listbox getListbox() {
057: final Component comp = getParent();
058: return comp != null ? (Listbox) comp.getParent() : null;
059: }
060:
061: /** Returns the set of footers that this belongs to.
062: * @deprecated As of release 2.4.1, due to confusion
063: */
064: public Listfoot getListfoot() {
065: return (Listfoot) getParent();
066: }
067:
068: /** Returns the column index, starting from 0.
069: */
070: public int getColumnIndex() {
071: int j = 0;
072: for (Iterator it = getParent().getChildren().iterator(); it
073: .hasNext(); ++j)
074: if (it.next() == this )
075: break;
076: return j;
077: }
078:
079: /** Returns the list header that is in the same column as
080: * this footer, or null if not available.
081: */
082: public Listheader getListheader() {
083: final Listbox listbox = getListbox();
084: if (listbox != null) {
085: final Listhead lcs = listbox.getListhead();
086: if (lcs != null) {
087: final int j = getColumnIndex();
088: final List lcschs = lcs.getChildren();
089: if (j < lcschs.size())
090: return (Listheader) lcschs.get(j);
091: }
092: }
093: return null;
094: }
095:
096: /** Returns number of columns to span this footer.
097: * Default: 1.
098: */
099: public int getSpan() {
100: return _span;
101: }
102:
103: /** Sets the number of columns to span this footer.
104: * <p>It is the same as the colspan attribute of HTML TD tag.
105: */
106: public void setSpan(int span) {
107: if (_span != span) {
108: _span = span;
109: smartUpdate("colspan", Integer.toString(_span));
110: }
111: }
112:
113: //-- super --//
114: public String getOuterAttrs() {
115: final StringBuffer sb = new StringBuffer(80).append(super
116: .getOuterAttrs());
117:
118: final String clkattrs = getAllOnClickAttrs(false);
119: if (clkattrs != null)
120: sb.append(clkattrs);
121:
122: final Listheader header = getListheader();
123: if (header != null)
124: sb.append(header.getColAttrs());
125:
126: if (_span != 1)
127: HTMLs.appendAttribute(sb, "colspan", _span);
128:
129: return sb.toString();
130: }
131:
132: //-- Component --//
133: public void setParent(Component parent) {
134: if (parent != null && !(parent instanceof Listfoot))
135: throw new UiException("Wrong parent: " + parent);
136: super.setParent(parent);
137: }
138: }
|