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

The following examples show how to use org.eclipse.swt.widgets.Display#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: AbstractCombo.java    From nebula with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Calculates and returns the location of popup.<br>
 * Called just before than the popup is dropped.
 */
protected void setPopupLocation() {
	Display display = Display.getCurrent();
	Rectangle r = getBounds();
	Point p = display.map(this, null, 0, r.height);
	Rectangle sb = display.getBounds();
	if (p.y + popup.getSize().y > sb.height) {
		p.y -= r.height + popup.getSize().y + getBorderWidth();
	}
	int popx = popup.getSize().x;
	if (p.x + popx > sb.width) {
		p.x -= popx - r.width + getBorderWidth();
	} else if (popx < r.width) {
		p.x += r.width - popx;
	}
	popup.setLocation(p.x, p.y);
}
 
Example 2
Source File: SWTHelper.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Ein Objekt auf dem Bildschirm zentrieren. Robust. Sollte nie eine Exception werfen. Ändert im
 * Zweifelsfall nichts an der Position.
 * */
public static void center(final Shell child){
	if (child != null) {
		Display display = UiDesk.getDisplay();
		if (display != null) {
			Rectangle par = display.getBounds();
			if (par != null) {
				Rectangle ch = child.getBounds();
				if (ch != null) {
					ch.width = Math.max(30, ch.width);
					ch.height = Math.max(20, ch.height);
					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 3
Source File: MainView.java    From Universal-FE-Randomizer with MIT License 5 votes vote down vote up
public MainView(Display mainDisplay) {
	super();
	
	Shell shell = new Shell(mainDisplay, SWT.SHELL_TRIM & ~SWT.MAX); 
	 shell.setText("Yune: A Universal Fire Emblem Randomizer (v0.9.1)");
	 shell.setImage(new Image(mainDisplay, Main.class.getClassLoader().getResourceAsStream("YuneIcon.png")));
	 
	 screenHeight = mainDisplay.getBounds().height;
	 for (Monitor monitor : mainDisplay.getMonitors()) {
		 screenHeight = Math.max(screenHeight, monitor.getClientArea().height);
	 }
	 
	 screenHeight -= 20;
	 
	 mainShell = shell;
	 
	 setupMainShell();
	 
	 resize();
	 
	 /* Open shell window */
	  mainShell.open();
	  
	  mainDisplay.addFilter(SWT.KeyDown, new Listener() {
		@Override
		public void handleEvent(Event event) {
			if (((event.stateMask & SWT.CTRL) != 0) && ((event.stateMask & SWT.SHIFT) != 0) && (event.keyCode == 'c') && !consoleShellOpened) {
				openConsole();
			}
		}
	  });
}
 
Example 4
Source File: CaptureDialog.java    From logbook with MIT License 5 votes vote down vote up
@Override
public void widgetSelected(SelectionEvent paramSelectionEvent) {
    try {
        Display display = Display.getDefault();
        // ダイアログを非表示にする
        CaptureDialog.this.shell.setVisible(false);
        // 消えるまで待つ
        Thread.sleep(WAIT);
        // ディスプレイに対してGraphics Contextを取得する(フルスクリーンキャプチャ)
        GC gc = new GC(display);
        Image image = new Image(display, display.getBounds());
        gc.copyArea(image, 0, 0);
        gc.dispose();

        try {
            // 範囲を取得する
            Rectangle rectangle = new FullScreenDialog(CaptureDialog.this.shell, image,
                    CaptureDialog.this.shell.getMonitor())
                            .open();

            if ((rectangle != null) && (rectangle.width > 1) && (rectangle.height > 1)) {
                CaptureDialog.this.rectangle = rectangle;
                CaptureDialog.this.text.setText("(" + rectangle.x + "," + rectangle.y + ")-("
                        + (rectangle.x + rectangle.width) + "," + (rectangle.y + rectangle.height) + ")");
                CaptureDialog.this.capture.setEnabled(true);
            }
        } finally {
            image.dispose();
        }
        CaptureDialog.this.shell.setVisible(true);
        CaptureDialog.this.shell.setActive();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 5
Source File: ContentAssistant.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Restores the code assist pop-up's size.
 * 
 * @return the stored size
 * @since 3.0
 */
protected Point restoreCompletionProposalPopupSize()
{
	if (fDialogSettings == null)
	{
		return null;
	}

	Point size = new Point(-1, -1);

	try
	{
		size.x = fDialogSettings.getInt(STORE_SIZE_X);
		size.y = fDialogSettings.getInt(STORE_SIZE_Y);
	}
	catch (NumberFormatException ex)
	{
		size.x = -1;
		size.y = -1;
	}

	// sanity check
	if (size.x == -1 && size.y == -1)
	{
		return null;
	}

	Rectangle maxBounds = null;
	if (fContentAssistSubjectControl != null && !fContentAssistSubjectControl.getControl().isDisposed())
	{
		maxBounds = fContentAssistSubjectControl.getControl().getDisplay().getBounds();
	}
	else
	{
		// fallback
		Display display = Display.getCurrent();
		if (display == null)
		{
			display = Display.getDefault();
		}
		if (display != null && !display.isDisposed())
		{
			maxBounds = display.getBounds();
		}
	}

	if (size.x > -1 && size.y > -1)
	{
		if (maxBounds != null)
		{
			size.x = Math.min(size.x, maxBounds.width);
			size.y = Math.min(size.y, maxBounds.height);
		}

		// Enforce an absolute minimal size
		size.x = Math.max(size.x, 30);
		size.y = Math.max(size.y, 30);
	}

	return size;
}
 
Example 6
Source File: Editor.java    From Rel with Apache License 2.0 4 votes vote down vote up
private void registerMultiLineEditorColumn(IConfigRegistry configRegistry, String columnLabel) {
	// configure the multi line text editor
	configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR,
			new MultiLineTextCellEditor(false) {
				protected Control activateCell(Composite parent, Object originalCanonicalValue) {
					editorBeenOpened(getRowIndex(), getColumnIndex());
					return super.activateCell(parent, originalCanonicalValue);
				}

				public void close() {
					editorBeenClosed(getRowIndex(), getColumnIndex());
					super.close();
				}
			}, DisplayMode.NORMAL, columnLabel);

	Style cellStyle = new Style();
	cellStyle.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.LEFT);
	configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL,
			columnLabel);
	configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.EDIT,
			columnLabel);

	// configure custom dialog settings
	Display display = Display.getCurrent();
	Map<String, Object> editDialogSettings = new HashMap<String, Object>();
	editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_TITLE, "Edit");
	editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_ICON, display.getSystemImage(SWT.ICON_WARNING));
	editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_RESIZABLE, Boolean.TRUE);

	Point size = new Point(400, 300);
	editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_SIZE, size);

	int screenWidth = display.getBounds().width;
	int screenHeight = display.getBounds().height;
	Point location = new Point((screenWidth / (2 * display.getMonitors().length)) - (size.x / 2),
			(screenHeight / 2) - (size.y / 2));
	editDialogSettings.put(ICellEditDialog.DIALOG_SHELL_LOCATION, location);

	configRegistry.registerConfigAttribute(EditConfigAttributes.EDIT_DIALOG_SETTINGS, editDialogSettings,
			DisplayMode.EDIT, columnLabel);
}
 
Example 7
Source File: PopOverShell.java    From swt-bling with MIT License 4 votes vote down vote up
private Point getPopOverShellLocation(Shell parentShell, PoppedOverItem poppedOverItem, Region popOverRegion) {

    Point location;
    Rectangle displayBounds = null;

    try {
      Display display = displaySafe.getLatestDisplay();
      displayBounds = display.getBounds();
    } catch (DisplaySafe.NullDisplayException nde) {
      LOG.warning("Could not find display");
    }

    Rectangle popOverBounds = popOverRegion.getBounds();
    Point poppedOverItemLocationRelativeToDisplay =
            getPoppedOverItemRelativeLocation(poppedOverItem);

    // Guess on the location first
    location = getPopOverDisplayPoint(popOverBounds, poppedOverItem, poppedOverItemLocationRelativeToDisplay,
            popOverEdgeCenteredOnParent, popOverAboveOrBelowParent);

    // Adjust as needed
    if (popOverAboveOrBelowParent == VerticalLocation.BELOW) {
      if (isBottomCutOff(displayBounds, location, popOverBounds)) {
        popOverAboveOrBelowParent = VerticalLocation.ABOVE;
        location.y = getPopOverYLocation(popOverBounds, poppedOverItem, poppedOverItemLocationRelativeToDisplay,
                popOverAboveOrBelowParent);
      }
    } else {
      if (isTopCutOff(location)) {
        popOverAboveOrBelowParent = VerticalLocation.BELOW;
        location.y = getPopOverYLocation(popOverBounds, poppedOverItem, poppedOverItemLocationRelativeToDisplay,
            popOverAboveOrBelowParent);
      }
    }

    if (popOverEdgeCenteredOnParent == CenteringEdge.LEFT) {
      if (isRightCutOff(displayBounds, location, popOverBounds)) {
        popOverEdgeCenteredOnParent = CenteringEdge.RIGHT;
        location.x = getPopOverXLocation(popOverBounds, poppedOverItem, poppedOverItemLocationRelativeToDisplay,
                popOverEdgeCenteredOnParent);
      }
    } else {
      if (isLeftCutOff(location)) {
        popOverEdgeCenteredOnParent = CenteringEdge.LEFT;
        location.x = getPopOverXLocation(popOverBounds, poppedOverItem, poppedOverItemLocationRelativeToDisplay,
            popOverEdgeCenteredOnParent);
      }
    }

    if (isStillOffScreen(displayBounds, location, popOverBounds)) {
      location = getPopOverLocationControlOffscreen(displayBounds, popOverRegion,
              poppedOverItemLocationRelativeToDisplay, location);
    }

    return location;
  }