use of org.eclipse.swt.SWTError in project eclipse.platform.swt by eclipse.
the class SwtTestUtil method assertSWTProblem.
public static void assertSWTProblem(String message, int expectedCode, Throwable actualThrowable) {
if (actualThrowable instanceof SWTError) {
SWTError error = (SWTError) actualThrowable;
assertEquals(message, expectedCode, error.code);
} else if (actualThrowable instanceof SWTException) {
SWTException exception = (SWTException) actualThrowable;
assertEquals(message, expectedCode, exception.code);
} else {
try {
SWT.error(expectedCode);
} catch (Throwable expectedThrowable) {
if (actualThrowable.getMessage().length() > expectedThrowable.getMessage().length()) {
assertTrue(message, actualThrowable.getMessage().startsWith(expectedThrowable.getMessage()));
} else {
assertEquals(message, expectedThrowable.getMessage(), actualThrowable.getMessage());
}
}
}
}
use of org.eclipse.swt.SWTError in project eclipse.platform.text by eclipse.
the class BrowserInformationControl method isAvailable.
/**
* Tells whether the SWT Browser widget and hence this information
* control is available.
*
* @param parent the parent component used for checking or <code>null</code> if none
* @return <code>true</code> if this control is available
*/
public static boolean isAvailable(Composite parent) {
if (!fgAvailabilityChecked) {
try {
Browser browser = new Browser(parent, SWT.NONE);
browser.dispose();
fgIsAvailable = true;
Slider sliderV = new Slider(parent, SWT.VERTICAL);
Slider sliderH = new Slider(parent, SWT.HORIZONTAL);
int width = sliderV.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
int height = sliderH.computeSize(SWT.DEFAULT, SWT.DEFAULT).y;
fgScrollBarSize = new Point(width, height);
sliderV.dispose();
sliderH.dispose();
} catch (SWTError er) {
fgIsAvailable = false;
} finally {
fgAvailabilityChecked = true;
}
}
return fgIsAvailable;
}
use of org.eclipse.swt.SWTError in project knime-core by knime.
the class HelpView method createPartControl.
/**
* {@inheritDoc}
*/
@Override
public void createPartControl(final Composite parent) {
getViewSite().getPage().addSelectionListener(this);
try {
m_text = null;
m_browser = new Browser(parent, SWT.NONE);
m_browser.addLocationListener(this);
// add us as listeners of the page selection
m_browser.setText("");
m_isFallback = false;
} catch (SWTError e) {
NodeLogger.getLogger(getClass()).warn("No html browser for node description available.", e);
m_browser = null;
m_text = new FallbackBrowser(parent, SWT.READ_ONLY | SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
m_isFallback = true;
}
}
use of org.eclipse.swt.SWTError in project knime-core by knime.
the class FontStore method defaultFont.
private static Font defaultFont() {
/* We want to use "Arial" as THE font.
* Fallback on Windows is:
* Microsoft Sans Serif, Trebuchet MS
* Fallback on Mac:
* Trebuchet MS
* Fallback on Linux:
* Nimbus Sans L
*/
// the "new Font(..." constructor does not verify the validity of a font name so we need to check first
// if the font is available.
Set<String> installedFontFamilyNames = Stream.of(Display.getCurrent().getFontList(null, true)).map(f -> f.getName()).collect(Collectors.toSet());
int defFontSize = getFontSizeFromKNIMEPrefPage();
Font defFont = null;
String name = "Arial";
try {
if (installedFontFamilyNames.contains(name)) {
defFont = new Font(Display.getDefault(), name, defFontSize, SWT.NORMAL);
}
} catch (SWTError e) {
LOGGER.warn("Font '" + name + "' is not available on your system. " + "Try to install it, if you want workflows to look the same on different computers.", e);
}
if (defFont == null) {
// Fall back to "common" fonts similar to Arial
if (Platform.OS_MACOSX.equals(Platform.getOS())) {
defFont = tryLoadFallbackFont(defFontSize, "Trebuchet MS", installedFontFamilyNames);
} else if (Platform.OS_LINUX.equals(Platform.getOS())) {
defFont = tryLoadFallbackFont(defFontSize, "Nimbus Sans L", installedFontFamilyNames);
} else {
defFont = tryLoadFallbackFont(defFontSize, "Microsoft Sans Serif", installedFontFamilyNames);
if (defFont == null) {
defFont = tryLoadFallbackFont(defFontSize, "Trebuchet MS", installedFontFamilyNames);
}
}
}
if (defFont == null) {
// last resort: use system default font. May look totally different on different systems.
defFont = Display.getDefault().getSystemFont();
LOGGER.warn("Using the system default font for annotations: " + defFont);
}
return defFont;
}
Aggregations