Java Code Examples for org.eclipse.swt.widgets.Display#getCursorLocation()

The following examples show how to use org.eclipse.swt.widgets.Display#getCursorLocation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SWTUtil.java    From SWET with MIT License 6 votes vote down vote up
private static Rectangle getCurrentMonitorBounds(Display dsp) {
	Monitor monitor = dsp.getPrimaryMonitor();

	// Choose current Monitor
	Point cursor = dsp.getCursorLocation();
	Monitor[] monitors = dsp.getMonitors();
	for (Monitor mon : monitors) {
		Rectangle mbounds = mon.getBounds();
		if (mbounds.contains(cursor)) {
			monitor = mon;
			break;
		}
	}

	return monitor.getBounds();
}
 
Example 2
Source File: KeybindingsManager.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
private Point getInitialLocation(ICommandElementsProvider commandElementsProvider)
{
	// Ask the commandElementsProvider to provide the location
	Point popupLocation = commandElementsProvider.getCommandElementsPopupLocation();
	if (popupLocation != null)
	{
		return popupLocation;
	}

	Display display = workbench.getDisplay();
	if (display != null)
	{
		return display.getCursorLocation();
	}

	return null;
}
 
Example 3
Source File: FindBarDecorator.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
void showOptions(boolean useMousePos)
{
	Menu menu = new Menu(UIUtils.getActiveShell(), SWT.POP_UP);

	for (FindBarOption option : fFindBarOptions)
	{
		option.createMenuItem(menu);
	}

	Point location;
	if (useMousePos)
	{
		Display current = UIUtils.getDisplay();
		location = current.getCursorLocation();
	}
	else
	{
		Rectangle bounds = options.getBounds();
		location = options.getParent().toDisplay(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
	}

	menu.setLocation(location);
	menu.setVisible(true);
}
 
Example 4
Source File: QuickMenuDialog.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected Point getInitialLocation(Point initialSize)
{
	Display display = getShell().getDisplay();
	if (display != null && !display.isDisposed())
	{
		return display.getCursorLocation();
	}
	return super.getInitialLocation(initialSize);
}
 
Example 5
Source File: InformationControlManager.java    From JDeodorant with MIT License 5 votes vote down vote up
@Override
protected void computeInformation() {
	Display display = getSubjectControl().getDisplay();
	Point mouseLocation = display.getCursorLocation();
	mouseLocation = getSubjectControl().toControl(mouseLocation);

	// Compute information input
	Object info = informationProvider.getInformation(mouseLocation);

	// Find an information control creator for the computed information input
	IInformationControlCreator customControlCreator = null;
	for (ICustomInformationControlCreator controlCreator : customControlCreators) {
		if (controlCreator.isSupported(info)) {
			customControlCreator = controlCreator;
			break;
		}
	}
	setCustomInformationControlCreator(customControlCreator);

	// Convert to String for default TextLabelInformationControl
	// (Fallback, if no custom control creator has been found)
	//if (info != null && customControlCreator == null) {
	//	info = info.toString();
	//}

	// Trigger the presentation of the computed information
	if(customControlCreator != null){
	Rectangle area = informationProvider.getArea(mouseLocation);
	setInformation(info, area);
	}
}
 
Example 6
Source File: EvalExpressionAction.java    From Pydev with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This hack just creates a Watch expression, gets result and removes the watch expression. 
 * This is simple, since the watch functionality is already there.
 * 
 * @see WatchExpressionAction#createExpression
 */
private void eval(final String expr) {
    final IWatchExpression expression = createWatchExpression(expr);

    final Shell shell = PydevDebugPlugin.getActiveWorkbenchWindow().getShell();
    Display display = PydevDebugPlugin.getDefault().getWorkbench().getDisplay();
    final Point point = display.getCursorLocation();

    Display.getDefault().asyncExec(new Runnable() {
        @Override
        public void run() {
            expression.evaluate();
            waitForExpressionEvaluation(expression);
            try {
                IValue value = expression.getValue();
                String result = null;
                if (value != null) {
                    result = expr + "\n" + value.getValueString();
                    DisplayPopup popup = new DisplayPopup(shell, point, result);
                    popup.open();
                }
            } catch (DebugException e) {
                DebugPlugin.log(e);
                return;
            } catch (Throwable t) {
                DebugPlugin.log(t);
            }
        }
    });
}
 
Example 7
Source File: Main.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the monitor on which the application was launched.
 *
 * @param display
 * @return
 */
private static Monitor getMonitor(Display display) {
    Point mouse = display.getCursorLocation();
    for (Monitor monitor : display.getMonitors()) {
        if (monitor.getBounds().contains(mouse)) {
            return monitor;
        }
    }
    return display.getPrimaryMonitor();
}