source: josm/trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java@ 3775

Last change on this file since 3775 was 3299, checked in by stoecker, 14 years ago

some minor cleanups

  • Property svn:eol-style set to native
File size: 5.2 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.actions;
3
4import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
5import static org.openstreetmap.josm.tools.I18n.tr;
6
7import java.awt.Dimension;
8import java.awt.Toolkit;
9import java.awt.datatransfer.Clipboard;
10import java.awt.datatransfer.ClipboardOwner;
11import java.awt.datatransfer.StringSelection;
12import java.awt.datatransfer.Transferable;
13import java.awt.event.ActionEvent;
14import java.awt.event.KeyEvent;
15import java.io.BufferedReader;
16import java.io.File;
17import java.io.FileReader;
18
19import javax.swing.JScrollPane;
20import javax.swing.JTextArea;
21
22import org.openstreetmap.josm.Main;
23import org.openstreetmap.josm.data.Version;
24import org.openstreetmap.josm.data.osm.DataSet;
25import org.openstreetmap.josm.data.osm.DatasetConsistencyTest;
26import org.openstreetmap.josm.gui.ExtendedDialog;
27import org.openstreetmap.josm.plugins.PluginHandler;
28import org.openstreetmap.josm.tools.Shortcut;
29
30/**
31 * @author xeen
32 *
33 * Opens a dialog with useful status information like version numbers for Java, JOSM and plugins
34 * Also includes preferences with stripped username and password
35 */
36public final class ShowStatusReportAction extends JosmAction {
37 public ShowStatusReportAction() {
38 super(
39 tr("Show Status Report"),
40 "clock",
41 tr("Show status report with useful information that can be attached to bugs"),
42 Shortcut.registerShortcut("help:showstatusreport", tr("Help: {0}",
43 tr("Show Status Report")), KeyEvent.VK_R, Shortcut.GROUP_NONE), true);
44
45 putValue("help", ht("/Action/ShowStatusReport"));
46 }
47
48 public static String getReportHeader()
49 {
50 StringBuilder text = new StringBuilder();
51 text.append(Version.getInstance().getReleaseAttributes());
52 text.append("\n");
53 text.append("Identification: " + Version.getInstance().getAgentString());
54 text.append("\n");
55 text.append("Memory Usage: ");
56 text.append(Runtime.getRuntime().totalMemory()/1024/1024);
57 text.append(" MB / ");
58 text.append(Runtime.getRuntime().maxMemory()/1024/1024);
59 text.append(" MB (");
60 text.append(Runtime.getRuntime().freeMemory()/1024/1024);
61 text.append(" MB allocated, but free)");
62 text.append("\n");
63 text.append("Java version: " + System.getProperty("java.version") + ", " + System.getProperty("java.vendor") + ", " + System.getProperty("java.vm.name"));
64 text.append("\n");
65 text.append("Operating system: "+ System.getProperty("os.name"));
66 text.append("\n");
67 DataSet dataset = Main.main.getCurrentDataSet();
68 if (dataset != null) {
69 String result = DatasetConsistencyTest.runTests(dataset);
70 if (result.length() == 0) {
71 text.append("Dataset consistency test: No problems found\n");
72 } else {
73 text.append("\nDataset consistency test:\n"+result+"\n");
74 }
75 }
76 text.append("\n");
77 text.append(PluginHandler.getBugReportText());
78 text.append("\n");
79
80 return text.toString();
81 }
82
83 public void actionPerformed(ActionEvent e) {
84 StringBuilder text = new StringBuilder();
85 text.append(getReportHeader());
86 try {
87 BufferedReader input = new BufferedReader(new FileReader(Main.pref
88 .getPreferencesDirFile()
89 + File.separator + "preferences"));
90 try {
91 String line = null;
92
93 while ((line = input.readLine()) != null) {
94 String toCheck = line.trim().toLowerCase();
95 if (toCheck.startsWith("osm-server.username")
96 || toCheck.startsWith("osm-server.password")
97 || toCheck.startsWith("marker.show")
98 || toCheck.startsWith("oauth.access-token.key")
99 || toCheck.startsWith("oauth.access-token.secret")) {
100 continue;
101 }
102 text.append(line);
103 text.append("\n");
104 }
105 } finally {
106 input.close();
107 }
108 } catch (Exception x) {
109 x.printStackTrace();
110 }
111
112 JTextArea ta = new JTextArea(text.toString());
113 ta.setWrapStyleWord(true);
114 ta.setLineWrap(true);
115 ta.setEditable(false);
116 JScrollPane sp = new JScrollPane(ta);
117
118 ExtendedDialog ed = new ExtendedDialog(Main.parent,
119 tr("Status Report"),
120 new String[] {tr("Copy to clipboard and close"), tr("Close") });
121 ed.setButtonIcons(new String[] {"copy.png", "cancel.png" });
122 ed.setContent(sp, false);
123 ed.setMinimumSize(new Dimension(500, 0));
124 ed.showDialog();
125
126 if(ed.getValue() != 1) return;
127 try {
128 Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
129 new StringSelection(text.toString()), new ClipboardOwner() {
130 public void lostOwnership(Clipboard clipboard, Transferable contents) {}
131 }
132 );
133 }
134 catch (RuntimeException x) {}
135 }
136}
Note: See TracBrowser for help on using the repository browser.