Java Code Examples for org.eclipse.swt.widgets.Shell#getBounds()
The following examples show how to use
org.eclipse.swt.widgets.Shell#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 |
private static void center(Rectangle region, Shell shell, double xfrac, double yfrac) { Rectangle s_bounds = shell.getBounds(); // System.out.println("Center: " + s_bounds); // System.out.println("Over: " + region); // int x = region.x + (region.width - s_bounds.width) / 2; // int y = region.y + (region.height - s_bounds.height) / 2; int x = region.x + (int) Math.round((region.width - s_bounds.width) * xfrac); int y = region.y + (int) Math.round((region.height - s_bounds.height) * yfrac); shell.setLocation(x, y); }
Example 2
Source File: OlapInputAboutDialog.java From pentaho-kettle with Apache License 2.0 | 6 votes |
/** * * @param shell * the shell. */ public OlapInputAboutDialog( final Shell shell ) { this.dialog = new Shell( shell, SWT.BORDER | SWT.CLOSE | SWT.APPLICATION_MODAL | SWT.SHEET ); GridLayout gridLayout = new GridLayout(); gridLayout.numColumns = 2; this.dialog.setLayout( gridLayout ); this.dialog.setText( BaseMessages.getString( PKG, "OlapInputDialog.About.Shell.Title" ) ); this.dialog.setImage( shell.getImage() ); this.buildIconCell(); this.buildPluginInfoCell(); this.buildOkButton(); this.dialog.pack(); Rectangle shellBounds = shell.getBounds(); Point dialogSize = this.dialog.getSize(); this.dialog.setLocation( shellBounds.x + ( shellBounds.width - dialogSize.x ) / 2, shellBounds.y + ( shellBounds.height - dialogSize.y ) / 2 ); }
Example 3
Source File: KeyAssistDialog.java From Pydev with Eclipse Public License 1.0 | 6 votes |
/** * Sets the position for the dialog based on the position of the workbench * window. The dialog is flush with the bottom right corner of the workbench * window. However, the dialog will not appear outside of the display's * client area. * * @param size * The final size of the dialog; must not be <code>null</code>. */ private final void configureLocation(final Point size) { final Shell shell = getShell(); final Shell workbenchWindowShell = EditorUtils.getShell(); final int xCoord; final int yCoord; if (workbenchWindowShell != null) { /* * Position the shell at the bottom right corner of the workbench * window */ final Rectangle workbenchWindowBounds = workbenchWindowShell.getBounds(); xCoord = workbenchWindowBounds.x + workbenchWindowBounds.width - size.x - 10; yCoord = workbenchWindowBounds.y + workbenchWindowBounds.height - size.y - 10; } else { xCoord = 0; yCoord = 0; } final Rectangle bounds = new Rectangle(xCoord, yCoord, size.x, size.y); shell.setBounds(getConstrainedShellBounds(bounds)); }
Example 4
Source File: DataOverrideHandler.java From pentaho-kettle with Apache License 2.0 | 6 votes |
private Shell getCenteredShell( Shell shell ) { Rectangle shellBounds = shell.getBounds(); Monitor monitor = shell.getDisplay().getPrimaryMonitor(); if ( shell.getParent() != null ) { monitor = shell.getParent().getMonitor(); } Rectangle monitorClientArea = monitor.getClientArea(); int middleX = monitorClientArea.x + ( monitorClientArea.width - shellBounds.width ) / 2; int middleY = monitorClientArea.y + ( monitorClientArea.height - shellBounds.height ) / 2; shell.setLocation( middleX, middleY ); return shell; }
Example 5
Source File: SelectionDialog.java From e4macs with Eclipse Public License 1.0 | 6 votes |
/** * Sets the position for the dialog based on the position of the workbench * window. The dialog is flush with the bottom right corner of the workbench * window. However, the dialog will not appear outside of the display's * client area. * * @param size * The final size of the dialog; must not be <code>null</code>. */ private final void configureLocation(final Point size) { final Shell shell = getShell(); final Shell workbenchWindowShell = editor.getEditorSite().getShell(); final int xCoord; final int yCoord; if (workbenchWindowShell != null) { /* * Position the shell at the bottom right corner of the workbench * window */ // TODO: The constants are just guesses final Rectangle workbenchWindowBounds = workbenchWindowShell .getBounds(); xCoord = workbenchWindowBounds.x + workbenchWindowBounds.width - size.x - 10; yCoord = workbenchWindowBounds.y + workbenchWindowBounds.height - size.y - 35; } else { xCoord = 0; yCoord = 0; } final Rectangle bounds = new Rectangle(xCoord, yCoord, size.x, size.y); shell.setBounds(getConstrainedShellBounds(bounds)); }
Example 6
Source File: SWTUtil.java From arx with Apache License 2.0 | 5 votes |
/** * 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 7
Source File: ToolTipHandler.java From Pydev with Eclipse Public License 1.0 | 5 votes |
/** * Sets the location for a hovering shell * @param shell the object that is to hover * @param position the position of a widget to hover over * @return the top-left location for a hovering box */ private void setHoverLocation(Shell shell, Point position) { Rectangle displayBounds = shell.getDisplay().getBounds(); Rectangle shellBounds = shell.getBounds(); shellBounds.x = Math.max(Math.min(position.x, displayBounds.width - shellBounds.width), 0); shellBounds.y = Math.max(Math.min(position.y + 16, displayBounds.height - shellBounds.height), 0); shell.setBounds(shellBounds); }
Example 8
Source File: ChoicesDialog.java From SWET with MIT License | 5 votes |
private void center(Shell shell) { Shell parent = (Shell) shell.getParent(); Rectangle bounds = parent.getBounds(); Point size = shell.getSize(); int x = bounds.x + bounds.width / 2 - size.x / 2; int y = bounds.y + bounds.height / 2 - size.y / 2; // System.err.println("ChoiceDialog: center: x=" + x + " y=" + y); shell.setLocation(x, (y < 0) ? 0 : y); }
Example 9
Source File: PackageDialog.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText(Messages.PackageAppItemDialog_PACKAGE_LOCATION); newShell.setSize(358, 400); Rectangle parentBounds = parentShell.getBounds(); Rectangle shellBounds = newShell.getBounds(); newShell.setLocation(parentBounds.x + (parentBounds.width - shellBounds.width) / 2, parentBounds.y + (parentBounds.height - shellBounds.height) / 2); }
Example 10
Source File: SyncApplicationDialog.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText(Messages.SYNCPROJECT); newShell.setSize(506, 500); if(parentShell!=null){ Rectangle parentBounds = parentShell.getBounds(); Rectangle shellBounds = newShell.getBounds(); newShell.setLocation(parentBounds.x + (parentBounds.width - shellBounds.width) / 2, parentBounds.y + (parentBounds.height - shellBounds.height) / 2); } }
Example 11
Source File: WindowProperty.java From hop with Apache License 2.0 | 5 votes |
public WindowProperty( Shell shell ) { name = shell.getText(); maximized = shell.getMaximized(); Rectangle rectangle = shell.getBounds(); this.x = rectangle.x; this.y = rectangle.y; this.width = rectangle.width; this.height = rectangle.height; }
Example 12
Source File: CreateFeatureDialog.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
@Override protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText(Messages.CreateFeatureDialog_CREARE_FEATURE); Rectangle parentBounds = parentShell.getBounds(); Rectangle shellBounds = newShell.getBounds(); newShell.setLocation(parentBounds.x + (parentBounds.width - shellBounds.width) / 2, parentBounds.y + (parentBounds.height - shellBounds.height) / 2); }
Example 13
Source File: TmfAbstractToolTipHandler.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
private static Rectangle getBounds(Shell shell) { Rectangle bounds = shell.getBounds(); if (SWT.getVersion() < 4902 && SWT.getPlatform().equals("gtk")) { //$NON-NLS-1$ /* Bug 319612 - [Gtk] Shell.getSize() returns wrong value when created with style SWT.RESIZE | SWT.ON_TOP */ bounds = shell.computeTrim(bounds.x, bounds.y, bounds.width, bounds.height); } return bounds; }
Example 14
Source File: RunMobileDialog.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
protected void configureShell(Shell newShell) { super.configureShell(newShell); newShell.setText(Messages.RunMobileDialog_SYNC_MOBILE); Rectangle parentBounds = parentShell.getBounds(); Rectangle shellBounds = newShell.getBounds(); newShell.setLocation(parentBounds.x + (parentBounds.width - shellBounds.width) / 2, parentBounds.y + (parentBounds.height - shellBounds.height) / 2); }
Example 15
Source File: SWTHelper.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
/** Ein Objekt innerhalb des parents zentrieren */ public static void center(final Shell parent, final Shell child){ if (parent != null && child != null) { Rectangle par = parent.getBounds(); Rectangle ch = child.getBounds(); if (par != null && ch != null) { int xOff = (par.width - ch.width) / 2; int yOff = (par.height - ch.height) / 2; child.setBounds(par.x + xOff, par.y + yOff, ch.width, ch.height); } } }
Example 16
Source File: BaseTransformDialog.java From hop with Apache License 2.0 | 5 votes |
/** * Sets the size of this dialog with respect to the given parameters. * * @param shell the shell * @param minWidth the minimum width * @param minHeight the minimum height * @param packIt true to pack the dialog components, false otherwise */ public static void setSize( Shell shell, int minWidth, int minHeight, boolean packIt ) { PropsUi props = PropsUi.getInstance(); WindowProperty winprop = props.getScreen( shell.getText() ); if ( winprop != null ) { winprop.setShell( shell, minWidth, minHeight ); } else { if ( packIt ) { shell.pack(); } else { shell.layout(); } // OK, sometimes this produces dialogs that are waay too big. // Try to limit this a bit, m'kay? // Use the same algorithm by cheating :-) // winprop = new WindowProperty( shell ); winprop.setShell( shell, minWidth, minHeight ); // Now, as this is the first time it gets opened, try to put it in the middle of the screen... Rectangle shellBounds = shell.getBounds(); Monitor monitor = shell.getDisplay().getPrimaryMonitor(); if ( shell.getParent() != null ) { monitor = shell.getParent().getMonitor(); } Rectangle monitorClientArea = monitor.getClientArea(); int middleX = monitorClientArea.x + ( monitorClientArea.width - shellBounds.width ) / 2; int middleY = monitorClientArea.y + ( monitorClientArea.height - shellBounds.height ) / 2; shell.setLocation( middleX, middleY ); } }
Example 17
Source File: ProgressModal.java From Universal-FE-Randomizer with MIT License | 4 votes |
public ProgressModal(Shell parent, String title) { display = Display.getDefault(); yuneImage = new Image(display, Main.class.getClassLoader().getResourceAsStream("YuneIcon_100x100.png")); dialogShell = new Shell(parent, SWT.PRIMARY_MODAL | SWT.DIALOG_TRIM); dialogShell.setText(title); dialogShell.setImage(yuneImage); progressBar = new ProgressBar(dialogShell, SWT.SMOOTH); FormLayout mainLayout = new FormLayout(); mainLayout.marginWidth = 5; mainLayout.marginHeight = 5; dialogShell.setLayout(mainLayout); imageLabel = new Label(dialogShell, SWT.NONE); imageLabel.setImage(yuneImage); FormData imageData = new FormData(100, 100); imageData.left = new FormAttachment(0, 10); imageData.top = new FormAttachment(0, 10); imageData.bottom = new FormAttachment(100, -10); imageLabel.setLayoutData(imageData); FormData progressData = new FormData(300, 20); progressData.left = new FormAttachment(imageLabel, 10); progressData.bottom = new FormAttachment(imageLabel, -50, SWT.CENTER); progressData.right = new FormAttachment(100, -10); progressBar.setLayoutData(progressData); statusLabel = new Label(dialogShell, SWT.NONE); FormData statusData = new FormData(); statusData.left = new FormAttachment(progressBar, 0, SWT.LEFT); statusData.top = new FormAttachment(progressBar, 5); statusData.right = new FormAttachment(100, -10); statusLabel.setLayoutData(statusData); dialogShell.layout(); final Point newSize = dialogShell.computeSize(SWT.DEFAULT, SWT.DEFAULT, true); dialogShell.setSize(newSize); Rectangle parentBounds = parent.getBounds(); Rectangle dialogBounds = dialogShell.getBounds(); dialogShell.setLocation(parentBounds.x + (parentBounds.width - dialogBounds.width) / 2, parentBounds.y + (parentBounds.height - dialogBounds.height) / 2); }
Example 18
Source File: WindowProperty.java From pentaho-kettle with Apache License 2.0 | 4 votes |
/** * Performs calculations to size and position a dialog If the size passed in is too large for the primary monitor * client area, it is shrunk to fit. If the positioning leaves part of the dialog outside the client area, it is * centered instead Note that currently, many of the defaults in org.pentaho.di.ui.core/default.properties have crazy * values. This causes the failsafe code in here to fire a lot more than is really necessary. * * @param shell * The dialog to position and size * @param onlyPosition * Unused argument. If the window is outside the viewable client are, it must be resized to prevent * inaccessibility. * @param minWidth * @param minHeight */ public void setShell( Shell shell, boolean onlyPosition, int minWidth, int minHeight ) { shell.setMaximized( maximized ); shell.setBounds( rectangle ); if ( minWidth > 0 || minHeight > 0 ) { Rectangle bounds = shell.getBounds(); if ( bounds.width < minWidth ) { bounds.width = minWidth; } if ( bounds.height < minHeight ) { bounds.height = minHeight; } shell.setSize( bounds.width, bounds.height ); } // Just to double check: what is the preferred size of this dialog? // This computed is a minimum. If the minimum is smaller than the // size of the current shell, we make it larger. // Point computedSize = shell.computeSize( SWT.DEFAULT, SWT.DEFAULT ); Rectangle shellSize = shell.getBounds(); if ( shellSize.width < computedSize.x ) { shellSize.width = computedSize.x; } if ( shellSize.height < computedSize.y ) { shellSize.height = computedSize.y; } shell.setBounds( shellSize ); Rectangle entireClientArea = shell.getDisplay().getClientArea(); Rectangle resizedRect = Geometry.copy( shellSize ); constrainRectangleToContainer( resizedRect, entireClientArea ); // If the persisted size/location doesn't perfectly fit // into the entire client area, the persisted settings // likely were not meant for this configuration of monitors. // Relocate the shell into either the parent monitor or if // there is no parent, the primary monitor then center it. // if ( !resizedRect.equals( shellSize ) || isClippedByUnalignedMonitors( resizedRect, shell.getDisplay() ) ) { Monitor monitor = shell.getDisplay().getPrimaryMonitor(); if ( shell.getParent() != null ) { monitor = shell.getParent().getMonitor(); } Rectangle monitorClientArea = monitor.getClientArea(); constrainRectangleToContainer( resizedRect, monitorClientArea ); resizedRect.x = monitorClientArea.x + ( monitorClientArea.width - resizedRect.width ) / 2; resizedRect.y = monitorClientArea.y + ( monitorClientArea.height - resizedRect.height ) / 2; shell.setBounds( resizedRect ); } }
Example 19
Source File: TSVExtendedHandler.java From hybris-commerce-eclipse-plugin with Apache License 2.0 | 4 votes |
@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 20
Source File: ConfigureExtensionModulesHandler.java From hybris-commerce-eclipse-plugin with Apache License 2.0 | 4 votes |
@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; }