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

📄 treetab.java

📁 eclipse 的程序源码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************* * Copyright (c) 2000, 2005 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: *     IBM Corporation - initial API and implementation *******************************************************************************/package org.eclipse.swt.examples.controlexample;import org.eclipse.swt.*;import org.eclipse.swt.layout.*;import org.eclipse.swt.widgets.*;import org.eclipse.swt.graphics.*;import org.eclipse.swt.events.*;class TreeTab extends ScrollableTab {	/* Example widgets and groups that contain them */	Tree tree1, tree2;	TreeItem textNode1, imageNode1;	Group treeGroup, imageTreeGroup, itemGroup;		/* Style widgets added to the "Style" group */	Button checkButton, fullSelectionButton;	/* Other widgets added to the "Other" group */	Button multipleColumns, headerVisibleButton, linesVisibleButton;		/* Controls and resources added to the "Colors" group */	Button itemForegroundButton, itemBackgroundButton, itemFontButton;	Color itemForegroundColor, itemBackgroundColor;	Image itemForegroundImage, itemBackgroundImage;	Font itemFont;		static String [] columnTitles	= {ControlExample.getResourceString("TableTitle_0"),		   ControlExample.getResourceString("TableTitle_1"),		   ControlExample.getResourceString("TableTitle_2"),		   ControlExample.getResourceString("TableTitle_3")};		   	static String[][] tableData = {			{ ControlExample.getResourceString("TableLine0_0"),					ControlExample.getResourceString("TableLine0_1"),					ControlExample.getResourceString("TableLine0_2"),					ControlExample.getResourceString("TableLine0_3") },			{ ControlExample.getResourceString("TableLine1_0"),					ControlExample.getResourceString("TableLine1_1"),					ControlExample.getResourceString("TableLine1_2"),					ControlExample.getResourceString("TableLine1_3") },			{ ControlExample.getResourceString("TableLine2_0"),					ControlExample.getResourceString("TableLine2_1"),					ControlExample.getResourceString("TableLine2_2"),					ControlExample.getResourceString("TableLine2_3") } };	/**	 * Creates the Tab within a given instance of ControlExample.	 */	TreeTab(ControlExample instance) {		super(instance);	}	/**	 * Creates the "Colors" group.	 */	void createColorGroup () {		super.createColorGroup();				itemGroup = new Group (colorGroup, SWT.NONE);		itemGroup.setText (ControlExample.getResourceString ("Tree_Item_Colors"));		GridData data = new GridData ();		data.horizontalSpan = 2;		itemGroup.setLayoutData (data);		itemGroup.setLayout (new GridLayout (2, false));		new Label (itemGroup, SWT.NONE).setText (ControlExample.getResourceString ("Foreground_Color"));		itemForegroundButton = new Button (itemGroup, SWT.PUSH);		new Label (itemGroup, SWT.NONE).setText (ControlExample.getResourceString ("Background_Color"));		itemBackgroundButton = new Button (itemGroup, SWT.PUSH);		itemFontButton = new Button (itemGroup, SWT.PUSH);		itemFontButton.setText(ControlExample.getResourceString("Font"));		itemFontButton.setLayoutData(new GridData (GridData.HORIZONTAL_ALIGN_FILL));				Shell shell = colorGroup.getShell ();		final ColorDialog foregroundDialog = new ColorDialog (shell);		final ColorDialog backgroundDialog = new ColorDialog (shell);		final FontDialog fontDialog = new FontDialog (shell);		int imageSize = 12;		Display display = shell.getDisplay ();		itemForegroundImage = new Image(display, imageSize, imageSize);		itemBackgroundImage = new Image(display, imageSize, imageSize);		/* Add listeners to set the colors and font */		itemForegroundButton.setImage(itemForegroundImage);		itemForegroundButton.addSelectionListener(new SelectionAdapter() {			public void widgetSelected(SelectionEvent event) {				Color oldColor = itemForegroundColor;				if (oldColor == null) oldColor = textNode1.getForeground ();				foregroundDialog.setRGB(oldColor.getRGB());				RGB rgb = foregroundDialog.open();				if (rgb == null) return;				oldColor = itemForegroundColor;				itemForegroundColor = new Color (event.display, rgb);				setItemForeground ();				if (oldColor != null) oldColor.dispose ();			}		});		itemBackgroundButton.setImage(itemBackgroundImage);		itemBackgroundButton.addSelectionListener(new SelectionAdapter() {			public void widgetSelected(SelectionEvent event) {				Color oldColor = itemBackgroundColor;				if (oldColor == null) oldColor = textNode1.getBackground ();				backgroundDialog.setRGB(oldColor.getRGB());				RGB rgb = backgroundDialog.open();				if (rgb == null) return;				oldColor = itemBackgroundColor;				itemBackgroundColor = new Color (event.display, rgb);				setItemBackground ();				if (oldColor != null) oldColor.dispose ();			}		});		itemFontButton.addSelectionListener(new SelectionAdapter () {			public void widgetSelected (SelectionEvent event) {				Font oldFont = itemFont;				if (oldFont == null) oldFont = textNode1.getFont ();				fontDialog.setFontList(oldFont.getFontData());				FontData fontData = fontDialog.open ();				if (fontData == null) return;				oldFont = itemFont;				itemFont = new Font (event.display, fontData);				setItemFont ();				setExampleWidgetSize ();				if (oldFont != null) oldFont.dispose ();			}		});		shell.addDisposeListener(new DisposeListener() {			public void widgetDisposed(DisposeEvent event) {				if (itemBackgroundImage != null) itemBackgroundImage.dispose();				if (itemForegroundImage != null) itemForegroundImage.dispose();				if (itemBackgroundColor != null) itemBackgroundColor.dispose();				if (itemForegroundColor != null) itemForegroundColor.dispose();				if (itemFont != null) itemFont.dispose();				itemBackgroundColor = null;				itemForegroundColor = null;							itemFont = null;			}		});	}	/**	 * Creates the "Other" group.	 */	void createOtherGroup () {		super.createOtherGroup ();			/* Create display controls specific to this example */		multipleColumns = new Button (otherGroup, SWT.CHECK);		multipleColumns.setText (ControlExample.getResourceString("Multiple_Columns"));		headerVisibleButton = new Button (otherGroup, SWT.CHECK);		headerVisibleButton.setText (ControlExample.getResourceString("Header_Visible"));		linesVisibleButton = new Button (otherGroup, SWT.CHECK);		linesVisibleButton.setText (ControlExample.getResourceString("Lines_Visible"));			/* Add the listeners */		multipleColumns.addSelectionListener (new SelectionAdapter () {			public void widgetSelected (SelectionEvent event) {				recreateExampleWidgets ();			}		});		headerVisibleButton.addSelectionListener (new SelectionAdapter () {			public void widgetSelected (SelectionEvent event) {				setWidgetHeaderVisible ();			}		});		linesVisibleButton.addSelectionListener (new SelectionAdapter () {			public void widgetSelected (SelectionEvent event) {				setWidgetLinesVisible ();			}		});	}		/**	 * Creates the "Example" group.	 */	void createExampleGroup () {		super.createExampleGroup ();				/* Create a group for the text tree */		treeGroup = new Group (exampleGroup, SWT.NONE);		treeGroup.setLayout (new GridLayout ());		treeGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));		treeGroup.setText ("Tree");			/* Create a group for the image tree */		imageTreeGroup = new Group (exampleGroup, SWT.NONE);		imageTreeGroup.setLayout (new GridLayout ());		imageTreeGroup.setLayoutData (new GridData (GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL));		imageTreeGroup.setText (ControlExample.getResourceString("Tree_With_Images"));	}		/**	 * Creates the "Example" widgets.	 */	void createExampleWidgets () {		/* Compute the widget style */		int style = getDefaultStyle();		if (singleButton.getSelection()) style |= SWT.SINGLE;		if (multiButton.getSelection()) style |= SWT.MULTI;		if (checkButton.getSelection()) style |= SWT.CHECK;		if (fullSelectionButton.getSelection ()) style |= SWT.FULL_SELECTION;		if (borderButton.getSelection()) style |= SWT.BORDER;			/* Create the text tree */		tree1 = new Tree (treeGroup, style);		if (multipleColumns.getSelection()) {			for (int i = 0; i < columnTitles.length; i++) {				TreeColumn treeColumn = new TreeColumn(tree1, SWT.NONE);				treeColumn.setText(columnTitles[i]);			}		}		for (int i = 0; i < 4; i++) {			TreeItem item = new TreeItem (tree1, SWT.NONE);			setItemText(item, i, ControlExample.getResourceString("Node_" + (i + 1)));			if (i < 3) {				TreeItem subitem = new TreeItem (item, SWT.NONE);				setItemText(subitem, i, ControlExample.getResourceString("Node_" + (i + 1) + "_1"));			}		}		TreeItem treeRoots[] = tree1.getItems ();

⌨️ 快捷键说明

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