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

📄 components.java

📁 非常接近C/S操作方式的Java Ajax框架-ZK 用ZK框架使你的B/S应用程序更漂亮更易操作。 官网:www.zkoss.org
💻 JAVA
字号:
/* Components.java{{IS_NOTE	Purpose:			Description:			History:		Mon Jun 13 20:55:18     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.zk.ui;import java.util.Iterator;import java.util.ListIterator;import java.util.Collection;import java.util.AbstractCollection;import java.util.ArrayList;import java.util.List;import java.util.Collections;import java.util.Arrays;import java.util.Comparator;/** * Utilities to access {@link Component}. * * @author tomyeh */public class Components {	protected Components() {}	/** Sorts the components in the list.	 *	 * <p>Note: you cannot use Collections.sort to sort	 * {@link Component#getChildren} because Collections.sort might cause	 * some replicated item in the list.	 */	public static void sort(List list, Comparator cpr) {		final Object ary[] = list.toArray();		Arrays.sort(ary, cpr);		ListIterator it = list.listIterator();		int j = 0;		for (; it.hasNext(); ++j) {			if (it.next() != ary[j]) {				it.remove();				if (it.hasNext()) {					if (it.next() == ary[j]) continue;					it.previous();				}				break;			}		}		while (it.hasNext()) {			it.next();			it.remove();		}		for (; j < ary.length; ++j)			list.add(ary[j]);	}	/** Tests whether node1 is an ancessor of node 2.	 * If node1 and node2 is the same, true is returned.	 */	public static boolean isAncestor(Component node1, Component node2) {		for (; node2 != null; node2 = node2.getParent()) {			if (node1 == node2)				return true;		}		return false;	}	/** Removes all children of the specified component.	 */	public static void removeAllChildren(Component comp) {		final List children = comp.getChildren();		if (children.isEmpty()) return;		for (Iterator it = new ArrayList(children).iterator(); it.hasNext();)			((Component)it.next()).setParent(null); //detach	}	/** Returns whether this component is real visible (all its parents	 * are visible).	 * @see Component#isVisible	 */	public static boolean isRealVisible(Component comp) {		for (; comp != null; comp = comp.getParent())			if (!comp.isVisible())				return false;		return true;	}	/** Returns a collection of visible children.	 * <p>The performance of the returned collection's size() is NO GOOD.	 */	public static Collection getVisibleChildren(Component comp) {		final Collection children = comp.getChildren();		return new AbstractCollection() {			public int size() {				int size = 0;				for (Iterator it = children.iterator(); it.hasNext();) {					if (((Component)it.next()).isVisible())						++size;				}				return size;			}			public Iterator iterator() {				return new Iterator() {					final Iterator _it = children.iterator();					Component _next;					public boolean hasNext() {						if (_next != null) return true;						_next = getNextVisible(false);						return _next != null;					}					public Object next() {						if (_next != null) {							final Component c = _next;							_next = null;							return c;						}						return getNextVisible(true);					}					public void remove() {						throw new UnsupportedOperationException();					}					private Component getNextVisible(boolean blind) {						while (blind || _it.hasNext()) {							final Component c = (Component)_it.next();							if (c.isVisible())								return c;						}						return null;					}				};			}		};	}	/** Converts a string to an integer that can be used to access	 * {@link Component#getAttribute(String, int)}	 */	public static final int getScope(String scope) {		if ("component".equals(scope)) return Component.COMPONENT_SCOPE;		if ("space".equals(scope)) return Component.SPACE_SCOPE;		if ("page".equals(scope)) return Component.PAGE_SCOPE;		if ("desktop".equals(scope)) return Component.DESKTOP_SCOPE;		if ("session".equals(scope)) return Component.SESSION_SCOPE;		if ("application".equals(scope)) return Component.APPLICATION_SCOPE;		if ("request".equals(scope)) return Component.REQUEST_SCOPE;		throw new IllegalArgumentException("Unknown scope: "+scope);	}	/** Converts an integer to the string representing the scope.	 * @param scope one of {@link Component#COMPONENT_SCOPE},	 * {@link Component#SPACE_SCOPE}, {@link Component#PAGE_SCOPE}, 	 * {@link Component#DESKTOP_SCOPE}, {@link Component#SESSION_SCOPE},	 * {@link Component#REQUEST_SCOPE}, and {@link Component#APPLICATION_SCOPE}.	 */	public static final String scopeToString(int scope) {		switch (scope) {		case Component.COMPONENT_SCOPE: return "component";		case Component.SPACE_SCOPE: return "space";		case Component.PAGE_SCOPE: return "page";		case Component.DESKTOP_SCOPE: return "desktop";		case Component.SESSION_SCOPE: return "session";		case Component.APPLICATION_SCOPE: return "application";		case Component.REQUEST_SCOPE: return "request";		}		throw new IllegalArgumentException("Unknown scope: "+scope);	}	/** Returns whether an ID is generated automatically.	 */	public static final boolean isAutoId(String id) {		return org.zkoss.zk.ui.sys.ComponentsCtrl.isAutoId(id);	}}

⌨️ 快捷键说明

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