Search in sources :

Example 16 with SWTError

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());
            }
        }
    }
}
Also used : SWTError(org.eclipse.swt.SWTError) SWTException(org.eclipse.swt.SWTException)

Example 17 with SWTError

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;
}
Also used : SWTError(org.eclipse.swt.SWTError) Slider(org.eclipse.swt.widgets.Slider) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) Browser(org.eclipse.swt.browser.Browser)

Example 18 with SWTError

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;
    }
}
Also used : SWTError(org.eclipse.swt.SWTError) IWebBrowser(org.eclipse.ui.browser.IWebBrowser) Browser(org.eclipse.swt.browser.Browser)

Example 19 with SWTError

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;
}
Also used : IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore) KNIMEConstants(org.knime.core.node.KNIMEConstants) Set(java.util.Set) HashMap(java.util.HashMap) Display(org.eclipse.swt.widgets.Display) Collectors(java.util.stream.Collectors) PreferenceConstants(org.knime.workbench.ui.preferences.PreferenceConstants) SWTError(org.eclipse.swt.SWTError) Stream(java.util.stream.Stream) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) NodeLogger(org.knime.core.node.NodeLogger) Map(java.util.Map) SWT(org.eclipse.swt.SWT) FontData(org.eclipse.swt.graphics.FontData) Platform(org.eclipse.core.runtime.Platform) KNIMEUIPlugin(org.knime.workbench.ui.KNIMEUIPlugin) Font(org.eclipse.swt.graphics.Font) ViewUtils(org.knime.core.node.util.ViewUtils) AnnotationData(org.knime.core.node.workflow.AnnotationData) SWTError(org.eclipse.swt.SWTError) Font(org.eclipse.swt.graphics.Font)

Aggregations

SWTError (org.eclipse.swt.SWTError)19 SWTException (org.eclipse.swt.SWTException)7 Point (org.eclipse.swt.graphics.Point)6 Cursor (org.eclipse.swt.graphics.Cursor)5 MessageBox (org.eclipse.swt.widgets.MessageBox)5 Browser (org.eclipse.swt.browser.Browser)4 FileDialog (org.eclipse.swt.widgets.FileDialog)4 Printer (org.eclipse.swt.printing.Printer)3 Test (org.junit.Test)3 StyledText (org.eclipse.swt.custom.StyledText)2 Image (org.eclipse.swt.graphics.Image)2 ImageData (org.eclipse.swt.graphics.ImageData)2 ImageLoader (org.eclipse.swt.graphics.ImageLoader)2 Button (org.eclipse.swt.widgets.Button)2 Combo (org.eclipse.swt.widgets.Combo)2 Label (org.eclipse.swt.widgets.Label)2 List (org.eclipse.swt.widgets.List)2 Table (org.eclipse.swt.widgets.Table)2 Text (org.eclipse.swt.widgets.Text)2 BufferedReader (java.io.BufferedReader)1