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());
}
}
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);
}
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));
}
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();
}
}
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());
}
Aggregations