rows.java

来自「非常接近C/S操作方式的Java Ajax框架-ZK 用ZK框架使你的B/S应」· Java 代码 · 共 129 行

JAVA
129
字号
/* Rows.java{{IS_NOTE	Purpose:			Description:			History:		Tue Oct 25 16:02:39     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.Set;import java.util.HashSet;import java.util.Iterator;import org.zkoss.zk.ui.Component;import org.zkoss.zk.ui.UiException;import org.zkoss.zk.ui.ext.render.Cropper;import org.zkoss.zul.impl.XulElement;import org.zkoss.zul.ext.Paginal;/** * Defines the rows of a grid. * Each child of a rows element should be a {@link Row} element. * * @author tomyeh */public class Rows extends XulElement {	/** Returns the grid that contains this rows. */	public Grid getGrid() {		return (Grid)getParent();	}	//Paging//	/** Returns the index of the first visible child.	 * <p>Used only for component development, not for application developers.	 */	public int getVisibleBegin() {		final Grid grid = getGrid();		if (grid == null || !grid.inPagingMold())			return 0;		final Paginal pgi = grid.getPaginal();		return pgi.getActivePage() * pgi.getPageSize();	}	/** Returns the index of the last visible child.	 * <p>Used only for component development, not for application developers.	 */	public int getVisibleEnd() {		final Grid grid = getGrid();		if (grid == null || !grid.inPagingMold())			return Integer.MAX_VALUE;		final Paginal pgi = grid.getPaginal();		return (pgi.getActivePage() + 1) * pgi.getPageSize() - 1; //inclusive	}	//-- Component --//	public void setParent(Component parent) {		if (parent != null && !(parent instanceof Grid))			throw new UiException("Unsupported parent for rows: "+parent);		final boolean changed = getParent() != parent;		super.setParent(parent);		if (changed && parent != null) ((Grid)parent).initAtClient();	}	public boolean insertBefore(Component child, Component insertBefore) {		if (!(child instanceof Row))			throw new UiException("Unsupported child for rows: "+child);		return super.insertBefore(child, insertBefore);	}	public void onChildAdded(Component child) {		super.onChildAdded(child);		final Grid grid = getGrid();		if (grid != null) {			grid.initAtClient();			if (grid.inPagingMold())				grid.getPaginal().setTotalSize(getChildren().size());		}	}	public void onChildRemoved(Component child) {		super.onChildRemoved(child);		final Grid grid = getGrid();		if (grid != null) {			grid.initAtClient();			if (grid.inPagingMold())				grid.getPaginal().setTotalSize(getChildren().size());		}    }	//-- 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 Cropper {		//--Cropper--//		public boolean isCropper() {			final Grid grid = getGrid();			return grid != null && grid.inPagingMold();		}		public Set getAvailableAtClient() {			final Grid grid = getGrid();			if (grid == null || !grid.inPagingMold())				return null;			final Set avail = new HashSet(37);			final Paginal pgi = grid.getPaginal();			int pgsz = pgi.getPageSize();			final int ofs = pgi.getActivePage() * pgsz;			for (final Iterator it = getChildren().listIterator(ofs);			--pgsz >= 0 && it.hasNext();)				avail.add(it.next());			return avail;		}	}}

⌨️ 快捷键说明

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