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

📄 tab.java

📁 SUN公司eclipse3.2.2经典例子
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
/******************************************************************************* * Copyright (c) 2000, 2007 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.graphics.*;import org.eclipse.swt.widgets.*;import org.eclipse.swt.layout.*;import org.eclipse.swt.events.*;/** * <code>Tab</code> is the abstract superclass of every page * in the example's tab folder.  Each page in the tab folder * describes a control. * * A Tab itself is not a control but instead provides a * hierarchy with which to share code that is common to * every page in the folder. * * A typical page in a Tab contains a two column composite. * The left column contains the "Example" group.  The right * column contains "Control" group.  The "Control" group * contains controls that allow the user to interact with * the example control.  The "Control" group typically * contains a "Style", "Other" and "Size" group.  Subclasses * can override these defaults to augment a group or stop * a group from being created. */abstract class Tab {	Shell shell;	Display display;		/* Common control buttons */	Button borderButton, enabledButton, visibleButton, backgroundImageButton, popupMenuButton;	Button preferredButton, tooSmallButton, smallButton, largeButton, fillHButton, fillVButton;	/* Common groups and composites */	Composite tabFolderPage;	Group exampleGroup, controlGroup, listenersGroup, otherGroup, sizeGroup, styleGroup, colorGroup, backgroundModeGroup;	/* Controlling instance */	final ControlExample instance;	/* Sizing constants for the "Size" group */	static final int TOO_SMALL_SIZE	= 10;	static final int SMALL_SIZE		= 50;	static final int LARGE_SIZE		= 100;		/* Right-to-left support */	static final boolean RTL_SUPPORT_ENABLE = false;	Group orientationGroup;	Button rtlButton, ltrButton, defaultOrietationButton;	/* Controls and resources for the "Colors & Fonts" group */	static final int IMAGE_SIZE = 12;	static final int FOREGROUND_COLOR = 0;	static final int BACKGROUND_COLOR = 1;	static final int FONT = 2;	Table colorAndFontTable;	ColorDialog colorDialog;	FontDialog fontDialog;	Color foregroundColor, backgroundColor;	Font font;		/* Controls and resources for the "Background Mode" group */	Combo backgroundModeCombo;	Button backgroundModeImageButton, backgroundModeColorButton;	/* Event logging variables and controls */	Text eventConsole;	boolean logging = false;	boolean [] eventsFilter;		/* Set/Get API controls */	Combo nameCombo;	Label returnTypeLabel;	Button getButton, setButton;	Text setText, getText;	static final Object [][] EVENT_NAMES = {		{"Activate", new Integer(SWT.Activate)}, 		{"Arm", new Integer(SWT.Arm)}, 		{"Close", new Integer(SWT.Close)},		{"Collapse", new Integer(SWT.Collapse)},		{"Deactivate", new Integer(SWT.Deactivate)},		{"DefaultSelection", new Integer(SWT.DefaultSelection)},		{"Deiconify", new Integer(SWT.Deiconify)}, 		{"Dispose", new Integer(SWT.Dispose)},		{"DragDetect", new Integer(SWT.DragDetect)}, 		{"EraseItem", new Integer(SWT.EraseItem)},		{"Expand", new Integer(SWT.Expand)}, 		{"FocusIn", new Integer(SWT.FocusIn)}, 		{"FocusOut", new Integer(SWT.FocusOut)},		{"HardKeyDown", new Integer(SWT.HardKeyDown)}, 		{"HardKeyUp", new Integer(SWT.HardKeyUp)},		{"Help", new Integer(SWT.Help)}, 		{"Hide", new Integer(SWT.Hide)},		{"Iconify", new Integer(SWT.Iconify)}, 		{"KeyDown", new Integer(SWT.KeyDown)},		{"KeyUp", new Integer(SWT.KeyUp)},		{"MeasureItem", new Integer(SWT.MeasureItem)},		{"MenuDetect", new Integer(SWT.MenuDetect)},		{"Modify", new Integer(SWT.Modify)}, 		{"MouseDoubleClick", new Integer(SWT.MouseDoubleClick)},		{"MouseDown", new Integer(SWT.MouseDown)}, 		{"MouseEnter", new Integer(SWT.MouseEnter)}, 		{"MouseExit", new Integer(SWT.MouseExit)}, 		{"MouseHover", new Integer(SWT.MouseHover)},		{"MouseMove", new Integer(SWT.MouseMove)}, 		{"MouseUp", new Integer(SWT.MouseUp)}, 		{"MouseWheel", new Integer(SWT.MouseWheel)},		{"Move", new Integer(SWT.Move)}, 		{"Paint", new Integer(SWT.Paint)}, 		{"PaintItem", new Integer(SWT.PaintItem)},		{"Resize", new Integer(SWT.Resize)}, 		{"Selection", new Integer(SWT.Selection)}, 		{"SetData", new Integer(SWT.SetData)},//		{"Settings", new Integer(SWT.Settings)},  // note: this event only goes to Display		{"Show", new Integer(SWT.Show)}, 		{"Traverse", new Integer(SWT.Traverse)}, 		{"Verify", new Integer(SWT.Verify)},	};		boolean samplePopup = false;	/**	 * Creates the Tab within a given instance of ControlExample.	 */	Tab(ControlExample instance) {		this.instance = instance;	}	/**	 * Creates the "Control" group.  The "Control" group	 * is typically the right hand column in the tab.	 */	void createControlGroup () {			/*		 * Create the "Control" group.  This is the group on the		 * right half of each example tab.  It consists of the		 * "Style" group, the "Other" group and the "Size" group.		 */			controlGroup = new Group (tabFolderPage, SWT.NONE);		controlGroup.setLayout (new GridLayout (2, true));		controlGroup.setLayoutData (new GridData(SWT.FILL, SWT.FILL, false, false));		controlGroup.setText (ControlExample.getResourceString("Parameters"));			/* Create individual groups inside the "Control" group */		createStyleGroup ();		createOtherGroup ();		createSetGetGroup();		createSizeGroup ();		createColorAndFontGroup ();		if (RTL_SUPPORT_ENABLE) {			createOrientationGroup ();		}			/*		 * For each Button child in the style group, add a selection		 * listener that will recreate the example controls.  If the		 * style group button is a RADIO button, ensure that the radio		 * button is selected before recreating the example controls.		 * When the user selects a RADIO button, the current RADIO		 * button in the group is deselected and the new RADIO button		 * is selected automatically.  The listeners are notified for		 * both these operations but typically only do work when a RADIO		 * button is selected.		 */		SelectionListener selectionListener = new SelectionAdapter () {			public void widgetSelected (SelectionEvent event) {				if ((event.widget.getStyle () & SWT.RADIO) != 0) {					if (!((Button) event.widget).getSelection ()) return;				}				recreateExampleWidgets ();			}		};		Control [] children = styleGroup.getChildren ();		for (int i=0; i<children.length; i++) {			if (children [i] instanceof Button) {				Button button = (Button) children [i];				button.addSelectionListener (selectionListener);			} else {				if (children [i] instanceof Composite) {					/* Look down one more level of children in the style group. */					Composite composite = (Composite) children [i];					Control [] grandchildren = composite.getChildren ();					for (int j=0; j<grandchildren.length; j++) {						if (grandchildren [j] instanceof Button) {							Button button = (Button) grandchildren [j];							button.addSelectionListener (selectionListener);						}					}				}			}		}		if (RTL_SUPPORT_ENABLE) {			rtlButton.addSelectionListener (selectionListener); 			ltrButton.addSelectionListener (selectionListener);					defaultOrietationButton.addSelectionListener (selectionListener);		}	}		/**	 * Append the Set/Get API controls to the "Other" group.	 */	void createSetGetGroup() {		/*		 * Create the button to access set/get API functionality.		 */		final String [] methodNames = getMethodNames ();		if (methodNames != null) {			Button setGetButton = new Button (otherGroup, SWT.PUSH);			setGetButton.setText (ControlExample.getResourceString ("Set_Get"));			setGetButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));			setGetButton.addSelectionListener (new SelectionAdapter() {				public void widgetSelected (SelectionEvent e) {					Button button = (Button)e.widget;					Point pt = button.getLocation();					pt = e.display.map(button, null, pt);					createSetGetDialog(pt.x, pt.y, methodNames);				}			});		}	}	/**	 * Creates the "Control" widget children.	 * Subclasses override this method to augment	 * the standard controls created in the "Style",	 * "Other" and "Size" groups.	 */	void createControlWidgets () {	}		/**	 * Creates the "Colors and Fonts" group. This is typically	 * a child of the "Control" group. Subclasses override	 * this method to customize color and font settings.	 */	void createColorAndFontGroup () {		/* Create the group. */		colorGroup = new Group(controlGroup, SWT.NONE);		colorGroup.setLayout (new GridLayout (2, true));		colorGroup.setLayoutData (new GridData (SWT.FILL, SWT.FILL, false, false));		colorGroup.setText (ControlExample.getResourceString ("Colors"));		colorAndFontTable = new Table(colorGroup, SWT.BORDER | SWT.V_SCROLL);		colorAndFontTable.setLayoutData(new GridData(SWT.FILL, SWT.BEGINNING, true, false, 2, 1));		TableItem item = new TableItem(colorAndFontTable, SWT.None);		item.setText(ControlExample.getResourceString ("Foreground_Color"));		colorAndFontTable.setSelection(0);		item = new TableItem(colorAndFontTable, SWT.None);		item.setText(ControlExample.getResourceString ("Background_Color"));		item = new TableItem(colorAndFontTable, SWT.None);		item.setText(ControlExample.getResourceString ("Font"));		Button changeButton = new Button (colorGroup, SWT.PUSH);		changeButton.setText(ControlExample.getResourceString("Change"));		changeButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));		Button defaultsButton = new Button (colorGroup, SWT.PUSH);		defaultsButton.setText(ControlExample.getResourceString("Defaults"));		defaultsButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));		/* Add listeners to set/reset colors and fonts. */		colorDialog = new ColorDialog (shell);		fontDialog = new FontDialog (shell);		colorAndFontTable.addSelectionListener(new SelectionAdapter() {			public void widgetDefaultSelected(SelectionEvent event) {				changeFontOrColor (colorAndFontTable.getSelectionIndex());			}		});		changeButton.addSelectionListener(new SelectionAdapter() {			public void widgetSelected(SelectionEvent event) {				changeFontOrColor (colorAndFontTable.getSelectionIndex());			}		});		defaultsButton.addSelectionListener(new SelectionAdapter () {			public void widgetSelected (SelectionEvent e) {				resetColorsAndFonts ();			}		});		shell.addDisposeListener(new DisposeListener() {			public void widgetDisposed(DisposeEvent event) {				if (foregroundColor != null) foregroundColor.dispose();				if (backgroundColor != null) backgroundColor.dispose();				if (font != null) font.dispose();				foregroundColor = null;				backgroundColor = null;				font = null;				if (colorAndFontTable != null && !colorAndFontTable.isDisposed()) {					TableItem [] items = colorAndFontTable.getItems();					for (int i = 0; i < items.length; i++) {						Image image = items[i].getImage();						if (image != null) image.dispose();					}				}			}		});	}		void changeFontOrColor(int index) {		switch (index) {			case FOREGROUND_COLOR: {				Color oldColor = foregroundColor;				if (oldColor == null) {					Control [] controls = getExampleControls ();					if (controls.length > 0) oldColor = controls [0].getForeground ();				}				if (oldColor != null) colorDialog.setRGB(oldColor.getRGB()); // seed dialog with current color				RGB rgb = colorDialog.open();				if (rgb == null) return;				oldColor = foregroundColor; // save old foreground color to dispose when done				foregroundColor = new Color (display, rgb);				setExampleWidgetForeground ();				if (oldColor != null) oldColor.dispose ();			}			break;			case BACKGROUND_COLOR: {				Color oldColor = backgroundColor;				if (oldColor == null) {					Control [] controls = getExampleControls ();					if (controls.length > 0) oldColor = controls [0].getBackground (); // seed dialog with current color				}				if (oldColor != null) colorDialog.setRGB(oldColor.getRGB());				RGB rgb = colorDialog.open();				if (rgb == null) return;				oldColor = backgroundColor; // save old background color to dispose when done				backgroundColor = new Color (display, rgb);				setExampleWidgetBackground ();				if (oldColor != null) oldColor.dispose ();			}			break;			case FONT: {				Font oldFont = font;				if (oldFont == null) {					Control [] controls = getExampleControls ();					if (controls.length > 0) oldFont = controls [0].getFont ();				}				if (oldFont != null) fontDialog.setFontList(oldFont.getFontData()); // seed dialog with current font				FontData fontData = fontDialog.open ();				if (fontData == null) return;				oldFont = font; // dispose old font when done				font = new Font (display, fontData);				setExampleWidgetFont ();				setExampleWidgetSize ();				if (oldFont != null) oldFont.dispose ();			}			break;		}	}	/**	 * Creates the "Other" group.  This is typically	 * a child of the "Control" group.	 */	void createOtherGroup () {		/* Create the group */

⌨️ 快捷键说明

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