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

The following examples show how to use org.eclipse.swt.widgets.Display#getCursorLocation() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: SWET   File: SWTUtil.java    License: 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
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
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
@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 Project: JDeodorant   File: InformationControlManager.java    License: 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
/**
 * 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 Project: arx   File: Main.java    License: 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();
}