Example usage for org.eclipse.jface.resource JFaceResources getDefaultFontDescriptor

List of usage examples for org.eclipse.jface.resource JFaceResources getDefaultFontDescriptor

Introduction

In this page you can find the example usage for org.eclipse.jface.resource JFaceResources getDefaultFontDescriptor.

Prototype

public static FontDescriptor getDefaultFontDescriptor() 

Source Link

Document

Returns the descriptor for JFace's standard font.

Usage

From source file:com.bdaum.zoom.ui.internal.views.LightboxView.java

License:Open Source License

private Font getSmallFont(int labelFontsize) {
    if (labelFontsize != currentFontsize) {
        currentFontsize = labelFontsize;
        if (smallFont != null) {
            smallFont.dispose();/*  w w  w  . jav  a  2 s  .  com*/
            smallFont = null;
        }
    }
    if (smallFont == null) {
        FontData[] fd = JFaceResources.getDefaultFontDescriptor().getFontData();
        smallFont = new Font(gallery.getDisplay(), fd[0].getName(), currentFontsize, fd[0].getStyle());
    }
    return smallFont;
}

From source file:org.eclipse.lsp4e.operations.hover.LSBasedHover.java

License:Open Source License

@Override
public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) {
    if (textViewer == null || hoverRegion == null) {
        return null;
    }/*www.j  a v  a  2 s .co m*/
    if (!(hoverRegion.equals(this.lastRegion) && textViewer.equals(this.textViewer) && this.requests != null)) {
        initiateHoverRequest(textViewer, hoverRegion.getOffset());
    }
    try {
        CompletableFuture.allOf(this.requests.toArray(new CompletableFuture[this.requests.size()])).get(500,
                TimeUnit.MILLISECONDS);
    } catch (InterruptedException | ExecutionException | TimeoutException e) {
        LanguageServerPlugin.logError(e);
    }
    String result = ""; //$NON-NLS-1$
    if (!(this.hoverResults == null || this.hoverResults.isEmpty())) {
        result += hoverResults.stream().filter(Objects::nonNull).map(LSBasedHover::getHoverString)
                .filter(Objects::nonNull).collect(Collectors.joining("\n\n")); //$NON-NLS-1$

    }
    if (result.isEmpty()) {
        return null;
    }
    result = MARKDOWN_PARSER.parseToHtml(result);
    // put CSS styling to match Eclipse style
    ColorRegistry colorRegistry = JFaceResources.getColorRegistry();
    Color foreground = colorRegistry.get("org.eclipse.ui.workbench.HOVER_FOREGROUND"); //$NON-NLS-1$
    Color background = colorRegistry.get("org.eclipse.ui.workbench.HOVER_BACKGROUND"); //$NON-NLS-1$
    String style = "<style TYPE='text/css'>html { " + //$NON-NLS-1$
            "font-family: " + JFaceResources.getDefaultFontDescriptor().getFontData()[0].getName() + "; " + //$NON-NLS-1$ //$NON-NLS-2$
            "font-size: " //$NON-NLS-1$
            + Integer.toString(JFaceResources.getDefaultFontDescriptor().getFontData()[0].getHeight()) + "pt; " //$NON-NLS-1$
            + (background != null ? "background-color: " + toHTMLrgb(background.getRGB()) + "; " : "") + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            (foreground != null ? "color: " + toHTMLrgb(foreground.getRGB()) + "; " : "") + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            " }</style>"; //$NON-NLS-1$

    int headIndex = result.indexOf("<head>"); //$NON-NLS-1$
    StringBuilder builder = new StringBuilder(result.length() + style.length());
    builder.append(result.substring(0, headIndex + "<head>".length())); //$NON-NLS-1$
    builder.append(style);
    builder.append(result.substring(headIndex + "<head>".length())); //$NON-NLS-1$
    return builder.toString();
}

From source file:org.eclipse.sapphire.ui.swt.gef.model.DiagramResourceCache.java

License:Open Source License

public DiagramResourceCache() {
    FontDescriptor descriptor = JFaceResources.getDefaultFontDescriptor();
    FontData[] fontData = descriptor.getFontData();
    FontData smallerFontData = new FontData(fontData[0].getName(), fontData[0].getHeight() - 1, 0);
    Font defaultFont = new Font(null, new FontData[] { smallerFontData });
    fonts.add(defaultFont);/*ww w.  jav  a  2s  .  co m*/
}

From source file:org.eclipse.scada.vi.details.swt.widgets.control.BlockControlImage.java

License:Open Source License

public BlockControlImage(final ControlImage controlImage, final int style,
        final RegistrationManager registrationManager) {
    super(controlImage.getClientSpace(), style);

    this.controlImage = controlImage;

    this.registrationManager = registrationManager;

    setLayout(new FillLayout());

    this.icon = new Label(this, SWT.NONE);
    this.icon.setImage(getEmptyImage());
    this.icon.addMouseListener(new MouseAdapter() {
        @Override/*from w  w w.  j  av  a2 s . c  om*/
        public void mouseUp(final MouseEvent e) {
            toggleBlock();
        }
    });

    this.registrationManager.addListener(this);

    final LocalResourceManager resources = new LocalResourceManager(JFaceResources.getResources(), this.icon);

    this.boldFont = resources.createFont(JFaceResources.getDefaultFontDescriptor().withStyle(SWT.BOLD));
    this.boldStyler = new Styler() {

        @Override
        public void applyStyles(final TextStyle textStyle) {
            textStyle.font = BlockControlImage.this.boldFont;
        }
    };
}

From source file:org.robotframework.red.graphics.FontsManagerTest.java

License:Apache License

@Test
public void managerProvidesArbitraryFonts() {
    assertThat(FontsManager.getFont(JFaceResources.getDefaultFontDescriptor())).isNotNull();
    assertThat(FontsManager.getFont(JFaceResources.getTextFontDescriptor())).isNotNull();

    assertThat(FontsManager.getFont(Display.getCurrent(), JFaceResources.getDefaultFontDescriptor()))
            .isNotNull();/*from w w  w. j  a va  2 s  . c om*/
    assertThat(FontsManager.getFont(Display.getCurrent(), JFaceResources.getTextFontDescriptor())).isNotNull();

    assertThat(FontsManager.size()).isEqualTo(2);
}

From source file:org.springsource.ide.eclipse.gradle.ui.taskview.TaskLabelProvider.java

License:Open Source License

private Font getTaskNameFont() {
    if (taskNameFont == null) {
        FontData[] fontData = FontDescriptor.copy(JFaceResources.getDefaultFontDescriptor().getFontData());
        for (int i = 0; i < fontData.length; i++) {
            fontData[i].setStyle(fontData[i].getStyle() | SWT.BOLD);
        }//from  ww  w  .j ava 2  s . co  m
        taskNameFont = FontDescriptor.createFrom(fontData).createFont(PlatformUI.getWorkbench().getDisplay());
    }
    return taskNameFont;
}

From source file:org.xmind.ui.internal.print.multipage.MultipagePrintClient.java

License:Open Source License

private Font getFont(String fontKey) {
    Font font = null;//w  w  w . j a v  a  2s  .  co  m
    String fontValue = settings.get(fontKey);
    if (fontValue != null) {
        FontData[] fontData = FontUtils.toFontData(fontValue);
        if (fontData != null) {
            for (FontData fd : fontData) {
                fd.setHeight(fd.getHeight() * dpi.y / UnitConvertor.getScreenDpi().y);
            }
            font = new Font(Display.getCurrent(), fontData);
        }
    }
    if (font == null) {
        FontData[] defaultFontData = JFaceResources.getDefaultFontDescriptor().getFontData();
        int defaultHeight = defaultFontData[0].getHeight();
        font = new Font(Display.getCurrent(),
                FontUtils.newHeight(defaultFontData, defaultHeight * dpi.y / UnitConvertor.getScreenDpi().y));
    }
    return font;
}