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