?? widget.java
字號:
* * @see #addDisposeListener * @see #removeDisposeListener * @see #checkWidget */public void dispose () { /* * Note: It is valid to attempt to dispose a widget * more than once. If this happens, fail silently. */ if (isDisposed ()) return; if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); releaseChild (); releaseWidget (); destroyWidget ();}/** * Does whatever widget specific cleanup is required, and then * uses the code in <code>SWTError.error</code> to handle the error. * * @param code the descriptive error code * * @see SWTError#error */void error (int code) { SWT.error(code);}boolean filters (int eventType) { return display.filters (eventType);}/** * Returns the application defined widget data associated * with the receiver, or null if it has not been set. 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> * * @return 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> * * @see #setData */public Object getData () { checkWidget(); return (state & KEYED_DATA) != 0 ? ((Object []) data) [0] : data;}/** * Returns the application defined property of the receiver * with the specified name, or null if it has not been set. * <p> * Applications may have associated 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 * @return the value of the property or null if it has not been set * * @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 #setData */public Object getData (String key) { checkWidget(); if (key == null) error (SWT.ERROR_NULL_ARGUMENT); if ((state & KEYED_DATA) != 0) { Object [] table = (Object []) data; for (int i=1; i<table.length; i+=2) { if (key.equals (table [i])) return table [i+1]; } } return null;}/** * Returns the <code>Display</code> that is associated with * the receiver. * <p> * A widget's display is either provided when it is created * (for example, top level <code>Shell</code>s) or is the * same as its parent's display. * </p> * * @return the receiver's display * * @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> */public Display getDisplay () { Display display = this.display; if (display == null) error (SWT.ERROR_WIDGET_DISPOSED); return display;}/** * Returns the name of the widget. This is the name of * the class without the package name. * * @return the name of the widget */String getName () { String string = getClass ().getName (); int index = string.lastIndexOf ('.'); if (index == -1) return string; return string.substring (index + 1, string.length ());}/* * Returns a short printable representation for the contents * of a widget. For example, a button may answer the label * text. This is used by <code>toString</code> to provide a * more meaningful description of the widget. * * @return the contents string for the widget * * @see #toString */String getNameText () { return ""; //$NON-NLS-1$}/** * Returns the receiver's style information. * <p> * Note that the value which is returned by this method <em>may * not match</em> the value which was provided to the constructor * when the receiver was created. This can occur when the underlying * operating system does not support a particular combination of * requested styles. For example, if the platform widget used to * implement a particular SWT widget always has scroll bars, the * result of calling this method would always have the * <code>SWT.H_SCROLL</code> and <code>SWT.V_SCROLL</code> bits set. * </p> * * @return the style bits * * @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> */public int getStyle () { checkWidget(); return style;}/* * Returns <code>true</code> if the specified eventType is * hooked, and <code>false</code> otherwise. Implementations * of SWT can avoid creating objects and sending events * when an event happens in the operating system but * there are no listeners hooked for the event. * * @param eventType the event to be checked * * @return <code>true</code> when the eventType is hooked and <code>false</code> otherwise * * @see #isListening */boolean hooks (int eventType) { if (eventTable == null) return false; return eventTable.hooks (eventType);}/** * Returns <code>true</code> if the widget has been disposed, * and <code>false</code> otherwise. * <p> * This method gets the dispose state for the widget. * When a widget has been disposed, it is an error to * invoke any other method using the widget. * </p> * * @return <code>true</code> when the widget is disposed and <code>false</code> otherwise */public boolean isDisposed () { return (state & DISPOSED) != 0;}/** * Returns <code>true</code> if there are any listeners * for the specified event type associated with the receiver, * and <code>false</code> otherwise. * * @param eventType the type of event * @return true if the event is hooked * * @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> */protected boolean isListening (int eventType) { checkWidget(); return hooks (eventType);}/* * Returns <code>true</code> when subclassing is * allowed and <code>false</code> otherwise * * @return <code>true</code> when subclassing is allowed and <code>false</code> otherwise */boolean isValidSubclass () { return Display.isValidClass (getClass ());}/* * Returns <code>true</code> when the current thread is * the thread that created the widget and <code>false</code> * otherwise. * * @return <code>true</code> when the current thread is the thread that created the widget and <code>false</code> otherwise */boolean isValidThread () { return getDisplay ().isValidThread ();}/** * Notifies all of the receiver's listeners for events * of the given type that one such event has occurred by * invoking their <code>handleEvent()</code> method. * * @param eventType the type of event which has occurred * @param event the event data * * @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> */public void notifyListeners (int eventType, Event event) { checkWidget(); if (event == null) event = new Event (); sendEvent (eventType, event);}void postEvent (int eventType) { sendEvent (eventType, null, false);}void postEvent (int eventType, Event event) { sendEvent (eventType, event, false);}/* * Releases the receiver, a child in a widget hierarchy, * from its parent. * <p> * When a widget is destroyed, it may be necessary to remove * it from an internal data structure of the parent. When * a widget has no handle, it may also be necessary for the * parent to hide the widget or otherwise indicate that the * widget has been disposed. For example, disposing a menu * bar requires that the menu bar first be released from the * shell when the menu bar is active. This could not be done * in <code>destroyWidget</code> for the menu bar because the * parent shell as well as other fields have been null'd out * already by <code>releaseWidget</code>. * </p> * This method is called first when a widget is disposed. * * @see #dispose * @see #releaseChild * @see #releaseWidget * @see #releaseHandle */void releaseChild () {}/* * Releases the widget's handle by zero'ing it out. * Does not destroy or release any operating system * resources. * <p> * This method is called after <code>releaseWidget</code> * or from <code>destroyWidget</code> when a widget is being * destroyed to ensure that the widget is marked as destroyed * in case the act of destroying the widget in the operating * system causes application code to run in callback that * could access the widget. * </p> * * @see #dispose * @see #releaseChild * @see #releaseWidget * @see #releaseHandle */void releaseHandle () { state |= DISPOSED; display = null;}void releaseResources () { releaseWidget (); releaseHandle ();}/* * Releases any internal resources back to the operating * system and clears all fields except the widget handle. * <p> * When a widget is destroyed, resources that were acquired * on behalf of the programmer need to be returned to the * operating system. For example, if the widget made a * copy of an icon, supplied by the programmer, this copy * would be freed in <code>releaseWidget</code>. Also, * to assist the garbage collector and minimize the amount * of memory that is not reclaimed when the programmer keeps * a reference to a disposed widget, all fields except the * handle are zero'd. The handle is needed by <code>destroyWidget</code>. * </p> * <p> * Typically, a widget with children will broadcast this * message to all children so that they too can release their * resources. The <code>releaseHandle</code> method is used * as part of this broadcast to zero the handle fields of the * children without calling <code>destroyWidget</code>. In * this scenario, the children are actually destroyed later, * when the operating system destroys the widget tree. * </p> * This method is called after <code>releaseChild</code>. * * @see #dispose * @see #releaseChild * @see #releaseWidget * @see #releaseHandle */void releaseWidget () { sendEvent (SWT.Dispose);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -