Java Code Examples for org.eclipse.swt.widgets.Monitor#getBounds()

The following examples show how to use org.eclipse.swt.widgets.Monitor#getBounds() . 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: SWTGraphicUtil.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Center a shell on the primary monitor
 *
 * @param shell shell to center
 */
public static void centerShell(final Shell shell) {
	final Monitor primary = shell.getDisplay().getPrimaryMonitor();
	final Rectangle bounds = primary.getBounds();
	final Rectangle rect = shell.getBounds();
	final int x = bounds.x + (bounds.width - rect.width) / 2;
	final int y = bounds.y + (bounds.height - rect.height) / 2;
	shell.setLocation(x, y);
}
 
Example 3
Source File: SWTGraphicUtil.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @param shell
 * @return the bounds of the monitor on which the shell is running
 */
public static Rectangle getBoundsOfMonitorOnWhichShellIsDisplayed(final Shell shell) {
	Monitor monitor = shell.getDisplay().getPrimaryMonitor();
	if(shell != null && shell.getMonitor() != null) {
		monitor = shell.getMonitor();
	} 
	
	return monitor.getBounds();
}
 
Example 4
Source File: Utils.java    From nebula with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Centers a dialog (Shell) on the <b>primary</b> (active) display.
 * 
 * @param shell Shell to center on screen
 * @see Shell
 */
public static void centerDialogOnScreen(final Shell shell) {
	// do it by monitor to support dual-head cards and still center things correctly onto the screen people are on.
    final Monitor monitor = Display.getDefault().getPrimaryMonitor();
    final Rectangle bounds = monitor.getBounds();

    final int screen_x = bounds.width;
    final int screen_y = bounds.height;

	shell.setLocation(screen_x / 2 - (shell.getBounds().width / 2), screen_y / 2 - (shell.getBounds().height / 2));
}
 
Example 5
Source File: ScrolledTextEx.java    From SWET with MIT License 5 votes vote down vote up
private static Point center(Display display, Shell shell) {
	Monitor primary = display.getPrimaryMonitor();
	Rectangle bounds = primary.getBounds();
	Rectangle rect = shell.getBounds();

	int x = bounds.x + (bounds.width - rect.width) / 2;
	int y = bounds.y + (bounds.height - rect.height) / 2;

	Point location = new Point(x, y);
	return location;
}
 
Example 6
Source File: SelectExamplePage.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
private Rectangle calculatePosition(int scale, int offset) {
	Monitor monitor = getMonitor();
	offset = offset * scale;
	int width = (monitor.getBounds().width + offset) / scale;
	int height = (monitor.getBounds().height + offset) / scale;
	int x = monitor.getBounds().x + (width - offset) / scale;
	int y = monitor.getBounds().y + (height - offset) / scale;
	return new Rectangle(x, y, width, height);
}
 
Example 7
Source File: ProjectOptionsDataPage.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
private void setShellLoc(Shell shell) {
	Monitor primary = Display.getCurrent().getPrimaryMonitor();
    Rectangle bounds = primary.getBounds();
    Rectangle rect = shell.getBounds();
    
    int x = bounds.x + (bounds.width - rect.width) / 2;
    int y = bounds.y + (bounds.height - rect.height) / 2;
    
    shell.setLocation(x, y);
	
}
 
Example 8
Source File: JframeApp.java    From jframe with Apache License 2.0 5 votes vote down vote up
public void layout2Center() {
    Monitor primary = shell.getDisplay().getPrimaryMonitor();
    Rectangle bounds = primary.getBounds();
    Rectangle rect = shell.getBounds();
    int x = bounds.x + (bounds.width - rect.width) / 2;
    int y = bounds.y + (bounds.height - rect.height) / 2;
    shell.setLocation(x, y);
}
 
Example 9
Source File: SWTUtil.java    From arx with Apache License 2.0 5 votes vote down vote up
/**
 * Centers the shell on the given monitor.
 *
 * @param shell
 * @param monitor
 */
public static void center(Shell shell, Monitor monitor) {
    Rectangle shellRect = shell.getBounds();
    Rectangle displayRect = monitor.getBounds();
    int x = (displayRect.width - shellRect.width) / 2;
    int y = (displayRect.height - shellRect.height) / 2;
    shell.setLocation(displayRect.x + x, displayRect.y + y);
}
 
Example 10
Source File: TipDayEx.java    From SWET with MIT License 4 votes vote down vote up
public void open(final Shell parent, Display... parentDisplay) {
	if (TipDayEx.index == -1) {
		TipDayEx.index = new Random().nextInt(this.tips.size());
	}
	this.shell = new Shell(parent,
			SWT.SYSTEM_MODAL | SWT.TITLE | SWT.BORDER | SWT.CLOSE | SWT.RESIZE);
	this.shell.setText("Tip of the day");
	this.shell.setLayout(new GridLayout(2, false));

	this.shell.addListener(SWT.Traverse, new Listener() {
		@Override
		public void handleEvent(final Event event) {
			switch (event.detail) {
			case SWT.TRAVERSE_ESCAPE:
				TipDayEx.this.shell.dispose();
				event.detail = SWT.TRAVERSE_NONE;
				event.doit = false;
				break;
			}
		}
	});
	buildLeftColumn();
	buildTip();
	buildButtons();

	this.shell.setDefaultButton(this.buttonClose);
	this.shell.pack();
	this.shell.open();

	if (parentDisplay != null) {
		display = parentDisplay[0];
	} else {

		display = this.shell.getDisplay();
	}
	Monitor primary = display.getPrimaryMonitor();
	Rectangle bounds = primary.getBounds();
	Rectangle rect = shell.getBounds();

	int x = bounds.x + (bounds.width - rect.width) / 2;
	int y = bounds.y + (bounds.height - rect.height) / 2;

	shell.setLocation(x, y);

	while (!this.shell.isDisposed()) {
		if (!display.readAndDispatch()) {
			display.sleep();
		}
	}
}
 
Example 11
Source File: TSVExtendedHandler.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
	
	Shell shell = new Shell();
	shell.setText("Extended TSV Analysis");
	shell.setSize(300, 400);
	
	Monitor primary = shell.getDisplay().getPrimaryMonitor();
    Rectangle bounds = primary.getBounds();
    Rectangle rect = shell.getBounds();
    
    int x = bounds.x + (bounds.width - rect.width) / 2;
    int y = bounds.y + (bounds.height - rect.height) / 2;
    
    shell.setLocation(x, y);
	
	// Set layout for shell
	GridLayout layout = new GridLayout();
	shell.setLayout(layout);
	
	// Create a composite to hold the children
	Composite composite = new Composite(shell, SWT.NONE);
	final ModuleTableViewer moduleTableViewer = new ModuleTableViewer(composite);
	if (moduleTableViewer.isPlatformFound()) {
		moduleTableViewer.getControl().addDisposeListener(new DisposeListener() {

			@Override
			public void widgetDisposed(DisposeEvent e) {
				moduleTableViewer.dispose();
			}
		});
		
		// Ask the shell to display its content
		shell.open();
		moduleTableViewer.run(shell);
	}
	else {
		MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
		dialog.setText("Platform extension not found");
		dialog.setMessage("The platform extension was not found in the workspace. Please import it and try again.");
		dialog.open();
	}
	
}
 
Example 12
Source File: ConfigureExtensionModulesHandler.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 4 votes vote down vote up
@Override
public Object execute(ExecutionEvent arg0) throws ExecutionException {
	
	Shell shell = new Shell();
	shell.setText("Extension Module Configurations");

	
	shell.setSize(500, 400);
	
	Monitor primary = shell.getDisplay().getPrimaryMonitor();
    Rectangle bounds = primary.getBounds();
    Rectangle rect = shell.getBounds();
    
    int x = bounds.x + (bounds.width - rect.width) / 2;
    int y = bounds.y + (bounds.height - rect.height) / 2;
    
    shell.setLocation(x, y);
	
	// Set layout for shell
	GridLayout layout = new GridLayout();
	shell.setLayout(layout);
	
	// Create a composite to hold the children
	Composite composite = new Composite(shell, SWT.NONE);
	final ModuleTableViewer moduleTableViewer = new ModuleTableViewer(composite);
	if (moduleTableViewer.isPlatformFound()) {
		moduleTableViewer.getControl().addDisposeListener(new DisposeListener() {

			@Override
			public void widgetDisposed(DisposeEvent e) {
				moduleTableViewer.dispose();
			}
		});
		
		// Ask the shell to display its content
		shell.open();
		moduleTableViewer.run(shell);
	}
	else {
		MessageBox dialog = new MessageBox(shell, SWT.ICON_WARNING | SWT.OK);
		dialog.setText("Platform extension not found");
		dialog.setMessage("The platform extension was not found in the workspace. Please import it and try again.");
		dialog.open();
	}
	
	return null;
}
 
Example 13
Source File: FullScreenDialog.java    From logbook with MIT License 4 votes vote down vote up
private static Rectangle getAbsoluteRectangle(Monitor monitor, Rectangle r) {
    Rectangle m = monitor.getBounds();
    return new Rectangle(r.x + m.x, r.y + m.y, r.width, r.height);
}