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

📄 viewform.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************* * 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.graphics.*;import org.eclipse.swt.widgets.*;import org.eclipse.swt.*;/** * Instances of this class implement a Composite that lays out three * children horizontally and allows programmatic control of layout and * border parameters. ViewForm is used in the workbench to implement a * view's label/menu/toolbar local bar. * <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>BORDER, FLAT</dd> * <dt><b>Events:</b></dt> * <dd>(None)</dd> * </dl> * <p> * IMPORTANT: This class is <em>not</em> intended to be subclassed. * </p> */public class ViewForm 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; 	/**	 * horizontalSpacing specifies the number of pixels between the right	 * edge of one cell and the left edge of its neighbouring cell to	 * the right.	 *	 * The default value is 1.	 */ 	public int horizontalSpacing = 1;	/**	 * verticalSpacing specifies the number of pixels between the bottom	 * edge of one cell and the top edge of its neighbouring cell underneath.	 *	 * The default value is 1.	 */ 	public int verticalSpacing = 1;		/**	 * 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	 */	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	 */	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	 */	public static RGB borderOutsideRGB = new RGB (171, 168, 165);		// SWT widgets	private Control topLeft;	private Control topCenter;	private Control topRight;	private Control content;		// Configuration and state info	private boolean separateTopCenter = false;	private boolean showBorder = false;		private int separator = -1;	private int borderTop = 0;	private int borderBottom = 0;	private int borderLeft = 0;	private int borderRight = 0;	private int highlight = 0;	private Rectangle oldArea;		private Color selectionBackground;		static final int OFFSCREEN = -200;	static final int BORDER1_COLOR = SWT.COLOR_WIDGET_NORMAL_SHADOW;	static final int SELECTION_BACKGROUND = SWT.COLOR_LIST_BACKGROUND;/** * 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#BORDER * @see SWT#FLAT * @see #getStyle() */		public ViewForm(Composite parent, int style) {	super(parent, checkStyle(style));		setBorderVisible((style & SWT.BORDER) != 0);		Listener listener = new Listener() {		public void handleEvent(Event e) {			switch (e.type) {				case SWT.Dispose: onDispose(); break;				case SWT.Paint: onPaint(e.gc); break;				case SWT.Resize: onResize(); break;			}		}	};		int[] events = new int[] {SWT.Dispose, SWT.Paint, SWT.Resize};		for (int i = 0; i < events.length; i++) {		addListener(events[i], listener);	}}static int checkStyle (int style) {	int mask = SWT.FLAT | SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;	return style & mask | SWT.NO_REDRAW_RESIZE;}//protected void checkSubclass () {//	String name = getClass().getName ();//	String validName = ViewForm.class.getName();//	if (!validName.equals(name)) {//		SWT.error (SWT.ERROR_INVALID_SUBCLASS);//	}//}public Point computeSize(int wHint, int hHint, boolean changed) {	checkWidget();	// size of title bar area	Point leftSize = new Point(0, 0);	if (topLeft != null) {		leftSize = topLeft.computeSize(SWT.DEFAULT, SWT.DEFAULT);	}	Point centerSize = new Point(0, 0);	if (topCenter != null) {		 centerSize = topCenter.computeSize(SWT.DEFAULT, SWT.DEFAULT);	}	Point rightSize = new Point(0, 0);	if (topRight != null) {		 rightSize = topRight.computeSize(SWT.DEFAULT, SWT.DEFAULT);	}	Point size = new Point(0, 0);	// calculate width of title bar	if (separateTopCenter ||	    (wHint != SWT.DEFAULT &&  leftSize.x + centerSize.x + rightSize.x > wHint)) {		size.x = leftSize.x + rightSize.x;		if (leftSize.x > 0 && rightSize.x > 0) size.x += horizontalSpacing;		size.x = Math.max(centerSize.x, size.x);		size.y = Math.max(leftSize.y, rightSize.y);		if (topCenter != null){			size.y += centerSize.y;			if (topLeft != null ||topRight != null)size.y += verticalSpacing;		}		} else {		size.x = leftSize.x + centerSize.x + rightSize.x;		int count = -1;		if (leftSize.x > 0) count++;		if (centerSize.x > 0) count++;		if (rightSize.x > 0) count++;		if (count > 0) size.x += count * horizontalSpacing;		size.y = Math.max(leftSize.y, Math.max(centerSize.y, rightSize.y));	}		if (content != null) {		if (topLeft != null || topRight != null || topCenter != null) size.y += 1; // allow space for a vertical separator		Point contentSize = new Point(0, 0);		contentSize = content.computeSize(SWT.DEFAULT, SWT.DEFAULT); 		size.x = Math.max (size.x, contentSize.x);		size.y += contentSize.y;		if (size.y > contentSize.y) size.y += verticalSpacing;	}		size.x += 2*marginWidth;	size.y += 2*marginHeight;		if (wHint != SWT.DEFAULT) size.x  = wHint;	if (hHint != SWT.DEFAULT) size.y = hHint;		Rectangle trim = computeTrim(0, 0, size.x, size.y);	return new Point (trim.width, trim.height);}public Rectangle computeTrim (int x, int y, int width, int height) {	checkWidget ();	int trimX = x - borderLeft - highlight;	int trimY = y - borderTop - highlight;	int trimWidth = width + borderLeft + borderRight + 2*highlight;	int trimHeight = height + borderTop + borderBottom + 2*highlight;	return new Rectangle(trimX, trimY, trimWidth, trimHeight);}public Rectangle getClientArea() {	checkWidget();	Rectangle clientArea = super.getClientArea();	clientArea.x += borderLeft;	clientArea.y += borderTop;	clientArea.width -= borderLeft + borderRight;	clientArea.height -= borderTop + borderBottom;	return clientArea;}/*** Returns the content area.* * @return the control in the content area of the pane or null*/public Control getContent() {	//checkWidget();	return content;}/*** Returns Control that appears in the top center of the pane.* Typically this is a toolbar.* * @return the control in the top center of the pane or null*/public Control getTopCenter() {	//checkWidget();	return topCenter;}/*** Returns the Control that appears in the top left corner of the pane.* Typically this is a label such as CLabel.* * @return the control in the top left corner of the pane or null*/public Control getTopLeft() {	//checkWidget();	return topLeft;}/*** Returns the control in the top right corner of the pane.* Typically this is a Close button or a composite with a Menu and Close button.* * @return the control in the top right corner of the pane or null*/public Control getTopRight() {	//checkWidget();	return topRight;}public void layout (boolean changed) {	checkWidget();	Rectangle rect = getClientArea();		Point leftSize = new Point(0, 0);	if (topLeft != null && !topLeft.isDisposed()) {		leftSize = topLeft.computeSize(SWT.DEFAULT, SWT.DEFAULT);	}	Point centerSize = new Point(0, 0);	if (topCenter != null && !topCenter.isDisposed()) {		 centerSize = topCenter.computeSize(SWT.DEFAULT, SWT.DEFAULT);	}	Point rightSize = new Point(0, 0);	if (topRight != null && !topRight.isDisposed()) {		 rightSize = topRight.computeSize(SWT.DEFAULT, SWT.DEFAULT);	}	

⌨️ 快捷键说明

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