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

📄 widget.java

📁 源码为Eclipse开源开发平台桌面开发工具SWT的源代码,
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	eventTable = null;	data = null;}/** * Removes the listener from the collection of listeners who will * be notifed when an event of the given type occurs. * * @param eventType the type of event to listen for * @param listener the listener which should no longer be notified when the event occurs * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @see Listener * @see #addListener */public void removeListener (int eventType, Listener listener) {	checkWidget();	if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);	if (eventTable == null) return;	eventTable.unhook (eventType, listener);}/** * Removes the listener from the collection of listeners who will * be notifed when an event of the given type occurs. * <p> * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT * public API. It is marked public only so that it can be shared * within the packages provided by SWT. It should never be * referenced from application code. * </p> * * @param eventType the type of event to listen for * @param listener the listener which should no longer be notified when the event occurs * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @see Listener * @see #addListener */protected void removeListener (int eventType, SWTEventListener listener) {	checkWidget();	if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);	if (eventTable == null) return;	eventTable.unhook (eventType, listener);}/** * Removes the listener from the collection of listeners who will * be notifed when the widget is disposed. * * @param listener the listener which should no longer be notified when the receiver is disposed * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li> * </ul> * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @see DisposeListener * @see #addDisposeListener */public void removeDisposeListener (DisposeListener listener) {	checkWidget();	if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);	if (eventTable == null) return;	eventTable.unhook (SWT.Dispose, listener);}void sendEvent (Event event) {	Display display = event.display;	if (!display.filterEvent (event)) {		if (eventTable != null) eventTable.sendEvent (event);	}}void sendEvent (int eventType) {	sendEvent (eventType, null, true);}void sendEvent (int eventType, Event event) {	sendEvent (eventType, event, true);}void sendEvent (int eventType, Event event, boolean send) {	if (eventTable == null && !display.filters (eventType)) {		return;	}	if (event == null) event = new Event ();	event.type = eventType;	event.display = display;	event.widget = this;	if (event.time == 0) {		event.time = display.getLastEventTime ();	}	if (send) {		sendEvent (event);	} else {		display.postEvent (event);	}}/** * Sets the application defined widget data associated * with the receiver to be the argument. The <em>widget * data</em> is a single, unnamed field that is stored * with every widget.  * <p> * Applications may put arbitrary objects in this field. If * the object stored in the widget data needs to be notified * when the widget is disposed of, it is the application's * responsibility to hook the Dispose event on the widget and * do so. * </p> * * @param data the widget data * * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li> * </ul> */public void setData (Object data) {	checkWidget();	if ((state & KEYED_DATA) != 0) {		((Object []) this.data) [0] = data;	} else {		this.data = data;	}}/** * Sets the application defined property of the receiver * with the specified name to the given value. * <p> * Applications may associate arbitrary objects with the * receiver in this fashion. If the objects stored in the * properties need to be notified when the widget is disposed * of, it is the application's responsibility to hook the * Dispose event on the widget and do so. * </p> * * @param key the name of the property * @param value the new value for the property * * @exception IllegalArgumentException <ul> *    <li>ERROR_NULL_ARGUMENT - if the key is null</li> * </ul> * @exception SWTException <ul> *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> * * @see #getData */public void setData (String key, Object value) {	checkWidget();	if (key == null) error (SWT.ERROR_NULL_ARGUMENT);	int index = 1;	Object [] table = null;	if ((state & KEYED_DATA) != 0) {		table = (Object []) data;		while (index < table.length) {			if (key.equals (table [index])) break;			index += 2;		}	}	if (value != null) {		if ((state & KEYED_DATA) != 0) {			if (index == table.length) {				Object [] newTable = new Object [table.length + 2];				System.arraycopy (table, 0, newTable, 0, table.length);				data = table = newTable;			}		} else {			table = new Object [3];			table [0] = data;			data = table;			state |= KEYED_DATA;		}		table [index] = key;		table [index + 1] = value;	} else {		if ((state & KEYED_DATA) != 0) {			if (index != table.length) {				int length = table.length - 2;				if (length == 1) {					data = table [0];					state &= ~KEYED_DATA;				} else {					Object [] newTable = new Object [length];					System.arraycopy (table, 0, newTable, 0, index);					System.arraycopy (table, index + 2, newTable, index, length - index);					data = newTable;				}			}		}	}}boolean setInputState (Event event, int type) {	if (OS.GetKeyState (OS.VK_MENU) < 0) event.stateMask |= SWT.ALT;	if (OS.GetKeyState (OS.VK_SHIFT) < 0) event.stateMask |= SWT.SHIFT;	if (OS.GetKeyState (OS.VK_CONTROL) < 0) event.stateMask |= SWT.CONTROL;	if (OS.GetKeyState (OS.VK_LBUTTON) < 0) event.stateMask |= SWT.BUTTON1;	if (OS.GetKeyState (OS.VK_MBUTTON) < 0) event.stateMask |= SWT.BUTTON2;	if (OS.GetKeyState (OS.VK_RBUTTON) < 0) event.stateMask |= SWT.BUTTON3;	switch (type) {		case SWT.MouseDown:		case SWT.MouseDoubleClick:			if (event.button == 1) event.stateMask &= ~SWT.BUTTON1;			if (event.button == 2) event.stateMask &= ~SWT.BUTTON2;			if (event.button == 3) event.stateMask &= ~SWT.BUTTON3;			break;		case SWT.MouseUp:			if (event.button == 1) event.stateMask |= SWT.BUTTON1;			if (event.button == 2) event.stateMask |= SWT.BUTTON2;			if (event.button == 3) event.stateMask |= SWT.BUTTON3;			break;		case SWT.KeyDown:		case SWT.Traverse:			if (event.keyCode == SWT.ALT) event.stateMask &= ~SWT.ALT;			if (event.keyCode == SWT.SHIFT) event.stateMask &= ~SWT.SHIFT;			if (event.keyCode == SWT.CONTROL) event.stateMask &= ~SWT.CONTROL;			break;		case SWT.KeyUp:			if (event.keyCode == SWT.ALT) event.stateMask |= SWT.ALT;			if (event.keyCode == SWT.SHIFT) event.stateMask |= SWT.SHIFT;			if (event.keyCode == SWT.CONTROL) event.stateMask |= SWT.CONTROL;			break;	}			return true;}boolean setKeyState (Event event, int type, int wParam, int lParam) {		/*	* Feature in Windows.  When the user presses Ctrl+Backspace	* or Ctrl+Enter, Windows sends a WM_CHAR with Delete (0x7F)	* and '\n' instead of '\b' and '\r'.  This is the correct	* platform behavior but is not portable.  The fix is to detect	* these cases and convert the character.	*/	switch (display.lastAscii) {		case SWT.DEL:			if (display.lastKey == SWT.BS) display.lastAscii = SWT.BS;			break;		case SWT.LF:			if (display.lastKey == SWT.CR) display.lastAscii = SWT.CR;			break;	}		/*	* Feature in Windows.  When the user presses either the Enter	* key or the numeric keypad Enter key, Windows sends a WM_KEYDOWN	* with wParam=VK_RETURN in both cases.  In order to distinguish	* between the keys, the extended key bit is tested. If the bit	* is set, assume that the numeric keypad Enter was pressed. 	*/	if (display.lastKey == SWT.CR && display.lastAscii == SWT.CR) {		if ((lParam & 0x1000000) != 0) display.lastKey = SWT.KEYPAD_CR;	}		if (display.lastVirtual) {		/*		* Feature in Windows.  The virtual key VK_DELETE is not		* treated as both a virtual key and an ASCII key by Windows.		* Therefore, we will not receive a WM_CHAR for this key.		* The fix is to treat VK_DELETE as a special case and map		* the ASCII value explictly (Delete is 0x7F).		*/		if (display.lastKey == OS.VK_DELETE) display.lastAscii = 0x7F;				/*		* Feature in Windows.  When the user presses Ctrl+Pause, the		* VK_CANCEL key is generated and a WM_CHAR is sent with 0x03,		* possibly to allow an application to look for Ctrl+C and the		* the Break key at the same time.  This is unexpected and		* unwanted.  The fix is to detect the case and set the character		* to zero. 		*/		if (display.lastKey == OS.VK_CANCEL) display.lastAscii = 0x0;				event.keyCode = Display.translateKey (display.lastKey);	} else {		event.keyCode = display.lastKey;	}	if (display.lastAscii != 0 || display.lastNull) {		event.character = Display.mbcsToWcs ((char) display.lastAscii);	}	if (event.keyCode == 0 && event.character == 0) {		if (!display.lastNull) return false;	}	return setInputState (event, type);}boolean SetWindowPos (int hWnd, int hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags) {	if (OS.IsWinCE) {		/*		* Feature in Windows.  On Windows CE, SetWindowPos() always causes		* a WM_SIZE message, even when the new size is the same as the old		* size.  The fix is to detect that the size has not changed and set		* SWP_NOSIZE.		*/		if ((uFlags & OS.SWP_NOSIZE) == 0) {			RECT lpRect = new RECT ();			OS.GetWindowRect (hWnd, lpRect);			if (cy == lpRect.bottom - lpRect.top && cx == lpRect.right - lpRect.left) {				/*				* Feature in Windows.  On Windows CE, SetWindowPos() when called				* with SWP_DRAWFRAME always causes a WM_SIZE message, even				* when SWP_NOSIZE is set and when the new size is the same as the				* old size.  The fix is to clear SWP_DRAWFRAME when the size is				* the same.				*/				uFlags &= ~OS.SWP_DRAWFRAME;				uFlags |= OS.SWP_NOSIZE;			}		}	}	return OS.SetWindowPos (hWnd, hWndInsertAfter, X, Y, cx, cy, uFlags);}/** * Returns a string containing a concise, human-readable * description of the receiver. * * @return a string representation of the receiver */public String toString () {	String string = "*Disposed*"; //$NON-NLS-1$	if (!isDisposed ()) {		string = "*Wrong Thread*"; //$NON-NLS-1$		if (isValidThread ()) string = getNameText ();	}	return getName () + " {" + string + "}"; //$NON-NLS-1$ //$NON-NLS-2$}}

⌨️ 快捷键说明

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