use of org.eclipse.swt.events.MouseTrackAdapter in project archi by archimatetool.
the class EditPartTipHelper method hookShellListeners.
@Override
protected void hookShellListeners() {
/*
* If the cursor leaves the tip window, hide the tooltip and dispose of
* its shell
*/
getShell().addMouseTrackListener(new MouseTrackAdapter() {
@Override
public void mouseExit(MouseEvent e) {
getShell().setCapture(false);
dispose();
}
});
/*
* If the mouseExit listener does not get called, dispose of the shell
* if the cursor is no longer in the tooltip. This occurs in the rare
* case that a mouseEnter is not received on the tooltip when it
* appears.
*/
getShell().addMouseMoveListener(new MouseMoveListener() {
@Override
public void mouseMove(MouseEvent e) {
Point eventPoint = getShell().toDisplay(new Point(e.x, e.y));
if (!getShell().getBounds().contains(eventPoint)) {
if (isShowing())
getShell().setCapture(false);
dispose();
}
}
});
// window.
if (shellListener == null) {
shellListener = new ShellAdapter() {
@Override
public void shellDeactivated(ShellEvent event) {
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
Shell active = Display.getCurrent().getActiveShell();
if (getShell() == active || control.getShell() == active || getShell().isDisposed())
return;
if (isShowing())
getShell().setCapture(false);
dispose();
}
});
}
};
control.getShell().addShellListener(shellListener);
getShell().addShellListener(shellListener);
}
/*
* Workaround for GTK Bug - Control.setCapture(boolean) not implemented:
* If the cursor is not over the shell when it is first painted, hide
* the tooltip and dispose of the shell.
*/
if (SWT.getPlatform().equals("gtk")) {
// $NON-NLS-1$
getShell().addPaintListener(new PaintListener() {
@Override
public void paintControl(PaintEvent event) {
Point cursorLoc = Display.getCurrent().getCursorLocation();
if (!getShell().getBounds().contains(cursorLoc)) {
// This must be run asynchronously. If not, other paint
// listeners may attempt to paint on a disposed control.
Display.getCurrent().asyncExec(new Runnable() {
@Override
public void run() {
if (isShowing())
getShell().setCapture(false);
dispose();
}
});
}
}
});
}
}
Aggregations