X-Git-Url: https://gerrit.simantics.org/r/gitweb?p=simantics%2Fplatform.git;a=blobdiff_plain;f=bundles%2Forg.simantics.utils.ui%2Fsrc%2Forg%2Fsimantics%2Futils%2Fui%2FSWTAWTComponent.java;h=2f2f604ec038e79b32112e153789bff1ee8f2981;hp=8031a93abb4f6728feb6a1afbfee586feece68ea;hb=2444a7d3ebc4aea7f9899dbf8aa84c8f94e75fd9;hpb=417eee8911a617038f5f10dfb1cae37ac4a45bef diff --git a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/SWTAWTComponent.java b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/SWTAWTComponent.java index 8031a93ab..2f2f604ec 100644 --- a/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/SWTAWTComponent.java +++ b/bundles/org.simantics.utils.ui/src/org/simantics/utils/ui/SWTAWTComponent.java @@ -60,6 +60,8 @@ import org.simantics.utils.ui.internal.awt.AwtFocusHandler; import org.simantics.utils.ui.internal.awt.CleanResizeListener; import org.simantics.utils.ui.internal.awt.EmbeddedChildFocusTraversalPolicy; import org.simantics.utils.ui.internal.awt.SwtFocusHandler; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** @@ -99,6 +101,8 @@ import org.simantics.utils.ui.internal.awt.SwtFocusHandler; */ public abstract class SWTAWTComponent extends Composite { + private static final Logger LOGGER = LoggerFactory.getLogger(SWTAWTComponent.class); + private static class AwtContext { private Frame frame; private Component swingComponent; @@ -342,14 +346,27 @@ public abstract class SWTAWTComponent extends Composite { private void workaroundJava7FocusProblem(Frame frame) { String ver = System.getProperty("java.version"); - if (ver.startsWith("1.7") || ver.startsWith("1.8")) { - try { - frame.addWindowListener(new Java7FocusFixListener(this, frame)); - } catch (SecurityException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); - } catch (NoSuchMethodException e) { - Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); + String[] split = ver.split("."); + + if (split.length < 2) { + LOGGER.warn("Focus fix listener: unrecognized Java version: " + ver); + return; + } + + try { + int major = Integer.parseInt(split[0]); + int minor = Integer.parseInt(split[1]); + if ((major == 1 && (minor == 7 || minor == 8)) || major >= 9) { + try { + frame.addWindowListener(new Java7FocusFixListener(this, frame)); + } catch (SecurityException e) { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); + } catch (NoSuchMethodException e) { + Activator.getDefault().getLog().log(new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e)); + } } + } catch (NumberFormatException e) { + LOGGER.error("Focus fix listener: unrecognized Java version: " + ver); } }