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

📄 cursor.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.graphics;import org.eclipse.swt.internal.win32.*;import org.eclipse.swt.*;/** * Instances of this class manage operating system resources that * specify the appearance of the on-screen pointer. To create a * cursor you specify the device and either a simple cursor style * describing one of the standard operating system provided cursors * or the image and mask data for the desired appearance. * <p> * Application code must explicitly invoke the <code>Cursor.dispose()</code>  * method to release the operating system resources managed by each instance * when those instances are no longer required. * </p> * <dl> * <dt><b>Styles:</b></dt> * <dd> *   CURSOR_ARROW, CURSOR_WAIT, CURSOR_CROSS, CURSOR_APPSTARTING, CURSOR_HELP, *   CURSOR_SIZEALL, CURSOR_SIZENESW, CURSOR_SIZENS, CURSOR_SIZENWSE, CURSOR_SIZEWE, *   CURSOR_SIZEN, CURSOR_SIZES, CURSOR_SIZEE, CURSOR_SIZEW, CURSOR_SIZENE, CURSOR_SIZESE, *   CURSOR_SIZESW, CURSOR_SIZENW, CURSOR_UPARROW, CURSOR_IBEAM, CURSOR_NO, CURSOR_HAND * </dd> * </dl> * <p> * Note: Only one of the above styles may be specified. * </p> */public final class Cursor {		/**	 * the handle to the OS cursor resource	 * (Warning: This field is platform dependent)	 */	public int handle;		/**	 * the device where this cursor was created	 */	Device device;		boolean isIcon;		/**	 * data used to create a HAND cursor.	 */	static final byte[] HAND_SOURCE = {		(byte)0xf9,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xf0,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xf0,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xf0,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xf0,(byte)0x3f,(byte)0xff,(byte)0xff,		(byte)0xf0,(byte)0x07,(byte)0xff,(byte)0xff,		(byte)0xf0,(byte)0x03,(byte)0xff,(byte)0xff,		(byte)0xf0,(byte)0x00,(byte)0xff,(byte)0xff,		(byte)0x10,(byte)0x00,(byte)0x7f,(byte)0xff,		(byte)0x00,(byte)0x00,(byte)0x7f,(byte)0xff,		(byte)0x80,(byte)0x00,(byte)0x7f,(byte)0xff,		(byte)0xc0,(byte)0x00,(byte)0x7f,(byte)0xff,		(byte)0xe0,(byte)0x00,(byte)0x7f,(byte)0xff,		(byte)0xf0,(byte)0x00,(byte)0x7f,(byte)0xff,		(byte)0xf8,(byte)0x00,(byte)0xff,(byte)0xff,		(byte)0xfc,(byte)0x01,(byte)0xff,(byte)0xff,		(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff,		(byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff	};	static final byte[] HAND_MASK = {		(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x06,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x06,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x06,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x06,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x06,(byte)0xc0,(byte)0x00,(byte)0x00,		(byte)0x06,(byte)0xd8,(byte)0x00,(byte)0x00,		(byte)0x06,(byte)0xd8,(byte)0x00,(byte)0x00,		(byte)0x07,(byte)0xdb,(byte)0x00,(byte)0x00,		(byte)0x67,(byte)0xfb,(byte)0x00,(byte)0x00,		(byte)0x3f,(byte)0xff,(byte)0x00,(byte)0x00,		(byte)0x1f,(byte)0xff,(byte)0x00,(byte)0x00,		(byte)0x0f,(byte)0xff,(byte)0x00,(byte)0x00,		(byte)0x07,(byte)0xff,(byte)0x00,(byte)0x00,		(byte)0x03,(byte)0xfe,(byte)0x00,(byte)0x00,		(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00,		(byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00	};/** * Prevents uninitialized instances from being created outside the package. */Cursor() {}/**	  * Constructs a new cursor given a device and a style * constant describing the desired cursor appearance. * <p> * You must dispose the cursor when it is no longer required.  * </p> * * @param device the device on which to allocate the cursor * @param style the style of cursor to allocate *  * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> *    <li>ERROR_INVALID_ARGUMENT - when an unknown style is specified</li> * </ul> * @exception SWTError <ul> *    <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li> * </ul> * * @see SWT#CURSOR_ARROW * @see SWT#CURSOR_WAIT * @see SWT#CURSOR_CROSS * @see SWT#CURSOR_APPSTARTING * @see SWT#CURSOR_HELP * @see SWT#CURSOR_SIZEALL * @see SWT#CURSOR_SIZENESW * @see SWT#CURSOR_SIZENS * @see SWT#CURSOR_SIZENWSE * @see SWT#CURSOR_SIZEWE * @see SWT#CURSOR_SIZEN * @see SWT#CURSOR_SIZES * @see SWT#CURSOR_SIZEE * @see SWT#CURSOR_SIZEW * @see SWT#CURSOR_SIZENE * @see SWT#CURSOR_SIZESE * @see SWT#CURSOR_SIZESW * @see SWT#CURSOR_SIZENW * @see SWT#CURSOR_UPARROW * @see SWT#CURSOR_IBEAM * @see SWT#CURSOR_NO * @see SWT#CURSOR_HAND */public Cursor(Device device, int style) {	if (device == null) device = Device.getDevice();	if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);	this.device = device;	int lpCursorName = 0;	switch (style) {		case SWT.CURSOR_HAND: 		lpCursorName = OS.IDC_HAND; break;		case SWT.CURSOR_ARROW: 		lpCursorName = OS.IDC_ARROW; break;		case SWT.CURSOR_WAIT: 		lpCursorName = OS.IDC_WAIT; break;		case SWT.CURSOR_CROSS: 		lpCursorName = OS.IDC_CROSS; break;		case SWT.CURSOR_APPSTARTING: 	lpCursorName = OS.IDC_APPSTARTING; break;		case SWT.CURSOR_HELP: 		lpCursorName = OS.IDC_HELP; break;		case SWT.CURSOR_SIZEALL: 	lpCursorName = OS.IDC_SIZEALL; break;		case SWT.CURSOR_SIZENESW: 	lpCursorName = OS.IDC_SIZENESW; break;		case SWT.CURSOR_SIZENS: 	lpCursorName = OS.IDC_SIZENS; break;		case SWT.CURSOR_SIZENWSE: 	lpCursorName = OS.IDC_SIZENWSE; break;		case SWT.CURSOR_SIZEWE: 	lpCursorName = OS.IDC_SIZEWE; break;		case SWT.CURSOR_SIZEN: 		lpCursorName = OS.IDC_SIZENS; break;		case SWT.CURSOR_SIZES: 		lpCursorName = OS.IDC_SIZENS; break;		case SWT.CURSOR_SIZEE: 		lpCursorName = OS.IDC_SIZEWE; break;		case SWT.CURSOR_SIZEW: 		lpCursorName = OS.IDC_SIZEWE; break;		case SWT.CURSOR_SIZENE: 	lpCursorName = OS.IDC_SIZENESW; break;		case SWT.CURSOR_SIZESE: 	lpCursorName = OS.IDC_SIZENWSE; break;		case SWT.CURSOR_SIZESW: 	lpCursorName = OS.IDC_SIZENESW; break;		case SWT.CURSOR_SIZENW: 	lpCursorName = OS.IDC_SIZENWSE; break;		case SWT.CURSOR_UPARROW: 	lpCursorName = OS.IDC_UPARROW; break;		case SWT.CURSOR_IBEAM: 		lpCursorName = OS.IDC_IBEAM; break;		case SWT.CURSOR_NO: 		lpCursorName = OS.IDC_NO; break;		default:			SWT.error(SWT.ERROR_INVALID_ARGUMENT);	}	handle = OS.LoadCursor(0, lpCursorName);	/*	* IDC_HAND is supported only on Windows 2000 and Windows 98.	* Create a hand cursor if running in other Windows platforms.	*/	if (handle == 0 && style == SWT.CURSOR_HAND) {		int width = OS.GetSystemMetrics(OS.SM_CXCURSOR);		int height = OS.GetSystemMetrics(OS.SM_CYCURSOR);		if (width == 32 && height == 32) {			int hInst = OS.GetModuleHandle(null);			if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED);			handle = OS.CreateCursor(hInst, 5, 0, 32, 32, HAND_SOURCE, HAND_MASK);		}	}	if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);	if (device.tracking) device.new_Object(this);}/**	  * Constructs a new cursor given a device, image and mask * data describing the desired cursor appearance, and the x * and y coordinates of the <em>hotspot</em> (that is, the point * within the area covered by the cursor which is considered * to be where the on-screen pointer is "pointing").

⌨️ 快捷键说明

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