Java Code Examples for org.eclipse.swt.widgets.Control#getDisplay()
The following examples show how to use
org.eclipse.swt.widgets.Control#getDisplay() .
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: FontUtils.java From saros with GNU General Public License v2.0 | 6 votes |
public static void changeFontSizeBy(Control control, int fontSizeInc) { FontData[] fontData = control.getFont().getFontData(); for (int i = 0; i < fontData.length; ++i) fontData[i].setHeight(fontData[i].getHeight() + fontSizeInc); final Font newFont = new Font(control.getDisplay(), fontData); control.setFont(newFont); // Since you created the font, you must dispose it control.addDisposeListener( new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { newFont.dispose(); } }); }
Example 2
Source File: CheckboxCellContentProvider.java From ice with Eclipse Public License 1.0 | 6 votes |
/** * Creates an <code>Image</code> from the specified <code>Control</code> * (widget). * * @param control * The <code>Control</code> to convert to an <code>Image</code>. * @return An <code>Image</code> of the specified <code>Control</code>. */ private static Image createImage(Control control) { // We have to create a separate Image per combination of // checked/unchecked (of course). We also have to create a single GC per // Image (not so obvious, but re-using them does not appear to work well // and does not sync with the UI thread properly, so you get the same // image multiple times [but not all the time]). Image image = new Image(control.getDisplay(), control.getBounds()); GC gc = new GC(image); control.print(gc); gc.dispose(); return image; }
Example 3
Source File: SWTUtil.java From eclipse-cs with GNU Lesser General Public License v2.1 | 6 votes |
/** * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent) */ @Override public void mouseDown(MouseEvent e) { Control theControl = (Control) e.widget; Display display = theControl.getDisplay(); Shell tip = new Shell(theControl.getShell(), SWT.ON_TOP | SWT.TOOL); tip.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); FillLayout layout = new FillLayout(); layout.marginHeight = 1; layout.marginWidth = 2; tip.setLayout(layout); Label label = new Label(tip, SWT.NONE); label.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); label.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); label.setText(theControl.getToolTipText()); label.addMouseTrackListener(this); Point size = tip.computeSize(SWT.DEFAULT, SWT.DEFAULT); Rectangle rect = theControl.getBounds(); Point pt = theControl.getParent().toDisplay(rect.x, rect.y); tip.setBounds(pt.x, pt.y, size.x, size.y); tip.setVisible(true); }
Example 4
Source File: ContentAssistant.java From APICloud-Studio with GNU General Public License v3.0 | 6 votes |
private void focusChanged(FocusEvent e) { Control control = fControl; if (Helper.okToUse(control)) { Display d = control.getDisplay(); if (d != null) { d.asyncExec(new Runnable() { public void run() { if (!fProposalPopup.hasFocus() && (fContextInfoPopup == null || !fContextInfoPopup.hasFocus())) { hide(); } } }); } } }
Example 5
Source File: TableComboPropertyHandler.java From nebula with Eclipse Public License 2.0 | 5 votes |
private void applyFont(final Control widget, final FontData fd) { if (widget.getFont() != null && !widget.getFont().equals(widget.getDisplay().getSystemFont())) { widget.getFont().dispose(); } final Font newFont = new Font(widget.getDisplay(), fd); widget.setFont(newFont); widget.addListener(SWT.Dispose, e -> { if (newFont != null && !newFont.isDisposed()) { newFont.dispose(); } }); }
Example 6
Source File: CheckBoxToolTip.java From pentaho-kettle with Apache License 2.0 | 5 votes |
public CheckBoxToolTip( Control control ) { super( control, ToolTip.RECREATE, true ); image = control.getDisplay().getSystemImage( SWT.ICON_INFORMATION ); listeners = new ArrayList<CheckBoxToolTipListener>(); visible = false; display = control.getDisplay(); super.setRespectMonitorBounds( true ); super.setRespectDisplayBounds( true ); super.setHideDelay( 50000 ); super.setPopupDelay( 0 ); super.setHideOnMouseDown( false ); }
Example 7
Source File: FontUtils.java From saros with GNU General Public License v2.0 | 5 votes |
public static void makeBold(Control control) { FontData[] boldFontData = modifyFontData(control.getFont().getFontData(), SWT.BOLD); final Font newFont = new Font(control.getDisplay(), boldFontData); control.setFont(newFont); // Since you created the font, you must dispose it control.addDisposeListener( new DisposeListener() { @Override public void widgetDisposed(DisposeEvent e) { newFont.dispose(); } }); }
Example 8
Source File: InformationPresenterControlManager.java From Pydev with Eclipse Public License 1.0 | 5 votes |
private void handleMouseMove(Event event) { if (!(event.widget instanceof Control)) { return; } Control control = (Control) event.widget; Display display = control.getDisplay(); if (!inKeepUpZone(event.x, event.y, control, display)) { hideInformationControl(); } }
Example 9
Source File: SwtUtils.java From xds-ide with Eclipse Public License 1.0 | 5 votes |
public static Font modifyFont(Control c, int flags) { Font f = c.getFont(); String fontName = f.getFontData()[0].getName(); int fontSize = f.getFontData()[0].getHeight(); int fontStyle = f.getFontData()[0].getStyle() | flags; return new Font(c.getDisplay(), new FontData(fontName, fontSize, fontStyle)); }
Example 10
Source File: CDateTimePropertyHandler.java From nebula with Eclipse Public License 2.0 | 5 votes |
private void applyFont(final Control widget, final FontData fd) { if (widget.getFont() != null && !widget.getFont().equals(widget.getDisplay().getSystemFont())) { widget.getFont().dispose(); } final Font newFont = new Font(widget.getDisplay(), fd); widget.setFont(newFont); widget.addListener(SWT.Dispose, e -> { if (newFont != null && !newFont.isDisposed()) { newFont.dispose(); } }); }
Example 11
Source File: SWTGraphicUtil.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Build a font from a given control. Useful if we just want a bold label for * example * * @param control control that handle the default font * @param style new style * @return a font with the given style */ public static Font buildFontFrom(final Control control, final int style, final int size) { final Font temp = control.getFont(); final FontData[] fontData = temp.getFontData(); if (fontData == null || fontData.length == 0) { return temp; } return new Font(control.getDisplay(), fontData[0].getName(), size, style); }
Example 12
Source File: SWTGraphicUtil.java From nebula with Eclipse Public License 2.0 | 5 votes |
/** * Build a font from a given control. Useful if we just want a bold label for * example * * @param control control that handle the default font * @param style new style * @return a font with the given style */ public static Font buildFontFrom(final Control control, final int style) { final Font temp = control.getFont(); final FontData[] fontData = temp.getFontData(); if (fontData == null || fontData.length == 0) { return temp; } return new Font(control.getDisplay(), fontData[0].getName(), fontData[0].getHeight(), style); }
Example 13
Source File: CheckBoxToolTip.java From hop with Apache License 2.0 | 5 votes |
public CheckBoxToolTip( Control control ) { super( control, ToolTip.RECREATE, true ); image = control.getDisplay().getSystemImage( SWT.ICON_INFORMATION ); listeners = new ArrayList<ICheckBoxToolTipListener>(); visible = false; display = control.getDisplay(); super.setRespectMonitorBounds( true ); super.setRespectDisplayBounds( true ); super.setHideDelay( 50000 ); super.setPopupDelay( 0 ); super.setHideOnMouseDown( false ); }
Example 14
Source File: StyledFontThemer.java From APICloud-Studio with GNU General Public License v3.0 | 4 votes |
public StyledFontThemer(Control control, int fontStyle, Color defaultBg) { super(control, defaultBg); this.fontStyle = fontStyle; defaultStyledFont = new Font(control.getDisplay(), SWTUtils.styleFont(control.getFont(), fontStyle)); }
Example 15
Source File: EmulatedNativeCheckBoxLabelProvider.java From Pydev with Eclipse Public License 1.0 | 4 votes |
private Image makeShot(Control control, boolean type) { /* Hopefully no platform uses exactly this color because we'll make it transparent in the image.*/ Color greenScreen = new Color(control.getDisplay(), 222, 223, 224); shell = new Shell(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), SWT.NO_TRIM | SWT.NO_BACKGROUND); // otherwise we have a default gray color shell.setBackground(greenScreen); Button button = new Button(shell, SWT.CHECK | SWT.NO_BACKGROUND); button.setBackground(greenScreen); button.setSelection(type); // otherwise an image is located in a corner button.setLocation(1, 1); Point bsize = button.computeSize(SWT.DEFAULT, SWT.DEFAULT); // otherwise an image is stretched by width bsize.x = Math.max(bsize.x - 1, bsize.y - 1); bsize.y = Math.max(bsize.x - 1, bsize.y - 1); button.setSize(bsize); GC gc = new GC(shell); Point shellSize = new Point(32, 32); shell.setSize(shellSize); shell.open(); Image image = new Image(control.getDisplay(), bsize.x, bsize.y); gc.copyArea(image, 0, 0); gc.dispose(); shell.close(); ImageData imageData = image.getImageData(); imageData.transparentPixel = imageData.palette.getPixel(greenScreen .getRGB()); Image img = new Image(control.getDisplay(), imageData); image.dispose(); return img; }
Example 16
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(); }
Example 17
Source File: SWTDebugMouseTrackListener.java From atdl4j with MIT License | 4 votes |
public SWTDebugMouseTrackListener(Control control) { this.control = control; defaultColor = control.getParent().getBackground(); remarkColor = new Color(control.getDisplay(), 255, 0, 0); }
Example 18
Source File: SWTGraphicUtil.java From nebula with Eclipse Public License 2.0 | 2 votes |
/** * @param control * @param red * @param green * @param blue * @return a color that will be disposed when <code>control</code> is disposed */ public static Color getDefaultColor(final Control control, final int red, final int green, final int blue) { final Color defaultColor = new Color(control.getDisplay(), red, green, blue); addDisposer(control, defaultColor); return defaultColor; }