Changeset 17337 in josm
- Timestamp:
- 2020-11-23T20:25:04+01:00 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java
r17210 r17337 9 9 import java.awt.Dimension; 10 10 import java.awt.DisplayMode; 11 import java.awt.GraphicsDevice; 11 12 import java.awt.GraphicsEnvironment; 12 13 import java.awt.Toolkit; … … 14 15 import java.awt.event.KeyEvent; 15 16 import java.awt.geom.AffineTransform; 17 import java.io.PrintWriter; 18 import java.io.StringWriter; 16 19 import java.lang.management.ManagementFactory; 17 20 import java.util.ArrayList; … … 79 82 */ 80 83 public static String getReportHeader() { 81 StringBuilder text = new StringBuilder(256); 84 StringWriter stringWriter = new StringWriter(256); 85 PrintWriter text = new PrintWriter(stringWriter); 82 86 String runtimeVersion = getSystemProperty("java.runtime.version"); 83 text. append(Version.getInstance().getReleaseAttributes())84 .append("\nIdentification: ").append(Version.getInstance().getAgentString());87 text.println(Version.getInstance().getReleaseAttributes()); 88 text.format("Identification: %s%n", Version.getInstance().getAgentString()); 85 89 String buildNumber = PlatformManager.getPlatform().getOSBuildNumber(); 86 90 if (!buildNumber.isEmpty()) { 87 text.append("\nOS Build number: ").append(buildNumber); 88 } 89 text.append("\nMemory Usage: ") 90 .append(Runtime.getRuntime().totalMemory()/1024/1024) 91 .append(" MB / ") 92 .append(Runtime.getRuntime().maxMemory()/1024/1024) 93 .append(" MB (") 94 .append(Runtime.getRuntime().freeMemory()/1024/1024) 95 .append(" MB allocated, but free)\nJava version: ") 96 .append(runtimeVersion != null ? runtimeVersion : getSystemProperty("java.version")).append(", ") 97 .append(getSystemProperty("java.vendor")).append(", ") 98 .append(getSystemProperty("java.vm.name")) 99 .append("\nLook and Feel: ") 100 .append(Optional.ofNullable(UIManager.getLookAndFeel()).map(laf -> laf.getClass().getName()).orElse("null")) 101 .append("\nScreen: "); 91 text.format("OS Build number: %s%n", buildNumber); 92 } 93 text.format("Memory Usage: %d MB / %d MB (%d MB allocated, but free)%n", 94 Runtime.getRuntime().totalMemory() / 1024 / 1024, 95 Runtime.getRuntime().maxMemory() / 1024 / 1024, 96 Runtime.getRuntime().freeMemory() / 1024 / 1024); 97 text.format("Java version: %s, %s, %s%n", 98 runtimeVersion != null ? runtimeVersion : getSystemProperty("java.version"), 99 getSystemProperty("java.vendor"), 100 getSystemProperty("java.vm.name")); 101 text.format("Look and Feel: %s%n", 102 Optional.ofNullable(UIManager.getLookAndFeel()).map(laf -> laf.getClass().getName()).orElse("null")); 102 103 if (!GraphicsEnvironment.isHeadless()) { 103 text.append(Arrays.stream(GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()).map(gd -> { 104 StringBuilder b = new StringBuilder(gd.getIDstring()); 105 DisplayMode dm = gd.getDisplayMode(); 106 if (dm != null) { 107 // Java 11: use DisplayMode#toString 108 b.append(' ').append(dm.getWidth()).append('x').append(dm.getHeight()); 109 AffineTransform transform = gd.getDefaultConfiguration().getDefaultTransform(); 110 b.append(" (scaling ").append(transform.getScaleX()).append('x').append(transform.getScaleY()).append(')'); 111 } 112 return b.toString(); 113 }).collect(Collectors.joining(", "))); 114 } 115 Dimension maxScreenSize = GuiHelper.getMaximumScreenSize(); 116 text.append("\nMaximum Screen Size: ") 117 .append((int) maxScreenSize.getWidth()).append('x') 118 .append((int) maxScreenSize.getHeight()).append('\n'); 104 text.append("Screen:"); 105 for (GraphicsDevice gd : GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices()) { 106 text.append(" ").append(gd.getIDstring()); 107 DisplayMode dm = gd.getDisplayMode(); 108 if (dm != null) { 109 AffineTransform transform = gd.getDefaultConfiguration().getDefaultTransform(); 110 // Java 11: use DisplayMode#toString 111 text.format(" %d\u00D7%d (scaling %.2f\u00D7%.2f)", 112 dm.getWidth(), dm.getHeight(), transform.getScaleX(), transform.getScaleY()); 113 } 114 } 115 text.println(); 116 } 117 text.format("Maximum Screen Size: %s%n", toString(GuiHelper.getMaximumScreenSize())); 119 118 if (!GraphicsEnvironment.isHeadless()) { 120 119 Dimension bestCursorSize16 = Toolkit.getDefaultToolkit().getBestCursorSize(16, 16); 121 120 Dimension bestCursorSize32 = Toolkit.getDefaultToolkit().getBestCursorSize(32, 32); 122 text.append("Best cursor sizes: 16x16 -> ") 123 .append(bestCursorSize16.width).append('x').append(bestCursorSize16.height) 124 .append(", 32x32 -> ") 125 .append(bestCursorSize32.width).append('x').append(bestCursorSize32.height) 126 .append('\n'); 121 text.format("Best cursor sizes: %sā%s, %sā%s%n", 122 toString(new Dimension(16, 16)), toString(bestCursorSize16), 123 toString(new Dimension(32, 32)), toString(bestCursorSize32)); 127 124 } 128 125 … … 130 127 PlatformHookUnixoid platform = (PlatformHookUnixoid) PlatformManager.getPlatform(); 131 128 // Add desktop environment 132 platform.getDesktopEnvironment().ifPresent(desktop -> text 133 .append("Desktop environment: ") 134 .append(desktop) 135 .append('\n')); 129 platform.getDesktopEnvironment().ifPresent(desktop -> text.format("Desktop environment: %s%n", desktop)); 136 130 // Add Java package details 137 131 String packageDetails = platform.getJavaPackageDetails(); 138 132 if (packageDetails != null) { 139 text.append("Java package: ") 140 .append(packageDetails) 141 .append('\n'); 133 text.format("Java package: %s%n", packageDetails); 142 134 } 143 135 // Add WebStart package details if run from JNLP … … 145 137 String webStartDetails = platform.getWebStartPackageDetails(); 146 138 if (webStartDetails != null) { 147 text.append("WebStart package: ") 148 .append(webStartDetails) 149 .append('\n'); 139 text.format("WebStart package: %s%n", webStartDetails); 150 140 } 151 141 } … … 153 143 String atkWrapperDetails = platform.getAtkWrapperPackageDetails(); 154 144 if (atkWrapperDetails != null) { 155 text.append("Java ATK Wrapper package: ") 156 .append(atkWrapperDetails) 157 .append('\n'); 145 text.format("Java ATK Wrapper package: %s%n", atkWrapperDetails); 158 146 } 159 147 String lang = System.getenv("LANG"); 160 148 if (lang != null) { 161 text.append("Environment variable LANG: ") 162 .append(lang) 163 .append('\n'); 149 text.format("Environment variable LANG: %s%n", lang); 164 150 } 165 151 // Add dependencies details if found … … 176 162 String details = PlatformHookUnixoid.getPackageDetails(p); 177 163 if (details != null) { 178 text. append(p).append(": ").append(details).append('\n');164 text.format("%s: %s%n", p, details); 179 165 } 180 166 } … … 206 192 } 207 193 if (!vmArguments.isEmpty()) { 208 text. append("VM arguments: ").append(vmArguments.toString().replace("\\\\", "\\")).append('\n');194 text.format("VM arguments: %s%n", vmArguments.toString().replace("\\\\", "\\")); 209 195 } 210 196 } catch (SecurityException e) { … … 213 199 List<String> commandLineArgs = MainApplication.getCommandLineArgs(); 214 200 if (!commandLineArgs.isEmpty()) { 215 text. append("Program arguments: ").append(Arrays.toString(paramCleanup(commandLineArgs).toArray())).append('\n');201 text.format("Program arguments: %s%n", Arrays.toString(paramCleanup(commandLineArgs).toArray())); 216 202 } 217 203 DataSet dataset = MainApplication.getLayerManager().getActiveDataSet(); … … 219 205 String result = DatasetConsistencyTest.runTests(dataset); 220 206 if (result.isEmpty()) { 221 text. append("Dataset consistency test: No problems found\n");207 text.println("Dataset consistency test: No problems found"); 222 208 } else { 223 text.append("\nDataset consistency test:\n").append(result).append('\n'); 224 } 225 } 226 text.append('\n'); 209 text.println(); 210 text.println("Dataset consistency test:"); 211 text.println(result); 212 } 213 } 214 text.println(); 227 215 appendCollection(text, "Plugins", Utils.transform(PluginHandler.getBugReportInformation(), i -> "+ " + i)); 228 216 appendCollection(text, "Tagging presets", getCustomUrls(PresetPrefHelper.INSTANCE)); … … 233 221 String osmApi = OsmApi.getOsmApi().getServerUrl(); 234 222 if (!Config.getUrls().getDefaultOsmApiUrl().equals(osmApi.trim())) { 235 text.append("OSM API: ").append(osmApi).append("\n\n"); 236 } 237 238 return text.toString(); 223 text.format("OSM API: %s%n", osmApi); 224 } 225 226 text.println(); 227 return stringWriter.toString(); 228 } 229 230 private static String toString(Dimension dimension) { 231 return dimension.width + "\u00D7" + dimension.height; 239 232 } 240 233 … … 294 287 } 295 288 296 private static void appendCollection( StringBuilder text, String label, Collection<String> col) {289 private static void appendCollection(PrintWriter text, String label, Collection<String> col) { 297 290 if (!col.isEmpty()) { 298 291 text.append(col.stream().map(o -> paramCleanup(o) + '\n')
Note:
See TracChangeset
for help on using the changeset viewer.