text.addListener( SWT.MouseDown, e -> { try { int offset = text.getOffsetAtLocation( new Point( e.x, e.y ) );
helpLabel.setLayoutData( helpLabelFormData ); helpLabel.addListener( SWT.MouseUp, new Listener() { public void handleEvent( Event event ) { helpLabel.addListener( SWT.MouseEnter, new Listener() { public void handleEvent( Event event ) { StyleRange style1 = new StyleRange(); helpLabel.addListener( SWT.MouseExit, new Listener() { public void handleEvent( Event event ) { StyleRange style1 = new StyleRange();
/** * New single line styled text. * * @param parent the parent * @param tip the tip * @return the styled text */ protected StyledText newSingleLineStyledText(Composite parent, String tip) { StyledText w = new StyledText(parent, SWT.SINGLE | SWT.BORDER); w.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); w.setToolTipText(tip); w.addListener(SWT.KeyUp, this); w.addVerifyKeyListener(this); w.addListener(SWT.MouseUp, this); // for paste operation return w; }
/** * Adds a modify listener. A Modify event is sent by the widget when the widget text * has changed. * * @param modifyListener the listener * @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> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void addModifyListener(ModifyListener modifyListener) { checkWidget(); if (modifyListener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); addListener(SWT.Modify, new TypedListener(modifyListener)); } /**
/** * Adds a caret listener. CaretEvent is sent when the caret offset changes. * * @param listener the listener * @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> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> * * @since 3.5 */ public void addCaretListener(CaretListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); addListener(ST.CaretMoved, new StyledTextListener(listener)); } /**
/** * Adds a caret listener. CaretEvent is sent when the caret offset changes. * * @param listener the listener * @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> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> * * @since 3.5 */ public void addCaretListener(CaretListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); addListener(ST.CaretMoved, new StyledTextListener(listener)); } /**
/** * Adds a verify key listener. A VerifyKey event is sent by the widget when a key * is pressed. The widget ignores the key press if the listener sets the doit field * of the event to false. * * @param listener the listener * @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> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void addVerifyKeyListener(VerifyKeyListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); addListener(ST.VerifyKey, new StyledTextListener(listener)); } /**
/** * Adds a modify listener. A Modify event is sent by the widget when the widget text * has changed. * * @param modifyListener the listener * @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> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void addModifyListener(ModifyListener modifyListener) { checkWidget(); if (modifyListener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); addListener(SWT.Modify, new TypedListener(modifyListener)); } /**
/** * Adds a modify listener. A Modify event is sent by the widget when the widget text * has changed. * * @param modifyListener the listener * @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> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void addModifyListener(ModifyListener modifyListener) { checkWidget(); if (modifyListener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); addListener(SWT.Modify, new TypedListener(modifyListener)); } /**
/** * Adds a verify key listener. A VerifyKey event is sent by the widget when a key * is pressed. The widget ignores the key press if the listener sets the doit field * of the event to false. * * @param listener the listener * @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> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void addVerifyKeyListener(VerifyKeyListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); addListener(ST.VerifyKey, new StyledTextListener(listener)); } /**
/** * Adds a verify key listener. A VerifyKey event is sent by the widget when a key * is pressed. The widget ignores the key press if the listener sets the doit field * of the event to false. * * @param listener the listener * @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> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void addVerifyKeyListener(VerifyKeyListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); addListener(ST.VerifyKey, new StyledTextListener(listener)); } /**
/** * Adds a caret listener. CaretEvent is sent when the caret offset changes. * * @param listener the listener * @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> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> * * @since 3.5 */ public void addCaretListener(CaretListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); addListener(ST.CaretMoved, new StyledTextListener(listener)); } /**
/** * Adds a verify key listener. A VerifyKey event is sent by the widget when a key * is pressed. The widget ignores the key press if the listener sets the doit field * of the event to false. * * @param listener the listener * @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> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void addVerifyKeyListener(VerifyKeyListener listener) { checkWidget(); if (listener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); addListener(ST.VerifyKey, new StyledTextListener(listener)); } /**
/** * Adds a modify listener. A Modify event is sent by the widget when the widget text * has changed. * * @param modifyListener the listener * @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> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void addModifyListener(ModifyListener modifyListener) { checkWidget(); if (modifyListener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); addListener(SWT.Modify, new TypedListener(modifyListener)); } /**
/** * Adds a modify listener. A Modify event is sent by the widget when the widget text * has changed. * * @param modifyListener the listener * @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> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void addModifyListener(ModifyListener modifyListener) { checkWidget(); if (modifyListener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); addListener(SWT.Modify, new TypedListener(modifyListener)); } /**
/** * Adds a verify listener. A Verify event is sent by the widget when the widget text * is about to change. The listener can set the event text and the doit field to * change the text that is set in the widget or to force the widget to ignore the * text change. * * @param verifyListener the listener * @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> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void addVerifyListener(VerifyListener verifyListener) { checkWidget(); if (verifyListener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); addListener(SWT.Verify, new TypedListener(verifyListener)); } /**
/** * Adds a verify listener. A Verify event is sent by the widget when the widget text * is about to change. The listener can set the event text and the doit field to * change the text that is set in the widget or to force the widget to ignore the * text change. * * @param verifyListener the listener * @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> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void addVerifyListener(VerifyListener verifyListener) { checkWidget(); if (verifyListener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); addListener(SWT.Verify, new TypedListener(verifyListener)); } /**
/** * Adds a verify listener. A Verify event is sent by the widget when the widget text * is about to change. The listener can set the event text and the doit field to * change the text that is set in the widget or to force the widget to ignore the * text change. * * @param verifyListener the listener * @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> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void addVerifyListener(VerifyListener verifyListener) { checkWidget(); if (verifyListener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); addListener(SWT.Verify, new TypedListener(verifyListener)); } /**
/** * Adds an extended modify listener. An ExtendedModify event is sent by the * widget when the widget text has changed. * * @param extendedModifyListener the listener * @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> * @exception IllegalArgumentException <ul> * <li>ERROR_NULL_ARGUMENT when listener is null</li> * </ul> */ public void addExtendedModifyListener(ExtendedModifyListener extendedModifyListener) { checkWidget(); if (extendedModifyListener == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); StyledTextListener typedListener = new StyledTextListener(extendedModifyListener); addListener(ST.ExtendedModify, typedListener); } /**
void installListeners() { styledText.addCaretListener(event -> { updateStatusBar(); updateToolBar(); }); styledText.addListener(SWT.MouseUp, event -> handleMouseUp(event)); styledText.addListener(SWT.KeyDown, event -> handleKeyDown(event)); styledText.addVerifyListener(event -> handleVerifyText(event)); styledText.addModifyListener(event -> handleModify(event)); styledText.addPaintObjectListener(event -> handlePaintObject(event)); styledText.addListener(SWT.Dispose, event -> { StyleRange[] styles = styledText.getStyleRanges(0, styledText.getCharCount(), false); for (StyleRange style : styles) { Object data = style.data; if (data != null) { if (data instanceof Image) ((Image)data).dispose(); if (data instanceof Control) ((Control)data).dispose(); } } }); shell.addControlListener(ControlListener.controlResizedAdapter(event -> handleResize(event))); }