1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package org.openstreetmap.josm.actions;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 |
|
---|
6 | import java.awt.Dimension;
|
---|
7 | import java.awt.Toolkit;
|
---|
8 | import java.awt.datatransfer.Clipboard;
|
---|
9 | import java.awt.datatransfer.ClipboardOwner;
|
---|
10 | import java.awt.datatransfer.StringSelection;
|
---|
11 | import java.awt.datatransfer.Transferable;
|
---|
12 | import java.awt.event.ActionEvent;
|
---|
13 | import java.awt.event.KeyEvent;
|
---|
14 | import java.io.BufferedReader;
|
---|
15 | import java.io.File;
|
---|
16 | import java.io.FileReader;
|
---|
17 |
|
---|
18 | import javax.swing.JScrollPane;
|
---|
19 | import javax.swing.JTextArea;
|
---|
20 |
|
---|
21 | import org.openstreetmap.josm.Main;
|
---|
22 | import org.openstreetmap.josm.gui.ExtendedDialog;
|
---|
23 | import org.openstreetmap.josm.plugins.PluginHandler;
|
---|
24 | import org.openstreetmap.josm.tools.Shortcut;
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * @author xeen
|
---|
28 | *
|
---|
29 | * Opens a dialog with useful status information like version numbers for Java, JOSM and plugins
|
---|
30 | * Also includes preferences with stripped username and password
|
---|
31 | */
|
---|
32 | public final class ShowStatusReportAction extends JosmAction {
|
---|
33 | public ShowStatusReportAction() {
|
---|
34 | super(
|
---|
35 | tr("Show Status Report"),
|
---|
36 | "clock",
|
---|
37 | tr("Show status report with useful information that can be attached to bugs"),
|
---|
38 | Shortcut.registerShortcut("help:showstatusreport", tr("Help: {0}",
|
---|
39 | tr("Show Status Report")), KeyEvent.VK_R, Shortcut.GROUP_NONE), true);
|
---|
40 |
|
---|
41 | }
|
---|
42 |
|
---|
43 | public static String getReportHeader()
|
---|
44 | {
|
---|
45 | StringBuilder text = new StringBuilder();
|
---|
46 | text.append(AboutAction.getTextBlock());
|
---|
47 | text.append("\n");
|
---|
48 | text.append("Memory Usage: ");
|
---|
49 | text.append(Runtime.getRuntime().totalMemory()/1024/1024);
|
---|
50 | text.append(" MB / ");
|
---|
51 | text.append(Runtime.getRuntime().maxMemory()/1024/1024);
|
---|
52 | text.append(" MB (");
|
---|
53 | text.append(Runtime.getRuntime().freeMemory()/1024/1024);
|
---|
54 | text.append(" MB allocated, but free)");
|
---|
55 | text.append("\n");
|
---|
56 | text.append("Java version: " + System.getProperty("java.version"));
|
---|
57 | text.append("\n\n");
|
---|
58 | text.append(PluginHandler.getBugReportText());
|
---|
59 | text.append("\n\n");
|
---|
60 | return text.toString();
|
---|
61 | }
|
---|
62 |
|
---|
63 | public void actionPerformed(ActionEvent e) {
|
---|
64 | StringBuilder text = new StringBuilder();
|
---|
65 | text.append(getReportHeader());
|
---|
66 | try {
|
---|
67 | BufferedReader input = new BufferedReader(new FileReader(Main.pref
|
---|
68 | .getPreferencesDirFile()
|
---|
69 | + File.separator + "preferences"));
|
---|
70 | try {
|
---|
71 | String line = null;
|
---|
72 |
|
---|
73 | while ((line = input.readLine()) != null) {
|
---|
74 | // Skip potential private information
|
---|
75 | if (line.trim().toLowerCase().startsWith("osm-server.username"))
|
---|
76 | continue;
|
---|
77 | if (line.trim().toLowerCase().startsWith("osm-server.password"))
|
---|
78 | continue;
|
---|
79 | if (line.trim().toLowerCase().startsWith("marker.show"))
|
---|
80 | continue;
|
---|
81 |
|
---|
82 | text.append(line);
|
---|
83 | text.append("\n");
|
---|
84 | }
|
---|
85 | } finally {
|
---|
86 | input.close();
|
---|
87 | }
|
---|
88 | } catch (Exception x) {
|
---|
89 | x.printStackTrace();
|
---|
90 | }
|
---|
91 |
|
---|
92 | JTextArea ta = new JTextArea(text.toString());
|
---|
93 | ta.setWrapStyleWord(true);
|
---|
94 | ta.setLineWrap(true);
|
---|
95 | ta.setEditable(false);
|
---|
96 | JScrollPane sp = new JScrollPane(ta);
|
---|
97 | sp.setPreferredSize(new Dimension(600, 500));
|
---|
98 |
|
---|
99 | int result = new ExtendedDialog(Main.parent, tr(tr("Status Report")), sp,
|
---|
100 | new String[] {tr("Copy to clipboard and close"), tr("Close") },
|
---|
101 | new String[] {"copy.png", "cancel.png" }).getValue();
|
---|
102 |
|
---|
103 | if(result != 1) return;
|
---|
104 | try {
|
---|
105 | Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
|
---|
106 | new StringSelection(text.toString()), new ClipboardOwner() {
|
---|
107 | public void lostOwnership(Clipboard clipboard, Transferable contents) {}
|
---|
108 | }
|
---|
109 | );
|
---|
110 | }
|
---|
111 | catch (RuntimeException x) {}
|
---|
112 | }
|
---|
113 | }
|
---|