下面列出了怎么用org.eclipse.swt.widgets.TypedListener的API类实例代码及写法,或者点击链接到github查看源代码。
public Popup2(final IPopupProvider provider, final Widget... controls) {
super(WorkbenchHelper.getShell(), PopupDialog.HOVER_SHELLSTYLE, false, false, false, false, false, null, null);
this.provider = provider;
final Shell parent = provider.getControllingShell();
parent.addListener(SWT.Move, hide);
parent.addListener(SWT.Resize, hide);
parent.addListener(SWT.Close, hide);
parent.addListener(SWT.Deactivate, hide);
parent.addListener(SWT.Hide, hide);
parent.addListener(SWT.Dispose, event -> close());
for (final Widget c : controls) {
if (c == null) {
continue;
}
final TypedListener typedListener = new TypedListener(mtl);
c.addListener(SWT.MouseEnter, typedListener);
c.addListener(SWT.MouseExit, typedListener);
c.addListener(SWT.MouseHover, typedListener);
}
}
private CursorLinePainter getCursorLinePainterInstalled(TextViewer viewer)
{
Listener[] listeners = viewer.getTextWidget().getListeners(3001/* StyledText.LineGetBackground */);
for (Listener listener : listeners)
{
if (listener instanceof TypedListener)
{
TypedListener typedListener = (TypedListener) listener;
if (typedListener.getEventListener() instanceof CursorLinePainter)
{
return (CursorLinePainter) typedListener.getEventListener();
}
}
}
return null;
}
/**
* An item may be considered visible, and will be returned with
* {@link CTree#getVisibleItems()}, even though it will not be
* painted on the screen. Paint status, on the other hand, refers to whether
* or not an item will actually be painted when the
* {@link CTree#paintBody(Event)} method is called.
*
* @return an array of items that will be painted to the screen during paint
* events
* @see #getVisibleItems()
*/
// public CTreeItem[] getPaintedItems() {
// return (CTreeItem[]) paintedItems.toArray(new
// CTreeItem[paintedItems.size()]);
// }
public void addSelectionListener(SelectionListener listener) {
checkWidget();
if (listener != null) {
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection, typedListener);
addListener(SWT.DefaultSelection, typedListener);
}
}
public void addTreeListener(TreeListener listener) {
checkWidget ();
if(listener != null) {
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Collapse, typedListener);
addListener (SWT.Expand, typedListener);
}
}
protected void addSelectionListener( SelectionListener listener )
{
if ( listener == null )
throw new SWTError( SWT.ERROR_NULL_ARGUMENT );
addListener( SWT.Selection, new TypedListener( listener ) );
}
public void addSelectionListener(SelectionListener listener){
checkWidget();
if (listener == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection, typedListener);
addListener(SWT.DefaultSelection, typedListener);
}
public void addSelectionListener(SelectionListener listener) {
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection, typedListener);
addListener(SWT.DefaultSelection, typedListener);
}
/**
* Removes the listener from the collection of listeners who will be notified
* when the control is selected by the user.
*
* @param listener the listener which should no longer be notified
*
* @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 SelectionListener
* @see #addSelectionListener
*/
@Override
public void removeSelectionListener(SelectionListener listener) {
checkWidget();
if (listener == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
final Iterator<Listener> it = listeners.iterator();
while (it.hasNext()) {
final Listener current = it.next();
if (current instanceof TypedListener) {
final TypedListener tl = (TypedListener) current;
if (tl.getEventListener() != null && tl.getEventListener().equals(listener)) {
it.remove();
}
}
}
}
public void addSelectionListener(SelectionListener listener) {
if (listener == null)
throw new SWTError(SWT.ERROR_NULL_ARGUMENT);
addListener(SWT.Selection, new TypedListener(listener));
}
private void addListener( Control el, int event, TypedListener listener ) {
if ( ArrayUtils.contains( el.getListeners( event ), listener ) ) {
return;
}
el.addListener( event, listener );
}
/**
* Adds the listener to the collection of listeners who will
* be notified when the receiver is expanded or collapsed
* by sending it one of the messages defined in the <code>ExpandListener</code>
* interface.
*
* @param listener the listener which should be notified
*
* @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 ExpandListener
* @see #removeExpandListener
*/
public void addExpandListener(ExpandListener listener)
{
checkWidget();
if (listener == null)
SWT.error(SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Expand, typedListener);
addListener(SWT.Collapse, typedListener);
}
/**
* Adds the listener to the collection of listeners who will be notified
* when the receiver's selection changes, by sending it one of the messages
* defined in the <code>SelectionListener</code> interface.
* <p>
* When <code>widgetSelected</code> is called, the item field of the event
* object is valid.
* </p>
*
* @param listener
* the listener which should be notified
*
* @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 SelectionListener
* @see #removeSelectionListener
* @see SelectionEvent
*/
public void addSelectionListener(SelectionListener listener) {
checkWidget();
if (listener == null)
SWT.error(SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection, typedListener);
addListener(SWT.DefaultSelection, typedListener);
}
/**
* Adds the listener to the collection of listeners who will be notified
* when an item in the receiver is expanded or collapsed by sending it one
* of the messages defined in the TreeListener interface.
*
* @param listener
*/
public void addTreeListener(TreeListener listener) {
checkWidget();
if (listener == null)
SWT.error(SWT.ERROR_NULL_ARGUMENT);
addListener(SWT.Expand, new TypedListener(listener));
}
/**
* Adds the listener to the collection of listeners who will be notified when
* the control is selected by the user, by sending it one of the messages
* defined in the <code>SelectionListener</code> interface.
* <p>
* <code>widgetDefaultSelected</code> is not called.
* </p>
*
* @param listener the listener which should be notified when the control is
* selected by the user,
*
* @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 SelectionListener
* @see #removeSelectionListener
* @see SelectionEvent
*/
@Override
public void addSelectionListener(SelectionListener listener) {
checkWidget();
if (listener == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
final TypedListener typedListener = new TypedListener(listener);
listeners.add(typedListener);
}
/**
* Adds the listener to the collection of listeners who will be notified
* when the row is resized, by sending it one of the messages defined in the
* <code>ControlListener</code> interface.
* <p>
* Clients who wish to override the standard row resize logic should use the
* untyped listener mechanisms. The untyped <code>Event</code> object passed
* to an untyped listener will have its <code>detail</code> field populated
* with the new row height. Clients may alter this value to, for example,
* enforce minimum or maximum row sizes. Clients may also set the
* <code>doit</code> field to false to prevent the entire resize operation.
*
* @param listener
* the listener which should be notified
*
* @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>
*/
public void addControlListener(ControlListener listener) {
checkWidget();
if (listener == null)
SWT.error(SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Resize, typedListener);
}
/**
* Adds the listener to the collection of listeners who will be notified
* when the receiver's is pushed, by sending it one of the messages defined
* in the <code>SelectionListener</code> interface.
*
* @param listener
* the listener which should be notified
* @throws IllegalArgumentException
* <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @throws org.eclipse.swt.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 addSelectionListener(SelectionListener listener) {
checkWidget();
if (listener == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
this.addListener(SWT.Selection, new TypedListener(listener));
}
/**
* Adds a listener to the list of listeners notified when the column is
* moved or resized.
*
* @param listener
* listener
* @throws IllegalArgumentException
* <ul>
* <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
* </ul>
* @throws org.eclipse.swt.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 addControlListener(ControlListener listener) {
checkWidget();
if (listener == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Resize, typedListener);
addListener(SWT.Move, typedListener);
}
/**
* Adds the listener to the collection of listeners who will
* be notified when an item in the receiver is expanded or collapsed
* by sending it one of the messages defined in the <code>TreeListener</code>
* interface.
*
* @param listener the listener which should be notified
*
* @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 TreeListener
* @see #removeTreeListener
*/
public void addTreeListener(TreeListener listener) {
checkWidget ();
if (listener == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
addListener (SWT.Expand, typedListener);
addListener (SWT.Collapse, typedListener);
}
/**
* Adds the listener to the collection of listeners who will
* be notified when the control is selected by the user, by sending
* it one of the messages defined in the <code>SelectionListener</code>
* interface.
* <p>
* <code>widgetSelected</code> is called when the control is selected by the user.
* <code>widgetDefaultSelected</code> is not called.
* </p>
* <p>
* When the <code>SWT.RADIO</code> style bit is set, the <code>widgetSelected</code> method is
* also called when the receiver loses selection because another item in the same radio group
* was selected by the user. During <code>widgetSelected</code> the application can use
* <code>getSelection()</code> to determine the current selected state of the receiver.
* </p>
*
* @param listener the listener which should be notified
*
* @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 SelectionListener
* @see #removeSelectionListener
* @see SelectionEvent
*/
public void addSelectionListener(SelectionListener listener) {
checkWidget();
if (listener == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
final TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection, typedListener);
addListener(SWT.DefaultSelection, typedListener);
}
/**
* Adds the listener to the collection of listeners who will be notified
* when the receiver's text is modified, by sending it one of the messages
* defined in the <code>ModifyListener</code> interface.
*
* @param listener the listener which should be notified
*
* @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 ModifyListener
* @see #removeModifyListener
*/
public void addModifyListener(ModifyListener listener) {
checkWidget();
if (listener == null)
SWT.error(SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Modify, typedListener);
}
/**
* Adds the listener to the collection of listeners who will be notified
* when the user changes the receiver's selection, by sending it one of the
* messages defined in the <code>SelectionListener</code> interface.
* <p>
* <code>widgetSelected</code> is called when the combo's list selection
* changes. <code>widgetDefaultSelected</code> is typically called when
* ENTER is pressed the combo's text area.
* </p>
*
* @param listener the listener which should be notified when the user
* changes the receiver's selection
*
* @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 SelectionListener
* @see #removeSelectionListener
* @see SelectionEvent
*/
public void addSelectionListener(SelectionListener listener) {
checkWidget();
if (listener == null)
SWT.error(SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection, typedListener);
addListener(SWT.DefaultSelection, typedListener);
}
/**
* Adds the listener to the collection of listeners who will be notified
* when the receiver's text is verified, by sending it one of the messages
* defined in the <code>VerifyListener</code> interface.
*
* @param listener the listener which should be notified
*
* @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 VerifyListener
* @see #removeVerifyListener
*
* @since 3.3
*/
public void addVerifyListener(VerifyListener listener) {
checkWidget();
if (listener == null)
SWT.error(SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Verify, typedListener);
}
/**
* Adds the listener to the collection of listeners who will
* be notified when the receiver's text is modified, by sending
* it one of the messages defined in the <code>ModifyListener</code>
* interface.
*
* @param listener the listener which should be notified
* @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 ModifyListener
* @see #removeModifyListener
*/
public void addModifyListener(ModifyListener listener) {
checkWidget();
if (listener == null)
SWT.error(SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Modify, typedListener);
}
/**
* Adds the listener to the collection of listeners who will
* be notified when the receiver's selection changes, by sending
* it one of the messages defined in the <code>SelectionListener</code>
* interface.
* <p>
* <code>widgetSelected</code> is called when the combo's list selection changes.
* <code>widgetDefaultSelected</code> is typically called when ENTER is pressed the combo's text area.
* </p>
*
* @param listener the listener which should be notified
* @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 SelectionListener
* @see #removeSelectionListener
* @see SelectionEvent
*/
public void addSelectionListener(SelectionListener listener) {
checkWidget();
if (listener == null)
SWT.error(SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection, typedListener);
addListener(SWT.DefaultSelection, typedListener);
}
/**
* Adds the listener to the collection of listeners who will
* be notified when the receiver's text is verified, by sending
* it one of the messages defined in the <code>VerifyListener</code>
* interface.
*
* @param listener the listener which should be notified
* @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 VerifyListener
* @see #removeVerifyListener
*/
public void addVerifyListener(VerifyListener listener) {
checkWidget();
if (listener == null)
SWT.error(SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Verify, typedListener);
}
/**
* Adds the listener to the collection of listeners who will
* be notified when the receiver's selection changes, by sending
* it one of the messages defined in the <code>SelectionListener</code>
* interface.
* <p>
* <code>widgetSelected</code> is called when the dates selection changes.
* </p>
*
* @param lsnr the listener which should be notified
* @see SelectionListener
* @see #removeSelectionListener
*/
public void addSelectionListener(SelectionListener lsnr) {
checkWidget();
if (lsnr == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
final TypedListener typedListener = new TypedListener(lsnr);
addListener(SWT.Selection, typedListener);
}
/**
* Adds the listener to the collection of listeners who will be notified when
* the receiver's text is modified, by sending it one of the messages defined in
* the <code>ModifyListener</code> interface.
*
* @param listener
* the listener which should be notified
*
* @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 ModifyListener
* @see #removeModifyListener
*/
public void addModifyListener(final ModifyListener listener) {
checkWidget();
if (listener == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
final TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Modify, typedListener);
}
/**
* Adds the listener to the collection of listeners who will be notified when
* the user changes the receiver's selection, by sending it one of the messages
* defined in the <code>SelectionListener</code> interface.
* <p>
* <code>widgetSelected</code> is called when the combo's list selection
* changes. <code>widgetDefaultSelected</code> is typically called when ENTER is
* pressed the combo's text area.
* </p>
*
* @param listener
* the listener which should be notified when the user changes the
* receiver's selection
*
* @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 SelectionListener
* @see #removeSelectionListener
* @see SelectionEvent
*/
public void addSelectionListener(final SelectionListener listener) {
checkWidget();
if (listener == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
final TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection, typedListener);
addListener(SWT.DefaultSelection, typedListener);
}
/**
* Adds the listener to the collection of listeners who will be notified when
* the receiver's text is verified, by sending it one of the messages defined in
* the <code>VerifyListener</code> interface.
*
* @param listener
* the listener which should be notified
*
* @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 VerifyListener
* @see #removeVerifyListener
*
* @since 3.3
*/
public void addVerifyListener(final VerifyListener listener) {
checkWidget();
if (listener == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
final TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Verify, typedListener);
}
/**
* Adds the listener to the collection of listeners who will be notified when
* the user changes the receiver's selection, by sending it one of the messages
* defined in the <code>SelectionListener</code> interface.
* <p>
* <code>widgetSelected</code> is called when the combo's list selection
* changes. <code>widgetDefaultSelected</code> is typically called when ENTER is
* pressed the combo's text area.
* </p>
*
* @param listener
* the listener which should be notified when the user changes the
* receiver's selection
*
* @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 SelectionListener
* @see #removeSelectionListener
* @see SelectionEvent
*/
public void addSelectionListener(final SelectionListener listener) {
checkWidget();
if (listener == null) {
SWT.error(SWT.ERROR_NULL_ARGUMENT);
}
final TypedListener typedListener = new TypedListener(listener);
addListener(SWT.Selection, typedListener);
addListener(SWT.DefaultSelection, typedListener);
}