⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tabbox.java

📁 非常接近C/S操作方式的Java Ajax框架-ZK 用ZK框架使你的B/S应用程序更漂亮更易操作。 官网:www.zkoss.org
💻 JAVA
字号:
/* Tabbox.java{{IS_NOTE	Purpose:			Description:			History:		Tue Jul 12 10:42:31     2005, Created by tomyeh}}IS_NOTECopyright (C) 2005 Potix Corporation. All Rights Reserved.{{IS_RIGHT	This program is distributed under GPL Version 2.0 in the hope that	it will be useful, but WITHOUT ANY WARRANTY.}}IS_RIGHT*/package org.zkoss.zul;import java.util.Iterator;import java.util.Set;import org.zkoss.lang.Objects;import org.zkoss.xml.HTMLs;import org.zkoss.zk.ui.Component;import org.zkoss.zk.ui.UiException;import org.zkoss.zk.ui.WrongValueException;import org.zkoss.zk.ui.event.Events;import org.zkoss.zk.ui.ext.client.Selectable;import org.zkoss.zk.au.AuScript;import org.zkoss.zul.impl.XulElement;/** * A tabbox. * * <p>Event: * <ol> * <li>org.zkoss.zk.ui.event.SelectEvent is sent when user changes * the tab.</li> * </ol> * * <p>Mold: * <dl> * <dt>default</dt> * <dd>The default tabbox.</dd> * <dt>accordion</dt> * <dd>The accordion tabbox.</dd> * </dl> * @author tomyeh */public class Tabbox extends XulElement {	private transient Tabs _tabs;	private transient Tabpanels _tabpanels;	private transient Tab _seltab;	private String _panelSpacing;	private String _orient = "horizontal";	public Tabbox() {	}	/** Returns whether it is in the accordion mold.	 */	/*package*/ boolean inAccordionMold() {		return "accordion".equals(getMold());	}	/** Returns the tabs that this tabbox owns.	 */	public Tabs getTabs() {		return _tabs;	}	/** Returns the tabpanels that this tabbox owns.	 */	public Tabpanels getTabpanels() {		return _tabpanels;	}	/** Returns the spacing between {@link Tabpanel}.	 * This is used by certain molds, such as accordion.	 * <p>Default: null (no spacing).	 */	public String getPanelSpacing() {		return _panelSpacing;	}	/** Sets the spacing between {@link Tabpanel}.	 * This is used by certain molds, such as accordion.	 */	public void setPanelSpacing(String panelSpacing) {		if (panelSpacing != null && panelSpacing.length() == 0)			panelSpacing = null;		if (!Objects.equals(_panelSpacing, panelSpacing)) {			_panelSpacing = panelSpacing;			invalidate();		}	}	/** Returns the selected index.	 */	public int getSelectedIndex() {		return _seltab != null ? _seltab.getIndex(): -1;	}	/*** Sets the selected index.	 */	public void setSelectedIndex(int j) {		final Tabs tabs = getTabs();		if (tabs == null)			throw new IllegalStateException("No tab at all");		setSelectedTab((Tab)tabs.getChildren().get(j));	}	/** Returns the selected tab panel.	 */	public Tabpanel getSelectedPanel() {		return _seltab != null ? _seltab.getLinkedPanel(): null;	}	/** Sets the selected tab panel.	 */	public void setSelectedPanel(Tabpanel panel) {		if (panel != null && panel.getTabbox() != this)			throw new UiException("Not a child: "+panel);		final Tab tab = panel.getLinkedTab();		if (tab != null)			setSelectedTab(tab);	}	/** Returns the selected tab.	 */	public Tab getSelectedTab() {		return _seltab;	}	/** Sets the selected tab.	 */	public void setSelectedTab(Tab tab) {		setSelectedTab0(tab, true);	}	private void setSelectedTab0(Tab tab, boolean update) {		if (tab == null)			throw new IllegalArgumentException("null tab");		if (tab.getTabbox() != this)			throw new UiException("Not my child: "+tab);		if (tab != _seltab) {			if (_seltab != null)				_seltab.setSelectedDirectly(false);			_seltab = tab;			_seltab.setSelectedDirectly(true);			if (update)				response("sel", new AuScript(					this, "zkTab.selTab('"+_seltab.getUuid()+"')"));		}	}	/** Returns the orient.	 *	 * <p>Default: "horizontal".	 *	 * <p>Note: only the default mold supports it (not supported if accordion).	 */	public String getOrient() {		return _orient;	}	/** Sets the orient.	 * @param orient either "horizontal" or "vertical".	 */	public void setOrient(String orient) throws WrongValueException {		if (!"horizontal".equals(orient) && !"vertical".equals(orient))			throw new WrongValueException(orient);		checkOrient(getMold(), orient);		if (!Objects.equals(_orient, orient)) {			_orient = orient;			invalidate();		}	}	private static void checkOrient(String mold, String orient)	throws WrongValueException {		if ("vertical".equals(orient) && !"default".equals(mold))			throw new WrongValueException("vertical can be used with the default mold");	}	//-- Component --//	public void setMold(String mold) {		checkOrient(mold, getOrient());		super.setMold(mold);	}	/** Auto-creates {@link Tabpanel} and select one of tabs if necessary.	 */	public void onCreate() {		if (_tabs != null) {			final int sz = _tabs.getChildren().size();			if (_tabpanels == null)				insertBefore(new Tabpanels(), null);			for (int n = _tabpanels.getChildren().size(); n < sz; ++n)				_tabpanels.insertBefore(new Tabpanel(), null);			if (sz > 0 && _seltab == null)				setSelectedTab((Tab)_tabs.getChildren().get(0));		}	}	public boolean insertBefore(Component child, Component insertBefore) {		if (child instanceof Tabs) {			if (_tabs != null && _tabs != child)				throw new UiException("Only one tabs is allowed: "+this);			_tabs = (Tabs)child;		} else if (child instanceof Tabpanels) {			if (_tabpanels != null && _tabpanels != child)				throw new UiException("Only one tabpanels is allowed: "+this);			_tabpanels = (Tabpanels)child;		} else {			throw new UiException("Unsupported child for tabbox: "+child);		}		if (super.insertBefore(child, insertBefore)) {			invalidate(); //due to DSP might implemented diff for children order			return true;		}		return false;	}	public void onChildRemoved(Component child) {		if (child instanceof Tabs) {			_tabs = null;			_seltab = null;		} else if (child instanceof Tabpanels) {			_tabpanels = null;		}		super.onChildRemoved(child);	}	//-- super --//	public String getOuterAttrs() {		final StringBuffer sb =			new StringBuffer(64).append(super.getOuterAttrs());		appendAsapAttr(sb, Events.ON_SELECT);		appendAsapAttr(sb, Events.ON_RIGHT_CLICK);			//no z.dbclk/z.lfclk since it is covered by both Tab and Tabpanel		//HTMLs.appendAttribute(sb, "z.orient", _orient);		return sb.toString();	}	//Cloneable//	public Object clone() {		final Tabbox clone = (Tabbox)super.clone();		int cnt = 0;		if (clone._tabs != null) ++cnt;		if (clone._tabpanels != null) ++cnt;		if (cnt > 0) clone.afterUnmarshal(cnt);		return clone;	}	private void afterUnmarshal(int cnt) {		for (Iterator it = getChildren().iterator(); it.hasNext();) {			final Object child = it.next();			if (child instanceof Tabs) {				_tabs = (Tabs)child;				for (Iterator e = _tabs.getChildren().iterator();				e.hasNext();) {					final Tab tab = (Tab)e.next();					if (tab.isSelected()) {						_seltab = tab;						break;					}				}				if (--cnt == 0) break;			} else if (child instanceof Tabpanels) {				_tabpanels = (Tabpanels)child;				if (--cnt == 0) break;			}		}	}	//-- Serializable --//	private synchronized void readObject(java.io.ObjectInputStream s)	throws java.io.IOException, ClassNotFoundException {		s.defaultReadObject();		afterUnmarshal(-1);	}	//-- ComponentCtrl --//	protected Object newExtraCtrl() {		return new ExtraCtrl();	}	/** A utility class to implement {@link #getExtraCtrl}.	 * It is used only by component developers.	 */	protected class ExtraCtrl extends XulElement.ExtraCtrl implements Selectable {		//-- Selectable --//		public void selectItemsByClient(Set selItems) {			if (selItems != null && selItems.size() == 1)				setSelectedTab0((Tab)selItems.iterator().next(), false);			else				throw new UiException("Exactly one selected tab is required: "+selItems); //debug purpose		}	}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -