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

📄 ctabfolder.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
/******************************************************************************* * Copyright (c) 2000, 2004 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v10.html *  * Contributors: *     IBM Corporation - initial API and implementation *******************************************************************************/package org.eclipse.swt.custom;import org.eclipse.swt.*;import org.eclipse.swt.accessibility.*;import org.eclipse.swt.events.*;import org.eclipse.swt.graphics.*;import org.eclipse.swt.widgets.*;/** *  * Instances of this class implement the notebook user interface * metaphor.  It allows the user to select a notebook page from * set of pages. * <p> * The item children that may be added to instances of this class * must be of type <code>CTabItem</code>. * <code>Control</code> children are created and then set into a * tab item using <code>CTabItem#setControl</code>. * </p><p> * Note that although this class is a subclass of <code>Composite</code>, * it does not make sense to set a layout on it. * </p><p> * <dl> * <dt><b>Styles:</b></dt> * <dd>CLOSE, TOP, BOTTOM, FLAT, BORDER, SINGLE, MULTI</dd> * <dt><b>Events:</b></dt> * <dd>Selection</dd> * <dd>"CTabFolder2"</dd> * </dl> * <p> * Note: Only one of the styles TOP and BOTTOM  * may be specified. * </p><p> * IMPORTANT: This class is <em>not</em> intended to be subclassed. * </p> */ public class CTabFolder extends Composite {		/**	 * marginWidth specifies the number of pixels of horizontal margin	 * that will be placed along the left and right edges of the form.	 *	 * The default value is 0.	 */ 	public int marginWidth = 0;	/**	 * marginHeight specifies the number of pixels of vertical margin	 * that will be placed along the top and bottom edges of the form.	 *	 * The default value is 0.	 */ 	public int marginHeight = 0;	 	/**	 * A multiple of the tab height that specifies the minimum width to which a tab 	 * will be compressed before scrolling arrows are used to navigate the tabs.	 * 	 * NOTE This field is badly named and can not be fixed for backwards compatability.	 * It should not be capitalized.	 * 	 * @deprecated This field is no longer used.  See setMinimumCharacters(int)	 */	public int MIN_TAB_WIDTH = 4;		/**	 * Color of innermost line of drop shadow border.	 * 	 * NOTE This field is badly named and can not be fixed for backwards compatability.	 * It should be capitalized.	 * 	 * @deprecated drop shadow border is no longer drawn in 3.0	 */	public static RGB borderInsideRGB  = new RGB (132, 130, 132);	/**	 * Color of middle line of drop shadow border.	 * 	 * NOTE This field is badly named and can not be fixed for backwards compatability.	 * It should be capitalized.	 * 	 * @deprecated drop shadow border is no longer drawn in 3.0	 */	public static RGB borderMiddleRGB  = new RGB (143, 141, 138);	/**	 * Color of outermost line of drop shadow border.	 * 	 * NOTE This field is badly named and can not be fixed for backwards compatability.	 * It should be capitalized.	 * 	 * @deprecated drop shadow border is no longer drawn in 3.0	 */	public static RGB borderOutsideRGB = new RGB (171, 168, 165); 	/* sizing, positioning */	int xClient, yClient;	boolean onBottom = false;	boolean single = false;	boolean simple = true;	int fixedTabHeight = SWT.DEFAULT;	int tabHeight;	int minChars = 10;		/* item management */	CTabItem items[] = new CTabItem[0];	int selectedIndex = -1;	int firstIndex = -1; // index of the left most visible tab.	/* External Listener management */	CTabFolder2Listener[] folderListeners = new CTabFolder2Listener[0];	// support for deprecated listener mechanism	CTabFolderListener[] tabListeners = new CTabFolderListener[0]; 		/* Selected item appearance */	Image selectionBgImage;	Color[] selectionGradientColors;	int[] selectionGradientPercents;	boolean selectionGradientVertical;	Color selectionForeground;	Color selectionBackground;		/* Unselected item appearance */	Image bgImage;	Color[] gradientColors;	int[] gradientPercents;	boolean gradientVertical;	boolean showUnselectedImage = true;		static Color borderColor;		// close, min/max and chevron buttons	boolean showClose = false;	boolean showUnselectedClose = true;		Rectangle chevronRect = new Rectangle(0, 0, 0, 0);	int chevronImageState = NORMAL;	boolean showChevron = false;		boolean showMin = false;	Rectangle minRect = new Rectangle(0, 0, 0, 0);	boolean minimized = false;	int minImageState = NORMAL;		boolean showMax = false;	Rectangle maxRect = new Rectangle(0, 0, 0, 0);	boolean maximized = false;	int maxImageState = NORMAL;		Control topRight;	Rectangle topRightRect = new Rectangle(0, 0, 0, 0);	int topRightAlignment = SWT.RIGHT;		// borders and shapes	int borderLeft = 0;	int borderRight = 0;	int borderTop = 0;	int borderBottom = 0;		int highlight_margin = 0;	int highlight_header = 0;		int[] curve;	int curveWidth = 0;	int curveIndent = 0;		// when disposing CTabFolder, don't try to layout the items or 	// change the selection as each child is destroyed.	boolean inDispose = false;	// keep track of size changes in order to redraw only affected area	// on Resize	Point oldSize;	Font oldFont;		// tooltip	int [] toolTipEvents = new int[] {SWT.MouseExit, SWT.MouseHover, SWT.MouseMove, SWT.MouseDown, SWT.DragDetect};	Listener toolTipListener;	Shell toolTipShell;	Label toolTipLabel;	// insertion marker	int insertionIndex = -2; // Index of insert marker.  Marker always shown after index.	                         // -2 means no insert marker		// internal constants	static final int DEFAULT_WIDTH = 64;	static final int DEFAULT_HEIGHT = 64;	static final int BUTTON_SIZE = 16;	static final int[] TOP_LEFT_CORNER = new int[] {0,6, 1,5, 1,4, 4,1, 5,1, 6,0};	static final int[] TOP_RIGHT_CORNER = new int[] {-6,0, -5,1, -4,1, -1,4, -1,5, 0,6};	static final int[] BOTTOM_LEFT_CORNER = new int[] {0,-6, 1,-5, 1,-4, 4,-1, 5,-1, 6,0};	static final int[] BOTTOM_RIGHT_CORNER = new int[] {-6,0, -5,-1, -4,-1, -1,-4, -1,-5, 0,-6};	static final int[] SIMPLE_TOP_LEFT_CORNER = new int[] {0,2, 1,1, 2,0};	static final int[] SIMPLE_TOP_RIGHT_CORNER = new int[] {-2,0, -1,1, 0,2};	static final int[] SIMPLE_BOTTOM_LEFT_CORNER = new int[] {0,-2, 1,-1, 2,0};	static final int[] SIMPLE_BOTTOM_RIGHT_CORNER = new int[] {-2,0, -1,-1, 0,-2};	static final int SELECTION_FOREGROUND = SWT.COLOR_LIST_FOREGROUND;	static final int SELECTION_BACKGROUND = SWT.COLOR_LIST_BACKGROUND;	static final int BORDER1_COLOR = SWT.COLOR_WIDGET_NORMAL_SHADOW;	static final int FOREGROUND = SWT.COLOR_WIDGET_FOREGROUND;	static final int BACKGROUND = SWT.COLOR_WIDGET_BACKGROUND;	static final int BUTTON_BORDER = SWT.COLOR_WIDGET_DARK_SHADOW;	static final int BUTTON_FILL = SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW;		static final int NONE = 0;	static final int NORMAL = 1;	static final int HOT = 2;	static final int SELECTED = 3;	static final RGB CLOSE_FILL = new RGB(252, 160, 160);	/** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. * <p> * The style value is either one of the style constants defined in * class <code>SWT</code> which is applicable to instances of this * class, or must be built by <em>bitwise OR</em>'ing together  * (that is, using the <code>int</code> "|" operator) two or more * of those <code>SWT</code> style constants. The class description * lists the style constants that are applicable to the class. * Style bits are also inherited from superclasses. * </p> * * @param parent a widget which will be the parent of the new instance (cannot be null) * @param style the style of widget to construct * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li> * </ul> * @exception SWTException <ul> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> * </ul> * * @see SWT#TOP * @see SWT#BOTTOM * @see SWT#FLAT * @see SWT#BORDER * @see SWT#SINGLE * @see SWT#MULTI * @see #getStyle() */public CTabFolder(Composite parent, int style) {	super(parent, checkStyle (parent, style));	int style2 = super.getStyle();	oldFont = getFont();	onBottom = (style2 & SWT.BOTTOM) != 0;	showClose = (style2 & SWT.CLOSE) != 0;//	showMin = (style2 & SWT.MIN) != 0; - conflicts with SWT.TOP//	showMax = (style2 & SWT.MAX) != 0; - conflicts with SWT.BOTTOM	single = (style2 & SWT.SINGLE) != 0;	borderLeft = borderRight = (style & SWT.BORDER) != 0 ? 1 : 0;	borderTop = onBottom ? borderLeft : 0;	borderBottom = onBottom ? 0 : borderLeft;	highlight_header = (style & SWT.FLAT) != 0 ? 1 : 3;	highlight_margin = (style & SWT.FLAT) != 0 ? 0 : 2;	//set up default colors	Display display = getDisplay();	selectionForeground = display.getSystemColor(SELECTION_FOREGROUND);	selectionBackground = display.getSystemColor(SELECTION_BACKGROUND);	borderColor = display.getSystemColor(BORDER1_COLOR);		initAccessible();		// Add all listeners	Listener listener = new Listener() {		public void handleEvent(Event event) {			switch (event.type) {				case SWT.Dispose:          onDispose(); break;				case SWT.DragDetect:		onDragDetect(event); break;				case SWT.FocusIn:          onFocus(event);	break;				case SWT.FocusOut:         onFocus(event);	break;				case SWT.KeyDown:			onKeyDown(event); break;				case SWT.MouseDoubleClick: onMouseDoubleClick(event); break;				case SWT.MouseDown:        onMouse(event);	break;				case SWT.MouseExit:        onMouse(event);	break;				case SWT.MouseHover:       onMouseHover(event); break;				case SWT.MouseMove:        onMouse(event); break;				case SWT.MouseUp:          onMouse(event); break;				case SWT.Paint:            onPaint(event);	break;				case SWT.Resize:           onResize();	break;				case SWT.Traverse:         onTraverse(event); break;			}		}	};	int[] folderEvents = new int[]{		SWT.Dispose,		SWT.DragDetect,		SWT.FocusIn, 		SWT.FocusOut, 		SWT.KeyDown,		SWT.MouseDoubleClick, 		SWT.MouseDown,		SWT.MouseExit,		SWT.MouseHover, 		SWT.MouseMove,		SWT.MouseUp,		SWT.Paint,		SWT.Resize,  		SWT.Traverse,	};	for (int i = 0; i < folderEvents.length; i++) {		addListener(folderEvents[i], listener);	}		toolTipListener = new Listener() {		public void handleEvent(Event event) {			switch (event.type) {				case SWT.MouseHover:				case SWT.MouseMove:					if (updateToolTip(event.x, event.y)) break;					// FALL THROUGH				case SWT.MouseExit:				case SWT.MouseDown:					hideToolTip();					break;			}		}	};}static int checkStyle (Composite parent, int style) {	int mask = SWT.CLOSE | SWT.TOP | SWT.BOTTOM | SWT.FLAT | SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT | SWT.SINGLE | SWT.MULTI;	style = style & mask;	// TOP and BOTTOM are mutually exlusive.	// TOP is the default	if ((style & SWT.TOP) != 0) 		style = style & ~(SWT.TOP | SWT.BOTTOM) | SWT.TOP;	// SINGLE and MULTI are mutually exlusive.	// MULTI is the default	if ((style & SWT.MULTI) != 0) 		style = style & ~(SWT.SINGLE | SWT.MULTI) | SWT.MULTI;	// reduce the flash by not redrawing the entire area on a Resize event	style |= SWT.NO_REDRAW_RESIZE;	//TEMPORARY CODE	/*	 * The default background on carbon and some GTK themes is not a solid color 	 * but a texture.  To show the correct default background, we must allow	 * the operating system to draw it and therefore, we can not use the 	 * NO_BACKGROUND style.  The NO_BACKGROUND style is not required on platforms	 * that use double buffering which is true in both of these cases.	 */	String platform = SWT.getPlatform();	if ("carbon".equals(platform) || "gtk".equals(platform)) return style; //$NON-NLS-1$ //$NON-NLS-2$		//TEMPORARY CODE	/*	 * In Right To Left orientation on Windows, all GC calls that use a brush are drawing 	 * offset by one pixel.  This results in some parts of the CTabFolder not drawing correctly.	 * To alleviate some of the appearance problems, allow the OS to draw the background.	 * This does not draw correctly but the result is less obviously wrong.	 */	if ((style & SWT.RIGHT_TO_LEFT) != 0) return style;	if ((parent.getStyle() & SWT.MIRRORED) != 0 && (style & SWT.LEFT_TO_RIGHT) == 0) return style;		return style | SWT.NO_BACKGROUND;}static void fillRegion(GC gc, Region region) {	// NOTE: region passed in to this function will be modified	Region clipping = new Region();	gc.getClipping(clipping);	region.intersect(clipping);	gc.setClipping(region);	gc.fillRectangle(region.getBounds());	gc.setClipping(clipping);	clipping.dispose();}/** *  * Adds the listener to the collection of listeners who will * be notified when a tab item is closed, minimized, maximized, * restored, or to show the list of items that are not  * currently visible. * * @param listener the listener which should be notified * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> *  * @exception SWTError <ul> *    <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> *    <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> * </ul> * * @see CTabFolder2Listener * @see #removeCTabFolder2Listener(CTabFolder2Listener) *  * @since 3.0 */public void addCTabFolder2Listener(CTabFolder2Listener listener) {	checkWidget();	if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);	// add to array	CTabFolder2Listener[] newListeners = new CTabFolder2Listener[folderListeners.length + 1];	System.arraycopy(folderListeners, 0, newListeners, 0, folderListeners.length);	folderListeners = newListeners;	folderListeners[folderListeners.length - 1] = listener;}/** * Adds the listener to the collection of listeners who will * be notified when a tab item is closed.

⌨️ 快捷键说明

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