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

📄 tabletree.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	palette = new PaletteData(new RGB[]{foreground.getRGB(), background.getRGB(), plusMinus.getRGB()});	imageData = new ImageData(itemHeight, itemHeight, 4, palette);	imageData.transparentPixel = 1;	minusImage = new Image(getDisplay(), imageData);	gc = new GC(minusImage);	gc.setBackground(background);	gc.fillRectangle(0, 0, itemHeight, itemHeight);	gc.setForeground(plusMinus);	gc.drawRectangle(indent, indent, size, size);	gc.setForeground(foreground);	gc.drawLine(indent + 2, midpoint, indent + size - 2, midpoint);	gc.dispose();}Image getPlusImage() {	if (plusImage == null) createImages();	return plusImage;}Image getMinusImage() {	if (minusImage == null) createImages();	return minusImage;}/** * Gets the index of an item. *  * <p>The widget is searched starting at 0 until an * item is found that is equal to the search item. * If no item is found, -1 is returned.  Indexing * is zero based.  This index is relative to the parent only. * * @param item the search item * @return the index of the item or -1 */public int indexOf (TableTreeItem item) {	//checkWidget();	for (int i = 0; i < items.length; i++) {		if (item == items[i]) return i;	}	return -1;}void onDispose(Event e) {	/*	 * Usually when an item is disposed, destroyItem will change the size of the items array	 * and dispose of the underlying table items.	 * Since the whole table tree is being disposed, this is not necessary.  For speed	 * the inDispose flag is used to skip over this part of the item dispose.	 */	inDispose = true;	for (int i = 0; i < items.length; i++) {		items[i].dispose();	}	inDispose = false;	if (plusImage != null) plusImage.dispose();	if (minusImage != null) minusImage.dispose();	if (sizeImage != null) sizeImage.dispose();	plusImage = minusImage = sizeImage = null;}void onResize(Event e) {	Point size = getSize();	table.setBounds(0, 0, size.x, size.y);}void onSelection(Event e) {	Event event = new Event();	TableItem tableItem = (TableItem)e.item;	TableTreeItem item = getItem(tableItem);    event.item = item;	if (e.type == SWT.Selection && e.detail == SWT.CHECK && item != null) {		event.detail = SWT.CHECK;		item.checked = tableItem.getChecked();	}	notifyListeners(e.type, event);}/** * Returns the item at the given point in the receiver * or null if no such item exists. The point is in the * coordinate system of the receiver. * * @param point the point used to locate the item * @return the item at the given point * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the point 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> */public TableTreeItem getItem(Point point) {	checkWidget();	TableItem item = table.getItem(point);	if (item == null) return null;	return getItem(item);	}TableTreeItem getItem(TableItem tableItem) {	if (tableItem == null) return null;	for (int i = 0; i < items.length; i++) {	    	TableTreeItem item = items[i].getItem(tableItem);	    	if (item != null) return item;	}	return null;}void onFocusIn (Event e) {	table.setFocus();}void onKeyDown (Event e) {	TableTreeItem[] selection = getSelection();	if (selection.length == 0) return;	TableTreeItem item = selection[0];	int type = 0;	if (e.keyCode == SWT.ARROW_RIGHT || e.keyCode == SWT.ARROW_LEFT) {		int trailKey = (getStyle() & SWT.MIRRORED) != 0 ? SWT.ARROW_LEFT : SWT.ARROW_RIGHT;		if (e.keyCode == trailKey) {			if (item.getItemCount() == 0) return;			if (item.getExpanded()) {				TableTreeItem newSelection = item.getItems()[0];				table.setSelection(new TableItem[]{newSelection.tableItem});				showItem(newSelection);				type = SWT.Selection;			} else {				item.setExpanded(true);				type = SWT.Expand;			}		} else {			if (item.getExpanded()) {				item.setExpanded(false);				type = SWT.Collapse;			} else {				TableTreeItem parent = item.getParentItem();				if (parent != null) {					int index = parent.indexOf(item);					if (index != 0) return;					table.setSelection(new TableItem[]{parent.tableItem});					type = SWT.Selection;				}			}		}	}	if (e.character == '*') {		item.expandAll(true);	}	if (e.character == '-') {		if (item.getExpanded()) {			item.setExpanded(false);			type = SWT.Collapse;		}	}	if (e.character == '+') {		if (item.getItemCount() > 0 && !item.getExpanded()) {			item.setExpanded(true);			type = SWT.Expand;		}	} 	if (type == 0) return;	Event event = new Event();	event.item = item;	notifyListeners(type, event);}void onMouseDown(Event event) {	/* If user clicked on the [+] or [-], expand or collapse the tree. */	TableItem[] items = table.getItems();	for (int i = 0; i < items.length; i++) {		Rectangle rect = items[i].getImageBounds(0);		if (rect.contains(event.x, event.y)) {			TableTreeItem item = (TableTreeItem) items[i].getData(ITEMID);			event = new Event();			event.item = item;			item.setExpanded(!item.getExpanded());			if (item.getExpanded()) {				notifyListeners(SWT.Expand, event);			} else {				notifyListeners(SWT.Collapse, event);			}			return;		}	}}/** * Removes all items. * <p> * This operation will fail when an item * could not be removed in the OS. * * @exception SWTError <ul> *	<li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread * 	<li>ERROR_WIDGET_DISPOSED when the widget has been disposed * 	<li>ERROR_ITEM_NOT_REMOVED when the operation fails * </ul> */public void removeAll () {	checkWidget();	setRedraw(false);	for (int i = items.length - 1; i >= 0; i--) {		items[i].dispose();	}	items = EMPTY_ITEMS;	setRedraw(true);}void removeItem(TableTreeItem item) {	int index = 0;	while (index < items.length && items[index] != item) index++;	if (index == items.length) return;	TableTreeItem[] newItems = new TableTreeItem[items.length - 1];	System.arraycopy(items, 0, newItems, 0, index);	System.arraycopy(items, index + 1, newItems, index, items.length - index - 1);	items = newItems;}/** * Removes the listener from the collection of listeners who will * be notified when the receiver's selection changes. * * @param listener the listener which should no longer 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 #addSelectionListener */public void removeSelectionListener (SelectionListener listener) {	checkWidget();	if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);	removeListener(SWT.Selection, listener);	removeListener(SWT.DefaultSelection, listener);}/** * Removes the listener from the collection of listeners who will * be notified when items in the receiver are expanded or collapsed.. * * @param listener the listener which should no longer 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 TreeListener * @see #addTreeListener */public void removeTreeListener (TreeListener listener) {	checkWidget();	if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);	removeListener(SWT.Expand, listener);	removeListener(SWT.Collapse, listener);}/** * Selects all of the items in the receiver. * <p> * If the receiver is single-select, do nothing. * * @exception SWTError <ul> *	<li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread *	<li>ERROR_WIDGET_DISPOSED when the widget has been disposed * </ul> */public void selectAll () {	checkWidget();	table.selectAll();}public void setBackground (Color color) {	super.setBackground(color);	table.setBackground(color);	if (sizeImage != null) {		GC gc = new GC (sizeImage);		gc.setBackground(getBackground());		Rectangle size = sizeImage.getBounds();		gc.fillRectangle(size);		gc.dispose();	}}public void setEnabled (boolean enabled) {	super.setEnabled(enabled);	table.setEnabled(enabled);}public void setFont (Font font) {	super.setFont(font);	table.setFont(font);}public void setForeground (Color color) {	super.setForeground(color);	table.setForeground(color);}public void setMenu (Menu menu) {	super.setMenu(menu);	table.setMenu(menu);}/** * Sets the receiver's selection to be the given array of items. * The current selection is cleared before the new items are selected. * <p> * Items that are not in the receiver are ignored. * If the receiver is single-select and multiple items are specified, * then all items are ignored. * * @param items the array of items * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the array of items is null</li> *    <li>ERROR_INVALID_ARGUMENT - if one of the item 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> * * @see TableTree#deselectAll() */public void setSelection (TableTreeItem[] items) {	checkWidget ();	if (items == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);	int length = items.length;	if (length == 0 || ((table.getStyle() & SWT.SINGLE) != 0 && length > 1)) {		deselectAll();		return;	}	TableItem[] tableItems = new TableItem[length];	for (int i = 0; i < length; i++) {		if (items[i] == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);		if (!items[i].getVisible()) expandItem (items[i]);		tableItems[i] = items[i].tableItem;	}	table.setSelection(tableItems);}public void setToolTipText (String string) {	super.setToolTipText(string);	table.setToolTipText(string);}/** * Shows the item.  If the item is already showing in the receiver, * this method simply returns.  Otherwise, the items are scrolled * and expanded until the item is visible. * * @param item the item to be shown * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the item is null</li> *    <li>ERROR_INVALID_ARGUMENT - if the item 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> * * @see TableTree#showSelection() */public void showItem (TableTreeItem item) {	checkWidget();	if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);	if (!item.getVisible()) expandItem (item);	TableItem tableItem = item.tableItem;	table.showItem(tableItem);}/** * Shows the selection. * <p> * If there is no selection or the selection * is already visible, this method does nothing. * If the selection is scrolled out of view, * the top index of the widget is changed such * that selection becomes visible. * * @exception SWTError <ul> *	<li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread *	<li>ERROR_WIDGET_DISPOSED when the widget has been disposed * </ul> */public void showSelection () {	checkWidget();	table.showSelection();}}

⌨️ 快捷键说明

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