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

📄 treetab.java

📁 SUN公司eclipse3.2.2经典例子
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	 */	void createSizeGroup () {		super.createSizeGroup();			packColumnsButton = new Button (sizeGroup, SWT.PUSH);		packColumnsButton.setText (ControlExample.getResourceString("Pack_Columns"));		packColumnsButton.addSelectionListener(new SelectionAdapter () {			public void widgetSelected (SelectionEvent event) {				packColumns (tree1);				packColumns (tree2);				setExampleWidgetSize ();			}		});	}		/**	 * Creates the "Style" group.	 */	void createStyleGroup() {		super.createStyleGroup();				/* Create the extra widgets */		checkButton = new Button (styleGroup, SWT.CHECK);		checkButton.setText ("SWT.CHECK");		fullSelectionButton = new Button (styleGroup, SWT.CHECK);		fullSelectionButton.setText ("SWT.FULL_SELECTION");	}		/**	 * Gets the "Example" widget children's items, if any.	 *	 * @return an array containing the example widget children's items	 */	Item [] getExampleWidgetItems () {		/* Note: We do not bother collecting the tree items		 * because tree items don't have any events. If events		 * are ever added to TreeItem, then this needs to change.		 */		Item [] columns1 = tree1.getColumns();		Item [] columns2 = tree2.getColumns();		Item [] allItems = new Item [columns1.length + columns2.length];		System.arraycopy(columns1, 0, allItems, 0, columns1.length);		System.arraycopy(columns2, 0, allItems, columns1.length, columns2.length);		return allItems;	}		/**	 * Gets the "Example" widget children.	 */	Widget [] getExampleWidgets () {		return new Widget [] {tree1, tree2};	}		/**	 * Returns a list of set/get API method names (without the set/get prefix)	 * that can be used to set/get values in the example control(s).	 */	String[] getMethodNames() {		return new String[] {"ColumnOrder", "Selection", "ToolTipText", "TopItem"};	}	Object[] parameterForType(String typeName, String value, Widget widget) {		if (typeName.equals("org.eclipse.swt.widgets.TreeItem")) {			TreeItem item = findItem(value, ((Tree) widget).getItems());			if (item != null) return new Object[] {item};		}		if (typeName.equals("[Lorg.eclipse.swt.widgets.TreeItem;")) {			String[] values = split(value, ',');			TreeItem[] items = new TreeItem[values.length];			for (int i = 0; i < values.length; i++) {				TreeItem item = findItem(values[i], ((Tree) widget).getItems());				if (item == null) break;				items[i] = item;							}			return new Object[] {items};		}		return super.parameterForType(typeName, value, widget);	}	TreeItem findItem(String value, TreeItem[] items) {		for (int i = 0; i < items.length; i++) {			TreeItem item = items[i];			if (item.getText().equals(value)) return item;			item = findItem(value, item.getItems());			if (item != null) return item;		}		return null;	}	/**	 * Gets the text for the tab folder item.	 */	String getTabText () {		return "Tree";	}	void packColumns (Tree tree) {		if (multipleColumns.getSelection()) {			int columnCount = tree.getColumnCount();			for (int i = 0; i < columnCount; i++) {				TreeColumn treeColumn = tree.getColumn(i);				treeColumn.pack();			}		}	}		/**	 * Sets the moveable columns state of the "Example" widgets.	 */	void setColumnsMoveable () {		boolean selection = moveableColumns.getSelection();		TreeColumn[] columns1 = tree1.getColumns();		for (int i = 0; i < columns1.length; i++) {			columns1[i].setMoveable(selection);		}		TreeColumn[] columns2 = tree2.getColumns();		for (int i = 0; i < columns2.length; i++) {			columns2[i].setMoveable(selection);		}	}	/**	 * Sets the resizable columns state of the "Example" widgets.	 */	void setColumnsResizable () {		boolean selection = resizableColumns.getSelection();		TreeColumn[] columns1 = tree1.getColumns();		for (int i = 0; i < columns1.length; i++) {			columns1[i].setResizable(selection);		}		TreeColumn[] columns2 = tree2.getColumns();		for (int i = 0; i < columns2.length; i++) {			columns2[i].setResizable(selection);		}	}	/**	 * Sets the foreground color, background color, and font	 * of the "Example" widgets to their default settings.	 * Also sets foreground and background color of the Node 1	 * TreeItems to default settings.	 */	void resetColorsAndFonts () {		super.resetColorsAndFonts ();		Color oldColor = itemForegroundColor;		itemForegroundColor = null;		setItemForeground ();		if (oldColor != null) oldColor.dispose();		oldColor = itemBackgroundColor;		itemBackgroundColor = null;		setItemBackground ();		if (oldColor != null) oldColor.dispose();		Font oldFont = font;		itemFont = null;		setItemFont ();		if (oldFont != null) oldFont.dispose();		oldColor = cellForegroundColor;		cellForegroundColor = null;		setCellForeground ();		if (oldColor != null) oldColor.dispose();		oldColor = cellBackgroundColor;		cellBackgroundColor = null;		setCellBackground ();		if (oldColor != null) oldColor.dispose();		oldFont = font;		cellFont = null;		setCellFont ();		if (oldFont != null) oldFont.dispose();	}		/**	 * Sets the state of the "Example" widgets.	 */	void setExampleWidgetState () {		setItemBackground ();		setItemForeground ();		setItemFont ();		setCellBackground ();		setCellForeground ();		setCellFont ();		if (!instance.startup) {			setColumnsMoveable ();			setColumnsResizable ();			setWidgetHeaderVisible ();			setWidgetSortIndicator ();			setWidgetLinesVisible ();		}		super.setExampleWidgetState ();		checkButton.setSelection ((tree1.getStyle () & SWT.CHECK) != 0);		checkButton.setSelection ((tree2.getStyle () & SWT.CHECK) != 0);		fullSelectionButton.setSelection ((tree1.getStyle () & SWT.FULL_SELECTION) != 0);		fullSelectionButton.setSelection ((tree2.getStyle () & SWT.FULL_SELECTION) != 0);		try {			TreeColumn column = tree1.getColumn(0);			moveableColumns.setSelection (column.getMoveable());			resizableColumns.setSelection (column.getResizable());		} catch (IllegalArgumentException ex) {}		headerVisibleButton.setSelection (tree1.getHeaderVisible());		linesVisibleButton.setSelection (tree1.getLinesVisible());	}		/**	 * Sets the background color of the Node 1 TreeItems in column 1.	 */	void setCellBackground () {		if (!instance.startup) {			textNode1.setBackground (1, cellBackgroundColor);			imageNode1.setBackground (1, cellBackgroundColor);		}		/* Set the background color item's image to match the background color of the cell. */		Color color = cellBackgroundColor;		if (color == null) color = textNode1.getBackground (1);		TableItem item = colorAndFontTable.getItem(CELL_BACKGROUND_COLOR);		Image oldImage = item.getImage();		if (oldImage != null) oldImage.dispose();		item.setImage (colorImage(color));	}		/**	 * Sets the foreground color of the Node 1 TreeItems in column 1.	 */	void setCellForeground () {		if (!instance.startup) {			textNode1.setForeground (1, cellForegroundColor);			imageNode1.setForeground (1, cellForegroundColor);		}		/* Set the foreground color item's image to match the foreground color of the cell. */		Color color = cellForegroundColor;		if (color == null) color = textNode1.getForeground (1);		TableItem item = colorAndFontTable.getItem(CELL_FOREGROUND_COLOR);		Image oldImage = item.getImage();		if (oldImage != null) oldImage.dispose();		item.setImage (colorImage(color));	}		/**	 * Sets the font of the Node 1 TreeItems in column 1.	 */	void setCellFont () {		if (!instance.startup) {			textNode1.setFont (1, cellFont);			imageNode1.setFont (1, cellFont);		}		/* Set the font item's image to match the font of the item. */		Font ft = cellFont;		if (ft == null) ft = textNode1.getFont (1);		TableItem item = colorAndFontTable.getItem(CELL_FONT);		Image oldImage = item.getImage();		if (oldImage != null) oldImage.dispose();		item.setImage (fontImage(ft));		item.setFont(ft);		colorAndFontTable.layout ();	}	/**	 * Sets the background color of the Node 1 TreeItems.	 */	void setItemBackground () {		if (!instance.startup) {			textNode1.setBackground (itemBackgroundColor);			imageNode1.setBackground (itemBackgroundColor);		}		/* Set the background button's color to match the background color of the item. */		Color color = itemBackgroundColor;		if (color == null) color = textNode1.getBackground ();		TableItem item = colorAndFontTable.getItem(ITEM_BACKGROUND_COLOR);		Image oldImage = item.getImage();		if (oldImage != null) oldImage.dispose();		item.setImage (colorImage(color));	}		/**	 * Sets the foreground color of the Node 1 TreeItems.	 */	void setItemForeground () {		if (!instance.startup) {			textNode1.setForeground (itemForegroundColor);			imageNode1.setForeground (itemForegroundColor);		}		/* Set the foreground button's color to match the foreground color of the item. */		Color color = itemForegroundColor;		if (color == null) color = textNode1.getForeground ();		TableItem item = colorAndFontTable.getItem(ITEM_FOREGROUND_COLOR);		Image oldImage = item.getImage();		if (oldImage != null) oldImage.dispose();		item.setImage (colorImage(color));	}		/**	 * Sets the font of the Node 1 TreeItems.	 */	void setItemFont () {		if (!instance.startup) {			textNode1.setFont (itemFont);			imageNode1.setFont (itemFont);		}		/* Set the font item's image to match the font of the item. */		Font ft = itemFont;		if (ft == null) ft = textNode1.getFont ();		TableItem item = colorAndFontTable.getItem(ITEM_FONT);		Image oldImage = item.getImage();		if (oldImage != null) oldImage.dispose();		item.setImage (fontImage(ft));		item.setFont(ft);		colorAndFontTable.layout ();	}	/**	 * Sets the header visible state of the "Example" widgets.	 */	void setWidgetHeaderVisible () {		tree1.setHeaderVisible (headerVisibleButton.getSelection ());		tree2.setHeaderVisible (headerVisibleButton.getSelection ());	}		/**	 * Sets the sort indicator state of the "Example" widgets.	 */	void setWidgetSortIndicator () {		if (sortIndicatorButton.getSelection ()) {			initializeSortState (tree1);			initializeSortState (tree2);		} else {			resetSortState (tree1);			resetSortState (tree2);		}	}		/**	 * Sets the initial sort indicator state and adds a listener	 * to cycle through sort states and columns.	 */	void initializeSortState (final Tree tree) {		/* Reset to known state: 'down' on column 0. */		tree.setSortDirection (SWT.DOWN);		TreeColumn [] columns = tree.getColumns();		for (int i = 0; i < columns.length; i++) {			TreeColumn column = columns[i];			if (i == 0) tree.setSortColumn(column);			SelectionListener listener = new SelectionAdapter() {				public void widgetSelected(SelectionEvent e) {					int sortDirection = SWT.DOWN;					if (e.widget == tree.getSortColumn()) {						/* If the sort column hasn't changed, cycle down -> up -> none. */						switch (tree.getSortDirection ()) {						case SWT.DOWN: sortDirection = SWT.UP; break;						case SWT.UP: sortDirection = SWT.NONE; break;						}					} else {						tree.setSortColumn((TreeColumn)e.widget);					}					tree.setSortDirection (sortDirection);				}			};			column.addSelectionListener(listener);			column.setData("SortListener", listener);	//$NON-NLS-1$		}	}	void resetSortState (final Tree tree) {		tree.setSortDirection (SWT.NONE);		TreeColumn [] columns = tree.getColumns();		for (int i = 0; i < columns.length; i++) {			SelectionListener listener = (SelectionListener)columns[i].getData("SortListener");	//$NON-NLS-1$			if (listener != null) columns[i].removeSelectionListener(listener);		}	}		/**	 * Sets the lines visible state of the "Example" widgets.	 */	void setWidgetLinesVisible () {		tree1.setLinesVisible (linesVisibleButton.getSelection ());		tree2.setLinesVisible (linesVisibleButton.getSelection ());	}	protected void specialPopupMenuItems(Menu menu, Event event) {    	MenuItem item = new MenuItem(menu, SWT.PUSH);    	item.setText("getItem(Point) on mouse coordinates");    	final Tree t = (Tree) event.widget;    	menuMouseCoords = t.toControl(new Point(event.x, event.y));    	item.addSelectionListener(new SelectionAdapter() {    		public void widgetSelected(SelectionEvent e) {    			eventConsole.append ("getItem(Point(" + menuMouseCoords + ")) returned: " + t.getItem(menuMouseCoords));    			eventConsole.append ("\n");    		};    	});	}}

⌨️ 快捷键说明

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