Search in sources :

Example 36 with FontData

use of org.eclipse.swt.graphics.FontData in project knime-core by knime.

the class FontStore method saveAnnotationFontToStyleRange.

/**
 * Persists the font data in the argument style range. It only saves
 * font name and size if it's different from the default (pref page) font
 * as otherwise the font should change with changing the pref page values.
 * @param toSaveTo The style range to save to.
 * @param f The used font
 */
public static void saveAnnotationFontToStyleRange(final AnnotationData.StyleRange toSaveTo, final Font f) {
    if (f != null) {
        final FontData fontData = f.getFontData()[0];
        String fontName = fontData.getName();
        int fontSize = fontData.getHeight();
        toSaveTo.setFontName(fontName);
        toSaveTo.setFontSize(fontSize);
        toSaveTo.setFontStyle(fontData.getStyle());
    }
}
Also used : FontData(org.eclipse.swt.graphics.FontData)

Example 37 with FontData

use of org.eclipse.swt.graphics.FontData in project knime-core by knime.

the class NightlyBuildLabel method fill.

@Override
public void fill(final Composite parent) {
    Label sep = new Label(parent, SWT.SEPARATOR);
    Composite outer = new Composite(parent, SWT.NONE);
    GridLayout outerLayout = new GridLayout(1, false);
    outerLayout.marginHeight = 0;
    outerLayout.marginWidth = 0;
    outer.setLayout(outerLayout);
    Label label = new Label(outer, SWT.SHADOW_NONE);
    label.setText("    You are using a nightly build!    ");
    Font initialFont = label.getFont();
    FontData[] fontData = initialFont.getFontData();
    for (int i = 0; i < fontData.length; i++) {
        fontData[i].setHeight(13);
        fontData[i].setStyle(SWT.BOLD | SWT.ITALIC);
    }
    Font newFont = new Font(Display.getCurrent(), fontData);
    label.setFont(newFont);
    label.setForeground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
    outer.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW));
    label.setToolTipText("If you encounter problems with this nightly build, please report them in our dedicated " + "forum section for nightly builds!");
    label.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, true));
    // compute the size of the label to get the width hint for the contribution
    Point preferredSize = label.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    StatusLineLayoutData data = new StatusLineLayoutData();
    data.widthHint = preferredSize.x;
    data.heightHint = preferredSize.y;
    outer.setLayoutData(data);
    data = new StatusLineLayoutData();
    data.heightHint = preferredSize.y;
    sep.setLayoutData(data);
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) FontData(org.eclipse.swt.graphics.FontData) Label(org.eclipse.swt.widgets.Label) GridData(org.eclipse.swt.layout.GridData) StatusLineLayoutData(org.eclipse.jface.action.StatusLineLayoutData) Point(org.eclipse.swt.graphics.Point) Font(org.eclipse.swt.graphics.Font) Point(org.eclipse.swt.graphics.Point)

Example 38 with FontData

use of org.eclipse.swt.graphics.FontData in project knime-core by knime.

the class ExportPreferencesDialog method createHeader.

private void createHeader(final Composite parent) {
    Composite header = new Composite(parent, SWT.FILL);
    Color white = Display.getDefault().getSystemColor(SWT.COLOR_WHITE);
    header.setBackground(white);
    GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
    header.setLayoutData(gridData);
    header.setLayout(new GridLayout(2, false));
    Label exec = new Label(header, SWT.NONE);
    exec.setBackground(white);
    exec.setText("Export KNIME Preferences");
    FontData[] fd = parent.getFont().getFontData();
    for (FontData f : fd) {
        f.setStyle(SWT.BOLD);
        f.setHeight(f.getHeight() + 2);
    }
    exec.setFont(new Font(parent.getDisplay(), fd));
    exec.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
    Label mkdirIcon = new Label(header, SWT.NONE);
    mkdirIcon.setBackground(white);
    Label txt = new Label(header, SWT.NONE);
    txt.setBackground(white);
    txt.setText("Please enter the name of the file the preferences should " + "be saved to. Or select a destination.");
    txt.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) Color(org.eclipse.swt.graphics.Color) FontData(org.eclipse.swt.graphics.FontData) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) Font(org.eclipse.swt.graphics.Font)

Example 39 with FontData

use of org.eclipse.swt.graphics.FontData in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_graphics_Font method test_getFontData.

@Test
public void test_getFontData() {
    // Test Font.getFontData()
    // valid normal 10-point font
    Font font = new Font(display, SwtTestUtil.testFontName, 10, SWT.NORMAL);
    try {
        FontData[] fontData = font.getFontData();
        assertTrue("No font data", fontData != null && fontData.length > 0);
        assertEquals("Wrong font name", SwtTestUtil.testFontName, fontData[0].getName());
        assertEquals("Wrong font height", 10, fontData[0].getHeight());
        assertEquals("Wrong font style", SWT.NORMAL, fontData[0].getStyle());
    } finally {
        font.dispose();
    }
    // valid bold 20-point font
    font = new Font(display, SwtTestUtil.testFontName, 20, SWT.BOLD);
    try {
        FontData[] fontData = font.getFontData();
        assertTrue("No font data", fontData != null && fontData.length > 0);
        assertEquals("Wrong font name", SwtTestUtil.testFontName, fontData[0].getName());
        assertEquals("Wrong font height", 20, fontData[0].getHeight());
        assertEquals("Wrong font style", SWT.BOLD, fontData[0].getStyle());
    } finally {
        font.dispose();
    }
    // valid italic 30-point font
    font = new Font(display, SwtTestUtil.testFontName, 30, SWT.ITALIC);
    try {
        FontData[] fontData = font.getFontData();
        assertTrue("No font data", fontData != null && fontData.length > 0);
        // assertEquals("Wrong font name", SwtTestUtil.testFontName, fontData[0].getName());
        assertEquals("Wrong font height", 30, fontData[0].getHeight());
        assertEquals("Wrong font style", SWT.ITALIC, fontData[0].getStyle());
    } finally {
        font.dispose();
    }
    // valid bold italic 40-point font
    font = new Font(display, SwtTestUtil.testFontName, 40, SWT.BOLD | SWT.ITALIC);
    try {
        FontData[] fontData = font.getFontData();
        font.dispose();
        assertTrue("No font data", fontData != null && fontData.length > 0);
        // assertEquals("Wrong font name", SwtTestUtil.testFontName, fontData[0].getName());
        assertEquals("Wrong font height", 40, fontData[0].getHeight());
        assertEquals("Wrong font style", SWT.BOLD | SWT.ITALIC, fontData[0].getStyle());
    } finally {
        font.dispose();
    }
    // valid 10-point font with unknown name
    font = new Font(display, "bad-font", 10, SWT.NORMAL);
    try {
        FontData[] fontData = font.getFontData();
        assertTrue("No font data", fontData != null && fontData.length > 0);
        // assertEquals("Wrong font name", "bad-font", fontData[0].getName());
        assertEquals("Wrong font height", 10, fontData[0].getHeight());
        assertEquals("Wrong font style", SWT.NORMAL, fontData[0].getStyle());
    } finally {
        font.dispose();
    }
}
Also used : FontData(org.eclipse.swt.graphics.FontData) Font(org.eclipse.swt.graphics.Font) Test(org.junit.Test)

Example 40 with FontData

use of org.eclipse.swt.graphics.FontData in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_graphics_FontData method test_hashCode.

@Test
public void test_hashCode() {
    FontData fd1 = new FontData(SwtTestUtil.testFontName, 10, SWT.NORMAL);
    FontData fd2 = new FontData(SwtTestUtil.testFontName, 10, SWT.NORMAL);
    assertEquals(fd1, fd2);
    assertEquals(fd1.hashCode(), fd2.hashCode());
    FontData fd3 = new FontData(SwtTestUtil.testFontName, 10, SWT.BOLD);
    assertFalse(fd1.hashCode() == fd3.hashCode());
}
Also used : FontData(org.eclipse.swt.graphics.FontData) Test(org.junit.Test)

Aggregations

FontData (org.eclipse.swt.graphics.FontData)147 Font (org.eclipse.swt.graphics.Font)89 GridData (org.eclipse.swt.layout.GridData)30 Label (org.eclipse.swt.widgets.Label)26 GridLayout (org.eclipse.swt.layout.GridLayout)25 Composite (org.eclipse.swt.widgets.Composite)25 Point (org.eclipse.swt.graphics.Point)23 Test (org.junit.Test)21 Color (org.eclipse.swt.graphics.Color)15 FontStyle (org.eclipse.gmf.runtime.notation.FontStyle)14 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)11 Button (org.eclipse.swt.widgets.Button)10 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)9 SelectionEvent (org.eclipse.swt.events.SelectionEvent)9 Display (org.eclipse.swt.widgets.Display)9 Text (org.eclipse.swt.widgets.Text)9 GC (org.eclipse.swt.graphics.GC)8 StyleRange (org.eclipse.swt.custom.StyleRange)7 Image (org.eclipse.swt.graphics.Image)7 IOException (java.io.IOException)6