Java Code Examples for org.eclipse.swt.widgets.Control#toDisplay()
The following examples show how to use
org.eclipse.swt.widgets.Control#toDisplay() .
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: TmfAbstractToolTipHandler.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
/** * Dispose the shell if we exit the range. * * @param e * The event which occurred */ private void disposeIfExited(Event e) { if (!(e.widget instanceof Control)) { return; } Control control = (Control) e.widget; if (control != null && !control.isDisposed()) { Point pt = control.toDisplay(e.x, e.y); Shell tipShell = fTipShell; if (tipShell != null && !tipShell.isDisposed()) { Rectangle bounds = getBounds(tipShell); bounds.x -= OFFSET; bounds.y -= OFFSET; bounds.height += 2 * OFFSET; bounds.width += 2 * OFFSET; if (!bounds.contains(pt) && !fInitialDeadzone.contains(pt)) { tipShell.dispose(); } } } }
Example 2
Source File: ErDiagramInformationControl.java From ermaster-b with Apache License 2.0 | 6 votes |
public ErDiagramInformationControl(ERDiagram diagram, Shell shell, Control composite) { super(shell, true); this.diagram = diagram; create(); int width = 300; int height = 300; Point loc = composite.toDisplay(0, 0); Point size = composite.getSize(); int x = (size.x - width) / 2 + loc.x; int y = (size.y - height) / 2 + loc.y; setSize(width, height); setLocation(new Point(x, y)); addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { dispose(); } }); }
Example 3
Source File: QuickOutlinePopup.java From xtext-eclipse with Eclipse Public License 2.0 | 5 votes |
@Override protected Point getDefaultLocation(Point initialSize) { Control textWidget = xtextEditor.getAdapter(Control.class); Point size = textWidget.getSize(); Point popupLocation = new Point((size.x / 2) - (initialSize.x / 2), (size.y / 2) - (initialSize.y / 2)); return textWidget.toDisplay(popupLocation); }
Example 4
Source File: ModulaQuickOutlineDialog.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
@Override protected void adjustBounds() { if (!getPersistSize()) { Point prefSize; int gap5W = SwtUtils.getTextWidth(filteredTree, "WWWWW"); //$NON-NLS-1$ prefSize = filteredTree.computeSize(SWT.DEFAULT, SWT.DEFAULT); prefSize.x += gap5W; prefSize.y += SWTFactory.getCharHeight(filteredTree)*3; Rectangle recDisplay = filteredTree.getDisplay().getPrimaryMonitor().getClientArea(); prefSize.x = Math.max(prefSize.x, SwtUtils.getTextWidth(filteredTree, "WWWWWWWWWWWWWWWWWWWWWWWWWWW")); //$NON-NLS-1$ prefSize.x = Math.min(prefSize.x, (int)((double)recDisplay.width / 1.5)); prefSize.y = Math.min(prefSize.y, (int)((double)recDisplay.height / 1.2)); // prefSize now is calculateg for all whole content. Clip it by decreased editor window size: Control edCtrl = (Control) editor.getAdapter(Control.class); Point edSize = edCtrl.getSize(); prefSize.x = Math.min(prefSize.x, Math.max(edSize.x - gap5W*5, gap5W*5)); prefSize.y = Math.min(prefSize.y, Math.max(edSize.y - gap5W*2, gap5W*5)); getShell().setSize(prefSize); if (!this.getPersistLocation()) { int xx = (edSize.x - prefSize.x) / 2; int yy = (edSize.y - prefSize.y) / 2; Point edPos = edCtrl.toDisplay(new Point(0,0)); getShell().setLocation(edPos.x + xx, edPos.y + yy); } } }
Example 5
Source File: SwtXYChartViewer.java From tracecompass with Eclipse Public License 2.0 | 5 votes |
@Override public void handleEvent(@Nullable Event event) { if (event == null) { return; } Control control = (Control) event.widget; Point display = control.toDisplay(event.x, event.y); Point location = getChart().getParent().toControl(display); /* Only set to visible if we are inside and in the right shell. */ boolean inside = getChart().getBounds().contains(location); boolean shell = control.getShell().equals(getChart().getShell()); fCloseButton.setVisible(inside && shell); }
Example 6
Source File: BalloonNotification.java From saros with GNU General Public License v2.0 | 4 votes |
/** * Opens a notification window next to a control. The notification window will show the given * title as the title of the balloon, The given text as the description. * * <p>The window will be hidden automatically after the value specified in the timeout expires * * <p><b>Note:</b> The balloon window is always anchored to the given control at position (0,0). * Specifying the balloon window anchor is relative to this point. * * <p>TODO wrap the contents so the balloon notification does not expand across two screens for a * long text. OR even better: do not show long notifications. users tend to ignore them anyway! * * @param control the control, next to where the widget will appear * @param anchor the anchor of the balloon window * @param title the title of the balloon * @param text the text to display as contents */ public static void showNotification(Control control, int anchor, String title, String text) { if (control != null && control.isDisposed()) { control = null; } /* * show message at least 8 secs, but show it longer for longer messages * Referenced by wikipedia, a user can read 2,5 words per second so we * approximate 400ms per word */ int timeout = Math.max(8000, text.split("\\s").length * 400); // close all previous balloon notifications like it is done in // windows to prevent overlapping of multiple balloons... BalloonNotification.removeAllActiveNotifications(); final BalloonWindow window = new BalloonWindow( control != null ? control.getShell() : null, SWT.NO_FOCUS | SWT.TOOL | SWT.TITLE); window.setAnchor(anchor); windows.add(window); /* * Note: if you add SWT.CLOSE to the style of the BalloonWindow, it will * only be closed when directly clicking on the close icon (x) and * therefore break user expectations. FIXME: find out a way to display * the closing X AND make the bubble close on any click anywhere on it. */ window.setText(title); /* * Adding the text to the contents. Pack() is required so the size of * the composite is recalculated, else the contents won't show */ Composite content = window.getContents(); content.setLayout(new FillLayout()); Label message = new Label(content, SWT.NONE); message.setText(text); content.pack(true); message.setBackground(WHITE); message.setForeground(BLACK); // make window close when clicking on balloon text, too window.addSelectionControl(message); // Locate the balloon to the widget location if (control != null) { Point widgetLocation = control.toDisplay(new Point(0, 0)); window.setLocation(widgetLocation); } // Runnable that will close the window after time has been expired final Runnable closeWindow = ThreadUtils.wrapSafe( log, new Runnable() { @Override public void run() { final Shell shell = window.getShell(); if (shell.isDisposed()) return; window.close(); } }); window.getShell().getDisplay().timerExec(timeout, closeWindow); Display display = control != null ? control.getDisplay() : Display.getCurrent(); Control lastControlWithFocus = display != null ? display.getFocusControl() : null; window.open(); if (lastControlWithFocus != null) lastControlWithFocus.setFocus(); }