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

📄 tableitem.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */public Image getImage (int index) {	checkWidget();	if (index == 0) return super.getImage ();	if (images != null) {		if (0 <= index && index < images.length) return images [index];	}	return null;}/** * Returns a rectangle describing the size and location * relative to its parent of an image at a column in the * table. * * @param index the index that specifies the column * @return the receiver's bounding image rectangle * * @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> */public Rectangle getImageBounds (int index) {	checkWidget();	int itemIndex = parent.indexOf (this);	if (itemIndex == -1) return new Rectangle (0, 0, 0, 0);	int hwnd = parent.handle;		int hwndHeader =  OS.SendMessage (hwnd, OS.LVM_GETHEADER, 0, 0);	int count = OS.SendMessage (hwndHeader, OS.HDM_GETITEMCOUNT, 0, 0);	if (!(0 <= index && index < count)) return new Rectangle (0, 0, 0, 0);	int gridWidth = parent.getLinesVisible () ? parent.getGridLineWidth () : 0;		/*	* Feature in Windows.  Calling LVM_GETSUBITEMRECT with LVIR_ICON and	* zero for the column number gives the bounds of the icon (despite the	* fact that this behaivor is only documented for values greater than	* one).	*/	RECT rect = new RECT ();	rect.top = index;	rect.left = OS.LVIR_ICON;	OS.SendMessage (hwnd, OS. LVM_GETSUBITEMRECT, itemIndex, rect);	if (index == 0) {		rect.left -= gridWidth;	}	int width = Math.max (0, rect.right - rect.left - gridWidth);	int height = Math.max (0, rect.bottom - rect.top - gridWidth);		/*	* Feature in Windows.  LVM_GETSUBITEMRECT returns a small width	* value even when the subitem does not contain an image.  The	* fix is to detect this case and set the width to zero.	*/	if (index != 0) {		LVITEM lvItem = new LVITEM ();		lvItem.mask = OS.LVIF_IMAGE;		lvItem.iItem = itemIndex;		lvItem.iSubItem = index;		OS.SendMessage (hwnd, OS.LVM_GETITEM, 0, lvItem);		if (lvItem.iImage < 0) width = 0;	}	/*	* Bug in Windows.  In version 5.80 of COMCTL32.DLL, the top	* of the rectangle returned by LVM_GETSUBITEMRECT is off by	* the grid width when the grid is visible.  The fix is to	* move the top of the rectangle up by the grid width.	*/	if ((OS.COMCTL32_MAJOR << 16 | OS.COMCTL32_MINOR) >= (5 << 16 | 80)) {		rect.top -= gridWidth;	}	return new Rectangle (rect.left + gridWidth, rect.top + gridWidth, width, height);}/** * Gets the image indent. * * @return the indent * * @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> */public int getImageIndent () {	checkWidget();	return imageIndent;}/** * Returns the receiver's parent, which must be a <code>Table</code>. * * @return the receiver's parent * * @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> */public Table getParent () {	checkWidget();	return parent;}/** * Returns the text stored at the given column index in the receiver, * or empty string if the text has not been set. * * @param index the column index * @return the text stored at the given column index in the receiver * * @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> * @exception SWTError <ul> *    <li>ERROR_CANNOT_GET_TEXT - if the column at index does not exist</li> * </ul> */public String getText (int index) {	checkWidget();	if (index == 0) return super.getText ();	if (strings != null) {		if (0 <= index && index < strings.length) {			String string = strings [index];			return string != null ? string : "";		}	}	return "";}void redraw (int column, boolean drawText, boolean drawImage) {	if ((parent.style & SWT.VIRTUAL) != 0) cached = true;	if (parent.ignoreRedraw || parent.drawCount != 0) return;	int hwnd = parent.handle;	if (OS.IsWindowVisible (hwnd)) {		RECT rect = new RECT ();		int index = parent.indexOf (this);		if (column == -1) {			OS.SendMessage (hwnd, OS.LVM_REDRAWITEMS, index, index);		} else {			if (drawText) rect.left |= OS.LVIR_LABEL;			if (drawImage) rect.left |= OS.LVIR_ICON;			if (column == 0) {				if (OS.SendMessage (hwnd, OS.LVM_GETITEMRECT, index, rect) != 0) {						OS.InvalidateRect (hwnd, rect, true);				}			} else {				rect.top = column;				if (OS.SendMessage (hwnd, OS. LVM_GETSUBITEMRECT, index, rect) != 0) {					if (drawText && !drawImage && images != null) {						RECT iconRect = new RECT ();						iconRect.left = OS.LVIR_ICON;						iconRect.top = column;						if (OS.SendMessage (hwnd, OS. LVM_GETSUBITEMRECT, index, iconRect) != 0) {							/*							* Feature in Windows.  LVM_GETSUBITEMRECT returns a small width							* value even when the subitem does not contain an image.  The							* fix is to detect this case and avoid subtracting the image							* from the damage rectangle. 							*/							boolean fixWidth = true;							if (column != 0) {								LVITEM lvItem = new LVITEM ();								lvItem.mask = OS.LVIF_IMAGE;								lvItem.iItem = index;								lvItem.iSubItem = column;								OS.SendMessage (hwnd, OS.LVM_GETITEM, 0, lvItem);								if (lvItem.iImage < 0) fixWidth = false;							}							if (fixWidth) rect.left = iconRect.right;							}					}					OS.InvalidateRect (hwnd, rect, true);				}			}		}	}}void releaseChild () {	super.releaseChild ();	parent.destroyItem (this);}void releaseWidget () {	super.releaseWidget ();	parent = null;	strings = null;	images = null;	cellBackground = cellForeground = cellFont = null;}/** * Sets the receiver's background color to the color specified * by the argument, or to the default system color for the item * if the argument is null. * * @param color the new color (or null) * * @exception IllegalArgumentException <ul> *    <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</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> *  * @since 2.0 *  */public void setBackground (Color color) {	checkWidget ();	if (color != null && color.isDisposed ()) {		SWT.error (SWT.ERROR_INVALID_ARGUMENT);	}	int pixel = -1;	if (color != null) {		parent.customDraw = true;		pixel = color.handle;	}	if (background == pixel) return;	background = pixel;	redraw (-1, true, true);}/** * Sets the background color at the given column index in the receiver  * to the color specified by the argument, or to the default system color for the item * if the argument is null. * * @param index the column index * @param color the new color (or null) * * @exception IllegalArgumentException <ul> *    <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</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> *  * @since 3.0 *  */public void setBackground (int index, Color color) {	checkWidget ();	if (color != null && color.isDisposed ()) {		SWT.error (SWT.ERROR_INVALID_ARGUMENT);	}	int count = Math.max (1, parent.getColumnCount ());	if (0 > index || index > count - 1) return;	int pixel = -1;	if (color != null) {		parent.customDraw = true;		pixel = color.handle;	}	if (cellBackground == null) {		cellBackground = new int [count];		for (int i = 0; i < count; i++) {			cellBackground [i] = -1;		}	}	if (cellBackground [index] == pixel) return;	cellBackground [index] = pixel;	redraw (index, true, true);}/** * Sets the checked state of the checkbox for this item.  This state change  * only applies if the Table was created with the SWT.CHECK style. * * @param checked the new checked state of the checkbox * * @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> */public void setChecked (boolean checked) {	checkWidget();	if ((parent.style & SWT.CHECK) == 0) return;	if (this.checked == checked) return;	setChecked (checked, false);}void setChecked (boolean checked, boolean notify) {	this.checked = checked;	if (notify) {		Event event = new Event();		event.item = this;		event.detail = SWT.CHECK;		parent.postEvent (SWT.Selection, event);	}	redraw (-1, true, true);}/** * Sets the font that the receiver will use to paint textual information * for this item to the font specified by the argument, or to the default font * for that kind of control if the argument is null. * * @param font the new font (or null) * * @exception IllegalArgumentException <ul> *    <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</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> *  * @since 3.0 */public void setFont (Font font){	checkWidget ();	if (font != null && font.isDisposed ()) {		SWT.error (SWT.ERROR_INVALID_ARGUMENT);	}	int hFont = -1;	if (font != null) {		parent.customDraw = true;		hFont = font.handle;	}	if (this.font == hFont) return;	this.font = hFont;	/*	* 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 ((parent.style & SWT.VIRTUAL) == 0 && cached) {		int itemIndex = parent.indexOf (this);		if (itemIndex != -1) {			int hwnd = parent.handle;			LVITEM lvItem = new LVITEM ();			lvItem.mask = OS.LVIF_TEXT;			lvItem.iItem = itemIndex;			lvItem.pszText = OS.LPSTR_TEXTCALLBACK;			OS.SendMessage (hwnd, OS.LVM_SETITEM, 0, lvItem);			cached = false;		}	}

⌨️ 快捷键说明

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