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

📄 table.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************* * Copyright (c) 2000, 2004 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html *  * Contributors: *     IBM Corporation - initial API and implementation *******************************************************************************/package org.eclipse.swt.widgets; import org.eclipse.swt.internal.win32.*;import org.eclipse.swt.*;import org.eclipse.swt.graphics.*;import org.eclipse.swt.events.*;/**  * Instances of this class implement a selectable user interface * object that displays a list of images and strings and issue * notificiation when selected. * <p> * The item children that may be added to instances of this class * must be of type <code>TableItem</code>. * </p><p> * Note that although this class is a subclass of <code>Composite</code>, * it does not make sense to add <code>Control</code> children to it, * or set a layout on it. * </p><p> * <dl> * <dt><b>Styles:</b></dt> * <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, HIDE_SELECTION, VIRTUAL</dd> * <dt><b>Events:</b></dt> * <dd>Selection, DefaultSelection</dd> * </dl> * <p> * Note: Only one of the styles SINGLE, and MULTI may be specified. * </p><p> * IMPORTANT: This class is <em>not</em> intended to be subclassed. * </p> */public class Table extends Composite {	TableItem [] items;	TableColumn [] columns;	ImageList imageList;	int lastIndexOf, lastWidth;	boolean fixScrollWidth;	boolean ignoreSelect, dragStarted, ignoreRedraw, mouseDown, customDraw, ignoreShrink;	static final int TableProc;	static final TCHAR TableClass = new TCHAR (0, OS.WC_LISTVIEW, true);	static {		WNDCLASS lpWndClass = new WNDCLASS ();		OS.GetClassInfo (0, TableClass, lpWndClass);		TableProc = lpWndClass.lpfnWndProc;	}/** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. * <p> * The style value is either one of the style constants defined in * class <code>SWT</code> which is applicable to instances of this * class, or must be built by <em>bitwise OR</em>'ing together  * (that is, using the <code>int</code> "|" operator) two or more * of those <code>SWT</code> style constants. The class description * lists the style constants that are applicable to the class. * Style bits are also inherited from superclasses. * </p> * * @param parent a composite control which will be the parent of the new instance (cannot be null) * @param style the style of control to construct * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li> * </ul> * @exception SWTException <ul> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> * </ul> * * @see SWT#SINGLE * @see SWT#MULTI * @see SWT#CHECK * @see SWT#FULL_SELECTION * @see SWT#HIDE_SELECTION * @see Widget#checkSubclass * @see Widget#getStyle */public Table (Composite parent, int style) {	super (parent, checkStyle (style));}TableItem _getItem (int index) {	if (items [index] != null) return items [index];	return items [index] = new TableItem (this, SWT.NONE, -1, false);}/** * Adds the listener to the collection of listeners who will * be notified when the receiver's selection changes, by sending * it one of the messages defined in the <code>SelectionListener</code> * interface. * <p> * When <code>widgetSelected</code> is called, the item field of the event object is valid. * If the reciever has <code>SWT.CHECK</code> style set and the check selection changes, * the event object detail field contains the value <code>SWT.CHECK</code>. * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked. * The item field of the event object is valid for default selection, but the detail field is not used. * </p> * * @param listener the listener which should be notified * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @see SelectionListener * @see #removeSelectionListener * @see SelectionEvent */public void addSelectionListener (SelectionListener listener) {	checkWidget ();	if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);	TypedListener typedListener = new TypedListener (listener);	addListener (SWT.Selection,typedListener);	addListener (SWT.DefaultSelection,typedListener);}int callWindowProc (int msg, int wParam, int lParam) {	if (handle == 0) return 0;	return OS.CallWindowProc (TableProc, handle, msg, wParam, lParam);}static int checkStyle (int style) {	/*	* Feature in Windows.  It is not possible to create	* a table that does not have scroll bars.  Therefore,	* no matter what style bits are specified, set the	* H_SCROLL and V_SCROLL bits so that the SWT style	* will match the widget that Windows creates.	*/	style |= SWT.H_SCROLL | SWT.V_SCROLL;	return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0);}protected void checkSubclass () {	if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);}/** * Clears the item at the given zero-relative index in the receiver. * The text, icon and other attribues of the item are set to the default * value.  If the table was created with the SWT.VIRTUAL style, these * attributes are requested again as needed. * * @param index the index of the item to clear * * @exception IllegalArgumentException <ul> *    <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> * </ul> * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> *  * @see SWT#VIRTUAL * @see SWT#SetData *  * @since 3.0 */public void clear (int index) {	checkWidget ();	int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);	if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE);	TableItem item = items [index];	if (item != null) {		item.clear ();		/*		* Bug in Windows.  Despite the fact that every item in the		* table always has LPSTR_TEXTCALLBACK, Windows caches the		* bounds for the selected items.  This means that 		* when you change the string to be something else, Windows		* correctly asks you for the new string but when the item		* is selected, the selection draws using the bounds of the		* previous item.  The fix is to reset LPSTR_TEXTCALLBACK		* even though it has not changed, causing Windows to flush		* cached bounds.		*/		if ((style & SWT.VIRTUAL) == 0 && item.cached) {			LVITEM lvItem = new LVITEM ();			lvItem.mask = OS.LVIF_TEXT | OS.LVIF_INDENT;			lvItem.pszText = OS.LPSTR_TEXTCALLBACK;			lvItem.iItem = index;			OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);			item.cached = false;		}		if (!ignoreRedraw && drawCount == 0 && OS.IsWindowVisible (handle)) {			OS.SendMessage (handle, OS.LVM_REDRAWITEMS, index, index);		}		setScrollWidth (item, false);	}}/** * Removes the items from the receiver which are between the given * zero-relative start and end indices (inclusive).  The text, icon * and other attribues of the items are set to their default values. * If the table was created with the SWT.VIRTUAL style, these attributes * are requested again as needed. * * @param start the start index of the item to clear * @param end the end index of the item to clear * * @exception IllegalArgumentException <ul> *    <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li> * </ul> * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> *  * @see SWT#VIRTUAL * @see SWT.SetData *  * @since 3.0 */public void clear (int start, int end) {	checkWidget ();	if (start > end) return;	int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);	if (!(0 <= start && start <= end && end < count)) {		error (SWT.ERROR_INVALID_RANGE);	}	if (start == 0 && end == count - 1) {		clearAll ();	} else {		LVITEM lvItem = null;		boolean cleared = false;		for (int i=start; i<=end; i++) {			TableItem item = items [i];			if (item != null) {				cleared = true;				item.clear ();				/*				* Bug in Windows.  Despite the fact that every item in the				* table always has LPSTR_TEXTCALLBACK, Windows caches the				* bounds for the selected items.  This means that 				* when you change the string to be something else, Windows				* correctly asks you for the new string but when the item				* is selected, the selection draws using the bounds of the				* previous item.  The fix is to reset LPSTR_TEXTCALLBACK				* even though it has not changed, causing Windows to flush				* cached bounds.				*/				if ((style & SWT.VIRTUAL) == 0 && item.cached) {					if (lvItem == null) {						lvItem = new LVITEM ();						lvItem.mask = OS.LVIF_TEXT | OS.LVIF_INDENT;						lvItem.pszText = OS.LPSTR_TEXTCALLBACK;					}					lvItem.iItem = i;					OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);					item.cached = false;				}			}		}		if (cleared) {			if (!ignoreRedraw && drawCount == 0 && OS.IsWindowVisible (handle)) {				OS.SendMessage (handle, OS.LVM_REDRAWITEMS, start, end);			}			TableItem item = start == end ? items [start] : null; 			setScrollWidth (item, false);		}	}}/** * Clears the items at the given zero-relative indices in the receiver. * The text, icon and other attribues of the items are set to their default * values.  If the table was created with the SWT.VIRTUAL style, these * attributes are requested again as needed. * * @param indices the array of indices of the items * * @exception IllegalArgumentException <ul> *    <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> *    <li>ERROR_NULL_ARGUMENT - if the indices array is null</li> * </ul> * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> *  * @see SWT#VIRTUAL * @see SWT.SetData *  * @since 3.0 */public void clear (int [] indices) {	checkWidget ();	if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);	if (indices.length == 0) return;	int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);	for (int i=0; i<indices.length; i++) {		if (!(0 <= indices [i] && indices [i] < count)) {			error (SWT.ERROR_INVALID_RANGE);		}	}	LVITEM lvItem = null;	boolean cleared = false;	for (int i=0; i<indices.length; i++) {		int index = indices [i];		TableItem item = items [index];		if (item != null) {			cleared = true;			item.clear ();			/*			* Bug in Windows.  Despite the fact that every item in the			* table always has LPSTR_TEXTCALLBACK, Windows caches the			* bounds for the selected items.  This means that 			* when you change the string to be something else, Windows			* correctly asks you for the new string but when the item			* is selected, the selection draws using the bounds of the			* previous item.  The fix is to reset LPSTR_TEXTCALLBACK			* even though it has not changed, causing Windows to flush			* cached bounds.			*/			if ((style & SWT.VIRTUAL) == 0 && item.cached) {				if (lvItem == null) {					lvItem = new LVITEM ();					lvItem.mask = OS.LVIF_TEXT | OS.LVIF_INDENT;					lvItem.pszText = OS.LPSTR_TEXTCALLBACK;				}				lvItem.iItem = i;				OS.SendMessage (handle, OS.LVM_SETITEM, 0, lvItem);				item.cached = false;			}			if (!ignoreRedraw && drawCount == 0 && OS.IsWindowVisible (handle)) {				OS.SendMessage (handle, OS.LVM_REDRAWITEMS, index, index);			}		}	}	if (cleared) setScrollWidth (null, false);}/** * Clears all the items in the receiver. The text, icon and other * attribues of the items are set to their default values. If the * table was created with the SWT.VIRTUAL style, these attributes * are requested again as needed. * * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> *  * @see SWT#VIRTUAL * @see SWT.SetData *  * @since 3.0 */public void clearAll () {	checkWidget ();	int count = OS.SendMessage (handle, OS.LVM_GETITEMCOUNT, 0, 0);	LVITEM lvItem = null;	boolean cleared = false;	for (int i=0; i<count; i++) {

⌨️ 快捷键说明

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