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