001: /* Tabpanel.java
002:
003: {{IS_NOTE
004: Purpose:
005:
006: Description:
007:
008: History:
009: Tue Jul 12 10:43:10 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.util.Iterator;
022:
023: import org.zkoss.xml.HTMLs;
024:
025: import org.zkoss.zk.ui.Component;
026: import org.zkoss.zk.ui.UiException;
027:
028: import org.zkoss.zul.impl.XulElement;
029:
030: /**
031: * A tab panel.
032: *
033: * <p>Default {@link #getSclass}:
034: * <table border="1" cellspacing="0">
035: * <tr>
036: * <td>sclass</td><td>tabbox's mold</td>
037: * <td>tabbox's orient {@link Tabbox#getOrient}</td>
038: * </tr>
039: * <tr><td>tabpanel</td><td>default</td><td>horizontal</td></tr>
040: * <tr><td>tabpanel-<em>something</em></td><td><em>something</em></td><td>horizontal</td></tr>
041: * <tr><td>vtabpanel</td><td>default</td><td>vertical</td></tr>
042: * <tr><td>vtabpanel-<em>something</em></td><td><em>something</em></td><td>vertical</td></tr>
043: * </table>
044: *
045: * @author tomyeh
046: */
047: public class Tabpanel extends XulElement {
048: public Tabpanel() {
049: }
050:
051: /** Returns the tabbox owns this component.
052: */
053: public Tabbox getTabbox() {
054: final Tabpanels panels = (Tabpanels) getParent();
055: return panels != null ? panels.getTabbox() : null;
056: }
057:
058: /** Returns the tab associated with this tab panel.
059: */
060: public Tab getLinkedTab() {
061: final int j = getIndex();
062: if (j >= 0) {
063: final Tabbox tabbox = getTabbox();
064: if (tabbox != null) {
065: final Tabs tabs = tabbox.getTabs();
066: if (tabs != null && tabs.getChildren().size() > j)
067: return (Tab) tabs.getChildren().get(j);
068: }
069: }
070: return null;
071: }
072:
073: /** Returns whether this tab panel is selected.
074: */
075: public boolean isSelected() {
076: final Tab tab = getLinkedTab();
077: return tab != null && tab.isSelected();
078: }
079:
080: /** Returns the index of this panel, or -1 if it doesn't belong to any
081: * tabpanels.
082: */
083: public int getIndex() {
084: final Tabpanels tabpanels = (Tabpanels) getParent();
085: if (tabpanels == null)
086: return -1;
087: int j = 0;
088: for (Iterator it = tabpanels.getChildren().iterator();; ++j)
089: if (it.next() == this )
090: return j;
091: }
092:
093: //-- super --//
094: public String getOuterAttrs() {
095: final String attrs = super .getOuterAttrs();
096: final String clkattrs = getAllOnClickAttrs(false);
097: return clkattrs == null ? attrs : attrs + clkattrs;
098: }
099:
100: /** Returns the style class.
101: *
102: * <p>The default style class, i.e., the style class is not defined (i.e.,
103: * {@link #setSclass} is not called or called with null or empty):
104: * <table border="1" cellspacing="0">
105: * <tr>
106: * <td>sclass</td><td>tabbox's mold</td>
107: * <td>tabbox's orient {@link Tabbox#getOrient}</td>
108: * </tr>
109: * <tr><td>tabpanel</td><td>default</td><td>horizontal</td></tr>
110: * <tr><td>tabpanel-<em>something</em></td><td><em>something</em></td><td>horizontal</td></tr>
111: * <tr><td>vtabpanel</td><td>default</td><td>vertical</td></tr>
112: * <tr><td>vtabpanel-<em>something</em></td><td><em>something</em></td><td>vertical</td></tr>
113: * </table>
114: *
115: * <p>Note: prior to 3.0.3, the default style class doesn't depend on
116: * the tabbox's orientation.
117: */
118: public String getSclass() {
119: final String scls = super .getSclass();
120: if (scls != null)
121: return scls;
122:
123: final Tabbox tabbox = getTabbox();
124: final boolean vert = tabbox != null && tabbox.isVertical();
125: final String mold = tabbox != null ? tabbox.getMold() : null;
126: return mold == null || "default".equals(mold) ? vert ? "vtabpanel"
127: : "tabpanel"
128: : (vert ? "vtabpanel-" : "tabpanel-") + mold;
129: }
130:
131: //-- Component --//
132: public boolean isVisible() {
133: return super .isVisible() && isSelected();
134: }
135:
136: public void setParent(Component parent) {
137: if (parent != null && !(parent instanceof Tabpanels))
138: throw new UiException("Wrong parent: " + parent);
139: super.setParent(parent);
140: }
141: }
|