- Timestamp:
- 2024-06-17T21:36:37+02:00 (11 months ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r19103 r19109 8 8 9 9 import java.awt.AWTError; 10 import java.awt.Color;11 10 import java.awt.Container; 12 11 import java.awt.Dimension; … … 19 18 import java.io.IOException; 20 19 import java.io.InputStream; 21 import java.lang.reflect.Field;22 20 import java.net.Authenticator; 23 21 import java.net.Inet6Address; … … 42 40 import java.util.Objects; 43 41 import java.util.Optional; 44 import java.util.ResourceBundle;45 42 import java.util.Set; 46 43 import java.util.TreeSet; … … 165 162 import org.openstreetmap.josm.tools.OsmUrlToBounds; 166 163 import org.openstreetmap.josm.tools.PlatformHook.NativeOsCallback; 167 import org.openstreetmap.josm.tools.PlatformHookWindows;168 164 import org.openstreetmap.josm.tools.PlatformManager; 169 import org.openstreetmap.josm.tools.ReflectionUtils;170 165 import org.openstreetmap.josm.tools.Shortcut; 171 166 import org.openstreetmap.josm.tools.Utils; … … 1069 1064 Utils.updateSystemProperty("http.agent", Version.getInstance().getAgentString()); 1070 1065 Utils.updateSystemProperty("user.language", Config.getPref().get("language")); 1071 // Workaround to fix a Java bug. This ugly hack comes from Sun bug database: https://bugs.openjdk.java.net/browse/JDK-62927391072 // Force AWT toolkit to update its internal preferences (fix #6345).1073 // Does not work anymore with Java 9, to remove with Java 9 migration1074 if (Utils.getJavaVersion() < 9 && !GraphicsEnvironment.isHeadless()) {1075 try {1076 Field field = Toolkit.class.getDeclaredField("resources");1077 ReflectionUtils.setObjectsAccessible(field);1078 field.set(null, ResourceBundle.getBundle("sun.awt.resources.awt"));1079 } catch (ReflectiveOperationException | RuntimeException e) { // NOPMD1080 // Catch RuntimeException in order to catch InaccessibleObjectException, new in Java 91081 Logging.log(Logging.LEVEL_WARN, null, e);1082 }1083 }1084 1066 // Possibility to disable SNI (not by default) in case of misconfigured https servers 1085 1067 // See #9875 + http://stackoverflow.com/a/14884941/2257172 … … 1116 1098 static void applyLaFWorkarounds() { 1117 1099 final String laf = UIManager.getLookAndFeel().getID(); 1118 final int javaVersion = Utils.getJavaVersion();1119 // Workaround for JDK-8180379: crash on Windows 10 1703 with Windows L&F and java < 8u141 / 9+1721120 // To remove during Java 9 migration1121 if (getSystemProperty("os.name").toLowerCase(Locale.ENGLISH).contains("windows 10") &&1122 PlatformManager.getPlatform().getDefaultStyle().equals(LafPreference.LAF.get())) {1123 try {1124 String build = PlatformHookWindows.getCurrentBuild();1125 if (build != null) {1126 final int currentBuild = Integer.parseInt(build);1127 final int javaUpdate = Utils.getJavaUpdate();1128 final int javaBuild = Utils.getJavaBuild();1129 // See https://technet.microsoft.com/en-us/windows/release-info.aspx1130 if (currentBuild >= 15_063 && ((javaVersion == 8 && javaUpdate < 141)1131 || (javaVersion == 9 && javaUpdate == 0 && javaBuild < 173))) {1132 // Workaround from https://bugs.openjdk.java.net/browse/JDK-81790141133 UIManager.put("FileChooser.useSystemExtensionHiding", Boolean.FALSE);1134 }1135 }1136 } catch (NumberFormatException | ReflectiveOperationException | JosmRuntimeException e) {1137 Logging.error(e);1138 } catch (ExceptionInInitializerError e) {1139 Logging.log(Logging.LEVEL_ERROR, null, e);1140 }1141 } else if (PlatformManager.isPlatformOsx() && javaVersion < 17) {1142 // Workaround for JDK-8251377: JTabPanel active tab is unreadable in Big Sur, see #20075, see #208211143 // os.version will return 10.16, or 11.0 depending on environment variable1144 // https://twitter.com/BriceDutheil/status/13309266492699566121145 final String macOSVersion = getSystemProperty("os.version");1146 if ((laf.contains("Mac") || laf.contains("Aqua"))1147 && (macOSVersion.startsWith("10.16") || macOSVersion.startsWith("11"))) {1148 UIManager.put("TabbedPane.foreground", Color.BLACK);1149 }1150 }1151 // Workaround for JDK-82620851152 if ("Metal".equals(laf) && javaVersion >= 11 && javaVersion < 17) {1153 UIManager.put("ToolTipUI", JosmMetalToolTipUI.class.getCanonicalName());1154 }1155 1156 1100 // See #20850. The upstream bug (JDK-6396936) is unlikely to ever be fixed due to potential compatibility 1157 1101 // issues. This affects Windows LaF only (includes Windows Classic, a sub-LaF of Windows LaF). … … 1271 1215 // if not yet enabled and if neither running on Gnome or KDE desktop 1272 1216 if (PlatformManager.isPlatformUnixoid() 1273 && Utils.getJavaVersion() >= 91274 1217 && UIManager.getLookAndFeelDefaults().get(RenderingHints.KEY_TEXT_ANTIALIASING) == null 1275 1218 && System.getProperty("awt.useSystemAAFontSettings") == null -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r18211 r19109 1718 1718 ImageReadParam param = readParamFunction.apply(reader); 1719 1719 BufferedImage bi = null; 1720 try { // NOPMD1720 try (stream) { 1721 1721 bi = reader.read(0, param); 1722 if (bi.getTransparency() != Transparency.TRANSLUCENT && (readMetadata || enforceTransparency) && Utils.getJavaVersion() < 11) {1723 Color color = getTransparentColor(bi.getColorModel(), reader);1724 if (color != null) {1725 Hashtable<String, Object> properties = new Hashtable<>(1);1726 properties.put(PROP_TRANSPARENCY_COLOR, color);1727 bi = new BufferedImage(bi.getColorModel(), bi.getRaster(), bi.isAlphaPremultiplied(), properties);1728 if (enforceTransparency) {1729 Logging.trace("Enforcing image transparency of {0} for {1}", stream, color);1730 bi = makeImageTransparent(bi, color);1731 }1732 }1733 }1734 1722 } catch (LinkageError e) { 1735 1723 // On Windows, ComponentColorModel.getRGBComponent can fail with "UnsatisfiedLinkError: no awt in java.library.path", see #13973 … … 1738 1726 } finally { 1739 1727 reader.dispose(); 1740 stream.close();1741 1728 } 1742 1729 return bi; -
trunk/src/org/openstreetmap/josm/tools/Utils.java
r19102 r19109 1003 1003 * a subclass of <code>klass</code>. The casted value otherwise. 1004 1004 */ 1005 @SuppressWarnings("unchecked")1006 1005 public static <T> T cast(Object o, Class<T> klass) { 1007 1006 if (klass.isInstance(o)) { 1008 return (T) o;1007 return klass.cast(o); 1009 1008 } 1010 1009 return null; … … 1784 1783 Config.getUrls().getJOSMWebsite() + "/remote/oracle-java-update-baseline.version"))) 1785 1784 .connect().fetchContent().split("\n", -1); 1786 if (getJavaVersion() <= 11 && isRunningWebStart()) { // OpenWebStart currently only has Java 11 1785 // OpenWebStart currently only has Java 21 1786 if (getJavaVersion() <= 21) { 1787 1787 for (String version : versions) { 1788 if (version.startsWith("11")) { 1789 return version; 1790 } 1791 } 1792 } else if (getJavaVersion() <= 17) { 1793 for (String version : versions) { 1794 if (version.startsWith("17")) { // Use current Java LTS 1788 if (version.startsWith("21")) { // Use current Java LTS 1795 1789 return version; 1796 1790 } … … 1852 1846 * Get a function that converts an object to a singleton stream of a certain 1853 1847 * class (or null if the object cannot be cast to that class). 1854 * 1848 * <p> 1855 1849 * Can be useful in relation with streams, but be aware of the performance 1856 1850 * implications of creating a stream for each element. … … 1877 1871 * @since 12604 1878 1872 */ 1879 @SuppressWarnings("unchecked")1880 1873 public static <T> void instanceOfThen(Object o, Class<T> klass, Consumer<? super T> consumer) { 1881 1874 if (klass.isInstance(o)) { 1882 consumer.accept( (T) o);1875 consumer.accept(klass.cast(o)); 1883 1876 } 1884 1877 } … … 1893 1886 * Optional otherwise 1894 1887 */ 1895 @SuppressWarnings("unchecked")1896 1888 public static <T> Optional<T> instanceOfAndCast(Object o, Class<T> klass) { 1897 1889 if (klass.isInstance(o)) 1898 return Optional.of( (T) o);1890 return Optional.of(klass.cast(o)); 1899 1891 return Optional.empty(); 1900 1892 }
Note:
See TracChangeset
for help on using the changeset viewer.